bug fix for the patient PDF report
[openemr.git] / library / calendar.inc
blobeefe3b4674b559cb327cf839c9332ee48b99d246
1 <?php
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 -->";
22         return $returnval;
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";
32         sqlStatement($query);
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;
43         return $returnval;
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']))
52                 return -1;
53         else
54                 return $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;
61         return $returnval;
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;
71         return $returnval;
73 function getUsername($uID) {
74         $pi = getProviderInfo($uID,false);
75         if (strlen($pi["username"]) > 0) {
76                 return $pi['username'];
77         }
79         return "";
82 //      returns an array of facility id and names
83 function getUserFacilities($uID) {
84   if (!$GLOBALS['restrict_user_facility']) {
85         $rez = sqlStatement("
86                 select id, name, color
87                 from facility
88                 where service_location != 0
89         ");
90   } else {
91           $rez = sqlStatement("
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' 
96                   and uf.table_id = ? 
97             ", array($uID) );
98   }
99   $returnVal = array();
100   while ($row = sqlFetchArray($rez)) 
101           $returnVal[] = $row;
102   return $returnVal;
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);
109         return $res;
112 //retrieve calendar information from calendar id
113 function getCalendarfromID ($calid) {
114         
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;
125         return $returnval;
126         
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- -->";
137         return $returnval;
138         
142 //add new calendar entry item
143 function newCalendarItem (
144 $pid,
145 $time,
146 $reason,
147 $owner,
148 $groupname
151 ) {
152         
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) );
159         
163 //save an edited calendar entry item
164 function saveCalendarUpdate (
165 $calid,
166 $pid,
167 $time,
168 $reason,
169 $owner,
170 $groupname
173 ) {
174         
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');
182         if(!isset($Date)) {
183         // if we still don't have a date then calculate it
184         $time = time();
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";
191     }
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));
198  /**
199  * Check if day is weekend day
200  * @param (int) $day
201  * @return boolean
202  */
203 function is_weekend_day($day){
205         if (in_array($day, $GLOBALS['weekend_days'])) {
206                 return true;
207         } else {
208                 return false;
209         }
213  * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed  event in the events table
214  * @param (int) $day
215  * @return boolean
216  */
217 function is_holiday($date){
218         Holidays_Controller::is_holiday($date);