X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=cards%2Fupdate_card.sh;h=7bfca2f3ab7d67a54135bc1f0a9683587a3195d5;hb=f703db26c2ea1e49e7580452ef0ee89557b18525;hp=fd0b2102ca0d352656e500837d65477a1e11838d;hpb=da1c1d9c76c6912ae2f2ff776b98d59bd4482618;p=lobster diff --git a/cards/update_card.sh b/cards/update_card.sh index fd0b210..7bfca2f 100755 --- a/cards/update_card.sh +++ b/cards/update_card.sh @@ -1,6 +1,6 @@ -#!/bin/zsh +#!/bin/sh -# Copyright 2014, 2016, 2019 Paul Hänsch +# Copyright 2014, 2016, 2019, 2020, 2021 Paul Hänsch # # This file is part of Confetti. # @@ -19,17 +19,17 @@ . "$_EXEC/pdiread.sh" . "$_EXEC/session_lock.sh" +. "$_EXEC/cgilite/storage.sh" unset filter order card action newfield -unset cardfile attfile tempfile +unset cardfile tempfile unset vcf field cnt delete_key filter="$(REF f)" order="$(REF o)" -card="$(POST card |PATH)" -cardfile="$_DATA/vcard/${card##*/}" -attfile="$_DATA/mappings/attendance" +card="$(POST card |PATH)"; card="${card##*/}" +cardfile="$_DATA/vcard/${card}" action="$(POST action)" newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')" @@ -49,40 +49,35 @@ elif [ "$(POST tid)" != "$(transid "$tempfile")" ]; then exit 0 fi -vcf_escape(){ - for each in "$@"; do - printf %s\\n "$each" \ - | sed -E ':X;$!{N;bX}; s;\r\n;\n;g; s;([;,\\]);\\\1;g; s;\n;\\n;g;' - done \ - | sed -E ':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]}")" +# && _POST[X-HEALTH-INSURANCE]="$(pdi_escape "${_POST[hi_company]}" "${_POST[hi_number]}" "${_POST[hi_status]}")" -# vcf="$(pdi_load "$cardfile")" vcf="$(pdi_load "$tempfile")" -vcf="$(pdi_update_value "$vcf" N 1 "$(vcf_escape "$(POST 1N)" "$(POST 2N)" "$(POST 3N)" "$(POST 4N)" "$(POST 5N)")")" -vcf="$(pdi_update_value "$vcf" FN 1 "$(vcf_escape "$(POST 4N) $(POST 2N) $(POST 3N) $(POST 1N) $(POST 5N)" \ - | sed -E 's;^ +;;; s; +$;;; s; +; ;g;')" )" +n1="$(POST 1N)" n2="$(POST 2N)" n3="$(POST 3N)" n4="$(POST 4N)" n5="$(POST 5N)" +# 3N (Middle Names) is not actually used +n3="${n2#${n2%% *}}" + +vcf="$(pdi_update_value "$vcf" N 1 "$(pdi_escape "$n1" "${n2%% *}" "${n3# }" "$n4" "$n5")")" +vcf="$(pdi_update_value "$vcf" FN 1 "$(pdi_escape "$n4 $n2 $n1 $n5" |sed -E 's;(^ +| +$);;g; s; +; ;g;')")" +vcf="$(printf '%s\n' "$vcf" |sed -E "/^CATEGORIES;[^:]*:.*$/d")" for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do for cnt in $(seq 1 $(POST_COUNT "$field")); do case "$field" in # (TEL) - # printf '%s;TYPE=%s:%s\r\n' "${field}" "${_POST[phonetype${key#TEL}]}" "$(vcf_escape "$(POST "$field" "$cnt")")" + # printf '%s;TYPE=%s:%s\r\n' "${field}" "${_POST[phonetype${key#TEL}]}" "$(pdi_escape "$(POST "$field" "$cnt")")" # ;; X-HEALTH-INSURANCE) hi_select="$(POST "$field" "$cnt")" if [ "$hi_select" = list ]; then - vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "hi_company" "$cnt")" \ + vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "hi_company" "$cnt")" \ "$(POST "hi_number" "$cnt")" \ "$(POST "hi_status" "$cnt")" \ )")" elif [ "$hi_select" = other ]; then - vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "hi_other" "$cnt")" \ + vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "hi_other" "$cnt")" \ "$(POST "hi_number" "$cnt")" \ "$(POST "hi_status" "$cnt")" \ )")" @@ -90,10 +85,10 @@ for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do ;; TEL) vcf="$(pdi_update_attrib "$vcf" TEL $cnt TYPE="$(POST teltype $cnt |grep -Exm1 'HOME|WORK|CELL|FAX')")" - vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")" + vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "$field" "$cnt")")")" ;; *) - vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")" + vcf="$(pdi_update_value "$vcf" "$field" "$cnt" "$(pdi_escape "$(POST "$field" "$cnt")")")" ;; esac done; done @@ -118,21 +113,6 @@ case "$action" in 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 - cp "$tempfile" "$cardfile" RELEASE_SLOCK "$cardfile" REDIRECT "/cards/?o=${order}&f=${filter}#${card#/}"