X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=cards%2Fnew_card.sh;fp=cards%2Fnew_card.sh;h=0273a2cb44ac481c2c6f7554e3e3782a855be3a0;hp=0000000000000000000000000000000000000000;hb=76c1e7bff1a8604ef2ef7da5d274d0db0e639139;hpb=90288ab07bb1ec83a91581fadc674a87a250a853 diff --git a/cards/new_card.sh b/cards/new_card.sh new file mode 100755 index 0000000..0273a2c --- /dev/null +++ b/cards/new_card.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# Copyright 2014, 2019 Paul Hänsch +# +# This file is part of Confetti. +# +# Confetti is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Confetti is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Confetti. If not, see . + +filter="$(REF f)" +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" + +mn="" +case $fn in + *\ *) + mn="${fn#* }" + fn="${fn%% *}" + ;; +esac + +mkdir -p "${_DATA}/lock/vcard/" +lockdir="${_DATA}/lock/vcard/${card}/" +lockfile=${lockdir}/${SESSION_ID} + +if mkdir "$lockdir"; then + cat >"$lockfile" <<-EOF + BEGIN:VCARD + VERSION:4.0 + N:$(vcf_escape "$ln" "$fn" "$mn" "" "") + FN:$(vcf_escape "${fn}${mn:+ }${mn} ${ln}") + BDAY:$(parse_date "${byear}-${bmonth}-01") + TEL:$(vcf_escape "$tel") + TEL;TYPE=CELL:$(vcf_escape "$tcell") + EMAIL:$(vcf_escape "$email") + X-ZACK-JOINDATE:$(parse_date "$date") + ADR: + NOTE:$(vcf_escape "$note") + UID:${uid} + END:VCARD + EOF + REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" +else + SET_COOKIE session message="EDITLOCK" + REDIRECT "/cards/?o=${order}&f=${filter}" +fi