Highway to PSR2
[openemr.git] / contrib / forms / psychiatrySet / psychiatrisch_onderzoek / autosave.php
blobfe4b63eb4157e472c2cf193e97bca9996ac4ef2d
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) {
17 $_POST[$k] = add_escape_custom($var);
18 // echo "$var\n";
21 /////////////////
22 // here we check to se if there was an autosave version prior to the real save
23 $vectAutosave = sqlQuery("SELECT id, autosave_flag, autosave_datetime FROM form_psychiatrisch_onderzoek
24 WHERE pid = ".$_SESSION["pid"].
25 " AND groupname='".$_SESSION["authProvider"].
26 "' AND user='".$_SESSION["authUser"]."' AND
27 authorized=$userauthorized AND activity=1
28 AND autosave_flag=1
29 ORDER by id DESC limit 1");
31 // if yes then update this else insert
32 if ($vectAutosave['autosave_flag'] == 1 || $_POST["mode"] == "update") {
33 if ($_POST["mode"] == "update") {
34 $newid = $_POST["id"];
35 } else {
36 $newid = $vectAutosave['id'];
39 $strSql = "UPDATE form_psychiatrisch_onderzoek
40 SET pid = ".$_SESSION["pid"].", groupname='".$_SESSION["authProvider"]."', user='".$_SESSION["authUser"]."',
41 authorized=$userauthorized, activity=1, date = NOW(),
42 datum_onderzoek='".$_POST["datum_onderzoek"]."',
43 reden_van_aanmelding='".$_POST["reden_van_aanmelding"]."',
44 conclusie_van_intake='".$_POST["conclusie_van_intake"]."',
45 medicatie='".$_POST["medicatie"]."',
46 anamnese='".$_POST["anamnese"]."',
47 psychiatrisch_onderzoek='".$_POST["psychiatrisch_onderzoek"]."',
48 beschrijvende_conclusie='".$_POST["beschrijvende_conclusie"]."',
49 behandelvoorstel='".$_POST["behandelvoorstel"]."',
50 autosave_flag=1,
51 autosave_datetime=NOW()
52 WHERE id = ".$newid.";";
54 sqlQuery($strSql);
56 //echo "DEBUG :: id=$newid, sql=$strSql<br>";
57 } else {
58 $newid = formSubmit("form_psychiatrisch_onderzoek", $_POST, $_GET["id"], $userauthorized);
59 addForm($encounter, "Psychiatric Examination", $newid, "psychiatrisch_onderzoek", $pid, $userauthorized);
61 //echo "Debug :: insert<br>";
65 //get timestamp
66 $result = sqlQuery("SELECT autosave_datetime FROM form_psychiatrisch_onderzoek
67 WHERE pid = ".$_SESSION["pid"].
68 " AND groupname='".$_SESSION["authProvider"].
69 "' AND user='".$_SESSION["authUser"]."' AND
70 authorized=$userauthorized AND activity=1 AND id=$newid
71 AND autosave_flag=1
72 ORDER by id DESC limit 1");
73 //$timestamp = mysql_result($result, 0);
75 //output timestamp
76 echo xl('Last Saved') . ': '.$result['autosave_datetime'];