+# Copyright 2014 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 <http://www.gnu.org/licenses/>.
+
+dtstart="$values[DTSTART]"
+[ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S)
+
+echo "$dtstart" |case "$dtstart" in
+ *Z)
+ 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'
+ ;;
+ TZID*)
+ 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'
+ ;;
+ *)
+ 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'
+ ;;
+esac |read dts_date
+
+dts_year=$(date -d "$dts_date" +%Y)
+dts_month=$(date -d "$dts_date" +%m)
+dts_dom=$(date -d "$dts_date" +%d)
+dts_dow=$(date -d "$dts_date" +%u)
+dts_weekday=$(date -d "$dts_date" +%A)
+dts_hour=$(date -d "$dts_date" +%H)
+dts_min=$(date -d "$dts_date" +%M)
+dts_sec=$(date -d "$dts_date" +%S)
+
+rrule="$values[RRULE]"
+rr_int="$(echo $rrule |sed -rn 's:^.*INTERVAL=([0-9]+)(;.*)?$:\1:p')"
+rr_count="$(echo $rrule |sed -rn 's:^.*COUNT=([0-9]+)(;.*)?$:\1:p')"
+rr_freq="$(echo $rrule |sed -rn 's:^.*FREQ=(YEARLY|MONTHLY|WEEKLY|DAILY)(;.*)?$:\1:p')"
+rr_uyear="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\1:p')"
+rr_umonth="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\2:p')"
+rr_uday="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\3:p')"
+rr_udate="$(echo $rrule |sed -rn 's:^.*UNTIL=([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:p')"
+if [ -n "$rr_count" ]; then
+ rr_limit=COUNT
+elif [ -n "$rr_uyear" ]; then
+ rr_limit=UNTIL
+else
+ rr_limit=ETERN
+fi
+
+coursemail=""
+
+echo '<div id="'${id}'" class="course">'
+echo '<form action="?action=update_course" method="POST">'
+echo '<input type="hidden" name="course" value="'${id}'"/>'
+echo ' <div class="section basic">'
+echo ' <h2>'$values[SUMMARY]'</h2>'
+echo ' <span class="text">'$(date -d "$dts_date" "+%A %B %d, %Y - %H:%M") $(l10n t_oclock)'</span>'
+[ "$rr_int" -eq 1 ] \
+&& echo '<span class="text">'$(l10n s$rr_freq)'</span>' \
+|| echo '<span class="text">'$(l10n t_every) ${rr_int} $(l10n $rr_freq)'</span>'
+case "$rr_limit" in
+ COUNT)
+ m1=$(echo $rr_freq |sed -r "s:DAILY:day:g;s:WEEKLY:week:g;s:MONTHLY:month:g;s:YEARLY:year:g;")
+ m2=$(($rr_int * $rr_count))
+ echo '<span class="text">'$(l10n t_until) $(date -d "$dts_date + $m2 $m1" "+%A %B %d, %Y - %H:%M")'</span>'
+ ;;
+ UNTIL)
+ echo '<span class="text">'$(l10n t_until) $(date -d "$rr_udate" "+%A %B %d, %Y - %H:%M")'</span>'
+ ;;
+esac
+echo ' </div>'
+
+echo ' <div class="section COMMENT">'
+echo ' <h3>'$(l10n COMMENT)'</h3>'
+for n in COMMENT COMMENT{0..10}; do [ -n "$values[$n]" ] &&\
+ echo ' <p class="item COMMENT">'$(echo "$values[$n]" |sed -r "s:$:<br/>:g" )'</p>'
+done
+echo ' </div>'
+
+echo ' <div class="section attendance">'
+echo ' <h3>'$(l10n course_attendance)'</h3>'
+list_attendance "$id" |sort -k 2 |sed -r 's:^([^ ]+) (.*)$:<a class="attendance" href="?p=cards#\1">\2</a>:'
+echo ' </div>'
+
+echo ' <div class="control">'
+echo ' <a class="item" href="?action=edit_course&course='${id}'">'$(l10n edit)'</a>'
+echo ' <a class="item" href="?action=generate_courselist&course='${id}'" target="_blank">'$(l10n courselist)'</a>'
+echo ' <a class="item" href="?action=export_ical&course='${id}'">'$(l10n ics_export)'</a>'
+echo ' <a class="item" href="mailto:zack@vuesch.org?bcc='$(course_mail "$id")'">'$(l10n course_mail)'</a>'
+echo ' </div>'
+echo '<input type="hidden" name="UID" value="'$values["UID"]'"/>'
+echo '</form>'
+echo '</div>'
+