# Copyright 2014, 2019 Paul Hänsch # # This file is part of Confetti. # # Confetti is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Confetti is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . check(){ [ "$1" = "$2" ] && printf 'checked="checked"' } edit="$(GET e)" order="$(GET o |grep -m1 -xE 'DOW|TOD')" w_sort_courses(){ cat <<-EOF [form .sort .search action="?" method="GET" [span .label $(l10n sort_order):] [radio "order" "DOW" $(check $order DOW) $(l10n order_DOW)] [radio "order" "TOD" $(check $order TOD) $(l10n order_TOD)] [submit "" "" $(l10n order_apply)] ] EOF } cal_date(){ { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -rnE ' 2q 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 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 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 ' } cal_item(){ local course="$1" local item cnt c shift 1 for item in $@; do cnt="$(pdi_count "$course" "$item")" case $item in SUMMARY) printf '[h2 ­%s]' "$(pdi_value "$course" SUMMARY)" ;; DTSTART) printf '[span .text .DTSTART %s %s ]' \ "$(date -d "$(pdi_value "$course" DTSTART |cal_date)" '+%A %B %d, %Y - %H:%M')" \ "$(l10n t_oclock)" ;; RRULE) dts_date="$(pdi_value "$course" DTSTART |cal_date)" rrule=" $(pdi_value "$course" RRULE)" rr_int="${rrule##*INTERVAL=}"; rr_int="${rr_int%%;*}" rr_count="${rrule##*COUNT=}"; rr_count="${rr_count%%;*}" rr_freq="${rrule##*FREQ=}"; rr_freq="${rr_freq%%;*}" rr_until="${rrule##*UNTIL=}"; rr_until="${rr_until%%;*}" rr_until="$(cal_date "${rr_until}")" [ "$rr_int" -eq 1 ] \ && printf '[span .text .RRULE %s]' "$(l10n "s$rr_freq")" \ || printf '[span .text .RRULE %s %s %s]' "$(l10n t_every)" "${rr_int}" "$(l10n $rr_freq)" case "$rrule $rr_freq" in *COUNT*DAILY*) printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) day" "+%A %B %d, %Y - %H:%M")" ;; *COUNT*WEEKLY*) printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) week" "+%A %B %d, %Y - %H:%M")" ;; *COUNT*MONTHLY*) printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) month" "+%A %B %d, %Y - %H:%M")" ;; *COUNT*YEARLY*) printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$dts_date + $((rr_int * rr_count)) year" "+%A %B %d, %Y - %H:%M")" ;; *UNTIL*) printf '[span .text %s %s]' "$(l10n t_until)" "$(date -d "$rr_until" "+%A %B %d, %Y - %H:%M")" ;; esac ;; attendance);; COMMENT)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do printf '[p .item .%s ­%s]' "$item" \ "$(pdi_value "$course" "$item" $c |unescape |HTML)" done ;; *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do printf '[span .item .%s ­%s]' "$item" \ "$(pdi_value "$course" "$item" $c |unescape |HTML)" done ;; esac done } edit_item(){ local course="$1" local item cnt c shift 1 for item in $@; do cnt="$(pdi_count "$course" "$item")" [ "$cnt" -lt 1 ] && cnt=1 case $item in DTSTART) local dtstart="$(pdi_value "$course" DTSTART |cal_date)" local ystart="${dtstart%%-*}"; ystart="${ystart##* }" local mstart="${dtstart#*-}"; mstart="${mstart%%-*}" local dstart="${dtstart##*-}"; dstart="${dstart%% *}" local hhstart="${dtstart##* }"; hhstart="${hhstart%%:*}" local mmstart="${dtstart##*:}"; local m mn cdow d printf '[div .section .DTSTART][h3 %s]' "$(l10n DTSTART)" printf '[select .DTSYEAR name="DTSYEAR" onchange="this.form.submit();"\n' seq $((ystart - 50)) $((ystart + 50)) |while read y; do printf '[option value="%i" %s %i]\n' $y "$([ $y -eq $ystart ] && printf selected)" $y done printf ']' printf '[select .DTSMONTH name="DTSMONTH" onchange="this.form.submit();"\n' m=1; for mn in $(l10n January February March April May June July August September October November December); do printf '[option value="%i" %s . %s]\n' $m "$(selected $m $mstart)" "$mn" m=$((m+1)) done printf '][submit "DTS" "update" .DTS %s]\n' "$(l10n edit_dtscal)" printf '[table .dtscalt [tr' printf '[th . %s]' $(l10n Mon Tue Wed Thu Fri Sat Sun) printf ']\n[tr ' cdow="$(date -d ${ystart}-${mstart}-1 +%u)" seq 2 $cdow |xargs -n1 printf '[td .padding .%s]' d=1; while [ "$d" -lt 29 ] || [ "$(date -d ${ystart}-${mstart}-${d} +%m)" -eq "$mstart" ]; do [ $cdow -eq 1 -a $d -ne 1 ] && printf ']\n[tr ' printf '[td [input .DTSCAL type="radio" name="DTSDAY" #DTSCAL_%i value="%i" %s][label .DTSCAL for="DTSCAL_%i" %i]]' \ $d $d "$(checked $d $dstart)" $d $d d=$((d + 1)); cdow=$(((cdow + 1) % 7)) done 2>/dev/null printf ']]\n' printf '[span .DTSTIME %s:][select .DTSTIME name="DTSHOUR"' "$(l10n time)" seq 00 23 |while read h; do printf '[option value="%i" %s %02i]' $h "$(selected "$h" "$hhstart")" $h done printf ']:[select .DTSTIME name="DTSMINUTE"' seq 00 5 55 |while read m; do printf '[option value="%i" %s %02i]' $m "$(selected "$m" "$mmstart")" $m done printf ']' ;; RRULE) ;; COMMENT) printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ "$item" $c "$item" $c "$item" $c "$(l10n delete)" printf '' \ "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)" done printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" ;; attendance);; SUMMARY|*)printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ "$item" $c "$item" $c "$item" $c "$(l10n delete)" printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \ "$item" "$item" "$(pdi_value "$course" "$item" $c |unescape |HTML)" "$(l10n "$item")" done printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" ;; esac done }