1 # Copyright 2014 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/>.
18 SUP_FIELDS=(SUMMARY COMMENT)
19 [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
21 dtstart="$values[DTSTART]"
22 [ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S)
24 echo "$dtstart" |case "$dtstart" in
26 sed -rn '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'
29 sed -rn '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'
32 sed -rn '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'
36 dts_year=$(date -d "$dts_date" +%Y)
37 dts_month=$(date -d "$dts_date" +%m)
38 dts_dom=$(date -d "$dts_date" +%d)
39 dts_dow=$(date -d "$dts_date" +%u)
40 dts_weekday=$(date -d "$dts_date" +%A)
41 dts_hour=$(date -d "$dts_date" +%H)
42 dts_min=$(date -d "$dts_date" +%M)
43 dts_sec=$(date -d "$dts_date" +%S)
45 rrule="$values[RRULE]"
46 rr_int="$(echo $rrule |sed -rn 's:^.*INTERVAL=([0-9]+)(;.*)?$:\1:p')"
47 rr_count="$(echo $rrule |sed -rn 's:^.*COUNT=([0-9]+)(;.*)?$:\1:p')"
48 rr_freq="$(echo $rrule |sed -rn 's:^.*FREQ=(YEARLY|MONTHLY|WEEKLY|DAILY)(;.*)?$:\1:p')"
49 rr_uyear="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\1:p')"
50 rr_umonth="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\2:p')"
51 rr_uday="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\3:p')"
52 if [ -n "$rr_count" ]; then
54 elif [ -n "$rr_uyear" ]; then
60 echo '<div id="'${id}'" class="course">'
61 echo '<form action="?action=update_course" method="POST">'
62 echo '<input type="hidden" name="course" value="'${id}'"/>'
63 echo ' <div class="section basic">'
64 echo ' <h2>'$(l10n SUMMARY)'</h2>'
65 echo ' <input type="text" class="item SUMMARY" name="SUMMARY" value="'$values[SUMMARY]'" />'
66 echo ' <h3>'$(l10n COMMENT)'</h3>'
67 for n in COMMENT COMMENT{0..10}; do [ -n "$values[$n]" ] &&\
68 echo ' <textarea class="item COMMENT" name="COMMENT">'$values[$n]'</textarea>'
71 echo ' </div><div class="section dtstart">'
72 echo ' <h3>'$(l10n DTSTART)'</h3>'
73 echo ' <select class="DTSYEAR" name="DTSYEAR" onchange="this.form.submit();">'
74 for y in {$(($dts_year - 50))..$(($dts_year + 50))}; do
75 echo ' <option value="'$y'" '$([ "$y" -eq "$dts_year" ] && echo 'selected="selected"')'>'$y'</option>'
78 echo ' <select class="DTSMONTH" name="DTSMONTH" onchange="this.form.submit();">'
80 echo ' <option value="'$m'" '$([ "$m" -eq "$dts_month" ] && echo 'selected="selected"')'>'$(date -d ${dts_year}-${m}-1 +%B)'</option>'
83 echo ' <button class="DTS" type="submit" name="DTS" value="update">'$(l10n edit_dtscal)'</button><br/>'
84 for wd in mon tue wed thu fri sat sun; do
85 echo -n '<span class="DTSCALHEAD">'$(date -d $wd +%a)'</span>'
87 fdom=$(date -d ${dts_year}-${dts_month}-1 +%u)
88 while [ "$fdom" -gt 1 ]; do
89 echo -n '<span class="DTSCAL"></span>'
92 cnt=$(date -d ${dts_year}-${dts_month}-1 +%s)
93 while [ "$(date -d @$cnt +%m)" = "$dts_month" ]; do
94 dn=$(date -d @$cnt +%d)
95 echo -n '<input type="radio" class="DTSCAL" name="DTSDAY" value="'$dn'" id="DTSCAL_'$dn'" '$([ $dn = $dts_dom ] && echo checked)'><label for="DTSCAL_'$dn'" class="DTSCAL">'$dn'</label>'
99 echo ' <span class="DTSTIME">'$(l10n time)':</span>'
100 echo ' <select class="DTSTIME" name="DTSHOUR">'
101 for h in {00..23}; do
102 echo ' <option value="'$h'" '$([ "$h" -eq "$dts_hour" ] && echo 'selected="selected"')'>'$h'</option>'
104 echo ' </select>:<select class="DTSTIME" name="DTSMINUTE">'
105 for m in 00 05 10 15 20 25 30 35 40 45 50 55; do
106 echo ' <option value="'$m'" '$([ "$m" -eq "$dts_min" ] && echo 'selected="selected"')'>'$m'</option>'
110 echo ' </div><div class="section recur">'
111 echo ' <h3>'$(l10n RRULE)'</h3>'
112 echo ' <span class="item">'
113 echo ' '$(l10n t_every)''
114 echo ' <select class="RRULE INTERVAL" name="RRULE_INTERVAL">'
115 for i in {1..365}; do
116 echo ' <option value="'$i'" '$([ "$i" = "$rr_int" ] && echo 'selected="selected"')'>'$i'</option>'
119 echo ' <select class="RRULE FREQ" name="RRULE_FREQ">'
120 for f in DAILY WEEKLY MONTHLY YEARLY; do
121 echo ' <option value="'$f'" '$([ "$f" = "$rr_freq" ] && echo 'selected="selected"')'>'$(l10n $f)'</option>'
123 echo ' </select></span>'
124 echo ' <span class="item">'
125 echo ' <input type="radio" name="RRULE_LIMIT" value="ETERN" '$([ "$rr_limit" = ETERN ] && echo 'checked="checked"')'>'$(l10n t_eternal)'</input><br/>'
126 echo ' </span><span class="item">'
127 echo ' <input type="radio" name="RRULE_LIMIT" value="COUNT" '$([ "$rr_limit" = COUNT ] && echo 'checked="checked"')'></input>'
128 echo ' <select class="RRULE COUNT" name="RRULE_COUNT">'
129 for t in {1..365}; do
130 echo ' <option value="'$t'" '$([ "$t" = "$rr_count" ] && echo 'selected="selected"')'>'$t'</option>'
132 echo ' </select>'$(l10n t_times)'</span>'
133 echo ' <span class="item">'
134 echo ' <input type="radio" name="RRULE_LIMIT" value="UNTIL" '$([ "$rr_limit" = UNTIL ] && echo 'checked="checked"')'>'$(l10n t_until)'</input>'
135 echo ' <select class="RRULE UYEAR" name="RRULE_UYEAR">'
136 for uy in {${dts_year}..$(($dts_year + 50))}; do
137 echo ' <option value="'$uy'" '$([ "$uy" = "$rr_uyear" ] && echo 'selected="selected"')'>'$uy'</option>'
140 echo ' <select class="RRULE UMONTH" name="RRULE_UMONTH">'
141 for um in {01..12}; do
142 echo ' <option value="'$um'" '$([ "$um" = "$rr_umonth" ] && echo 'selected="selected"')'>'$(date -d 2000-${um}-1 +%B)'</option>'
145 echo ' <select class="RRULE UDAY" name="RRULE_UDAY">'
146 for ud in {01..31}; do
147 echo ' <option value="'$ud'" '$([ "$ud" = "$rr_uday" ] && echo 'selected="selected"')'>'$ud'</option>'
149 echo ' </select></span>'
151 echo ' </div><div class="section select_attendance">'
152 echo ' <h3>'$(l10n course_attendance)'</h3>'
153 listcards |while read card; do
154 cfile="$_DATA/vcard/$card"
155 aname=$(sed -rn 's:^N(;[^"\:]+|;"[^"]+")*\:([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\5 \3 \4 \2 \6:p' "$cfile" \
156 |sed -r 's:,: :;s:\;: :g;s: +: :g' \
159 selected=$(sed -rn "/^$id\t$card\$/{s;^.*\$;checked=\"checked\";p;q}" "${_DATA}/mappings/attendance")
160 echo ' <label><input type="checkbox" class="item" name="attendance" value="'$card'" '$selected'>'$aname'</label>'
163 echo ' </div><div class="control">'
164 echo ' <select class="item" name="newfield">'
165 echo ' <option value="" disabled="disabled" selected="selected">'$(l10n edit_addfieldtext)'</option>'
166 for f in $SUP_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done
168 echo ' ><button class="item" type="submit" name="action" value="addfield">'$(l10n edit_addfield)'</button>'
169 echo ' <button class="item" type="submit" name="action" value="update">'$(l10n edit_update)'</button>'
170 echo ' <button class="item" type="submit" name="action" value="delete">'$(l10n edit_delete)'</button>'
171 echo ' <button class="item" type="submit" name="action" value="cancel">'$(l10n edit_cancel)'</button>'
173 echo '<input type="hidden" name="UID" value="'$values["UID"]'"/>'