2 //Require once the holidays controller for the is holiday function
4 require_once($GLOBALS['incdir']."/main/holidays/Holidays_Controller.php");
5 //function returns the next most recent appointment given a pid
6 function getNextAppointment($pid)
8 $query = "select * from calendar where pid=$pid and time>now() order by time limit 1";
9 $rez = sqlStatement($query);
10 echo "<!-- getNextAppointment $pid -$query- -->";
11 return sqlFetchArray($rez);
15 //this function returns calendar data given date and provider
16 function getCalendarDay($datetime, $owner, $groupname)
18 $query = "select * from calendar where time like '$datetime%' and owner like '$owner' and groupname like '$groupname' order by time";
19 $rez = sqlStatement($query);
20 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
21 $returnval[$iter]=$row;
24 echo "<!-- getCalendarDay -$query- $datetime $owner $groupname -->";
28 //toggle the status of a noshow calendar entry
29 function toggleNoShow($cid)
31 $rez = sqlStatement("select noshow from calendar where id=$cid");
32 $row=sqlFetchArray($rez);
33 $oldnoshowval = $row{noshow};
34 $newnoshowval = !($oldnoshowval);
35 $query = "update calendar set noshow='$newnoshowval' where id=$cid";
40 //return array of provider usernames
41 function getProviderUsernames()
43 $rez = sqlStatement("select distinct username, lname, fname from users " .
44 "where authorized = 1 and username != ''");
45 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
46 $returnval[$iter]=$row;
53 function getIDfromUser($name)
55 $query = "select id from users where username=\"" . add_escape_custom($name) . "\" limit 1";
56 $rez = sqlStatement($query);
57 $row = sqlFetchArray($rez);
58 if (!is_numeric($row['id'])) {
64 function getAuthorizedIDs()
66 $query = "select id, username from users where authorized=1 and username != ''";
67 $rez = sqlStatement($query);
68 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
69 $returnval[$iter]=$row;
76 function getUserInfo()
78 $rez = sqlStatement("select distinct id, username, lname, fname, authorized, " .
79 "info, facility from users where username != ''");
80 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
81 $returnval[$iter]=$row;
86 function getUsername($uID)
88 $pi = getProviderInfo($uID, false);
89 if (strlen($pi["username"]) > 0) {
90 return $pi['username'];
96 // returns an array of facility id and names
97 function getUserFacilities($uID)
99 if (!$GLOBALS['restrict_user_facility']) {
100 $rez = sqlStatement("
101 select id, name, color
103 where service_location != 0
106 $rez = sqlStatement("
107 select uf.facility_id as id, f.name, f.color
108 from users_facility uf
109 left join facility f on (uf.facility_id = f.id)
110 where uf.tablename='users'
115 $returnVal = array();
116 while ($row = sqlFetchArray($rez)) {
123 //retrieve the name based on the username
124 function getNamefromUsername($username)
126 $query = "select * from users where username like '$username' and username != ''";
127 $res = sqlQuery($query);
131 //retrieve calendar information from calendar id
132 function getCalendarfromID($calid)
135 //this table is deprecated and has been removed from new versions
136 //return sqlQuery("select * from calendar where id='$calid'");
139 //get calendar dates in a range of dates
140 function getCalendarRanges($fromdate, $todate, $username)
142 $rez = sqlStatement("select * from calendar where time>='$fromdate' and time<'$todate' and owner like '$username' order by time");
143 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
144 $returnval[$iter]=$row;
151 //get calendar dates in a range of dates
152 function getCalendarbyTimeandRange($time, $fromdate, $todate, $username)
154 $query = "select * from calendar where time like '% $time%' and time>='$fromdate' and time<'$todate' and owner like '$username' order by time";
155 $rez = sqlStatement($query);
156 for ($iter=0; $row=sqlFetchArray($rez); $iter++) {
157 $returnval[$iter]=$row;
160 echo "<!-- getcalendarbytimeandrange -$query- -->";
165 //add new calendar entry item
166 function newCalendarItem(
174 sqlQuery("insert into calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now()", array($pid, $time, $reason, $owner, $groupname));
177 //delete a calendar entry item
178 function deleteCalendarItem($calid, $pid)
180 sqlQuery("delete from calendar where id=? and pid=?", array($calid, $pid));
184 //save an edited calendar entry item
185 function saveCalendarUpdate(
194 sqlQuery("update calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now() where id=?", array($pid, $time, $reason, $owner, $groupname, $calid));
198 //replicated functionality of postcalendar_getDate
199 function pc_getDate($format = '%Y%m%d')
201 // list($Date,$jumpday,$jumpmonth,$jumpyear) = pnVarCleanFromInput('Date','jumpday','jumpmonth','jumpyear');
203 // if we still don't have a date then calculate it
205 // check the jump menu
206 if (!isset($jumpday)) {
207 $jumpday = strftime('%d', $time);
210 if (!isset($jumpmonth)) {
211 $jumpmonth = strftime('%m', $time);
214 if (!isset($jumpyear)) {
215 $jumpyear = strftime('%Y', $time);
218 // create the correct date string
219 $Date = (int) "$jumpyear$jumpmonth$jumpday";
222 $y = substr($Date, 0, 4);
223 $m = substr($Date, 4, 2);
224 $d = substr($Date, 6, 2);
225 return strftime($format, mktime(0, 0, 0, $m, $d, $y));
229 * Check if day is weekend day
233 function is_weekend_day($day)
236 if (in_array($day, $GLOBALS['weekend_days'])) {
244 * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed event in the events table
248 function is_holiday($date)
250 Holidays_Controller::is_holiday($date);