1 # Copyright 2014, 2019 Paul Hänsch
3 # This file is part of Confetti.
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Confetti is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
19 [ "$1" = "$2" ] && printf 'checked="checked"'
23 order="$(GET o |grep -m1 -xE 'DOW|TOD')"
27 [form .sort .search action="?" method="GET"
28 [span .label $(l10n sort_order):]
29 [radio "order" "DOW" $(check $order DOW) $(l10n order_DOW)]
30 [radio "order" "TOD" $(check $order TOD) $(l10n order_TOD)]
31 [submit "" "" $(l10n order_apply)]
37 { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -rnE '
39 s/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/\1-\2-\3 \4:\5:\6 UTC/p;t
40 s/^TZID=(.+)\:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$/TZ="\1" \2-\3-\4 \5:\6:\7/p;t
41 s/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$/\1-\2-\3 \4:\5:\6/p;t
51 cnt="$(pdi_count "$course" "$item")"
55 printf '[h2 ­%s]' "$(pdi_value "$course" SUMMARY)"
58 printf '[span .text .DTSTART %s %s ]' \
59 "$(date -d "$(pdi_value "$course" DTSTART |cal_date)" '+%A %B %d, %Y - %H:%M')" \
63 dts_date="$(pdi_value "$course" DTSTART |cal_date)"
64 rrule=" $(pdi_value "$course" RRULE)"
65 rr_int="${rrule##*INTERVAL=}"; rr_int="${rr_int%%;*}"
66 rr_count="${rrule##*COUNT=}"; rr_count="${rr_count%%;*}"
67 rr_freq="${rrule##*FREQ=}"; rr_freq="${rr_freq%%;*}"
68 rr_until="${rrule##*UNTIL=}"; rr_until="${rr_until%%;*}"
69 rr_until="$(cal_date "${rr_until}")"
72 && printf '[span .text .RRULE %s]' "$(l10n "s$rr_freq")" \
73 || printf '[span .text .RRULE %s %s %s]' "$(l10n t_every)" "${rr_int}" "$(l10n $rr_freq)"
74 case "$rrule $rr_freq" in
76 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) day" "+%A %B %d, %Y - %H:%M")"
79 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) week" "+%A %B %d, %Y - %H:%M")"
82 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) month" "+%A %B %d, %Y - %H:%M")"
85 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) year" "+%A %B %d, %Y - %H:%M")"
88 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$rr_until" "+%A %B %d, %Y - %H:%M")"
93 COMMENT)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
94 seq 1 $cnt |while read c; do
95 printf '[p .item .%s ­%s]' "$item" \
96 "$(pdi_value "$course" "$item" $c |unescape |HTML)"
99 *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
100 seq 1 $cnt |while read c; do
101 printf '[span .item .%s ­%s]' "$item" \
102 "$(pdi_value "$course" "$item" $c |unescape |HTML)"
115 cnt="$(pdi_count "$course" "$item")"
116 [ "$cnt" -lt 1 ] && cnt=1
120 local dtstart="$(pdi_value "$course" DTSTART |cal_date)"
121 local ystart="${dtstart%%-*}"; ystart="${ystart##* }"
122 local mstart="${dtstart#*-}"; mstart="${mstart%%-*}"
123 local dstart="${dtstart##*-}"; dstart="${dstart%% *}"
124 local hhstart="${dtstart##* }"; hhstart="${hhstart%%:*}"
125 local mmstart="${dtstart##*:}";
128 printf '[div .section .DTSTART][h3 %s]' "$(l10n DTSTART)"
129 printf '[select .DTSYEAR name="DTSYEAR" onchange="this.form.submit();"\n'
130 seq $((ystart - 50)) $((ystart + 50)) |while read y; do
131 printf '[option value="%i" %s %i]\n' $y "$([ $y -eq $ystart ] && printf selected)" $y
134 printf '[select .DTSMONTH name="DTSMONTH" onchange="this.form.submit();"\n'
135 m=1; for mn in $(l10n January February March April May June July August September October November December); do
136 printf '[option value="%i" %s . %s]\n' $m "$(selected $m $mstart)" "$mn"
139 printf '][submit "DTS" "update" .DTS %s]\n' "$(l10n edit_dtscal)"
140 printf '[table .dtscalt [tr'
141 printf '[th . %s]' $(l10n Mon Tue Wed Thu Fri Sat Sun)
143 cdow="$(date -d ${ystart}-${mstart}-1 +%u)"
144 seq 2 $cdow |xargs -n1 printf '[td .padding .%s]'
145 d=1; while [ "$d" -lt 29 ] || [ "$(date -d ${ystart}-${mstart}-${d} +%m)" -eq "$mstart" ]; do
146 [ $cdow -eq 1 -a $d -ne 1 ] && printf ']\n[tr '
147 printf '[td [input .DTSCAL type="radio" name="DTSDAY" #DTSCAL_%i value="%i" %s][label .DTSCAL for="DTSCAL_%i" %i]]' \
148 $d $d "$(checked $d $dstart)" $d $d
149 d=$((d + 1)); cdow=$(((cdow + 1) % 7))
152 printf '[span .DTSTIME %s:][select .DTSTIME name="DTSHOUR"' "$(l10n time)"
153 seq 00 23 |while read h; do
154 printf '[option value="%i" %s %02i]' $h "$(selected "$h" "$hhstart")" $h
156 printf ']:[select .DTSTIME name="DTSMINUTE"'
157 seq 00 5 55 |while read m; do
158 printf '[option value="%i" %s %02i]' $m "$(selected "$m" "$mmstart")" $m
165 printf '[h3 %s]' "$(l10n "$item")"
166 seq 1 $cnt |while read c; do
167 printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
168 "$item" $c "$item" $c "$item" $c "$(l10n delete)"
169 printf '<textarea class="item %s" name="%s">%s</textarea>' \
170 "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)"
172 printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
175 SUMMARY|*)printf '[h3 %s]' "$(l10n "$item")"
176 seq 1 $cnt |while read c; do
177 printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
178 "$item" $c "$item" $c "$item" $c "$(l10n delete)"
179 printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
180 "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)" "$(l10n "$item")"
182 printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"