]> git.plutz.net Git - confetti/blobdiff - courses/export_pdf.sh
process split fields as arrays
[confetti] / courses / export_pdf.sh
index 3e5593d2b8a439a4b13d1dd622ea064a11e765be..10230b89c8457281a09d8c0fba8549cb75986cd4 100755 (executable)
@@ -7,16 +7,16 @@ coursefile="${_DATA}/ical/$(GET course)"
 
 if [ ! -r "$coursefile" ]; then
   SET_COOKIE 0 message="Cannot read course file"
-  REDIRECT /courses/
+  REDIRECT "${_BASE}/courses/"
   return 0
 elif ! mkdir -p "$_DATA/export"; then
   SET_COOKIE 0 message="Cannot create export directory"
-  REDIRECT /courses/
+  REDIRECT "${_BASE}/courses/"
   return 0
 fi
 
 ics="$(pdi_load "$coursefile")"
-htmlfile="${_DATA}/export/$(pdi_value "$ics" SUMMARY |URL |tr / _).html"
+htmlfile="${_DATA}/export/$(pdi_value "$ics" SUMMARY |unescape |tr \\n/ __).html"
 pdffile=${htmlfile%.html}.pdf
 
 pdi_date() {
@@ -90,9 +90,10 @@ style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
   ]
 ][body lang="de_DE"
   [table width="100%" style="page-break-after: always;"
-    [col width=10*] [col width=5*] [col width=10*] [col width=15*]
+    [col width=2*] [col width=10*] [col width=5*] [col width=10*] [col width=15*]
     [thead
-      [tr [th $style_td . $(l10n N)] [th $style_td . $(l10n BDAY)] [th $style_td . $(l10n TEL)] [th $style_td . $(l10n NOTE)]]
+      [tr [th $style_td . $(l10n No.)] [th $style_td . $(l10n N)] [th $style_td . $(l10n BDAY)]
+          [th $style_td . $(l10n TEL)] [th $style_td . $(l10n NOTE)]]
     ][tbody
       $(grep -F "${coursefile##*/}     " "$_DATA/mappings/attendance" |while read discard each; do
         vcf="$(pdi_load "$_DATA/vcard/$each")"
@@ -101,12 +102,16 @@ style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
                   [ "$type" ] && type="$(l10n "TYPE=$type"):"
                   printf '%s %s<br>' "$type" "$(pdi_value "$vcf" TEL $n)"
                 done  )"
-        printf '[tr valign=top [td %s .N . %s] [td %s .BDAY . %s] [td %s .TEL . %s] [td %s .NOTE . %s]]\n' \
+        printf '[tr valign=top [td %s .No @@No@@] [td %s .N . %s] [td %s .BDAY . %s] [td %s .TEL . %s] [td %s .NOTE . %s]]\n' \
+               "${style_td%\"} text-align: right;\"" \
                "$style_td" "$(pdi_value "$vcf" FN   |unescape |HTML)" \
                "$style_td" "$(pdi_value "$vcf" BDAY |unescape |HTML)" \
                "$style_td" "$tel" \
                "$style_td" "$(pdi_value "$vcf" NOTE |unescape |HTML)"
-      done |sort)]
+      done |sort |while read -r line; do
+        attno=$((${attno-0} + 1))
+        printf '%s%2i%s\n' "${line%%@@No@@*}" $attno "${line#*@@No@@}"
+      done)]
   ]
   [table width="100%"
     [col width=30*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*] [col width=10*]
@@ -123,10 +128,10 @@ style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
 ]]
 EOF
 
-export            HOME="$_DATA"
+export            HOME="$_DATA/"
 export XDG_CONFIG_HOME="$_DATA/xdg_config"
 export  XDG_CACHE_HOME="$_DATA/xdg_cache"
 export   XDG_DATA_HOME="$_DATA/xdg_local"
 
 lowriter --convert-to pdf --outdir "$_DATA/export/" "$htmlfile" >/dev/null
-REDIRECT "/export/${pdffile##*/}"
+REDIRECT "$(URL "${_BASE}/export/${pdffile##*/}")"