3 # Copyright 2014, 2015 Paul Hänsch
5 # This file is part of Confetti.
7 # Confetti is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Confetti is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
22 course="${_POST[course]}"
23 tempfile="temp/$course"
24 coursefile="ical/$course"
25 attfile="$_DATA/mappings/attendance"
30 tzid=$(cat /etc/timezone)
31 tstamp=$(TZ="$tzid" date +%Y%m%dT%H%M%S)
33 dts_year="${_POST[DTSYEAR]}"
34 dts_month="${_POST[DTSMONTH]}"
35 dts_day="${_POST[DTSDAY]}"
36 [ -n "${_POST[DTSDAY0]}" ] && dts_day="${_POST[DTSDAY0]}"
37 dts_hour="${_POST[DTSHOUR]}"
38 dts_minute="${_POST[DTSMINUTE]}"
40 [ -z $dts_year ] && dts_year=$(date +%Y)
41 [ -z $dts_month ] && dts_month=$(date +%m)
42 [ -z $dts_day ] && dts_day=$(date +%d)
43 date -d ${dts_year}-${dts_month}-${dts_day} >/dev/null 2>/dev/null || dts_day="01"
44 [ -z $dts_hour ] && dts_hour=$(date +%H)
45 [ -z $dts_minute ] && dts_minute=$(date +%M)
47 dtstart="TZID=${tzid}:${dts_year}${dts_month}${dts_day}T${dts_hour}${dts_minute}00"
49 rr_int="${_POST[RRULE_INTERVAL]}"
50 rr_freq="${_POST[RRULE_FREQ]}"
51 rr_limit="${_POST[RRULE_LIMIT]}"
54 rrule="FREQ=$rr_freq;INTERVAL=$rr_int"
57 t="${_POST[RRULE_COUNT]}"
58 rrule="FREQ=$rr_freq;INTERVAL=$rr_int;COUNT=$t"
61 uy="${_POST[RRULE_UYEAR]}"
62 um="${_POST[RRULE_UMONTH]}"
63 ud="${_POST[RRULE_UDAY]}"
64 rrule="FREQ=$rr_freq;INTERVAL=$rr_int;UNTIL=${uy}${um}${ud}T000000Z"
68 echo "BEGIN:VCALENDAR\r" >"$tempfile"
69 echo "VERSION:2.0\r" >>"$tempfile"
70 echo "PRODID:Berlin RAW Confetti\r" >>"$tempfile"
71 echo "BEGIN:VEVENT\r" >>"$tempfile"
72 echo "UID:$uid\r" >>"$tempfile"
73 echo "DTSTAMP:TZID=${tzid}:${tstamp}\r" >>"$tempfile"
74 echo "DTSTART:${dtstart}\r" >>"$tempfile"
75 echo "RRULE:${rrule}\r" >>"$tempfile"
76 for field in SUMMARY COMMENT; do
77 value="${_POST[$field]}"
79 while [ -n "$value" ]; do
80 value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')"
81 echo "${field}:${value}\r"
82 value="${_POST[$field$n]}"
87 case "${_POST[action]}" in
89 echo "${_POST[newfield]}:\r" >>"$tempfile"
90 echo "END:VEVENT\r" >>"$tempfile"
91 echo "END:VCALENDAR\r" >>"$tempfile"
92 echo -n "Location: ?p=courses&edit=$course\n\n"
96 for att in attendance attendance{0..100}; do
97 [ -n "${_POST[$att]}" ] && attendance+=("${_POST[$att]}")
99 sed -rn 's:^'$course'\t(.+)$:\1:p' "$attfile" |while read card; do
100 touch "$_DATA/vcard/$card"
102 sed -i -r '/^'$course'\t(.+)$/d' "$attfile"
103 for each in $attendance; do
104 echo "$course\t$each"
106 sed -rn 's:^'$course'\t(.+)$:\1:p' "$attfile" |while read card; do
107 touch "$_DATA/vcard/$card"
110 echo "END:VEVENT\r" >>"$tempfile"
111 echo "END:VCALENDAR\r" >>"$tempfile"
112 mv "$tempfile" "$coursefile"
113 echo -n "Location: ?p=courses#$course\n\n"
117 [ -f "$coursefile" ] \
118 && echo -n "Location: ?p=courses#$course\n\n" \
119 || echo -n "Location: ?p=courses\n\n"
122 rm "$tempfile" "$coursefile"
123 echo -n "Location: ?p=courses\n\n"
126 echo "END:VEVENT\r" >>"$tempfile"
127 echo "END:VCALENDAR\r" >>"$tempfile"
128 echo -n "Location: ?p=courses&edit=$course\n\n"