_EXEC="$(realpath "${0%/*}")"
. "$_EXEC/cgilite/cgilite.sh"
-. "$_EXEC/cgilite/logging.sh"
-. "$_EXEC/cgilite/storage.sh"
+# . "$_EXEC/cgilite/logging.sh"
. "$_EXEC/cgilite/session.sh"
+. "$_EXEC/cgilite/storage.sh"
+. "$_EXEC/cgilite/file.sh"
-SESSION_COOKIE
+. "$_EXEC/db23.sh"
+. "$_EXEC/form.sh"
-yield_page(){
-printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
-"$_EXEC/cgilite/html-sh.sed" <<EOF
-[html [head
- [meta name="viewport" content="width=device-width"]
- [link rel="stylesheet" type="text/css" href="/invoices.css"]
- [title Invoices]
-] [body class="$1"
- [div #menu
- [a "/invoices/" Rechnungen]
- [a "/clients/" Klienten]
- [a "/senders/" Absender]
- ]
- $(cat)
-] ]
-EOF
-}
+SESSION_COOKIE
-info="$(PATH "${PATH_INFO#http://*/}")"
+_() { printf '%s\n' "$*"; }
+# . "$_EXEC/l10n.sh"
which git && [ ! -d .git ] && {
git init
- mkdir -p clients/ invoices/ senders/
+ mkdir -p documents/ export/
printf 'export/
serverkey' >.gitignore
- git add clients/ invoices/ senders/ .gitignore
- git commit -m 'initialisation of invoice repo'
+ git add documents/ .gitignore
+ git commit -m 'initialisation of document repo'
} >&2
-case $info in
- /invoices.css)
- . "$_EXEC/cgilite/file.sh"
- FILE "$_EXEC/invoices.css"
- ;;
- /clients|/clients/)
- . "$_EXEC/clients.sh"
- { list_clients
- printf '[a .new href="/clients/%s" New]' "$(timeid)"
- } | yield_page clients
- ;;
- /clients/*)
- . "$_EXEC/clients.sh"
- edit_client "${info#/clients/}" |yield_page client
+[ "$REQUEST_METHOD" = POST ] && case $(POST action) in
+ new_invoice)
+ id="$(timeid)" file="$_DATA/${id}.kvd"
+ DB3 new
+ DB3 set type "$(POST type)"
+ DB3 set status open
+ DB3 write "$file"
+ REDIRECT "/doc/${id}"
;;
- /update_client)
- . "$_EXEC/clients.sh"
- update_client
+ update_invoice)
+ id="$(POST id)" file="$_DATA/${id}.kvd" seq=''
+ if [ "$(POST tid)" = "$(transid "$file")" ] && LOCK "$file"; then
+ DB3 open "$file"
+ for key in $(POST_KEYS); do case $key in
+ id|tid|session_key|action):;;
+ *)set --
+ for seq in $(seq 1 "$(POST_COUNT "$key")"); do
+ set -- "$@" "$(POST "$key" $seq)"
+ done
+ DB3 set "$key" "$@"
+ ;;
+ esac; done
+ DB3 write "$file"
+ RELEASE "$file"
+ [ -d .git ] && {
+ git -C "$_DATA" add "$file"
+ git -C "$_DATA" commit -m 'Update invoice info for "'"${id}"'"' -- "$file"
+ } >/dev/null
+ else
+ debug "TID mismatch updating $file"
+ fi
+ REDIRECT "$PATH_INFO"
;;
- /senders|/senders/)
- . "$_EXEC/senders.sh"
- { list_senders
- printf '[a .new href="/senders/%s" New]' "$(timeid)"
- } | yield_page senders
+ *)
+ REDIRECT /
;;
- /senders/*)
- . "$_EXEC/senders.sh"
- edit_sender "${info#/senders/}" |yield_page sender
- ;;
- /update_sender)
- . "$_EXEC/senders.sh"
- update_sender
- ;;
- /invoices|/invoices/)
- . "$_EXEC/invoices.sh"
- { printf '[a .new href="/invoices/%s" New]' "$(timeid)"
- list_invoices
- } | yield_page invoices
- ;;
- /invoices/*)
- . "$_EXEC/invoices.sh"
- edit_invoice "${info#/invoices/}" |yield_page invoice
+esac
+
+[ "$REQUEST_METHOD" != POST ] && case $PATH_INFO in
+ *.css|*.jpeg|*.png)
+ FILE "$_EXEC/${PATH_INFO#/}"
;;
- /update_invoice)
- . "$_EXEC/invoices.sh"
- update_invoice
+ /)
+ . "$_EXEC/doclist.sh"
;;
- /export/*.pdf/*)
- . "$_EXEC/cgilite/file.sh"
- file="${info%/*}"
- FILE "${file#/}" application/pdf
+ /doc/*)
+ id="${PATH_INFO##*/}" tid="$(transid "${_DATA}/${id}.kvd")"
+ DB3 open "${_DATA}/${id}.kvd" || REDIRECT /
+ type="$(DB3 get type)"
+ [ -d "${_EXEC}/${type}/" ] \
+ && . "${_EXEC}/${type}/form.sh"
+ yield_form
;;
- *) REDIRECT /invoices
+ *) REDIRECT /
;;
esac