]> git.plutz.net Git - invoices/blob - senders.sh
handle line breaks in $time and $work definitions
[invoices] / senders.sh
1 #!/bin/sh
2
3 edit_sender(){
4   local id="$1" address iban bic
5   [ -f "senders/$id" ] \
6   && read -r address iban bic <"senders/$id"
7
8   iban="$(UNSTRING "${iban#iban=}")"
9    bic="$(UNSTRING "${bic#bic=}")"
10
11   [ "${address#address=}" ] \
12   && address="$(UNSTRING "${address#address=}")" \
13   || address="Name
14 Street
15 City
16
17 Phone:
18 000 000000
19
20 Tax no.
21 xxx / 000 / ###
22 "
23   printf '
24     [form method="POST" action="/update_sender"
25       [hidden "id" "%s"]
26       <textarea name="address" placeholder="address">%s</textarea>
27       [label IBAN:][input name=iban value="%s" placeholder=IBAN]
28       [label BIC:][input name=bic value="%s" placeholder=BIC]
29       [submit "update" "%s" Update]
30     ]' \
31     "$(HTML $id)" "$(HTML "${address}")" \
32     "$(HTML "${iban}")" "$(HTML "${bic}")" \
33     "$(transid "senders/$id")"
34 }
35
36 list_senders(){
37   [ -d senders/ ] && for s in senders/*; do
38     read -r address iban bic <"$s"
39
40     [ "${address#address=}" ] \
41     && address="$(UNSTRING "${address#address=}")" \
42     || address="(no address)"
43
44     printf '[div .sender .address <!--
45       -->%s[a href="/senders/%s" Edit]]
46     ' "$(HTML "$address")" "$(HTML "${s#senders/}")"
47   done
48 }
49
50 update_sender(){
51   id="$(POST id |checkid)"
52   if [ "$(POST update)" = "$(transid "senders/$id")" ]; then
53     mkdir -p senders
54     printf 'address=%s  iban=%s bic=%s\n' \
55     $(POST address |STRING) $(POST iban |STRING) \
56     $(POST bic |STRING) >"senders/$id"
57
58     [ -d .git ] && {
59       git add "senders/$id"
60       git commit -m 'Update sender info for "'"$(POST address |sed 1q)"'"' -- "senders/$id"
61     } >/dev/null
62
63     REDIRECT "/senders/"
64   else
65     REDIRECT "/senders/$id"
66   fi
67 }