]> git.plutz.net Git - confetti/blobdiff - actions/update_therapy.sh
unify view functions for cards
[confetti] / actions / update_therapy.sh
index 43a2e1fdff49cd1421765bf34f0c46e2c1a63e3a..6ba06cbd41214d84efe623d7c640020cd049d191 100755 (executable)
@@ -26,7 +26,7 @@ tempfile="$_DATA/temp/$tpy"
 
 # serialize POST array into file
 for key in ${(k)_POST}; do
-  printf %s:%s\\n "$key" "${_POST[$key]//$BR/\\n}"
+  [ "$key" != imagedata ] && printf %s:%s\\n "$key" "${_POST[$key]//$BR/\\n}"
 done >"$tempfile"
 
 if [ -n "$_POST[delete_session]" ]; then
@@ -42,13 +42,27 @@ if [ -n "$_POST[delete_session]" ]; then
 
 elif [ -n "$_POST[new_session]" ]; then
   sid="$_POST[new_session]"
-  printf '%s:exists\n' "$sid" >>"$tempfile"
 
-  identify "$_EXEC/templates/therapy_background.png" \
+  identify "$_EXEC/static/therapy_background.png" \
   | sed -r 's;^.* ([0-9]+x[0-9]+) .*$;\1;' \
   | read dim
 
   convert -size "$dim" xc:transparent "${tpyfile%.tpy}_${sid}.png"
+
+  printf '%s:exists\n' "$sid" >>"$tempfile"
+  printf '%s_open:checked\n' "$sid" >>"$tempfile"
+
+elif [ -n "$_POST[imagedata]" ]; then
+  sed -rn 's;^(session[0-9]+)_open:checked$;\1;p' "$tempfile" \
+  | sort -n \
+  | tail -n1 \
+  | read sid
+
+  convert "${tpyfile%.tpy}_${sid}.png" \
+          -strokewidth 2 -fill '#00000000' \
+          -draw "${_POST[imagedata]}" -transparent white \
+          "${tpyfile%.tpy}_${sid}.png"
+  sync
 fi
 
 mv "$tempfile" "$tpyfile"