PHP7 project, commit 1.
[openemr.git] / contrib / forms / psychiatrySet / psychiatrisch_onderzoek / autosave.php
blob7c90fa11b4f9e442abfd08baa19a0f0191ed0cf3
1 <?php
2 ////////////////////////////////////////////////////////////////////
3 // Form: Psychiatrisch Onderzoek - Autosave
4 // Package: Psychiatric Research - Dutch specific form
5 // Created by: Larry Lart
6 // Version: 1.0 - 29-03-2008
7 ////////////////////////////////////////////////////////////////////
9 //local includes
10 include_once("../../globals.php");
11 include_once("$srcdir/api.inc");
12 include_once("$srcdir/forms.inc");
15 // escape the strings
16 foreach ($_POST as $k => $var)
18 $_POST[$k] = add_escape_custom($var);
19 // echo "$var\n";
22 /////////////////
23 // here we check to se if there was an autosave version prior to the real save
24 $vectAutosave = sqlQuery( "SELECT id, autosave_flag, autosave_datetime FROM form_psychiatrisch_onderzoek
25 WHERE pid = ".$_SESSION["pid"].
26 " AND groupname='".$_SESSION["authProvider"].
27 "' AND user='".$_SESSION["authUser"]."' AND
28 authorized=$userauthorized AND activity=1
29 AND autosave_flag=1
30 ORDER by id DESC limit 1" );
32 // if yes then update this else insert
33 if( $vectAutosave['autosave_flag'] == 1 || $_POST["mode"] == "update" )
35 if( $_POST["mode"] == "update" )
36 $newid = $_POST["id"];
37 else
38 $newid = $vectAutosave['id'];
40 $strSql = "UPDATE form_psychiatrisch_onderzoek
41 SET pid = ".$_SESSION["pid"].", groupname='".$_SESSION["authProvider"]."', user='".$_SESSION["authUser"]."',
42 authorized=$userauthorized, activity=1, date = NOW(),
43 datum_onderzoek='".$_POST["datum_onderzoek"]."',
44 reden_van_aanmelding='".$_POST["reden_van_aanmelding"]."',
45 conclusie_van_intake='".$_POST["conclusie_van_intake"]."',
46 medicatie='".$_POST["medicatie"]."',
47 anamnese='".$_POST["anamnese"]."',
48 psychiatrisch_onderzoek='".$_POST["psychiatrisch_onderzoek"]."',
49 beschrijvende_conclusie='".$_POST["beschrijvende_conclusie"]."',
50 behandelvoorstel='".$_POST["behandelvoorstel"]."',
51 autosave_flag=1,
52 autosave_datetime=NOW()
53 WHERE id = ".$newid.";";
55 sqlQuery( $strSql );
57 //echo "DEBUG :: id=$newid, sql=$strSql<br>";
59 } else
61 $newid = formSubmit( "form_psychiatrisch_onderzoek", $_POST, $_GET["id"], $userauthorized );
62 addForm( $encounter, "Psychiatric Examination", $newid, "psychiatrisch_onderzoek", $pid, $userauthorized );
64 //echo "Debug :: insert<br>";
68 //get timestamp
69 $result = sqlQuery("SELECT autosave_datetime FROM form_psychiatrisch_onderzoek
70 WHERE pid = ".$_SESSION["pid"].
71 " AND groupname='".$_SESSION["authProvider"].
72 "' AND user='".$_SESSION["authUser"]."' AND
73 authorized=$userauthorized AND activity=1 AND id=$newid
74 AND autosave_flag=1
75 ORDER by id DESC limit 1" );
76 //$timestamp = mysql_result($result, 0);
78 //output timestamp
79 echo xl('Last Saved') . ': '.$result['autosave_datetime'];