2 //function returns the next most recent appointment given a pid
3 function getNextAppointment ($pid) {
4 $query = "select * from calendar where pid=$pid and time>now() order by time limit 1";
5 $rez = sqlStatement($query);
6 echo "<!-- getNextAppointment $pid -$query- -->";
7 return sqlFetchArray($rez);
11 //this function returns calendar data given date and provider
12 function getCalendarDay($datetime,$owner,$groupname) {
13 $query = "select * from calendar where time like '$datetime%' and owner like '$owner' and groupname like '$groupname' order by time";
14 $rez = sqlStatement($query);
15 for($iter=0; $row=sqlFetchArray($rez); $iter++)
16 $returnval[$iter]=$row;
18 echo "<!-- getCalendarDay -$query- $datetime $owner $groupname -->";
22 //toggle the status of a noshow calendar entry
23 function toggleNoShow( $cid) {
24 $rez = sqlStatement("select noshow from calendar where id=$cid");
25 $row=sqlFetchArray($rez);
26 $oldnoshowval = $row{noshow};
27 $newnoshowval = !($oldnoshowval);
28 $query = "update calendar set noshow='$newnoshowval' where id=$cid";
33 //return array of provider usernames
34 function getProviderUsernames() {
35 $rez = sqlStatement("select distinct username, lname, fname from users " .
36 "where authorized = 1 and username != ''");
37 for($iter=0; $row=sqlFetchArray($rez); $iter++)
38 $returnval[$iter]=$row;
44 function getIDfromUser($name) {
45 $query = "select id from users where username=\"" . mysql_real_escape_string($name) . "\" limit 1";
46 $rez = sqlStatement($query);
47 $row = sqlFetchArray($rez);
48 if (!is_numeric($row['id']))
53 function getAuthorizedIDs() {
54 $query = "select id, username from users where authorized=1 and username != ''";
55 $rez = sqlStatement($query);
56 for($iter=0; $row=sqlFetchArray($rez); $iter++)
57 $returnval[$iter]=$row;
62 function getUserInfo() {
63 $rez = sqlStatement("select distinct id, username, lname, fname, authorized, " .
64 "info, facility from users where username != ''");
65 for($iter=0; $row=sqlFetchArray($rez); $iter++)
66 $returnval[$iter]=$row;
70 function getUsername($uID) {
71 $pi = getProviderInfo($uID,false);
72 if (strlen($pi["username"]) > 0) {
73 return $pi['username'];
79 // returns an array of facility id and names
80 function getUserFacilities($uID) {
81 if (!$GLOBALS['restrict_user_facility']) {
83 select id, name, color
85 where service_location != 0
89 select uf.facility_id as id, f.name, f.color
90 from users_facility uf
91 left join facility f on (uf.facility_id = f.id)
92 where uf.tablename='users'
97 while ($row = sqlFetchArray($rez))
102 //retrieve the name based on the username
103 function getNamefromUsername($username) {
104 $query = "select * from users where username like '$username' and username != ''";
105 $res = sqlQuery($query);
109 //retrieve calendar information from calendar id
110 function getCalendarfromID ($calid) {
112 //this table is deprecated and has been removed from new versions
113 //return sqlQuery("select * from calendar where id='$calid'");
116 //get calendar dates in a range of dates
117 function getCalendarRanges ($fromdate, $todate, $username) {
118 $rez = sqlStatement("select * from calendar where time>='$fromdate' and time<'$todate' and owner like '$username' order by time");
119 for($iter=0; $row=sqlFetchArray($rez); $iter++)
120 $returnval[$iter]=$row;
127 //get calendar dates in a range of dates
128 function getCalendarbyTimeandRange ($time, $fromdate, $todate, $username) {
129 $query = "select * from calendar where time like '% $time%' and time>='$fromdate' and time<'$todate' and owner like '$username' order by time";
130 $rez = sqlStatement($query);
131 for($iter=0; $row=sqlFetchArray($rez); $iter++)
132 $returnval[$iter]=$row;
133 echo "<!-- getcalendarbytimeandrange -$query- -->";
139 //add new calendar entry item
140 function newCalendarItem (
150 sqlQuery("insert into calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now()", array($pid, $time, $reason, $owner, $groupname) );
153 //delete a calendar entry item
154 function deleteCalendarItem( $calid,$pid) {
155 sqlQuery("delete from calendar where id=? and pid=?", array($calid, $pid) );
160 //save an edited calendar entry item
161 function saveCalendarUpdate (
172 sqlQuery("update calendar set pid=?,time=?,reason=?,owner=?,groupname=?,date=now() where id=?", array($pid, $time, $reason, $owner, $groupname, $calid) );
176 //replicated functionality of postcalendar_getDate
177 function pc_getDate($format='%Y%m%d') {
178 // list($Date,$jumpday,$jumpmonth,$jumpyear) = pnVarCleanFromInput('Date','jumpday','jumpmonth','jumpyear');
180 // if we still don't have a date then calculate it
182 // check the jump menu
183 if(!isset($jumpday)) $jumpday = strftime('%d',$time);
184 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time);
185 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time);
186 // create the correct date string
187 $Date = (int) "$jumpyear$jumpmonth$jumpday";
189 $y = substr($Date,0,4);
190 $m = substr($Date,4,2);
191 $d = substr($Date,6,2);
192 return strftime($format,mktime(0,0,0,$m,$d,$y));