1 # Copyright 2014, 2019, 2020 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 [fieldset .order [legend $(l10n sort_order):]
29 [radio "order" "DOW" $(check $order DOW) $(l10n order_DOW)]
30 [radio "order" "TOD" $(check $order TOD) $(l10n order_TOD)]
32 [submit "" "" $(l10n order_apply)]
38 { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -nE '
40 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
41 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
42 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
52 cnt="$(pdi_count "$course" "$item")"
56 printf '[h2 ­%s]' "$(pdi_value "$course" SUMMARY)"
59 printf '[span .text .DTSTART %s %s ]' \
60 "$(LANG=de_DE.UTF-8 date -d "$(pdi_value "$course" DTSTART |cal_date)" '+%A, %d. %B %Y - %H:%M')" \
64 dts_date="$(pdi_value "$course" DTSTART |cal_date)"
65 rrule=" $(pdi_value "$course" RRULE)"
66 rr_int="${rrule##*INTERVAL=}"; rr_int="${rr_int%%;*}"
67 rr_count="${rrule##*COUNT=}"; rr_count="${rr_count%%;*}"
68 rr_freq="${rrule##*FREQ=}"; rr_freq="${rr_freq%%;*}"
69 rr_until="${rrule##*UNTIL=}"; rr_until="${rr_until%%;*}"
70 rr_until="$(cal_date "${rr_until}")"
73 && printf '[span .text .RRULE %s]' "$(l10n "s$rr_freq")" \
74 || printf '[span .text .RRULE %s %s %s]' "$(l10n t_every)" "${rr_int}" "$(l10n $rr_freq)"
75 case "$rrule $rr_freq" in
77 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) day" "+%A %B %d, %Y - %H:%M")"
80 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) week" "+%A %B %d, %Y - %H:%M")"
83 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) month" "+%A %B %d, %Y - %H:%M")"
86 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) year" "+%A %B %d, %Y - %H:%M")"
89 printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$rr_until" "+%A %B %d, %Y - %H:%M")"
94 COMMENT)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
95 seq 1 $cnt |while read c; do
96 printf '[p .item .%s . %s]' "$item" \
97 "$(pdi_value "$course" "$item" $c |unescape |HTML)"
100 *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
101 seq 1 $cnt |while read c; do
102 printf '[span .item .%s . %s]' "$item" \
103 "$(pdi_value "$course" "$item" $c |unescape |HTML)"
116 cnt="$(pdi_count "$course" "$item")"
117 [ "$cnt" -lt 1 ] && cnt=1
121 local dtstart="$(pdi_value "$course" DTSTART |cal_date)"
122 local ystart="${dtstart%%-*}"; ystart="${ystart##* }"
123 local mstart="${dtstart#*-}"; mstart="${mstart%%-*}"
124 local dstart="${dtstart##*-}"; dstart="${dstart%% *}"
125 local hhstart="${dtstart##* }"; hhstart="${hhstart%%:*}"
126 local mmstart="${dtstart##* }"; mmstart="${mmstart#*:}"; mmstart="${mmstart%:*}"
130 [h3 . $(l10n DTSTART)]
131 [input type="number" name="DTS_YEAR" value="${ystart}" placeholder="$(l10n YYYY)"]
132 [select name="DTS_MONTH" onchange="this.form.submit();"
133 $(m=1; for mn in $(l10n January February March April May June July August September October November December); do
134 printf ' [option value="%02i" %s . %s]\n' $m "$(selected $m $mstart)" "$mn"
137 ][submit "DTS" "update" . $(l10n edit_dtscal)]
139 [tr $(printf '[th . %s]' $(l10n Mon Tue Wed Thu Fri Sat Sun))]
142 cdow="$(date -d ${ystart}-${mstart}-1 +%u)"
143 seq 2 $cdow |xargs -n1 printf '[td .padding .%s]'
144 d=1; while [ "$d" -lt 29 ] || [ "$(date -d ${ystart}-${mstart}-${d} +%m)" -eq "$mstart" ]; do
145 [ $cdow -eq 1 -a $d -ne 1 ] && printf ']\n [tr '
146 printf '[td [input type="radio" name="DTS_DAY" #DTSCAL_%i value="%02i" %s][label for="DTSCAL_%i" %i]]' \
147 $d $d "$(checked $d $dstart)" $d $d
148 d=$((d + 1)); cdow=$(((cdow + 1) % 7))
152 [label .DTSTIME $(l10n time):]
153 [input type="number" name="DTS_HOUR" value="$hhstart" min="0" max="23"]:[input type="number" name="DTS_MINUTE" value="$mmstart" min="0" max="59"]
157 local dtstart="$(pdi_value "$course" DTSTART |cal_date)"
158 local ystart="${dtstart%%-*}"; ystart="${ystart##* }"
159 local mstart="${dtstart#*-}"; mstart="${mstart%%-*}"
160 local dstart="${dtstart##*-}"; dstart="${dstart%% *}"
162 local rrule="$(pdi_value "$course" RRULE)"
163 local rr_int="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?INTERVAL=([0-9]+)(\;.*)?$;\2;p')"
164 local rr_count="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?COUNT=([0-9]+)(\;.*)?$;\2;p')"
165 local rr_freq="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(\;.*)?$;\2;p')"
166 local rr_until="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?UNTIL=([0-9]{8}T[0-9]{6}Z)(\;.*)?$;\2;p')"
167 local rr_uyear="${rr_until%????T??????Z}"
168 local rr_umonth=${rr_until#????}; rr_umonth="${rr_umonth%??T??????Z}"
169 local rr_uday=${rr_until#??????}; rr_uday="${rr_uday%T??????Z}"
170 local rr_limit="ETERN"
171 [ "$rr_count" ] && [ "$rr_count" -ge 0 ] && rr_limit="COUNT"
172 [ "$rr_uyear" ] && [ "$rr_uyear" -ge 0 ] && rr_limit="UNTIL"
175 [h3 . $(l10n "$item")]
176 [span .item . $(l10n t_every)
177 [input type="number" .RRULE .INTERVAL name="RRULE_INTERVAL" placeholder="#N" value="${rr_int:-1}" min="1"]
178 [select .RRULE .FREQ name="RRULE_FREQ"
179 $(for f in DAILY WEEKLY MONTHLY YEARLY; do
180 printf ' [option value="%s" %s . %s]\n' "$f" "$(selected $f "$rr_freq")" "$(l10n $f)"
183 [label .item [input type="radio" name="RRULE_LIMIT" value="ETERN" $(checked "$rr_limit" ETERN)] $(l10n t_eternal)]
185 [input type="radio" name="RRULE_LIMIT" value="COUNT" $(checked "$rr_limit" COUNT)]
186 [input type="number" .RRULE .COUNT name="RRULE_COUNT" placeholder="#N" value="${rr_count:-1}" min="1"] $(l10n t_times)
189 [input type="radio" name="RRULE_LIMIT" value="UNTIL" $(checked "$rr_limit" UNTIL)] $(l10n t_until)
190 [input type="number" .RRULE .UYEAR name="RRULE_UYEAR" placeholder="$(l10n YYYY)" value="${rr_uyear:-$ystart}" min="$ystart"]
191 [input type="number" .RRULE .UMONTH name="RRULE_UMONTH" placeholder="$(l10n MM)" value="${rr_umonth:-$mstart}" min="1" max="12"]
192 [input type="number" .RRULE .UDAY name="RRULE_UDAY" placeholder="$(l10n DD)" value="${rr_uday:-$dstart}" min="1" max="31"]
197 printf '[h3 %s]' "$(l10n "$item")"
198 seq 1 $cnt |while read c; do
199 printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
200 "$item" $c "$item" $c "$item" $c "$(l10n delete)"
201 printf '<textarea class="item %s" name="%s">%s</textarea>' \
202 "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)"
204 printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
207 printf '[h3 %s]' "$(l10n course_attendance)"
208 printf '[div .attendance\n'
209 for vcf in "$_DATA"/vcard/*.vcf; do
210 fn="$(pdi_value "$(pdi_load "$vcf")" FN)"
211 printf '%s/%s\n' "${vcf##*/}" "$fn"
214 | while IFS=/ read -r vcf fn; do
215 printf '[span .item [input type="checkbox" id="att%s" name="attendance" value="%s" %s][label for="att%s" . %s]]' \
216 "$vcf" "$vcf" "$(grep -qxF "${coursefile##*/} $vcf" "$_DATA/mappings/attendance" && printf 'checked="checked"')" "$vcf" "$fn"
221 printf '[h3 %s]' "$(l10n "$item")"
222 printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
223 "$item" "$item" "$(pdi_value "$course" "$item" |unescape |HTML)" "$(l10n "$item")"
226 printf '[h3 %s]' "$(l10n "$item")"
227 seq 1 $cnt |while read c; do
228 printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
229 "$item" $c "$item" $c "$item" $c "$(l10n delete)"
230 printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
231 "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)" "$(l10n "$item")"
233 printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"