X-Git-Url: http://git.plutz.net/?p=invoices;a=blobdiff_plain;f=senders.sh;h=8c98737a39b4195ad681172777eb734753fffb87;hp=90c3d3815b49fde8179d73bcecf860bc3e956874;hb=b037f9960718351b0470ab7ea67271b291bebb0e;hpb=de8eaf901067d4e0c72e5b0ca05f6dc12553fd79 diff --git a/senders.sh b/senders.sh index 90c3d38..8c98737 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}")" \ + "$(tid "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,13 @@ list_senders(){ update_sender(){ id="$(POST id |checkid)" - if [ "$(POST update)" = update -a "$id" ]; then + if [ "$(POST update)" = "$(tid "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" + REDIRECT "/senders/" + else + REDIRECT "/senders/$id" fi }