show attendees in course list
[confetti] / actions / update_attendee.sh
1 #!/bin/zsh
2
3 cgi_post
4 cgi_refdata
5
6 filter="&filter=$_REF[\"filter\"]"
7 filtertype="&filtertype=$_REF[\"filtertype\"]"
8 order="&order=$_REF[\"order\"]"
9
10 card="$_POST[\"card\"]"
11 tempfile="$_DATA/temp/$card"
12 cardfile="$_DATA/vcard/$card"
13 attfile="$_DATA/mappings/attendance"
14
15 echo "BEGIN:VCARD\r" >"$tempfile"
16 echo "VERSION:4.0\r" >>"$tempfile"
17 echo "N:$_POST[\"0N\"];$_POST[\"1N\"];$_POST[\"2N\"];$_POST[\"3N\"];$_POST[\"4N\"]\r" >>"$tempfile"
18 echo "UID:$_POST[\"UID\"]\r" >>"$tempfile"
19 for field in $VCF_FIELDS; do
20   value="$_POST[\"$field\"]"
21   n=0
22   while [ -n "$value" ]; do
23     value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')"
24     echo "${field}:${value}\r"
25     value="$_POST[\"$field$n\"]"
26     n=$(($n + 1))
27   done
28 done >>"$tempfile"
29
30 case "$_POST[\"action\"]" in
31   addfield)
32     echo "$_POST[\"newfield\"]:\r" >>"$tempfile"
33     echo "END:VCARD\r" >>"$tempfile"
34     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}&edit=$card\n\n"
35     ;;
36   update)
37     attendance=()
38     for att in attendance attendance{0..100}; do
39       [ -n "$_POST[\"$att\"]" ] && attendance+=("$_POST[\"$att\"]")
40     done
41     sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
42       touch "$_DATA/ical/$course"
43     done
44     sed -i -r '/^(.+)\t'$card'$/d' "$attfile"
45     for each in $attendance; do
46       echo "$each\t$card"
47     done >>"$attfile"
48     sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
49       touch "$_DATA/ical/$course"
50     done
51
52     echo "END:VCARD\r" >>"$tempfile"
53     mv "$tempfile" "$cardfile"
54     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n"
55     ;;
56   cancel)
57     rm "$tempfile"
58     [ -f "$cardfile" ] \
59       && echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n" \
60       || echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
61     ;;
62   delete)
63     rm "$tempfile" "$cardfile"
64     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
65     ;;
66 esac