]> git.plutz.net Git - lobster/blobdiff - cards/update_card.sh
reverse session list - newest first
[lobster] / cards / update_card.sh
index c13b6ec2cbf251e4eda4b5f97363b33e900104ba..84d9c7e9b310662d403a9eb495dd8248a5796f54 100755 (executable)
@@ -49,37 +49,32 @@ 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 "$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" N 1 "$(pdi_escape "$(POST 1N)" "$(POST 2N)" "$(POST 3N)" "$(POST 4N)" "$(POST 5N)")")"
+vcf="$(pdi_update_value "$vcf" FN 1 "$(pdi_escape "$(POST 4N) $(POST 2N) $(POST 3N) $(POST 1N) $(POST 5N)" \
+                                       | sed -E 's;^ +;;; s; +$;;; s; +; ;g;')" )"
 
 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")" \
                                                           )")"
@@ -87,10 +82,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
@@ -108,7 +103,7 @@ vcf="$(printf '%s\n' "$vcf" |sed -E "/^[^:]+:delete=${delete_key}\$/d")"
 if [ "$action" = addfield ]; then
   vcf="$(pdi_update_value "$vcf" "$newfield" $(( $(pdi_count "$vcf" "$newfield") + 1 )) '')"
 fi
-printf '%s' "$vcf" |grep -vx '' >"$tempfile"
+printf '%s' "$vcf" | sed -E '/^$/d; s/^([^:]+);:/\1:/;' >"$tempfile"
 
 case "$action" in
   addfield)