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 9953a22..aacacbb 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 376199e..27cdf04 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 c53cdd3..cab5bde 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 fcc608d..06aacdd 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; }