simplify ui bu removing addfield drop down
[confetti] / cards / new_card.sh
index 2d6c39b..edc7bc9 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/zsh
 
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2019 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
-cgi_post
-cgi_refdata
+filter="$(REF f)"
+order="$(REF o)"
 
-filter="&filter=${_REF[filter]}"
-filtertype="&filtertype=${_REF[filtertype]}"
-order="&order=${_REF[order]}"
-
-uid=$(uuidgenerator)
+uid="$(timeid)$(randomid)"  # 32 Octets UID, starting with timestamp
 card="${uid}.vcf"
 
-tempfile="$_DATA/temp/$card"
-
-cat >"$tempfile" <<EOF
-BEGIN:VCARD
-VERSION:4.0
-N:;;;;
-BDAY:
-TEL:
-EMAIL:
-ADR:
-NOTE:
-UID:$uid
-END:VCARD
-EOF
+mkdir -p "${_DATA}/lock/vcard/"
+lockdir="${_DATA}/lock/vcard/${card}/"
+lockfile=${lockdir}/${SESSION_ID}
 
-echo -n "Location: ?p=cards${filter}${filtertype}${order}&edit=$card\n\n"
+if mkdir "$lockdir"; then
+  cat >"$lockfile" <<-EOF
+       BEGIN:VCARD
+       VERSION:4.0
+       N:;;;;
+       BDAY:
+       TEL:
+       EMAIL:
+       ADR:
+       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