X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=actions%2Fupdate_card.sh;h=1be16765cd20e8f0bf9340679e1da274606e5edf;hp=2250f1967abc5edb8a66c4b83ddc73527b27b437;hb=2805ee334bead55e2ab08b7c4dbdbf07dcebf8e9;hpb=3df0e6c3d9ff72b4ace395bb78582765ef4bc6fb diff --git a/actions/update_card.sh b/actions/update_card.sh index 2250f19..1be1676 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. # @@ -29,32 +29,35 @@ 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:;: :')" +_POST[0N]="${_POST[0N]//;/,}" +_POST[1N]="${_POST[1N]//;/,}" +_POST[2N]="${_POST[2N]//;/,}" +_POST[3N]="${_POST[3N]//;/,}" +_POST[4N]="${_POST[4N]//;/,}" +[ -n "${_POST[hi_number]}" -o -n "${_POST[hi_company]}" ] \ +&& _POST[X-HEALTH-INSURANCE]="${_POST[hi_number]//;/,};${_POST[hi_company]//;/,}" -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" +sed -r 's;$;\r;' >"$tempfile" <>"$tempfile" +done +[ "${_POST[action]}" = addfield ] && printf '%s:\n' "${_POST[newfield]}" +) +END:VCARD +EOF case "${_POST[action]}" in addfield) - echo "${_POST[newfield]}:\r" >>"$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 +75,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