3 # Copyright 2014 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"
29 tzid=$(cat /etc/timezone)
30 tstamp=$(TZ="$tzid" date +%Y%m%dT%H%M%S)
32 dts_year="${_POST[DTSYEAR]}"
33 dts_month="${_POST[DTSMONTH]}"
34 dts_day="${_POST[DTSDAY]}"
35 [ -n "${_POST[DTSDAY0]}" ] && dts_day="${_POST[DTSDAY0]}"
36 dts_hour="${_POST[DTSHOUR]}"
37 dts_minute="${_POST[DTSMINUTE]}"
39 [ -z $dts_year ] && dts_year=$(date +%Y)
40 [ -z $dts_month ] && dts_month=$(date +%m)
41 [ -z $dts_day ] && dts_day=$(date +%d)
42 date -d ${dts_year}-${dts_month}-${dts_day} >/dev/null 2>/dev/null || dts_day="01"
43 [ -z $dts_hour ] && dts_hour=$(date +%H)
44 [ -z $dts_minute ] && dts_minute=$(date +%M)
46 dtstart="TZID=${tzid}:${dts_year}${dts_month}${dts_day}T${dts_hour}${dts_minute}00"
48 rr_int="${_POST[RRULE_INTERVAL]}"
49 rr_freq="${_POST[RRULE_FREQ]}"
50 rr_limit="${_POST[RRULE_LIMIT]}"
53 rrule="FREQ=$rr_freq;INTERVAL=$rr_int"
56 t="${_POST[RRULE_COUNT]}"
57 rrule="FREQ=$rr_freq;INTERVAL=$rr_int;COUNT=$t"
60 uy="${_POST[RRULE_UYEAR]}"
61 um="${_POST[RRULE_UMONTH]}"
62 ud="${_POST[RRULE_UDAY]}"
63 rrule="FREQ=$rr_freq;INTERVAL=$rr_int;UNTIL=${uy}${um}${ud}T000000Z"
67 echo "BEGIN:VCALENDAR\r" >"$tempfile"
68 echo "VERSION:2.0\r" >>"$tempfile"
69 echo "PRODID:Berlin RAW Confetti\r" >>"$tempfile"
70 echo "BEGIN:VEVENT\r" >>"$tempfile"
71 echo "UID:$uid\r" >>"$tempfile"
72 echo "DTSTAMP:TZID=${tzid}:${tstamp}\r" >>"$tempfile"
73 echo "DTSTART:${dtstart}\r" >>"$tempfile"
74 echo "RRULE:${rrule}\r" >>"$tempfile"
75 for field in SUMMARY COMMENT; do
76 value="${_POST[$field]}"
78 while [ -n "$value" ]; do
79 value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')"
80 echo "${field}:${value}\r"
81 value="${_POST[$field$n]}"
86 case "${_POST[action]}" in
88 echo "${_POST[newfield]}:\r" >>"$tempfile"
89 echo "END:VEVENT\r" >>"$tempfile"
90 echo "END:VCALENDAR\r" >>"$tempfile"
91 echo -n "Location: ?p=courses&edit=$course\n\n"
94 echo "END:VEVENT\r" >>"$tempfile"
95 echo "END:VCALENDAR\r" >>"$tempfile"
96 mv "$tempfile" "$coursefile"
97 echo -n "Location: ?p=courses#$course\n\n"
101 [ -f "$coursefile" ] \
102 && echo -n "Location: ?p=courses#$course\n\n" \
103 || echo -n "Location: ?p=courses\n\n"
106 rm "$tempfile" "$coursefile"
107 echo -n "Location: ?p=courses\n\n"
110 echo "END:VEVENT\r" >>"$tempfile"
111 echo "END:VCALENDAR\r" >>"$tempfile"
112 echo -n "Location: ?p=courses&edit=$course\n\n"