seed field for entering card record from spreadsheet
authorPaul Hänsch <paul@plutz.net>
Tue, 2 Feb 2021 13:06:22 +0000 (14:06 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 2 Feb 2021 13:06:22 +0000 (14:06 +0100)
cards/index.cgi
cards/new_card.sh
style.css

index 933b1d1..e25843c 100755 (executable)
@@ -18,8 +18,12 @@ edit="${edit##*/}"
   printf '
   [form class="newcard" action="/cards/new_card.sh" method="POST"
     [button type="submit" %s]
-  ]' "$(l10n newcard)"
-
+    [input name="seed" placeholder="%s %s      %s      %s      %s      %s      %s      ()      %s      ()      %s"]
+  ]' "$(l10n newcard)" \
+     "$(l10n X-ZACK-JOINDATE)" "$(l10n n_first)" "$(l10n n_last)" \
+     "$(l10n BDAY) $(l10n month)" "$(l10n BDAY) $(l10n year)" \
+     "$(l10n TEL)" "$(l10n TEL) $(l10n 'TYPE=CELL')" "$(l10n EMAIL)" \
+     "$(l10n NOTE)"
   [ "$edit" ] && edit_card "$edit"
   list_cards
 } | yield_page cards #/cards/cards.css
index db353e1..1e37b70 100755 (executable)
@@ -23,6 +23,22 @@ order="$(REF o)"
 uid="$(timeid)$(randomid)"  # 32 Octets UID, starting with timestamp
 card="${uid}.vcf"
 
+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'
+}
+
+IFS='|' read -r date fn ln bmonth byear tel tcell junk1 email junk2 note <<-EOF
+       $(POST seed |tr \\t \|)
+       EOF
+
+[ ${#byear} = 1 ] && byear="200$byear"
+[ ${#byear} = 2 ] && byear="20$byear"
+[ ${#bmonth} = 1 ] && bmonth="0$bmonth"
+
 mkdir -p "${_DATA}/lock/vcard/"
 lockdir="${_DATA}/lock/vcard/${card}/"
 lockfile=${lockdir}/${SESSION_ID}
@@ -31,12 +47,15 @@ if mkdir "$lockdir"; then
   cat >"$lockfile" <<-EOF
        BEGIN:VCARD
        VERSION:4.0
-       N:;;;;
-       BDAY:
-       TEL:
-       EMAIL:
+       N:$(vcf_escape "$ln");$(vcf_escape "$fn");;;
+       FN:$(vcf_escape "$fn $ln")
+       BDAY:$(vcf_escape "${byear}-${bmonth}-01")
+       TEL:$(vcf_escape "$tel")
+       TEL;TYPE=CELL:$(vcf_escape "$tcell")
+       EMAIL:$(vcf_escape "$email")
+       X-ZACK-JOINDATE:$(vcf_escape "$date")
        ADR:
-       NOTE:
+       NOTE:$(vcf_escape "$note")
        UID:${uid}
        END:VCARD
        EOF
index 83ceae7..e02a695 100644 (file)
--- a/style.css
+++ b/style.css
@@ -171,6 +171,9 @@ form.filter button[type=submit] {
 
 body.courses form .order { display: inline-block; margin-right: 2em;}
 
+body.cards form.newcard { display: flex; }
+body.cards form.newcard input[name=seed] { flex: 1; }
+
 
 /* ============ LIST ITEMS, Generic ============= */