From 4e07a73ed0ab92f276d1d8ce6942bd92651efc3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 25 Aug 2020 02:23:42 +0200 Subject: [PATCH] introduce transaction id for therapy updates --- therapies/autosave.js | 3 ++- therapies/page.sh | 2 +- therapies/update_therapy.sh | 24 +++++++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/therapies/autosave.js b/therapies/autosave.js index b4020dd..665a601 100644 --- a/therapies/autosave.js +++ b/therapies/autosave.js @@ -4,6 +4,7 @@ var formdata = ''; function postsubmit(){ if ( this.status == 200 ) { + document.querySelector('#report input[name="tid"]').setAttribute('value', this.response); console.log('successful auto submit of form data'); button.setAttribute('style', 'display: none;'); } else { @@ -18,7 +19,7 @@ function failsubmit(){ function formencode(fd){ var send; - send='autosubmit=false'; + send='autosubmit=true'; for (var tup of fd.entries()){ send += '&' + encodeURIComponent(tup[0]) + '=' + encodeURIComponent(tup[1]); } diff --git a/therapies/page.sh b/therapies/page.sh index a38372f..fb86050 100755 --- a/therapies/page.sh +++ b/therapies/page.sh @@ -152,7 +152,7 @@ fi cat <. . "$_EXEC/pdiread.sh" -tpy=$(POST id) +tpy="$(POST id)" tpyfile="$_DATA/therapies/${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 + # serialize POST array into file for key in $(POST_KEYS); do case "$key" in - imagedata) : ;; + imagedata|tid) : ;; session*_date) value="$(POST "$key")" y=0 mon=0 dom=0 @@ -96,11 +106,15 @@ 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}" else REDIRECT "/therapies/${tpy%.*}/${tpy#*.}" fi -- 2.39.2