X-Git-Url: http://git.plutz.net/?p=invoices;a=blobdiff_plain;f=senders.sh;h=757ce22e1aeaa55a54c3374525ce2e1eb60787ac;hp=90c3d3815b49fde8179d73bcecf860bc3e956874;hb=HEAD;hpb=de8eaf901067d4e0c72e5b0ca05f6dc12553fd79 diff --git a/senders.sh b/senders.sh index 90c3d38..757ce22 100755 --- a/senders.sh +++ b/senders.sh @@ -1,11 +1,16 @@ #!/bin/sh edit_sender(){ - id="$1" - if [ -f "senders/$id" ]; then - address="$(cat "senders/$id")" - fi - [ "$address" ] || address="Name + local id="$1" address iban bic + [ -f "senders/$id" ] \ + && read -r address iban bic <"senders/$id" + + iban="$(UNSTRING "${iban#iban=}")" + bic="$(UNSTRING "${bic#bic=}")" + + [ "${address#address=}" ] \ + && address="$(UNSTRING "${address#address=}")" \ + || address="Name Street City @@ -19,16 +24,23 @@ xxx / 000 / ### [form method="POST" action="/update_sender" [hidden "id" "%s"] - [submit "update" "update" Update] + [label IBAN:][input name=iban value="%s" placeholder=IBAN] + [label BIC:][input name=bic value="%s" placeholder=BIC] + [submit "update" "%s" Update] ]' \ - "$(HTML $id)" \ - "$(HTML "${address}")" + "$(HTML $id)" "$(HTML "${address}")" \ + "$(HTML "${iban}")" "$(HTML "${bic}")" \ + "$(transid "senders/$id")" } list_senders(){ [ -d senders/ ] && for s in senders/*; do - address=$(cat "$s") - [ "$address" ] || address="(no address)" + read -r address iban bic <"$s" + + [ "${address#address=}" ] \ + && address="$(UNSTRING "${address#address=}")" \ + || address="(no address)" + printf '[div .sender .address %s[a href="/senders/%s" Edit]] ' "$(HTML "$address")" "$(HTML "${s#senders/}")" @@ -37,8 +49,19 @@ list_senders(){ update_sender(){ id="$(POST id |checkid)" - if [ "$(POST update)" = update -a "$id" ]; then + if [ "$(POST update)" = "$(transid "senders/$id")" ]; then mkdir -p senders - POST address >"senders/$id" + printf 'address=%s iban=%s bic=%s\n' \ + $(POST address |STRING) $(POST iban |STRING) \ + $(POST bic |STRING) >"senders/$id" + + [ -d .git ] && { + git add "senders/$id" + git commit -m 'Update sender info for "'"$(POST address |sed 1q)"'"' -- "senders/$id" + } >/dev/null + + REDIRECT "/senders/" + else + REDIRECT "/senders/$id" fi }