Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / library / pid.inc
blobbc0ebe0fe43f2147c599a0ca94b15bfcdb94e719
1 <?php
2 /**
3  * pid.inc
4  *
5  * @package   OpenEMR
6  * @link      http://www.open-emr.org
7  * @author    Brady Miller <brady.g.miller@gmail.com>
8  * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
9  * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
10  */
13 require_once(dirname(__FILE__). "/../interface/globals.php");
15 use OpenEMR\Common\Logging\EventAuditLogger;
17 // Function called to set the global session variable for patient id (pid) number.
18 function setpid($new_pid)
20     global $pid, $encounter;
22   // Escape $new_pid by forcing it to an integer to protect from sql injection
23     $new_pid_int = intval($new_pid);
24   // If the $new_pid was not an integer, then send an error to error log
25     if (!is_numeric($new_pid)) {
26         error_log("Critical OpenEMR Error: Attempt to set pid to following non-integer value was denied: ".$new_pid, 0);
27         error_log("Requested pid ".$new_pid, 0);
28         error_log("Returned pid ".$new_pid_int, 0);
29     }
31   // Be careful not to clear the encounter unless the pid is really changing.
32     if (!isset($_SESSION['pid']) || $pid != $new_pid_int || $pid != $_SESSION['pid']) {
33         $_SESSION['encounter'] = $encounter = 0;
34     }
36   // unset therapy_group session when set session for patient
37     if ($_SESSION['pid'] != 0 && isset($_SESSION['therapy_group'])) {
38         unset($_SESSION['therapy_group']);
39     }
42   // Set pid to the escaped pid
43     $_SESSION['pid'] = $new_pid_int;
44     $pid = $new_pid_int;
46     EventAuditLogger::instance()->newEvent("view", $_SESSION["authUser"], $_SESSION["authProvider"], 1, '', $pid);