3 # Copyright 2016, 2020 Paul Hänsch
5 # This file is part of Confetti.
7 # Confetti is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Confetti is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
24 tpyfile="$_DATA/therapies/${tpy}.tpy"
25 tempfile="$_DATA/temp/${tpy}.tpy"
27 # serialize POST array into file
28 for key in $(POST_KEYS); do
29 [ "$key" != imagedata ] && printf %s:%s\\n "$key" "$(POST "$key" |sed ':X;N;$!bX; s;\n;\\n;g;')"
32 if [ "$(POST delete_session)" ]; then
33 n="$(POST delete_session)"
34 sed -Ei '/^session'$n'[_:]/d' "$tempfile"
35 rm "${tpyfile%.tpy}_session${n}.png"
37 while grep -Eq '^session'$(($n + 1))'_' "$tempfile"; do
38 sed -Ei 's;^session'$(($n + 1))'(_|:);session'$n'\1;' "$tempfile"
39 mv "${tpyfile%.tpy}_session$(($n+1)).png" "${tpyfile%.tpy}_session${n}.png"
43 elif [ "$(POST new_session)" ]; then
44 sid="$(POST new_session)"
46 read junkx junky dim junkz <<-E_READ
47 $(identify "$_EXEC/therapies/therapy_background.png")
50 convert -size "$dim" xc:transparent "${tpyfile%.tpy}_${sid}.png"
52 printf '%s:exists\n' "$sid" >>"$tempfile"
53 printf '%s_open:checked\n' "$sid" >>"$tempfile"
55 elif [ "$(POST imagedata)" ]; then
56 sid="$(sed -En 's;^(session[0-9]+)_open:checked$;\1;p' "$tempfile" \
61 convert "${tpyfile%.tpy}_${sid}.png" \
62 -draw "$(POST imagedata)" -transparent white \
63 "${tpyfile%.tpy}_${sid}.png"
67 mv "$tempfile" "$tpyfile"
69 REDIRECT "/therapies/${tpy%.*}/${tpy#*.}"