X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=sidebyside;f=cards%2Fupdate_card.sh;h=84d9c7e9b310662d403a9eb495dd8248a5796f54;hb=369cfbad801d25084da063f8ad3250dee9442fa9;hp=a1143c3d72057359ef7b42a07c919c3d21ef33f4;hpb=43e7c60df0632fd383306a2d3c6dc8c4213d4b9d;p=lobster
diff --git a/cards/update_card.sh b/cards/update_card.sh
index a1143c3..84d9c7e 100755
--- a/cards/update_card.sh
+++ b/cards/update_card.sh
@@ -1,6 +1,6 @@
#!/bin/zsh
-# Copyright 2014, 2016 Paul Hänsch
+# Copyright 2014, 2016, 2019 Paul Hänsch
#
# This file is part of Confetti.
#
@@ -17,86 +17,127 @@
# You should have received a copy of the GNU Affero General Public License
# along with Confetti. If not, see .
-cgi_refdata
+. "$_EXEC/pdiread.sh"
+. "$_EXEC/session_lock.sh"
-filter="&filter=${_REF[filter]}"
-filtertype="&filtertype=${_REF[filtertype]}"
-order="&order=${_REF[order]}"
+unset filter order card action newfield
+unset cardfile attfile tempfile
+unset vcf field cnt delete_key
-card="${_POST[card]}"
-tempfile="$_DATA/temp/$card"
-cardfile="$_DATA/vcard/$card"
+filter="$(REF f)"
+order="$(REF o)"
+
+card="$(POST card |PATH)"
+cardfile="$_DATA/vcard/${card##*/}"
attfile="$_DATA/mappings/attendance"
-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'
-}
-
-[ "${_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"
+
+case "$action" in
addfield)
- redirect "?p=cards${filter}${filtertype}${order}&edit=$card"
+ REDIRECT "/cards/?o=${order}&f=${filter}&e=${card#/}"
;;
update)
- attendance=()
- for att in attendance attendance{0..100}; do
- [ -n "${_POST[$att]}" ] && attendance+=("${_POST[$att]}")
- done
- sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
- touch "$_DATA/ical/$course"
- done
- sed -i -r '/^(.+)\t'$card'$/d' "$attfile"
- for each in $attendance; do
- echo "$each\t$card"
- done >>"$attfile"
- sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
- touch "$_DATA/ical/$course"
- done
-
- mv "$tempfile" "$cardfile"
- redirect "?p=cards${filter}${filtertype}${order}#$card"
+ # attendance=()
+ # for att in attendance attendance{0..100}; do
+ # [ -n "${_POST[$att]}" ] && attendance+=("${_POST[$att]}")
+ # done
+ # sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
+ # touch "$_DATA/ical/$course"
+ # done
+ # sed -i -r '/^(.+)\t'$card'$/d' "$attfile"
+ # for each in $attendance; do
+ # echo "$each\t$card"
+ # done >>"$attfile"
+ # sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
+ # touch "$_DATA/ical/$course"
+ # done
+
+ cp "$tempfile" "$cardfile"
+ RELEASE_SLOCK "$cardfile"
+ REDIRECT "/cards/?o=${order}&f=${filter}#${card#/}"
;;
cancel)
- rm "$tempfile"
+ RELEASE_SLOCK "$cardfile"
[ -f "$cardfile" ] \
- && redirect "?p=cards${filter}${filtertype}${order}#$card" \
- || redirect "?p=cards${filter}${filtertype}${order}"
+ && REDIRECT "/cards/?o=${order}&f=${filter}#${card#/}" \
+ || REDIRECT "/cards/?o=${order}&f=${filter}"
;;
delete)
- rm "$tempfile" "$cardfile"
- redirect "?p=cards${filter}${filtertype}${order}"
+ rm "$cardfile"
+ RELEASE_SLOCK "$cardfile"
+ REDIRECT "/cards/?o=${order}&f=${filter}"
;;
esac