X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=clients.sh;fp=clients.sh;h=fc047a2447aad54669b64e3f927631785b7aa628;hb=de8eaf901067d4e0c72e5b0ca05f6dc12553fd79;hp=0000000000000000000000000000000000000000;hpb=c9bb4a41908f01e2e9698d17cf1027255b53a47b;p=invoices diff --git a/clients.sh b/clients.sh new file mode 100755 index 0000000..fc047a2 --- /dev/null +++ b/clients.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +edit_client(){ + id="$1" + if [ -f "clients/$id" ]; then + read -r address hourly <"clients/$id" + fi + [ "$address" ] || address="address=" + [ "$hourly" ] || hourly="hourly=" + printf ' + [form method="POST" action="/update_client" + [hidden "id" "%s"] + + [label for=hourly Hourly Rate:] + [input #hourly type=number name=hourly value="%s"] + [submit "update" "update" Update] + ]' \ + "$(HTML $id)" \ + "$(UNSTRING "${address#address=}" |HTML)" \ + "$(UNSTRING "${hourly#hourly=}" |grep -xE '[0-9]+')" +} + +list_clients(){ + [ -d clients/ ] && for c in clients/*; do + read -r address hourly <"$c" + address="$(UNSTRING "${address#address=}")" + [ "$address" ] || address="(no address)" + printf '[div .client .address %s + +[label Hourly Rate:] %s€ + [a href="/clients/%s" Edit]] + ' "$(HTML "$address")" \ + "$(HTML "${hourly#hourly=}")" \ + "$(HTML "${c#clients/}")" + done +} + +update_client(){ + id="$(POST id |checkid)" + if [ "$(POST update)" = update -a "$id" ]; then + mkdir -p clients + printf 'address=%s hourly=%s' \ + "$(POST address |STRING)" "$(POST hourly |STRING)" \ + >"clients/$id" + else + echo Invalid Data "$(POST id)" "$(POST update)" >&2 + fi +}