X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=therapies%2Fupdate_therapy.sh;h=e084e6ddc9e7dfe361e625f44c541fdf62fd2cda;hb=b67065bfb57b072dd1c344eedabfbb545eae6629;hp=a8d78017f3abc4674e24332a1d3d3d4e8a011fc3;hpb=6d2d03223a03794d2cef013b2b204b1a4eb983a0;p=lobster diff --git a/therapies/update_therapy.sh b/therapies/update_therapy.sh index a8d7801..e084e6d 100755 --- a/therapies/update_therapy.sh +++ b/therapies/update_therapy.sh @@ -17,19 +17,38 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -BR=' -' -tpy=$(POST id) +. "$_EXEC/pdiread.sh" +tpy="$(POST id)" tpyfile="$_DATA/therapies/${tpy}.tpy" -tempfile="$_DATA/temp/${tpy}.tpy" +tempfile="$_DATA/lock/${tpy}.$$.tpy" + +if [ "$(POST tid)" != "$(transid "$tpyfile")" ]; then + if [ "$(POST autosubmit)" = "true" ]; then + printf 'Status: 409 Conflict\r\nContent-Length: 0\r\n\r\n' + exit 0 + else + SET_COOKIE session message="TRANSACTION_CONFLICT" + REDIRECT "/therapies/${tpy%.*}/${tpy#*.}" + fi +fi + +if [ "$(POST formend)" != "formend" ]; then + if [ "$(POST autosubmit)" = "true" ]; then + printf 'Status: 409 Conflict\r\nContent-Length: 0\r\n\r\n' + exit 0 + else + SET_COOKIE session message="INCOMPLETE_SUBMIT" + REDIRECT "/therapies/${tpy%.*}/${tpy#*.}" + fi +fi # serialize POST array into file for key in $(POST_KEYS); do case "$key" in - imagedata) true ;; + imagedata|tid|formend) : ;; session*_date) - value="$(POST "$key" |sed ':X;N;$!bX; s;\n;\\n;g;')" + value="$(POST "$key")" y=0 mon=0 dom=0 case $value in *.*.*) IFS=. read dom mon y <<-END @@ -58,7 +77,7 @@ for key in $(POST_KEYS); do date -d "${y}-${mon}-${dom}" + && printf %s:%s\\n "$key" "$(date -d "${y}-${mon}-${dom}" +%F)" \ || printf %s:\\n "$key" ;; - *) printf %s:%s\\n "$key" "$(POST "$key" |sed ':X;N;$!bX; s;\n;\\n;g;')" ;; + *) printf %s:%s\\n "$key" "$(pdi_escape "$(POST "$key")")" ;; esac done >"$tempfile" 2>&- @@ -97,11 +116,17 @@ elif [ "$(POST imagedata)" ]; then sync fi -mv "$tempfile" "$tpyfile" -rm -f "${_DATA}/cache/${tpy%%.*}.vcf.cache" +if ! diff -q "$tempfile" "$tpyfile" >/dev/null; then + mv "$tempfile" "$tpyfile" + rm -f -- "${_DATA}/cache/${tpy%%.*}.vcf.cache" +fi if [ "$(POST autosubmit)" = "true" ]; then - printf 'HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n' + msg="$(transid "$tpyfile")" + printf 'HTTP/1.1 200 OK\r\nContent-Length: %i\r\n\r\n%s' \ + "${#msg}" "${msg}" +elif [ "$(POST vcfreturn)" ]; then + REDIRECT "/cards/#${tpy%.*}.vcf" else REDIRECT "/therapies/${tpy%.*}/${tpy#*.}" fi