keep filter and order settings when updating a card
[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     echo "${field}:${value}\r"
23     value="$_POST[\"$field$n\"]"
24     n=$(($n + 1))
25   done
26 done >>"$tempfile"
27
28 case "$_POST[\"action\"]" in
29   addfield)
30     echo "$_POST[\"newfield\"]:\r" >>"$tempfile"
31     echo "END:VCARD\r" >>"$tempfile"
32     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}&edit=$card\n\n"
33     ;;
34   update)
35     echo "END:VCARD\r" >>"$tempfile"
36     mv "$tempfile" "$cardfile"
37     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n"
38     ;;
39   cancel)
40     rm "$tempfile"
41     [ -f "$cardfile" ] \
42       && echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}#$card\n\n" \
43       || echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
44     ;;
45   delete)
46     rm "$tempfile" "$cardfile"
47     echo -n "Location: http://$HTTP_HOST/?page=attendees${filter}${filtertype}${order}\n\n"
48     ;;
49 esac