]> git.plutz.net Git - confetti/blobdiff - courses/export_pdf.sh
styling for iban assignment
[confetti] / courses / export_pdf.sh
index 7a9a9dd17ee49e876d40cfc7cd62ddad06d7b8ef..92e10c5f900626b0805da4224f3b5599bcbec039 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() {
@@ -64,12 +64,15 @@ get_dates() {
 
   while [ "$dts_date" -lt "$today" ]; do dts_date="$(date -d "${dts_date} + ${rec}" +%Y%m%d)"; done
   for n in 1 2 3 4 5 6 7 8 9 10; do
-    LANG=de_DE.UTF-8 date -d "$dts_date" +"%A, %d. %b."
+    LANG=de_DE.UTF-8 date -d "$dts_date" +"%d. %b."
     dts_date="$(date -d "${dts_date} + ${rec}" +%Y%m%d)"
   done
 }
 
-"$_EXEC/cgilite/html-sh.sed" <<-EOF |sed -E 's;<(td|th)([^>]*)>;<\1 \2 style="border: 1pt solid\; padding: 1mm 2mm\;">;g' >"$htmlfile"
+# some table styles need to be inline, because this is how libreoffice works
+style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
+
+"$_EXEC/cgilite/html-sh.sed" <<-EOF >"$htmlfile"
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 [html [head
   [meta http-equiv="content-type" content="text/html; charset=utf-8"]
@@ -86,10 +89,10 @@ get_dates() {
     th, td { text-align: left; }
   ]
 ][body lang="de_DE"
-  [table width="100%"
+  [table width="100%" style="page-break-after: always;"
     [col width=10*] [col width=5*] [col width=10*] [col width=15*]
     [thead
-      [tr [th . $(l10n N)] [th . $(l10n BDAY)] [th . $(l10n TEL)] [th . $(l10n NOTE)]]
+      [tr [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")"
@@ -98,26 +101,32 @@ get_dates() {
                   [ "$type" ] && type="$(l10n "TYPE=$type"):"
                   printf '%s %s<br>' "$type" "$(pdi_value "$vcf" TEL $n)"
                 done  )"
-        printf '[tr [td .N . %s] [td .BDAY . %s] [td .TEL . %s] [td .NOTE . %s]]\n' \
-               "$(pdi_value "$vcf" FN   |unescape |HTML)" \
-               "$(pdi_value "$vcf" BDAY |unescape |HTML)" \
-               "$tel" \
-               "$(pdi_value "$vcf" NOTE |unescape |HTML)"
-      done |sort -k4)]
+        printf '[tr valign=top [td %s .N . %s] [td %s .BDAY . %s] [td %s .TEL . %s] [td %s .NOTE . %s]]\n' \
+               "$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)]
   ]
-  [table width="100%" style="page-break-before: always;"
+  [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*]
     [thead
-      [tr [th ] $(get_dates |xargs -d\\n printf '[th . %s]')]
+      [tr [th $style_td ] $(get_dates |xargs -d\\n printf "[th $style_td . %s]")]
     ][tbody
     $(grep -F "${coursefile##*/}       " "$_DATA/mappings/attendance" |while read discard each; do
       vcf="$(pdi_load "$_DATA/vcard/$each")"
-      printf '[tr [td .N . %s] [td] [td] [td] [td] [td] [td] [td] [td] [td] [td]]\n' \
-             "$(pdi_value "$vcf" FN |unescape |HTML)"
-    done |sort -k4)]
+      printf '[tr [td %s .N . %s] [td %s] [td %s] [td %s] [td %s] [td %s] [td %s] [td %s] [td %s] [td %s] [td %s]]\n' \
+             "$style_td" "$(pdi_value "$vcf" FN |unescape |HTML)" \
+             "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td"
+    done |sort)]
   ]
 ]]
 EOF
 
-lowriter --convert-to pdf --outdir "$_DATA/export/" "$htmlfile"
-REDIRECT "/export/${pdffile##*/}"
+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 "$(URL "${_BASE}/export/${pdffile##*/}")"