]> git.plutz.net Git - lobster/commitdiff
allow exporting list as csv
authorPaul Hänsch <paul@plutz.net>
Fri, 5 Feb 2021 01:32:06 +0000 (02:32 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 5 Feb 2021 01:32:06 +0000 (02:32 +0100)
cards/export_csv.sh [new file with mode: 0755]
cards/filter_card.sh
cards/widgets.sh
l10n.sh
style.css

diff --git a/cards/export_csv.sh b/cards/export_csv.sh
new file mode 100755 (executable)
index 0000000..a1004f7
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+. $_EXEC/pdiread.sh
+. $_EXEC/cards/l10n.sh
+. $_EXEC/cards/list.sh
+
+upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; '
+
+filter="$(GET f)"
+order="$(GET o)"
+
+[ "$order" ] || order=firstname
+
+list_attendance() {
+  grep -F "    ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do
+    { pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)"; } |unescape
+  done \
+  | sed -E 's;";\\";g;'
+}
+
+list_item() {
+  local item="$1"
+  local cnt="$(pdi_count "$card" "$item")"
+  local ret=''
+  
+  seq 1 $cnt |while read n; do case $item in
+    TEL)
+      tel="$(pdi_value "$card" "$item" "$n" |unescape)"
+      [ "$tel" ] && printf '%s: %s\n' "$(l10n "TYPE=$(pdi_attrib "$card" "$item" "$n" TYPE)")" "$tel"
+      ;;
+    GENDER)
+      gen="$(pdi_value "$card" "$item" "$n" |unescape)"
+      [ "$gen" ] && l10n "gender_$gen"
+      ;;
+    *) pdi_value "$card" "$item" "$n" |unescape
+      ;;
+  esac; done \
+  | sed -E 's;";\\";g;'
+}
+
+printf '%s\r\n' \
+       'Content-Type: text/csv; charset=utf-8' \
+       'Content-Disposition: inline; filename="confetti_export_'$(date +%F_%T)'.csv"' \
+       ''
+
+printf '"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"\n' \
+       "$(l10n FN)" "$(l10n GENDER)" "$(l10n BDAY)" \
+       "$(l10n TEL)" "$(l10n EMAIL)" "$(l10n ADR)" \
+       "$(l10n NOTE)" "$(l10n courses)" "$(l10n CATEGORIES)" \
+| sed -E 's;&shy\;;;g;'
+
+
+filter_cards \
+| order_cards \
+| while read cardfile; do
+  card="$(pdi_load "$cardfile")"
+  printf '"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"\n' \
+  "$(list_item FN)" "$(list_item GENDER)" "$(list_item BDAY)" \
+  "$(list_item TEL)" "$(list_item EMAIL)" "$(list_item ADR)" \
+  "$(list_item NOTE)" "$(list_attendance)" "$(list_item CATEGORIES)"
+done
index 9953a225553f760a733463704ab8f77af68f8b02..aacacbb2b42033b4fded4f9da2a807107cdc7402 100755 (executable)
@@ -49,6 +49,9 @@ case $(POST choice) in
   new_filter)
     REDIRECT "/cards/?o=$(POST order)&f=${filter}&newfilter=yes"
     ;;
+  export_csv)
+    REDIRECT "/cards/export_csv.sh?o=$(POST order)&f=${filter}"
+    ;;
   *)
     REDIRECT '/cards/'
     ;;
index 376199efe24397931c22c921de5b2f271d32678c..27cdf04670a24e9af2e4eb32fdb232601d2376d6 100755 (executable)
@@ -75,6 +75,7 @@ w_filter_diag(){
     ]
     [button type="submit" name="choice" value="filter" $(l10n filter_apply)]
     [button type="submit" name="choice" value="del_filter" $(l10n filter_cancel)]
+    [button type="submit" name="choice" value="export_csv" $(l10n export_csv)]
   ]
 EOF
 }
diff --git a/l10n.sh b/l10n.sh
index c53cdd386197b8701ece0392cc85336ac38f4438..cab5bdeada481d6bc8a4cbfbe7cd12722c6314ee 100755 (executable)
--- a/l10n.sh
+++ b/l10n.sh
@@ -112,6 +112,7 @@ l10n_global() {
     filter_more) printf %s "+ mehr Filter";;
     filter_apply) printf %s "Filtern";;
     filter_cancel) printf %s "Filter löschen";;
+    export_csv) printf %s "Liste als CSV-Datei";;
 
     # UI Labels Special
     course_attendance) printf %s "Kurs&shy;teil&shy;nahme";;
index fcc608dd0a908d798ca091bbfe6062256e121d59..06aacdde32e5ff98dbc80debdbde025c83ea0d13 100644 (file)
--- a/style.css
+++ b/style.css
@@ -173,6 +173,8 @@ form.filter button[type=submit] {
   margin-top: .5em; margin-bottom: .5em;
 }
 
+form.filter button[value=export_csv] { margin-left: 1em; }
+
 body.courses form .order { display: inline-block; margin-right: 2em;}
 
 body.cards form.newcard { display: flex; }