Fixes for restoreSession logic. (#4378)
[openemr.git] / library / calendar.inc
blobe3954c28ce4c2c4c8860fbb2cdc6e3b86fe0b1a0
1 <?php
3 //Require once the holidays controller for the is_holiday() function
4 require_once($GLOBALS['incdir'] . "/main/holidays/Holidays_Controller.php");
6 function getIDfromUser($name)
8     $query = "select id from users where username=? limit 1";
9     $rez = sqlStatement($query, array($name));
10     $row = sqlFetchArray($rez);
11     if (!is_numeric($row['id'])) {
12         return -1;
13     } else {
14         return $row['id'];
15     }
18 // Returns an array of the facility ids and names that the user is allowed to access.
19 // Access might be for inventory purposes ($inventory=true) or calendar purposes.
21 function getUserFacilities($uID, $orderby = 'id', $inventory = false)
23     $restrict = $inventory ? $GLOBALS['gbl_fac_warehouse_restrictions'] : $GLOBALS['restrict_user_facility'];
24     if ($restrict) {
25         // No entries in this table means the user is not restricted.
26         $countrow = sqlQuery(
27             "SELECT count(*) AS count FROM users_facility WHERE " .
28             "tablename = 'users' AND table_id = ?",
29             array($uID)
30         );
31     }
32     if (!$restrict || empty($countrow['count'])) {
33         $rez = sqlStatement(
34             "SELECT id, name, color FROM facility " .
35             "ORDER BY $orderby"
36         );
37     } else {
38         // This query gets facilities that the user is authorized to access.
39         $rez = sqlStatement(
40             "SELECT f.id, f.name, f.color " .
41             "FROM facility AS f " .
42             "JOIN users AS u ON u.id = ? " .
43             "WHERE f.id = u.facility_id OR f.id IN " .
44             "(SELECT DISTINCT uf.facility_id FROM users_facility AS uf WHERE uf.tablename = 'users' AND uf.table_id = u.id) " .
45             "ORDER BY f.$orderby",
46             array($uID)
47         );
48     }
49     $returnVal = array();
50     while ($row = sqlFetchArray($rez)) {
51         $returnVal[] = $row;
52     }
53     return $returnVal;
56 // Returns an array of warehouse IDs for the given user and facility.
57 function getUserFacWH($uID, $fID)
59     $res = sqlStatement(
60         "SELECT warehouse_id FROM users_facility WHERE tablename = ? " .
61         "AND table_id = ? AND facility_id = ?",
62         array('users', $uID, $fID)
63     );
64     $returnVal = array();
65     while ($row = sqlFetchArray($res)) {
66         if ($row['warehouse_id'] === '') {
67             continue;
68         }
69         $returnVal[] = $row['warehouse_id'];
70     }
71     return $returnVal;
74 //retrieve the name based on the username
75 function getNameFromUsername($username)
77     $query = "select * from users where username like ? and username != ''";
78     $res = sqlQuery($query, [$username]);
79     return $res;
82  /**
83  * Check if day is weekend day
84  * @param (int) $day
85  * @return boolean
86  */
87 function is_weekend_day($day)
90     if (in_array($day, $GLOBALS['weekend_days'])) {
91         return true;
92     } else {
93         return false;
94     }
97 /**
98  * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed event in the events table
99  * @param (int) $day
100  * @return boolean
101  */
102 function is_holiday($date)
104     Holidays_Controller::is_holiday($date);