]> git.plutz.net Git - confetti/blobdiff - actions/update_card.sh
moved some decision logic out of template
[confetti] / actions / update_card.sh
index 1be16765cd20e8f0bf9340679e1da274606e5edf..f18c9ee3e659832c2da4e568a967385188220bf9 100755 (executable)
@@ -34,8 +34,10 @@ _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]//;/,}"
+
+[ "$_POST[hi_select]" = "list" ] && hi_company="${_POST[hi_company]}" || hi_company="${_POST[hi_other]}"
+[ -n "${_POST[hi_company]}${_POST[hi_number]}${_POST[hi_status]}" ] \
+&& _POST[X-HEALTH-INSURANCE]="${hi_company//;/,};${_POST[hi_number]//;/,};${_POST[hi_status]//;/,}"
 
 sed -r 's;$;\r;' >"$tempfile" <<EOF
 BEGIN:VCARD
@@ -45,9 +47,10 @@ UID:${_POST[UID]}
 $(
 for field in $VCF_FIELDS; do
   for key in $field $field{0..100}; do
-    [ -z "$_POST[$key]" ] && break
+    [ -z "${_POST[$key]+x}" ] && break
     value="$(printf %s "$_POST[$key]" |sed -r ':a;N;$!ba;s:\n:\\n:g;s:\r:\\r:g')"
-    printf '%s:%s\n' "${field}" "$value"
+    [ "${key%%[0-9]*}" = TEL ] && tag="TYPE=${_POST[phonetype${key#TEL}]}" || tag=''
+    [ -n "$value" ] && printf '%s:%s\n' "${field}${tag:+;$tag}" "$value"
   done
 done
 [ "${_POST[action]}" = addfield ] && printf '%s:\n' "${_POST[newfield]}"