]> git.plutz.net Git - confetti/blobdiff - cards/update_card.sh
improved styling for pdf export
[confetti] / cards / update_card.sh
index 52ccfcda6e2d7cefe3106866055e462b09657350..bf8bce170698a24fd0ed914a7945160b86616500 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/zsh
 
-# Copyright 2014, 2016, 2019 Paul Hänsch
+# Copyright 2014, 2016, 2019, 2020 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 
 . "$_EXEC/pdiread.sh"
 . "$_EXEC/session_lock.sh"
+. "$_EXEC/cgilite/storage.sh"
+
+unset filter order card action newfield
+unset cardfile attfile tempfile
+unset vcf field cnt delete_key
 
 filter="$(REF f)"
 order="$(REF o)"
 
-card="$(POST card)"
-cardfile="$_DATA/vcard/$card"
+card="$(POST card |PATH)"; card="${card##*/}"
+cardfile="$_DATA/vcard/${card}"
 attfile="$_DATA/mappings/attendance"
 
 action="$(POST action)"
-newfield="$(POST newfield)"
+newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')"
+
+if printf '%s\n' "$action" |grep -qxE 'addfield [A-Z][A-Z0-9]*'; then
+  newfield="${action##* }"
+  action=addfield
+fi
 
 if ! tempfile=$(CHECK_SLOCK "$cardfile"); then
   SET_COOKIE 0 message="NO VALID FILE LOCK"
@@ -92,20 +102,21 @@ case "$action" in
     REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}"
     ;;
   update)
-    # attendance=()
-    # for att in attendance attendance{0..100}; do
-    #   [ -n "${_POST[$att]}" ] && attendance+=("${_POST[$att]}")
-    # done
-    # sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
-    #   touch "$_DATA/ical/$course"
-    # done
-    # sed -i -r '/^(.+)\t'$card'$/d' "$attfile"
-    # for each in $attendance; do
-    #   echo "$each\t$card"
-    # done >>"$attfile"
-    # sed -rn 's:^(.+)'$card'$:\1:p' "$attfile" |while read course; do
-    #   touch "$_DATA/ical/$course"
-    # done
+    if LOCK "$attfile"; then
+      grep -F "        ${card}" "$attfile" |while read course junk; do
+        touch "$_DATA/ical/${course}"
+      done
+      sed -i -E "/^.+  ${card}\$/d" "$attfile"
+      seq 1 $(POST_COUNT attendance) |while read n; do
+        printf '%s     %s\n' "$(POST attendance $n)" "$card"
+      done >>"$attfile"
+      grep -F "        ${card}" "$attfile" |while read course junk; do
+        touch "$_DATA/ical/${course}"
+      done
+      RELEASE "$attfile"
+    else
+      SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS"
+    fi
 
     cp "$tempfile" "$cardfile"
     RELEASE_SLOCK "$cardfile"
@@ -120,6 +131,15 @@ case "$action" in
   delete)
     rm "$cardfile"
     RELEASE_SLOCK "$cardfile"
+    if LOCK "$attfile"; then
+      grep -F "        ${card}" "$attfile" |while read course junk; do
+        touch "$_DATA/ical/${course}"
+      done
+      sed -i -E "/^.+  ${card}\$/d" "$attfile"
+      RELEASE "$attfile"
+    else
+      SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS"
+    fi
     REDIRECT "/cards/?o=${order}&f=${filter}"
     ;;
 esac