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) {
7 $query = "select * from calendar where pid=$pid and time>now() order by time limit 1";
8 $rez = sqlStatement($query);
9 echo "<!-- getNextAppointment $pid -$query- -->";
10 return sqlFetchArray($rez);
14 //this function returns calendar data given date and provider
15 function getCalendarDay($datetime,$owner,$groupname) {
16 $query = "select * from calendar where time like '$datetime%' and owner like '$owner' and groupname like '$groupname' order by time";
17 $rez = sqlStatement($query);
18 for($iter=0; $row=sqlFetchArray($rez); $iter++)
19 $returnval[$iter]=$row;
21 echo "<!-- getCalendarDay -$query- $datetime $owner $groupname -->";
25 //toggle the status of a noshow calendar entry
26 function toggleNoShow( $cid) {
27 $rez = sqlStatement("select noshow from calendar where id=$cid");
28 $row=sqlFetchArray($rez);
29 $oldnoshowval = $row{noshow};
30 $newnoshowval = !($oldnoshowval);
31 $query = "update calendar set noshow='$newnoshowval' where id=$cid";
36 //return array of provider usernames
37 function getProviderUsernames() {
38 $rez = sqlStatement("select distinct username, lname, fname from users " .
39 "where authorized = 1 and username != ''");
40 for($iter=0; $row=sqlFetchArray($rez); $iter++)
41 $returnval[$iter]=$row;
47 function getIDfromUser($name) {
48 $query = "select id from users where username=\"" . add_escape_custom($name) . "\" limit 1";
49 $rez = sqlStatement($query);
50 $row = sqlFetchArray($rez);
51 if (!is_numeric($row['id']))
56 function getAuthorizedIDs() {
57 $query = "select id, username from users where authorized=1 and username != ''";
58 $rez = sqlStatement($query);
59 for($iter=0; $row=sqlFetchArray($rez); $iter++)
60 $returnval[$iter]=$row;
65 function getUserInfo() {
66 $rez = sqlStatement("select distinct id, username, lname, fname, authorized, " .
67 "info, facility from users where username != ''");
68 for($iter=0; $row=sqlFetchArray($rez); $iter++)
69 $returnval[$iter]=$row;
73 function getUsername($uID) {
74 $pi = getProviderInfo($uID,false);
75 if (strlen($pi["username"]) > 0) {
76 return $pi['username'];
82 // returns an array of facility id and names
83 function getUserFacilities($uID) {
84 if (!$GLOBALS['restrict_user_facility']) {
86 select id, name, color
88 where service_location != 0
92 select uf.facility_id as id, f.name, f.color
93 from users_facility uf
94 left join facility f on (uf.facility_id = f.id)
95 where uf.tablename='users'
100 while ($row = sqlFetchArray($rez))
105 //retrieve the name based on the username
106 function getNamefromUsername($username) {
107 $query = "select * from users where username like '$username' and username != ''";
108 $res = sqlQuery($query);
112 //retrieve calendar information from calendar id
113 function getCalendarfromID ($calid) {
115 //this table is deprecated and has been removed from new versions
116 //return sqlQuery("select * from calendar where id='$calid'");
119 //get calendar dates in a range of dates
120 function getCalendarRanges ($fromdate, $todate, $username) {
121 $rez = sqlStatement("select * from calendar where time>='$fromdate' and time<'$todate' and owner like '$username' order by time");
122 for($iter=0; $row=sqlFetchArray($rez); $iter++)
123 $returnval[$iter]=$row;
130 //get calendar dates in a range of dates
131 function getCalendarbyTimeandRange ($time, $fromdate, $todate, $username) {
132 $query = "select * from calendar where time like '% $time%' and time>='$fromdate' and time<'$todate' and owner like '$username' order by time";
133 $rez = sqlStatement($query);
134 for($iter=0; $row=sqlFetchArray($rez); $iter++)
135 $returnval[$iter]=$row;
136 echo "<!-- getcalendarbytimeandrange -$query- -->";
142 //add new calendar entry item
143 function newCalendarItem (
153 sqlQuery("insert into calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now()", array($pid, $time, $reason, $owner, $groupname) );
156 //delete a calendar entry item
157 function deleteCalendarItem( $calid,$pid) {
158 sqlQuery("delete from calendar where id=? and pid=?", array($calid, $pid) );
163 //save an edited calendar entry item
164 function saveCalendarUpdate (
175 sqlQuery("update calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now() where id=?", array($pid, $time, $reason, $owner, $groupname, $calid) );
179 //replicated functionality of postcalendar_getDate
180 function pc_getDate($format='%Y%m%d') {
181 // list($Date,$jumpday,$jumpmonth,$jumpyear) = pnVarCleanFromInput('Date','jumpday','jumpmonth','jumpyear');
183 // if we still don't have a date then calculate it
185 // check the jump menu
186 if(!isset($jumpday)) $jumpday = strftime('%d',$time);
187 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time);
188 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time);
189 // create the correct date string
190 $Date = (int) "$jumpyear$jumpmonth$jumpday";
192 $y = substr($Date,0,4);
193 $m = substr($Date,4,2);
194 $d = substr($Date,6,2);
195 return strftime($format,mktime(0,0,0,$m,$d,$y));
199 * Check if day is weekend day
203 function is_weekend_day($day){
205 if (in_array($day, $GLOBALS['weekend_days'])) {
213 * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed event in the events table
217 function is_holiday($date){
218 Holidays_Controller::is_holiday($date);