]> git.plutz.net Git - invoices/blobdiff - invoices.cgi
sort invoice list, newest to oldest
[invoices] / invoices.cgi
index 7e2f35193ae76bfd1012f3d91e0f62c7a40c3837..338f180e2a5b7f15899cc21a5ee4969f60b5be7c 100755 (executable)
@@ -6,6 +6,8 @@ _EXEC="$(realpath "${0%/*}")"
 . "$_EXEC/cgilite/storage.sh"
 . "$_EXEC/cgilite/session.sh"
 
+SESSION_COOKIE
+
 yield_page(){
 printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
 "$_EXEC/cgilite/html-sh.sed" <<EOF
@@ -24,14 +26,23 @@ printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
 EOF
 }
 
-info="$(PATH "${PATH_INFO}")"
+info="$(PATH "${PATH_INFO#http://*/}")"
+
+which git && [ ! -d .git ] && {
+  git init
+  mkdir -p clients/ invoices/ senders/
+  printf 'export/
+serverkey' >.gitignore
+  git add clients/ invoices/ senders/ .gitignore
+  git commit -m 'initialisation of invoice repo'
+} >&2
 
 case $info in
   /invoices.css)
     . "$_EXEC/cgilite/file.sh"
     FILE "$_EXEC/invoices.css"
     ;;
-  /clients)
+  /clients|/clients/)
     . "$_EXEC/clients.sh"
     { list_clients
       printf '[a .new href="/clients/%s" New]' "$(timeid)"
@@ -44,9 +55,8 @@ case $info in
   /update_client)
     . "$_EXEC/clients.sh"
     update_client
-    REDIRECT /clients/
     ;;
-  /senders)
+  /senders|/senders/)
     . "$_EXEC/senders.sh"
     { list_senders
       printf '[a .new href="/senders/%s" New]' "$(timeid)"
@@ -59,22 +69,25 @@ case $info in
   /update_sender)
     . "$_EXEC/senders.sh"
     update_sender
-    REDIRECT /senders/
     ;;
-  /invoices)
+  /invoices|/invoices/)
     . "$_EXEC/invoices.sh"
-    { list_invoices
-      printf '[a .new href="/invoice/%s" New]' "$(timeid)"
+    { printf '[a .new href="/invoices/%s" New]' "$(timeid)"
+      list_invoices
     } | yield_page invoices
     ;;
-  /invoice/*)
+  /invoices/*)
     . "$_EXEC/invoices.sh"
-    edit_invoice "${info#/invoice/}" |yield_page invoice
+    edit_invoice "${info#/invoices/}" |yield_page invoice
     ;;
   /update_invoice)
     . "$_EXEC/invoices.sh"
     update_invoice
-    REDIRECT "/invoice/$id"
+    ;;
+  /export/*.pdf/*)
+    . "$_EXEC/cgilite/file.sh"
+    file="${info%/*}"
+    FILE "${file#/}" application/pdf
     ;;
   *) REDIRECT /invoices
     ;;