Fix for exporting a large number of lists.
[openemr.git] / library / calendar.inc
blob061254da710f437ef6a0e485a42ed3f7a2f11ea3
1 <?php
3 /**
4  * Holds functions for the calendar, one is for holidays
5  * @package   OpenEMR
6  * @link      https://www.open-emr.org
7  * @author    Brady Miller <brady.g.miller@gmail.com>
8  * @copyright Copyright (c) 2005 Brady Miller <brady.g.miller@gmail.com>
9  * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 //Require once the holidays controller for the is_holiday() function
13 require_once($GLOBALS['incdir'] . "/main/holidays/Holidays_Controller.php");
15 // Returns an array of the facility ids and names that the user is allowed to access.
16 // Access might be for inventory purposes ($inventory=true) or calendar purposes.
18 function getUserFacilities($uID, $orderby = 'id', $inventory = false)
20     $restrict = $inventory ? $GLOBALS['gbl_fac_warehouse_restrictions'] : $GLOBALS['restrict_user_facility'];
21     if ($restrict) {
22         // No entries in this table means the user is not restricted.
23         $countrow = sqlQuery(
24             "SELECT count(*) AS count FROM users_facility WHERE " .
25             "tablename = 'users' AND table_id = ?",
26             array($uID)
27         );
28     }
29     if (!$restrict || empty($countrow['count'])) {
30         $rez = sqlStatement(
31             "SELECT id, name, color FROM facility " .
32             "ORDER BY $orderby"
33         );
34     } else {
35         // This query gets facilities that the user is authorized to access.
36         $rez = sqlStatement(
37             "SELECT f.id, f.name, f.color " .
38             "FROM facility AS f " .
39             "JOIN users AS u ON u.id = ? " .
40             "WHERE f.id = u.facility_id OR f.id IN " .
41             "(SELECT DISTINCT uf.facility_id FROM users_facility AS uf WHERE uf.tablename = 'users' AND uf.table_id = u.id) " .
42             "ORDER BY f.$orderby",
43             array($uID)
44         );
45     }
46     $returnVal = array();
47     while ($row = sqlFetchArray($rez)) {
48         $returnVal[] = $row;
49     }
50     return $returnVal;
53 // Returns an array of warehouse IDs for the given user and facility.
54 function getUserFacWH($uID, $fID)
56     $res = sqlStatement(
57         "SELECT warehouse_id FROM users_facility WHERE tablename = ? " .
58         "AND table_id = ? AND facility_id = ?",
59         array('users', $uID, $fID)
60     );
61     $returnVal = array();
62     while ($row = sqlFetchArray($res)) {
63         if ($row['warehouse_id'] === '') {
64             continue;
65         }
66         $returnVal[] = $row['warehouse_id'];
67     }
68     return $returnVal;
71  /**
72  * Check if day is weekend day
73  * @param (int) $day
74  * @return boolean
75  */
76 function is_weekend_day($day)
79     if (in_array($day, $GLOBALS['weekend_days'])) {
80         return true;
81     } else {
82         return false;
83     }
86 /**
87  * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed event in the events table
88  * @param (int) $day
89  * @return boolean
90  */
91 function is_holiday($date)
93     Holidays_Controller::is_holiday($date);