3 . "${_EXEC}/pdiread.sh"
4 . "$_EXEC/cards/l10n.sh"
6 coursefile="${_DATA}/ical/$(GET course)"
8 if [ ! -r "$coursefile" ]; then
9 SET_COOKIE 0 message="Cannot read course file"
12 elif ! mkdir -p "$_DATA/export"; then
13 SET_COOKIE 0 message="Cannot create export directory"
18 ics="$(pdi_load "$coursefile")"
19 htmlfile="${_DATA}/export/$(pdi_value "$ics" SUMMARY |URL |tr / _).html"
20 pdffile=${htmlfile%.html}.pdf
23 local pdt y m d H M S Z
24 [ $# -eq 0 ] && read pdt || pdt="$*"
28 Z=UTC; pdt="${pdt%Z}";;
30 Z="${pdt%%:*}"; Z=${Z#TZID=}; pdt=${pdt#TZID=*:};;
33 y="${pdt%%????T*}" pdt=${pdt#????}
34 m="${pdt%%??T*}" pdt=${pdt#??}
35 d="${pdt%%T*}" pdt=${pdt#??T}
36 H="${pdt%%????}" pdt=${pdt#??}
37 M="${pdt%%??}" pdt=${pdt#??}
41 UTC) date -d "${y}-${m}-${d} ${H}:${M}:${S} UTC" +%s;;
42 '') date -d "${y}-${m}-${d} ${H}:${M}:${S}" +%s;;
43 *) date -d "TZ=\"${Z}\" ${y}-${m}-${d} ${H}:${M}:${S}" +%s;;
48 local dts_date rrule rr_int rr_freq rec today="$(date +%Y%m%d)"
50 dts_date="$(pdi_value "$ics" DTSTART || printf %s "$today")"
51 dts_date="${dts_date#TZID=*:}" dts_date="${dts_date%%T*}"
52 rrule="$(pdi_value "$ics" RRULE)"
53 rr_int="${rrule##*INTERVAL=}" rr_int="${rr_int%%;*}"
54 rr_freq="${rrule##*FREQ=}" rr_freq="${rr_freq%%;*}"
56 [ "$rr_int" -ge 0 ] || rr_int=1 2>/dev/null
58 YEARLY) rec="$rr_int year";;
59 MONTHLY) rec="$rr_int month";;
60 DAILY) rec="$rr_int day";;
61 WEEKLY) rec="$rr_int week";;
62 *) rec="$rr_int week";;
65 while [ "$dts_date" -lt "$today" ]; do dts_date="$(date -d "${dts_date} + ${rec}" +%Y%m%d)"; done
66 for n in 1 2 3 4 5 6 7 8 9 10; do
67 LANG=de_DE.UTF-8 date -d "$dts_date" +"%d. %b."
68 dts_date="$(date -d "${dts_date} + ${rec}" +%Y%m%d)"
72 # some table styles need to be inline, because this is how libreoffice works
73 style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
75 "$_EXEC/cgilite/html-sh.sed" <<-EOF >"$htmlfile"
76 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
78 [meta http-equiv="content-type" content="text/html; charset=utf-8"]
80 [meta name="generator" content="Confetti"]
81 [meta name="created" content="$(date +%FT%T)"]
82 [meta name="changed" content="$(date +%FT%T)"]
83 [style type="text/css"
84 @page { size: 29.7cm 21cm; margin: 1.5cm; }
85 * { background: inherit; }
86 body { background: transparent; font-family: Liberation Sans, Sans-Serif; }
88 th { white-space: pre; }
89 th, td { text-align: left; }
92 [table width="100%" style="page-break-after: always;"
93 [col width=10*] [col width=5*] [col width=10*] [col width=15*]
95 [tr [th $style_td . $(l10n N)] [th $style_td . $(l10n BDAY)] [th $style_td . $(l10n TEL)] [th $style_td . $(l10n NOTE)]]
97 $(grep -F "${coursefile##*/} " "$_DATA/mappings/attendance" |while read discard each; do
98 vcf="$(pdi_load "$_DATA/vcard/$each")"
99 tel="$( seq 1 $(pdi_count "$vcf" TEL) |while read n; do
100 type="$(pdi_attrib "$vcf" TEL $n TYPE)"
101 [ "$type" ] && type="$(l10n "TYPE=$type"):"
102 printf '%s %s<br>' "$type" "$(pdi_value "$vcf" TEL $n)"
104 printf '[tr valign=top [td %s .N . %s] [td %s .BDAY . %s] [td %s .TEL . %s] [td %s .NOTE . %s]]\n' \
105 "$style_td" "$(pdi_value "$vcf" FN |unescape |HTML)" \
106 "$style_td" "$(pdi_value "$vcf" BDAY |unescape |HTML)" \
108 "$style_td" "$(pdi_value "$vcf" NOTE |unescape |HTML)"
112 [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*]
114 [tr [th $style_td ] $(get_dates |xargs -d\\n printf "[th $style_td . %s]")]
116 $(grep -F "${coursefile##*/} " "$_DATA/mappings/attendance" |while read discard each; do
117 vcf="$(pdi_load "$_DATA/vcard/$each")"
118 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' \
119 "$style_td" "$(pdi_value "$vcf" FN |unescape |HTML)" \
120 "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td" "$style_td"
126 lowriter --convert-to pdf --outdir "$_DATA/export/" "$htmlfile"
127 REDIRECT "/export/${pdffile##*/}"