#!/bin/zsh
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2015 Paul Hänsch
#
# This file is part of Confetti.
#
course="${_POST[course]}"
tempfile="temp/$course"
coursefile="ical/$course"
+attfile="$_DATA/mappings/attendance"
# DURATION:
uid="${_POST[UID]}"
echo -n "Location: ?p=courses&edit=$course\n\n"
;;
update)
+ attendance=()
+ for att in attendance attendance{0..100}; do
+ [ -n "${_POST[$att]}" ] && attendance+=("${_POST[$att]}")
+ done
+ sed -rn 's:^'$course'\t(.+)$:\1:p' "$attfile" |while read card; do
+ touch "$_DATA/vcard/$card"
+ done
+ sed -i -r '/^'$course'\t(.+)$/d' "$attfile"
+ for each in $attendance; do
+ echo "$course\t$each"
+ done >>"$attfile"
+ sed -rn 's:^'$course'\t(.+)$:\1:p' "$attfile" |while read card; do
+ touch "$_DATA/vcard/$card"
+ done
+
echo "END:VEVENT\r" >>"$tempfile"
echo "END:VCALENDAR\r" >>"$tempfile"
mv "$tempfile" "$coursefile"