implemented course section
[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="temp/$card"
12 cardfile="vcard/$card"
13
14 echo "BEGIN:VCARD\r" >"$tempfile"
15 echo "VERSION:4.0\r" >>"$tempfile"
16 echo "N:$_POST[\"0N\"];$_POST[\"1N\"];$_POST[\"2N\"];$_POST[\"3N\"];$_POST[\"4N\"]\r" >>"$tempfile"
17 echo "UID:$_POST[\"UID\"]\r" >>"$tempfile"
18 for field in $VCF_FIELDS; do
19   value="$_POST[\"$field\"]"
20   n=0
21   while [ -n "$value" ]; do
22     value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')"
23     echo "${field}:${value}\r"
24     value="$_POST[\"$field$n\"]"
25     n=$(($n + 1))
26   done
27 done >>"$tempfile"
28
29 case "$_POST[\"action\"]" in
30   addfield)
31     echo "$_POST[\"newfield\"]:\r" >>"$tempfile"
32     echo "END:VCARD\r" >>"$tempfile"
33     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}&edit=$card\n\n"
34     ;;
35   update)
36     echo "END:VCARD\r" >>"$tempfile"
37     mv "$tempfile" "$cardfile"
38     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n"
39     ;;
40   cancel)
41     rm "$tempfile"
42     [ -f "$cardfile" ] \
43       && echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n" \
44       || echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
45     ;;
46   delete)
47     rm "$tempfile" "$cardfile"
48     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
49     ;;
50 esac