X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=sidebyside;f=actions%2Fupdate_card.sh;h=a1143c3d72057359ef7b42a07c919c3d21ef33f4;hb=0dc31a9e7992c227b680180d3ceee031ac293169;hp=2250f1967abc5edb8a66c4b83ddc73527b27b437;hpb=69e661b5c8ec195bd3c4998a623a60607b47059e;p=lobster
diff --git a/actions/update_card.sh b/actions/update_card.sh
index 2250f19..a1143c3 100755
--- a/actions/update_card.sh
+++ b/actions/update_card.sh
@@ -1,6 +1,6 @@
#!/bin/zsh
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2016 Paul Hänsch
#
# This file is part of Confetti.
#
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Confetti. If not, see .
-cgi_post
cgi_refdata
filter="&filter=${_REF[filter]}"
@@ -29,32 +28,47 @@ tempfile="$_DATA/temp/$card"
cardfile="$_DATA/vcard/$card"
attfile="$_DATA/mappings/attendance"
-_POST[0N]="$(echo "${_POST[0N]}" |sed 's:;: :')"
-_POST[1N]="$(echo "${_POST[1N]}" |sed 's:;: :')"
-_POST[2N]="$(echo "${_POST[2N]}" |sed 's:;: :')"
-_POST[3N]="$(echo "${_POST[3N]}" |sed 's:;: :')"
-_POST[4N]="$(echo "${_POST[4N]}" |sed 's:;: :')"
+vcf_escape(){
+ for each in "$@"; do
+ printf %s\\n "$each" \
+ | sed -r ':X;$!{N;bX}; s;\r\n;\n;g; s;([;,\\]);\\\1;g; s;\n;\\n;g;'
+ done \
+ | sed -r ':X;$!{N;bX}; s;\n;\;;g'
+}
-echo "BEGIN:VCARD\r" >"$tempfile"
-echo "VERSION:4.0\r" >>"$tempfile"
-echo "N:${_POST[0N]};${_POST[1N]};${_POST[2N]};${_POST[3N]};${_POST[4N]}\r" >>"$tempfile"
-echo "UID:${_POST[UID]}\r" >>"$tempfile"
-for field in $VCF_FIELDS; do
- value="${_POST[$field]}"
- n=0
- while [ -n "$value" ]; do
- value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')"
- echo "${field}:${value}\r"
- value="${_POST[$field$n]}"
- n=$(($n + 1))
- done
-done >>"$tempfile"
+[ "${_POST[hi_select]}" = "list" ] || _POST[hi_company]="${_POST[hi_other]}"
+[ -n "${_POST[hi_company]}${_POST[hi_number]}${_POST[hi_status]}" ] \
+&& _POST[X-HEALTH-INSURANCE]="$(vcf_escape "${_POST[hi_company]}" "${_POST[hi_number]}" "${_POST[hi_status]}")"
+
+sed -r 's;$;\r;' >"$tempfile" <>"$tempfile"
- echo "END:VCARD\r" >>"$tempfile"
- echo -n "Location: ?p=cards${filter}${filtertype}${order}&edit=$card\n\n"
+ redirect "?p=cards${filter}${filtertype}${order}&edit=$card"
;;
update)
attendance=()
@@ -72,18 +86,17 @@ case "${_POST[action]}" in
touch "$_DATA/ical/$course"
done
- echo "END:VCARD\r" >>"$tempfile"
mv "$tempfile" "$cardfile"
- echo -n "Location: ?p=cards${filter}${filtertype}${order}#$card\n\n"
+ redirect "?p=cards${filter}${filtertype}${order}#$card"
;;
cancel)
rm "$tempfile"
[ -f "$cardfile" ] \
- && echo -n "Location: ?p=cards${filter}${filtertype}${order}#$card\n\n" \
- || echo -n "Location: ?p=cards${filter}${filtertype}${order}\n\n"
+ && redirect "?p=cards${filter}${filtertype}${order}#$card" \
+ || redirect "?p=cards${filter}${filtertype}${order}"
;;
delete)
rm "$tempfile" "$cardfile"
- echo -n "Location: ?p=cards${filter}${filtertype}${order}\n\n"
+ redirect "?p=cards${filter}${filtertype}${order}"
;;
esac