]> git.plutz.net Git - lobster/blob - therapies/index.cgi
6284c0033f504e53422e5c09cedade5fb4598811
[lobster] / therapies / index.cgi
1 #!/bin/sh
2
3 # Copyright 2016, 2020 Paul Hänsch
4 #
5 # This file is part of Lobster.
6
7 # Lobster 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.
11
12 # Lobster 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.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Lobster.  If not, see <http://www.gnu.org/licenses/>. 
19
20 case "$_PATH" in
21   /therapies/therapy.css)
22     . $_EXEC/cgilite/file.sh
23     FILE $_EXEC/therapies/therapy.css
24     return 0
25     ;;
26   /therapies/*.*_session*.png)
27     if [ -r "$_DATA/$_PATH" ]; then
28       . $_EXEC/cgilite/file.sh
29       FILE "$_DATA/$_PATH"
30     fi
31     return 0
32     ;;
33   /therapies/*/new)
34     card="${_PATH#/therapies/}"
35     card="${card%/new}"
36     uid="$(timeid)$(randomid)"
37     if [ -f "${_DATA}/vcard/${card}.vcf" ]; then
38       touch "${_DATA}/therapies/${card}.${uid}.tpy"
39       rm -f "${_DATA}/cache/${card}.vcf.cache"
40       REDIRECT "/therapies/${card}/${uid}"
41     fi
42     return 0
43     ;;
44 esac
45
46 . $_EXEC/pdiread.sh
47 . $_EXEC/therapies/l10n.sh
48
49 id="${_PATH#/therapies/}"
50 id="${id%/*}.${id#*/}"
51
52 read junkx junky bg_dim junkz <<-E_READ
53         $(identify "$_EXEC/therapies/therapy_background.png")
54 E_READ
55
56 vcffile="${_DATA}/vcard/${id%.*}.vcf"
57 mpxfile="${_DATA}/prescriptions/${id}.mpx"
58 tpyfile="${_DATA}/therapies/${id}.tpy"
59
60 vcf="$(pdi_load "$vcffile")"
61 mpx="$(sed '1s;^;\n;; s/:/;:/' "$mpxfile")"
62 tpy="$(sed '1s;^;\n;; s/:/;:/' "$tpyfile")"
63
64 VCF(){ pdi_value "$vcf" "$@"; }
65 MPX(){ pdi_value "$mpx" "$@"; }
66 TPY(){ pdi_value "$tpy" "$@" >/dev/null && pdi_value "$tpy" "$@" |pdi_unescape; }
67
68 . $_EXEC/therapies/page.sh \
69 | yield_page therapy /therapies/therapy.css