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'])) {
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'];
25 // No entries in this table means the user is not restricted.
27 "SELECT count(*) AS count FROM users_facility WHERE " .
28 "tablename = 'users' AND table_id = ?",
32 if (!$restrict || empty($countrow['count'])) {
34 "SELECT id, name, color FROM facility " .
38 // This query gets facilities that the user is authorized to access.
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",
50 while ($row = sqlFetchArray($rez)) {
56 // Returns an array of warehouse IDs for the given user and facility.
57 function getUserFacWH($uID, $fID)
60 "SELECT warehouse_id FROM users_facility WHERE tablename = ? " .
61 "AND table_id = ? AND facility_id = ?",
62 array('users', $uID, $fID)
65 while ($row = sqlFetchArray($res)) {
66 if ($row['warehouse_id'] === '') {
69 $returnVal[] = $row['warehouse_id'];
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]);
83 * Check if day is weekend day
87 function is_weekend_day($day)
90 if (in_array($day, $GLOBALS['weekend_days'])) {
98 * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed event in the events table
102 function is_holiday($date)
104 Holidays_Controller::is_holiday($date);