X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=therapies%2Fupdate_therapy.sh;h=c72d0408de3af39e0c5606a72f7f9476e460c25f;hb=0f24ecb921cf09e1760a3a4f08197b5c260d7c16;hp=dafa1b20692d474484eb3f5b24ff5d69496272dc;hpb=3e174383701ddbfb7d4dee4c350e30387b1770f4;p=lobster diff --git a/therapies/update_therapy.sh b/therapies/update_therapy.sh index dafa1b2..c72d040 100755 --- a/therapies/update_therapy.sh +++ b/therapies/update_therapy.sh @@ -18,15 +18,35 @@ # along with Confetti. If not, see . . "$_EXEC/pdiread.sh" -tpy=$(POST id) +tpy="$(POST id)" tpyfile="$_DATA/therapies/${tpy}.tpy" -tempfile="$_DATA/temp/${tpy}.tpy" +tempfile="$_DATA/temp/${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) : ;; + imagedata|tid|formend) : ;; session*_date) value="$(POST "$key")" y=0 mon=0 dom=0 @@ -96,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