#!/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
[form method="POST" action="/update_sender"
[hidden "id" "%s"]
<textarea name="address" placeholder="address">%s</textarea>
- [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/}")"
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
}