quick minor path updates (#1968)
[openemr.git] / library / calendar.inc
blob2dc8f00b0a4772ce48b08f69b5eb6a61d246cd89
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)
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;
22     }
24     echo "<!-- getCalendarDay -$query- $datetime $owner $groupname -->";
25     return $returnval;
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";
36     sqlStatement($query);
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;
47     }
49     return $returnval;
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'])) {
59         return -1;
60     } else {
61         return $row['id'];
62     }
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;
70     }
72     return $returnval;
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;
82     }
84     return $returnval;
86 function getUsername($uID)
88     $pi = getProviderInfo($uID, false);
89     if (strlen($pi["username"]) > 0) {
90         return $pi['username'];
91     }
93     return "";
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
102                 from facility
103                 where service_location != 0
104         ");
105     } else {
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' 
111                   and uf.table_id = ? 
112             ", array($uID));
113     }
115     $returnVal = array();
116     while ($row = sqlFetchArray($rez)) {
117         $returnVal[] = $row;
118     }
120     return $returnVal;
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);
128     return $res;
131 //retrieve calendar information from calendar id
132 function getCalendarfromID($calid)
134     
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;
145     }
147     return $returnval;
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;
158     }
160     echo "<!-- getcalendarbytimeandrange -$query- -->";
161     return $returnval;
165 //add new calendar entry item
166 function newCalendarItem(
167     $pid,
168     $time,
169     $reason,
170     $owner,
171     $groupname
172 ) {
173     
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(
186     $calid,
187     $pid,
188     $time,
189     $reason,
190     $owner,
191     $groupname
192 ) {
193     
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');
202     if (!isset($Date)) {
203         // if we still don't have a date then calculate it
204         $time = time();
205         // check the jump menu
206         if (!isset($jumpday)) {
207             $jumpday = strftime('%d', $time);
208         }
210         if (!isset($jumpmonth)) {
211             $jumpmonth = strftime('%m', $time);
212         }
214         if (!isset($jumpyear)) {
215             $jumpyear = strftime('%Y', $time);
216         }
218         // create the correct date string
219         $Date = (int) "$jumpyear$jumpmonth$jumpday";
220     }
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));
228  /**
229  * Check if day is weekend day
230  * @param (int) $day
231  * @return boolean
232  */
233 function is_weekend_day($day)
236     if (in_array($day, $GLOBALS['weekend_days'])) {
237         return true;
238     } else {
239         return false;
240     }
244  * This function checks if a certain date (YYYY/MM/DD) is a marked as a holiday/closed  event in the events table
245  * @param (int) $day
246  * @return boolean
247  */
248 function is_holiday($date)
250     Holidays_Controller::is_holiday($date);