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