From 4e7da5b8a7edf35a5f0432c296ae8fcbcd9cf91c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sat, 11 May 2024 22:09:22 +0200 Subject: [PATCH] form submit of assignments --- ledgers/iban_assign.sh | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/ledgers/iban_assign.sh b/ledgers/iban_assign.sh index cabeae7..9faf223 100755 --- a/ledgers/iban_assign.sh +++ b/ledgers/iban_assign.sh @@ -1,15 +1,22 @@ #!/bin/sh -printf '%s\r\n' "Content-Type: text/plain" "" +. "$_EXEC/pdiread.sh" +. "$_EXEC/session_lock.sh" + +UIDLIST="$( + pdi_load "$_DATA/vcard/"*.vcf \ + | sed -Ez ' + s/\nBEGIN;:VCARD\n([^\n]+\n)*FN;:([^\n]+)\n([^\n]+\n)*UID;:([^\n]+)\n([^\n]+\n)*END;:VCARD\n/UID:\4 FN:\2/g + ' +)" + +# printf '%s\r\n' "Content-Type: text/plain" "" for key in $(POST_KEYS); do case $key in use_*) use_iban="${use_iban} ${key#use_} " ;; esac; done -echo Use IBANS: -echo "$use_iban" -echo [ "$use_iban" ] && for key in $(POST_KEYS); do case $key in check_*_*) @@ -17,12 +24,26 @@ echo [ ! "${use_iban##* "${iban}" *}" ] && check="${check} ${key#check_} " ;; esac; done -echo Checked: -echo "$check" -echo -for use in $check; do - iban="${use%_*}" - fn="$(POST "fn_${use}")" - echo Assign $iban to $fn -done +{ printf '[ul .results' + for use in $check; do + iban="${use%_*}" + fn="$(POST "fn_${use}")" + uid="${UIDLIST%% FN:"$fn"${BR}*}" uid="${uid##*${BR}UID:}" + + cfile="${_DATA}/vcard/${uid}.vcf" + if SLOCK "$cfile" >/dev/null; then + card="$(pdi_load "$cfile")" + cnum="$(pdi_count "$card" X-IBAN)" + pdi_update_value "$card" X-IBAN "$((cnum + 1))" "$iban" >"$cfile" + printf '[li .success . [span .name . %s] [span .uid . (UID: %s)] assigned IBAN [span .iban . %s]]' \ + "$(HTML "$fn")" "$(HTML "$uid")" "$(HTML "$iban")" + RELEASE_SLOCK "$cfile" + else + printf '[li .error . [span .name . %s] [span .uid . (UID: %s)] is being edited elsewhere]' + "$(HTML "$fn")" "$(HTML "$uid")" + fi + done + printf ']' + printf '[a .button href=/ledgers/ . %s]' "$(l10n Back)" +} | yield_page ledgers_assign -- 2.39.2