Syntax fixes - static methods, call by reference and undefined variables
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnuserapi.php
blobb10f63123d69562a4c4137f8ff15b32c6d726f39
1 <?php
2 @define('__POSTCALENDAR__','PostCalendar');
3 /**
4 * $Id$
6 * PostCalendar::PostNuke Events Calendar Module
7 * Copyright (C) 2002 The PostCalendar Team
8 * http://postcalendar.tv
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * To read the license please read the docs/license.txt or visit
25 * http://www.gnu.org/copyleft/gpl.html
29 //=========================================================================
30 // Require utility classes
31 //=========================================================================
32 require_once($GLOBALS['fileroot']."/library/patient.inc");
33 include_once($GLOBALS['fileroot']."/library/encounter_events.inc.php");
34 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
35 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
36 require_once("modules/$pcDir/common.api.php");
37 unset($pcModInfo,$pcDir);
39 function postcalendar_userapi_getLongDayName($args)
41 extract($args); unset($args);
42 if(!isset($Date)) { return false; }
43 $pc_long_day = array(_CALLONGFIRSTDAY,
44 _CALLONGSECONDDAY,
45 _CALLONGTHIRDDAY,
46 _CALLONGFOURTHDAY,
47 _CALLONGFIFTHDAY,
48 _CALLONGSIXTHDAY,
49 _CALLONGSEVENTHDAY);
50 return $pc_long_day[Date("w",$Date)];
53 /**
54 * postcalendar_userapi_buildView
56 * Builds the calendar display
57 * @param string $Date mm/dd/yyyy format (we should use timestamps)
58 * @return string generated html output
59 * @access public
61 function postcalendar_userapi_buildView($args)
63 $print = pnVarCleanFromInput('print');
64 $show_days = pnVarCleanFromInput('show_days');
65 extract($args); unset($args);
66 $schedule_start = $GLOBALS[schedule_start];
67 $schedule_end = $GLOBALS[schedule_end];
69 // $times is an array of associative arrays, where each sub-array
70 // has keys 'hour', 'minute' and 'mer'.
72 $times = array();
74 // For each hour in the schedule...
76 for($blocknum = $schedule_start; $blocknum <= $schedule_end; $blocknum++){
77 $mer = ($blocknum >= 12) ? 'pm' : 'am';
79 // $minute is an array of time slot strings within this hour.
80 $minute = array('00');
82 for($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) {
83 if($minutes <= '9'){
84 $under_ten = "0" . $minutes;
85 array_push($minute, "$under_ten");
87 else if($minutes >= '60') {
88 break;
90 else {
91 array_push($minute, "$minutes");
95 foreach($minute as $m ){
96 array_push($times, array("hour"=>$blocknum, "minute"=>$m, "mer"=>$mer));
100 //=================================================================
101 // get the module's information
102 //=================================================================
103 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
104 $pcDir = $modinfo['directory'];
105 unset($modinfo);
107 //=================================================================
108 // grab the for post variable
109 //=================================================================
110 // $pc_username = pnVarCleanFromInput('pc_username');
111 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
112 $category = pnVarCleanFromInput('pc_category');
113 $topic = pnVarCleanFromInput('pc_topic');
115 //=================================================================
116 // set the correct date
117 //=================================================================
118 $Date =postcalendar_getDate();
120 //=================================================================
121 // get the current view
122 //=================================================================
123 if(!isset($viewtype)) { $viewtype = 'month'; }
125 //=================================================================
126 // Find out what Template we're using
127 //=================================================================
128 $template_name = _SETTING_TEMPLATE;
129 if(!isset($template_name)) { $template_name = 'default'; }
131 //=================================================================
132 // Find out what Template View to use
133 //=================================================================
134 $template_view = pnVarCleanFromInput('tplview');
135 if(!isset($template_view)) { $template_view = 'default'; }
137 //=================================================================
138 // See if the template view exists
139 //=================================================================
140 if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) {
141 $template_view_load = 'default';
142 } else {
143 $template_view_load = pnVarPrepForOS($template_view);
146 //=================================================================
147 // Grab the current theme information
148 //=================================================================
149 pnThemeLoad(pnUserGetTheme());
150 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2;
152 //=================================================================
153 // Insert necessary JavaScript into the page
154 //=================================================================
155 $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup');
157 //=================================================================
158 // Setup Smarty Template Engine
159 //=================================================================
160 $tpl = new pcSmarty();
162 //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) {
163 //diable caching completely
164 if (true) {
165 //=================================================================
166 // Let's just finish setting things up
167 //=================================================================
168 $the_year = substr($Date,0,4);
169 $the_month = substr($Date,4,2);
170 $the_day = substr($Date,6,2);
171 $last_day = Date_Calc::daysInMonth($the_month,$the_year);
173 //=================================================================
174 // populate the template object with information for
175 // Month Names, Long Day Names and Short Day Names
176 // as translated in the language files
177 // (may be adding more here soon - based on need)
178 //=================================================================
179 $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN,
180 _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC);
182 $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT,
183 _CALTUESDAYSHORT, _CALWEDNESDAYSHORT,
184 _CALTHURSDAYSHORT, _CALFRIDAYSHORT,
185 _CALSATURDAYSHORT);
187 $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY,
188 _CALTUESDAY, _CALWEDNESDAY,
189 _CALTHURSDAY, _CALFRIDAY,
190 _CALSATURDAY);
191 //=================================================================
192 // here we need to set up some information for later
193 // variable creation. This helps us establish the correct
194 // date ranges for each view. There may be a better way
195 // to handle all this, but my brain hurts, so your comments
196 // are very appreciated and welcomed.
197 //=================================================================
198 switch (_SETTING_FIRST_DAY_WEEK)
200 case _IS_MONDAY:
201 $pc_array_pos = 1;
202 $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year));
203 $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year));
204 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
205 if($end_dow != 0) {
206 $the_last_day = $last_day+(7-$end_dow);
207 } else {
208 $the_last_day = $last_day;
210 break;
211 case _IS_SATURDAY:
212 $pc_array_pos = 6;
213 $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year));
214 $week_day = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year));
215 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
216 if($end_dow == 6) {
217 $the_last_day = $last_day+6;
218 } elseif($end_dow != 5) {
219 $the_last_day = $last_day+(5-$end_dow);
220 } else {
221 $the_last_day = $last_day;
223 break;
224 case _IS_SUNDAY:
225 default:
226 $pc_array_pos = 0;
227 $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
228 $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year));
229 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
230 if($end_dow != 6) {
231 $the_last_day = $last_day+(6-$end_dow);
232 } else {
233 $the_last_day = $last_day;
235 break;
238 // passing the times array to the tpl the times array is for the days schedule
239 $tpl->assign_by_ref("times",$times);
240 // load the table width to the template
241 // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']);
243 //=================================================================
244 // Week View is a bit of a pain in the ass, so we need to
245 // do some extra setup for that view. This section will
246 // find the correct starting and ending dates for a given
247 // seven day period, based on the day of the week the
248 // calendar is setup to run under (Sunday, Saturday, Monday)
249 //=================================================================
250 $first_day_of_week = sprintf('%02d',$the_day-$week_day);
251 $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
252 list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day);
253 $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
254 array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year)));
255 $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
256 list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day);
257 $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
258 array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year)));
260 $week_view_start = date('Y-m-d',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
261 $week_view_end = date('Y-m-d',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
263 //=================================================================
264 // Setup some information so we know the actual month's dates
265 // also get today's date for later use and highlighting
266 //=================================================================
267 $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year));
268 $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year));
269 $today_date = postcalendar_today('%Y-%m-%d');
271 //=================================================================
272 // Setup the starting and ending date ranges for pcGetEvents()
273 //=================================================================
274 switch($viewtype) {
275 case 'day' :
276 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
277 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
278 break;
279 case 'week' :
280 $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year";
281 $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year";
282 $calendarView = Date_Calc::getCalendarWeek($week_first_day_date,
283 $week_first_day_month,
284 $week_first_day_year,
285 '%Y-%m-%d');
286 break;
287 case 'month' :
288 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year));
289 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year));
290 $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d');
291 break;
292 case 'year' :
293 $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year));
294 $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1));
295 $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d');
296 break;
300 //=================================================================
301 // Identify the Providers whose schedules we should load
302 //=================================================================
304 //==================================
305 //FACILITY FILTERING (CHEMED)
306 if ( $_SESSION['pc_facility'] ) {
307 $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
308 } else {
309 $provinfo = getProviderInfo();
311 //EOS FACILITY FILTERING (CHEMED)
312 //==================================
314 $single = array();
315 $provIDs = array(); // array of numeric provider IDs
317 // filter the display on the requested username, the provinfo array is
318 // used to build columns in the week view.
320 foreach($provinfo as $provider) {
321 if(is_array($pc_username)){
322 foreach($pc_username as $uname) {
323 if (!empty($pc_username) && $provider['username'] == $uname) {
324 array_push($single,$provider);
325 array_push($provIDs,$provider['id']);
329 else {
330 if (!empty($pc_username) && $provider['username'] == $pc_username) {
331 array_push($single,$provider);
332 array_push($provIDs,$provider['id']);
336 if ($single != null) {
337 $provinfo = $single;
340 //=================================================================
341 // Load the events
342 //=================================================================
343 if($viewtype != 'year') {
344 $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype, 'provider_id' => $provIDs));
345 } else {
346 $eventsByDate = array();
350 //=================================================================
351 // Create an array with the day names in the correct order
352 //=================================================================
353 $daynames = array();
354 $numDays = count($pc_long_day_names);
355 for($i=0; $i < $numDays; $i++) {
356 if($pc_array_pos >= $numDays) {
357 $pc_array_pos = 0;
359 array_push($daynames,$pc_long_day_names[$pc_array_pos]);
360 $pc_array_pos++;
362 unset($numDays);
363 $sdaynames = array();
364 $numDays = count($pc_short_day_names);
365 for($i=0; $i < $numDays; $i++) {
366 if($pc_array_pos >= $numDays) {
367 $pc_array_pos = 0;
369 array_push($sdaynames,$pc_short_day_names[$pc_array_pos]);
370 $pc_array_pos++;
372 unset($numDays);
374 //=================================================================
375 // Prepare some values for the template
376 //=================================================================
377 $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d');
378 $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d');
380 $pc_prev = pnModURL(__POSTCALENDAR__,'user','view',
381 array('tplview'=>$template_view,
382 'viewtype'=>'month',
383 'Date'=>$prev_month,
384 'pc_username'=>$pc_username,
385 'pc_category'=>$category,
386 'pc_topic'=>$topic));
388 $pc_next = pnModURL(__POSTCALENDAR__,'user','view',
389 array('tplview'=>$template_view,
390 'viewtype'=>'month',
391 'Date'=>$next_month,
392 'pc_username'=>$pc_username,
393 'pc_category'=>$category,
394 'pc_topic'=>$topic));
396 $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d');
397 $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d');
398 $pc_prev_day = pnModURL(__POSTCALENDAR__,'user','view',
399 array('tplview'=>$template_view,
400 'viewtype'=>'day',
401 'Date'=>$prev_day,
402 'pc_username'=>$pc_username,
403 'pc_category'=>$category,
404 'pc_topic'=>$topic));
406 $pc_next_day = pnModURL(__POSTCALENDAR__,'user','view',
407 array('tplview'=>$template_view,
408 'viewtype'=>'day',
409 'Date'=>$next_day,
410 'pc_username'=>$pc_username,
411 'pc_category'=>$category,
412 'pc_topic'=>$topic));
414 $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year));
415 $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year));
416 $pc_prev_week = pnModURL(__POSTCALENDAR__,'user','view',
417 array('viewtype'=>'week',
418 'Date'=>$prev_week,
419 'pc_username'=>$pc_username,
420 'pc_category'=>$category,
421 'pc_topic'=>$topic));
422 $pc_next_week = pnModURL(__POSTCALENDAR__,'user','view',
423 array('viewtype'=>'week',
424 'Date'=>$next_week,
425 'pc_username'=>$pc_username,
426 'pc_category'=>$category,
427 'pc_topic'=>$topic));
429 $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1));
430 $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1));
431 $pc_prev_year = pnModURL(__POSTCALENDAR__,'user','view',
432 array('viewtype'=>'year',
433 'Date'=>$prev_year,
434 'pc_username'=>$pc_username,
435 'pc_category'=>$category,
436 'pc_topic'=>$topic));
437 $pc_next_year = pnModURL(__POSTCALENDAR__,'user','view',
438 array('viewtype'=>'year',
439 'Date'=>$next_year,
440 'pc_username'=>$pc_username,
441 'pc_category'=>$category,
442 'pc_topic'=>$topic));
444 //=================================================================
445 // Populate the template
446 //=================================================================
447 $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
449 if(isset($calendarView)) {
450 $tpl->assign_by_ref('CAL_FORMAT',$calendarView);
453 if ($viewtype == "week") {
454 $last_blocks = array();
455 foreach($eventsByDate as $cdate => $day) {
456 $tblock = array_reverse($day['blocks']);
457 $last_blocks[$cdate] = count($tblock) -1;
458 for ($i=0;$i<count($tblock);$i++) {
459 if (!empty($tblock[$i])) {
460 $last_blocks[$cdate] = count($tblock) - $i;
461 break;
465 $tpl->assign("last_blocks",$last_blocks);
468 $tpl->assign('STYLE',$GLOBALS['style']);
469 $tpl->assign('show_days',$show_days);
471 //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other");
472 $tpl->assign_by_ref('providers', $provinfo);
474 if (pnVarCleanFromInput("show_days") != 1) {
475 $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1");
478 $tpl->assign('interval', $GLOBALS['calendar_interval']);
479 $tpl->assign_by_ref('VIEW_TYPE',$viewtype);
480 $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names);
481 $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names);
482 $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names);
483 $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames);
484 $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames);
485 $tpl->assign_by_ref('A_EVENTS',$eventsByDate);
486 $tpl->assign_by_ref('A_CATEGORY',$all_categories);
487 $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev);
488 $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next);
489 $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day);
490 $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day);
491 $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week);
492 $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week);
493 $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year);
494 $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year);
495 $tpl->assign_by_ref('WEEK_START_DATE',$week_view_start);
496 $tpl->assign_by_ref('WEEK_END_DATE',$week_view_end);
497 $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start);
498 $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end);
499 $tpl->assign_by_ref('TODAY_DATE',$today_date);
500 $tpl->assign_by_ref('DATE',$Date);
501 $tpl->assign('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__,'user','submit'));
502 $tpl->assign_by_ref('interval',$intervals);
505 //=================================================================
506 // Parse the template
507 //=================================================================
508 $template = "$template_name/views/$viewtype/$template_view_load.html";
509 if(!$print) {
510 $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
511 $output .= $tpl->fetch($template,$cacheid); // cache id
512 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
513 } else {
514 $theme = pnUserGetTheme();
515 echo "<html><head>";
516 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
517 echo "<style type=\"text/css\">\n";
518 echo "@import url(\"themes/$theme/style/style.css\"); ";
519 echo "</style>\n";
520 echo "</head><body>\n";
521 echo $output;
522 $tpl->display($template,$cacheid);
523 echo postcalendar_footer();
524 echo "\n</body></html>";
525 session_write_close();
526 exit;
528 //=================================================================
529 // Return the output
530 //=================================================================
531 return $output;
535 * postcalendar_userapi_eventPreview
536 * Creates the detailed event display and outputs html.
537 * Accepts an array of key/value pairs
538 * @param array $event array of event details from the form
539 * @return string html output
540 * @access public
542 function postcalendar_userapi_eventPreview($args)
544 // get the theme globals :: is there a better way to do this?
545 pnThemeLoad(pnUserGetTheme());
546 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
547 global $textcolor1, $textcolor2;
549 extract($args); unset($args);
550 $uid = pnUserGetVar('uid');
551 //=================================================================
552 // Setup Smarty Template Engine
553 //=================================================================
554 $tpl = new pcSmarty();
555 $tpl->caching = false;
556 // add preceding zeros
557 $event_starttimeh = sprintf('%02d',$event_starttimeh);
558 $event_starttimem = sprintf('%02d',$event_starttimem);
559 $event_startday = sprintf('%02d',$event_startday);
560 $event_startmonth = sprintf('%02d',$event_startmonth);
561 $event_endday = sprintf('%02d',$event_endday);
562 $event_endmonth = sprintf('%02d',$event_endmonth);
564 if(!(bool)_SETTING_TIME_24HOUR) {
565 if($event_startampm == _PM_VAL) {
566 if($event_starttimeh != 12) {
567 $event_starttimeh+=12;
569 } elseif($event_startampm == _AM_VAL) {
570 if($event_starttimeh == 12) {
571 $event_starttimeh = 00;
576 $event_startampm." - ";
577 $startTime = $event_starttimeh.':'.$event_starttimem.' ';
579 $event = array();
580 $event['eid'] = '';
581 $event['uname'] = $uname;
582 $event['catid'] = $event_category;
583 if($pc_html_or_text == 'html') {
584 $prepFunction = 'pcVarPrepHTMLDisplay';
585 } else {
586 $prepFunction = 'pcVarPrepForDisplay';
588 $event['title'] = $prepFunction($event_subject);
589 $event['hometext'] = $prepFunction($event_desc);
590 $event['desc'] = $event['hometext'];
591 $event['date'] = $event_startyear.$event_startmonth.$event_startday;
592 $event['duration'] = $event_duration;
593 $event['duration_hours'] = $event_dur_hours;
594 $event['duration_minutes'] = $event_dur_minutes;
595 $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
596 $event['startTime'] = $startTime;
597 $event['recurrtype'] = '';
598 $event['recurrfreq'] = '';
599 $event['recurrspec'] = $event_recurrspec;
600 $event['topic'] = $event_topic;
601 $event['alldayevent'] = $event_allday;
602 $event['conttel'] = $prepFunction($event_conttel);
603 $event['contname'] = $prepFunction($event_contname);
604 $event['contemail'] = $prepFunction($event_contemail);
605 $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website));
606 $event['fee'] = $prepFunction($event_fee);
607 $event['location'] = $prepFunction($event_location);
608 $event['street1'] = $prepFunction($event_street1);
609 $event['street2'] = $prepFunction($event_street2);
610 $event['city'] = $prepFunction($event_city);
611 $event['state'] = $prepFunction($event_state);
612 $event['postal'] = $prepFunction($event_postal);
614 //=================================================================
615 // get event's topic information
616 //=================================================================
617 if(_SETTING_DISPLAY_TOPICS) {
618 list($dbconn) = pnDBGetConn();
619 $pntable = pnDBGetTables();
620 $topics_table = $pntable['topics'];
621 $topics_column = $pntable['topics_column'];
622 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
623 FROM $topics_table
624 WHERE $topics_column[topicid] = $event[topic]
625 LIMIT 1";
626 $topic_result = $dbconn->Execute($topicsql);
627 list($event['topictext'],$event['topicimg']) = $topic_result->fields;
628 $topic_result->Close();
629 } else {
630 $event['topictext'] = $event['topicimg'] = '';
632 //=================================================================
633 // Find out what Template we're using
634 //=================================================================
635 $template_name = _SETTING_TEMPLATE;
636 if(!isset($template_name)) {
637 $template_name = 'default';
639 //=================================================================
640 // populate the template
641 //=================================================================
642 if(!empty($event['location']) || !empty($event['street1']) ||
643 !empty($event['street2']) || !empty($event['city']) ||
644 !empty($event['state']) || !empty($event['postal'])) {
645 $tpl->assign('LOCATION_INFO',true);
646 } else {
647 $tpl->assign('LOCATION_INFO',false);
649 if(!empty($event['contname']) || !empty($event['contemail']) ||
650 !empty($event['conttel']) || !empty($event['website'])) {
651 $tpl->assign('CONTACT_INFO',true);
652 } else {
653 $tpl->assign('CONTACT_INFO',false);
655 $tpl->assign_by_ref('A_EVENT',$event);
656 $tpl->assign('STYLE',$GLOBALS['style']);
657 //=================================================================
658 // Parse the template
659 //=================================================================
660 $output = "\n\n<!-- POSTCALENDAR HTTP://WWW.BAHRAINI.TV -->\n\n";
661 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE START -->\n\n";
662 $output .= $tpl->fetch($template_name.'/user/preview.html');
663 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE END -->\n\n";
665 return $output;
669 * checkEventCollision
670 * Returns an array containing any events that collide with the specified event
671 * @params array(key=>value)
672 * @return array $events[][]
674 function checkEventCollision($edata) {
676 extract($edata);
677 $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear);
678 $edate = $sdate;
679 //hour from forms is 12 not 24 format, convert here
680 if($event_startampm == 2 && $event_starttimeh != 12)
681 $event_starttimeh += 12;
682 elseif ($event_startampm == 1 && $event_starttimeh == 12)
683 $event_starttimeh -= 12;
685 $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00'));
686 $etime = date("H:i:00",$event_duration + strtotime($stime));
687 //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
688 $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime);
689 $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
690 //print_r($eventsByDate);
691 $collisions = array();
692 foreach ($eventsByDate as $day) {
693 foreach ($day as $event) {
694 if ($event['duration'] == 0 && $event['alldayevent'] == 0) {
695 continue;
697 elseif($event['alldayevent'] == 1) {
698 $collisions[] = $event;
700 $festart = strtotime($event['startTime']);
701 $feend = strtotime($event['startTime'] + $event['duration']);
702 $estart = strtotime($stime);
703 $eend = strtotime($etime);
705 //echo "festart = $festart feend = $feend estart = $estart eend = $eend<br />";
706 if ($festart < $eend && $feend > $estart) {
707 $collisions[] = $event;
709 elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) {
710 $collisions[] = $event;
712 elseif ($festart >= $estart && $festart < $eend) {
713 $collisions[] = $event;
717 //foreach ($collisions as $collide) {
718 // echo "collided: " . $collide['title'] . "<br />";
720 return $collisions;
724 * postcalendar_userapi_pcQueryEventsFA
725 * Returns an array containing the event's information for first available queiries
726 * @params array(key=>value)
727 * @params string key eventstatus
728 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
729 * @return array $events[][]
731 function &postcalendar_userapi_pcQueryEventsFA($args) {
733 $end = '0000-00-00';
734 extract($args);
735 $eventstatus = 1;
736 if (is_numeric($event_status))
737 $eventstatus = $event_status;
739 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
740 list($sy,$sm,$sd) = explode('-',$start);
742 list($dbconn) = pnDBGetConn();
743 $pntable = pnDBGetTables();
744 // link to the events tables
745 $table = $pntable['postcalendar_events'];
746 $cattable = $pntable['postcalendar_categories'];
748 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " .
749 "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " .
750 "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " .
751 "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " .
752 "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " .
753 "a.pc_prefcatid, " .
754 "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " .
755 "concat(u.fname,' ',u.lname) as provider_name, " .
756 "concat(pd.fname,' ',pd.lname) as patient_name, " .
757 "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob, " .
758 "a.pc_facility" .
759 "FROM ( $table AS a ) " .
760 "LEFT JOIN $cattable AS b ON b.pc_catid = a.pc_catid " .
761 "LEFT JOIN users as u ON a.pc_aid = u.id " .
762 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
763 "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " .
764 "WHERE a.pc_eventstatus = $eventstatus " .
765 "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " .
766 "AND a.pc_eventDate <= '$end' " .
767 "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')";
769 //======================================================================
770 // START SEARCH FUNCTIONALITY
771 //======================================================================
772 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
773 if(!empty($s_category)) $sql .= "AND ($s_category) ";
774 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
775 if(!empty($collide_etime) && !empty($collide_stime)) {
776 $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL ";
778 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
779 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
780 //======================================================================
781 // Search sort and limitation
782 //======================================================================
783 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC";
784 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
785 //======================================================================
786 // END SEARCH FUNCTIONALITY
787 //======================================================================
788 //echo "<Br />sql: $sql<br />";
789 $result = $dbconn->Execute($sql);
790 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
792 // put the information into an array for easy access
793 $events = array();
794 // return an empty array if we don't have any results
795 if(!isset($result)) { return $events; }
797 for($i=0; !$result->EOF; $result->MoveNext()) {
799 // get the results from the query
800 if(isset($tmp)) { unset($tmp); } $tmp = array();
801 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
802 $tmp['title'], $tmp['time'], $tmp['hometext'],
803 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
804 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
805 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
806 $tmp['location'], $tmp['conttel'], $tmp['contname'],
807 $tmp['contemail'], $tmp['website'], $tmp['fee'],
808 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
809 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
810 $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'],
811 $tmp['owner_name'], $tmp['patient_dob'], $tmp['facility']) = $result->fields;
813 // grab the name of the topic
814 $topicname = pcGetTopicName($tmp['topic']);
815 // get the user id of event's author
816 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
817 // check the current event's permissions
818 // the user does not have permission to view this event
819 // if any of the following evaluate as false
820 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
821 continue;
822 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
823 continue;
824 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
825 continue;
826 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
827 continue;
828 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
829 continue;
832 // add event to the array if we passed the permissions check
833 // this is the common information
834 $events[$i]['eid'] = $tmp['eid'];
835 $events[$i]['uname'] = $tmp['uname'];
836 $events[$i]['uid'] = $cuserid;
837 $events[$i]['catid'] = $tmp['catid'];
838 $events[$i]['time'] = $tmp['time'];
839 $events[$i]['eventDate'] = $tmp['eventDate'];
840 $events[$i]['duration'] = $tmp['duration'];
841 // there has to be a more intelligent way to do this
842 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
843 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
844 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
845 $events[$i]['endDate'] = $tmp['endDate'];
846 $events[$i]['startTime'] = $tmp['startTime'];
847 $events[$i]['recurrtype'] = $tmp['recurrtype'];
848 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
849 $events[$i]['recurrspec'] = $tmp['recurrspec'];
851 $rspecs = unserialize($tmp['recurrspec']);
852 $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
853 $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
854 $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
855 $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
856 $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
858 $events[$i]['topic'] = $tmp['topic'];
859 $events[$i]['alldayevent'] = $tmp['alldayevent'];
860 $events[$i]['catcolor'] = $tmp['catcolor'];
861 $events[$i]['catname'] = $tmp['catname'];
862 $events[$i]['catdesc'] = $tmp['catdesc'];
863 $events[$i]['pid'] = $tmp['pid'];
864 $events[$i]['patient_name']= $tmp['patient_name'];
865 $events[$i]['provider_name'] = $tmp['provider_name'];
866 $events[$i]['owner_name'] = $tmp['owner_name'];
867 $events[$i]['patient_dob'] = $tmp['patient_dob'];
868 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
869 $events[$i]['facility'] = getfacility($tmp['facility']);
870 $events[$i]['sharing'] = $tmp['sharing'];
871 $events[$i]['prefcatid'] = $tmp['prefcatid'];
872 $events[$i]['aid'] = $tmp['aid'];
873 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
874 if($events[$i]['intervals'] == 0)
875 $events[$i]['intervals'] = 1;
876 // is this a public event to be shown as busy?
877 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
878 // make it not display any information
879 $events[$i]['title'] = _USER_BUSY_TITLE;
880 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
881 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
882 $events[$i]['conttel'] = '';
883 $events[$i]['contname'] = '';
884 $events[$i]['contemail'] = '';
885 $events[$i]['website'] = '';
886 $events[$i]['fee'] = '';
887 $events[$i]['location'] = '';
888 $events[$i]['street1'] = '';
889 $events[$i]['street2'] = '';
890 $events[$i]['city'] = '';
891 $events[$i]['state'] = '';
892 $events[$i]['postal'] = '';
893 } else {
894 $display_type = substr($tmp['hometext'],0,6);
895 if($display_type == ':text:') {
896 $prepFunction = 'pcVarPrepForDisplay';
897 $tmp['hometext'] = substr($tmp['hometext'],6);
898 } elseif($display_type == ':html:') {
899 $prepFunction = 'pcVarPrepHTMLDisplay';
900 $tmp['hometext'] = substr($tmp['hometext'],6);
901 } else {
902 $prepFunction = 'pcVarPrepHTMLDisplay';
904 unset($display_type);
905 $events[$i]['title'] = $prepFunction($tmp['title']);
906 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
907 $events[$i]['desc'] = $events[$i]['hometext'];
908 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
909 $events[$i]['contname'] = $prepFunction($tmp['contname']);
910 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
911 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
912 $events[$i]['fee'] = $prepFunction($tmp['fee']);
913 $loc = unserialize($tmp['location']);
914 $events[$i]['location'] = $prepFunction($loc['event_location']);
915 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
916 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
917 $events[$i]['city'] = $prepFunction($loc['event_city']);
918 $events[$i]['state'] = $prepFunction($loc['event_state']);
919 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
921 $i++;
923 unset($tmp);
924 $result->Close();
925 return $events;
930 * postcalendar_userapi_pcQueryEvents
931 * INPUT
932 * $args = Array of values possibly containing:
933 * $provider_id = array of provider ID numbers
935 * Returns an array containing the event's information
936 * @params array(key=>value)
937 * @params string key eventstatus
938 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
939 * @return array $events[][]
941 function &postcalendar_userapi_pcQueryEvents($args)
943 $end = '0000-00-00';
944 extract($args);
946 // echo "<!-- args = "; print_r($args); echo " -->\n"; // debugging
948 // $pc_username = pnVarCleanFromInput('pc_username');
949 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
950 if (empty($pc_username) || is_array($pc_username)) {
951 $pc_username = "__PC_ALL__";
954 //echo "DEBUG pc_username: $pc_username \n"; // debugging
956 $topic = pnVarCleanFromInput('pc_topic');
957 $category = pnVarCleanFromInput('pc_category');
958 if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) {
959 if($pc_username=='__PC_ALL__' || $pc_username == -1) {
960 $ruserid = -1;
961 } else {
962 $ruserid = getIDfromUser($pc_username);
966 if(!isset($eventstatus)) { $eventstatus = 1; }
967 // sanity check on eventstatus
968 if((int)$eventstatus < -1 || (int)$eventstatus > 1) { $eventstatus = 1; }
969 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
970 list($sy,$sm,$sd) = explode('-',$start);
972 list($dbconn) = pnDBGetConn();
973 $pntable = pnDBGetTables();
974 // link to the events tables
975 $table = $pntable['postcalendar_events'];
976 $cattable = $pntable['postcalendar_categories'];
977 $topictable = $pntable['postcalendar_topics'];
979 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " .
980 "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " .
981 "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " .
982 "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " .
983 "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " .
984 "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " .
985 "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " .
986 "concat(u.fname,' ',u.lname) as provider_name, " .
987 "concat(pd.lname,', ',pd.fname) as patient_name, " .
988 "concat(u2.fname, ' ', u2.lname) as owner_name, " .
989 "DOB as patient_dob, a.pc_facility, pd.pubpid " .
990 "FROM ( $table AS a ) " .
991 "LEFT JOIN $cattable AS b ON b.pc_catid = a.pc_catid ".
992 "LEFT JOIN users as u ON a.pc_aid = u.id " .
993 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
994 "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " .
995 "WHERE a.pc_eventstatus = $eventstatus " .
996 "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " .
997 "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " .
998 "a.pc_eventDate <= '$end')) ";
1000 //==================================
1001 //FACILITY FILTERING (lemonsoftware)(CHEMED)
1002 if ( $_SESSION['pc_facility'] ) {
1003 $pc_facility = $_SESSION['pc_facility'];
1004 $sql .= " AND a.pc_facility = $pc_facility "; /*
1005 AND u.facility_id = $pc_facility
1006 AND u2.facility_id = $pc_facility "; */
1008 else if ($pc_facility) {
1009 // pc_facility could be provided in the search arguments -- JRM March 2008
1010 $sql .= " AND a.pc_facility = $pc_facility "; /*.
1011 " AND u.facility_id = $pc_facility".
1012 " AND u2.facility_id = $pc_facility "; */
1014 //EOS FACILITY FILTERING (lemonsoftware)
1015 //==================================
1018 // The above 3 lines replaced these:
1019 // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00')
1020 // AND a.pc_eventDate <= '$end' ";
1022 if(!empty($providerID)) { $ruserid = $providerID; }
1024 // eliminate ruserid if we're trying to query by provider_id -- JRM
1025 if (!empty($provider_id)) { unset($ruserid); }
1027 if(isset($ruserid)) {
1028 // get all events for the specified username
1029 if($ruserid == -1) {
1030 $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY . "' ";
1031 $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC . "') ";
1032 } else {
1033 $sql .= "AND a.pc_aid = " . $ruserid . " ";
1035 } elseif(!pnUserLoggedIn()) {
1036 // get all events for anonymous users
1037 $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL . "' ";
1038 } elseif(!empty($provider_id)) {
1039 // get all events for a variety of provider IDs -- JRM
1040 if ($provider_id[0] != "_ALL_") {
1041 $sql .= "AND a.pc_aid in (" . implode(",", $provider_id). ") ";
1043 } else {
1044 // get all events for logged in user plus global events
1045 $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL . "') ";
1048 //======================================================================
1049 // START SEARCH FUNCTIONALITY
1050 //======================================================================
1051 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
1052 if(!empty($s_category)) $sql .= "AND ($s_category) ";
1053 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
1054 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
1055 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
1057 //======================================================================
1058 // Search sort and limitation
1059 //======================================================================
1060 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC";
1061 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
1063 //======================================================================
1064 // END SEARCH FUNCTIONALITY
1065 //======================================================================
1066 //echo "<br>sq: $sql<br />";
1068 // echo "<!-- " . $sql . " -->\n"; // debugging
1070 $result = $dbconn->Execute($sql);
1071 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
1073 // put the information into an array for easy access
1074 $events = array();
1075 // return an empty array if we don't have any results
1076 if(!isset($result)) { return $events; }
1078 for($i=0; !$result->EOF; $result->MoveNext()) {
1080 // WHY are we using an array for intermediate storage??? -- Rod
1082 // get the results from the query
1083 if(isset($tmp)) { unset($tmp); } $tmp = array();
1084 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
1085 $tmp['title'], $tmp['time'], $tmp['hometext'],
1086 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
1087 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
1088 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
1089 $tmp['location'], $tmp['conttel'], $tmp['contname'],
1090 $tmp['contemail'], $tmp['website'], $tmp['fee'],
1091 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
1092 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
1093 $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'],
1094 $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'],
1095 $tmp['facility'], $tmp['pubpid']) = $result->fields;
1097 // grab the name of the topic
1098 $topicname = pcGetTopicName($tmp['topic']);
1099 // get the user id of event's author
1100 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
1101 // check the current event's permissions
1102 // the user does not have permission to view this event
1103 // if any of the following evaluate as false
1104 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
1105 continue;
1106 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
1107 continue;
1108 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
1109 continue;
1110 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
1111 continue;
1112 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
1113 continue;
1116 // add event to the array if we passed the permissions check
1117 // this is the common information
1119 $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span
1120 print_r($events[$i]['intervals']);
1122 $events[$i]['eid'] = $tmp['eid'];
1123 $events[$i]['uname'] = $tmp['uname'];
1124 $events[$i]['uid'] = $cuserid;
1125 $events[$i]['catid'] = $tmp['catid'];
1126 $events[$i]['time'] = $tmp['time'];
1127 $events[$i]['eventDate'] = $tmp['eventDate'];
1128 $events[$i]['duration'] = $tmp['duration'];
1129 // there has to be a more intelligent way to do this
1130 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
1131 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1132 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1133 $events[$i]['endDate'] = $tmp['endDate'];
1134 $events[$i]['startTime'] = $tmp['startTime'];
1135 $events[$i]['recurrtype'] = $tmp['recurrtype'];
1136 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
1137 $events[$i]['recurrspec'] = $tmp['recurrspec'];
1138 $events[$i]['topic'] = $tmp['topic'];
1139 $events[$i]['alldayevent'] = $tmp['alldayevent'];
1140 $events[$i]['catcolor'] = $tmp['catcolor'];
1141 // Modified 06-2009 by BM to translate the category if applicable
1142 $events[$i]['catname'] = xl_appt_category($tmp['catname']);
1143 $events[$i]['catdesc'] = $tmp['catdesc'];
1144 $events[$i]['pid'] = $tmp['pid'];
1145 $events[$i]['apptstatus'] = $tmp['apptstatus'];
1146 $events[$i]['pubpid'] = $tmp['pubpid'];
1147 $events[$i]['patient_name']= $tmp['patient_name'];
1148 $events[$i]['provider_name'] = $tmp['provider_name'];
1149 $events[$i]['owner_name'] = $tmp['owner_name'];
1150 $events[$i]['patient_dob'] = $tmp['patient_dob'];
1151 $events[$i]['patient_age'] = getPatientAge($tmp['patient_dob']);
1152 $events[$i]['facility'] = getFacility($tmp['facility']);
1153 $events[$i]['sharing'] = $tmp['sharing'];
1154 $events[$i]['prefcatid'] = $tmp['prefcatid'];
1155 $events[$i]['aid'] = $tmp['aid'];
1156 $events[$i]['topictext'] = $topicname;
1157 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
1158 if($events[$i]['intervals'] == 0)
1159 $events[$i]['intervals'] = 1;
1160 // is this a public event to be shown as busy?
1161 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
1162 // make it not display any information
1163 $events[$i]['title'] = _USER_BUSY_TITLE;
1164 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
1165 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
1166 $events[$i]['conttel'] = '';
1167 $events[$i]['contname'] = '';
1168 $events[$i]['contemail'] = '';
1169 $events[$i]['website'] = '';
1170 $events[$i]['fee'] = '';
1171 $events[$i]['location'] = '';
1172 $events[$i]['street1'] = '';
1173 $events[$i]['street2'] = '';
1174 $events[$i]['city'] = '';
1175 $events[$i]['state'] = '';
1176 $events[$i]['postal'] = '';
1177 } else {
1178 $display_type = substr($tmp['hometext'],0,6);
1179 if($display_type == ':text:') {
1180 $prepFunction = 'pcVarPrepForDisplay';
1181 $tmp['hometext'] = substr($tmp['hometext'],6);
1182 } elseif($display_type == ':html:') {
1183 $prepFunction = 'pcVarPrepHTMLDisplay';
1184 $tmp['hometext'] = substr($tmp['hometext'],6);
1185 } else {
1186 $prepFunction = 'pcVarPrepHTMLDisplay';
1188 unset($display_type);
1189 $events[$i]['title'] = $prepFunction($tmp['title']);
1190 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
1191 $events[$i]['desc'] = $events[$i]['hometext'];
1192 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
1193 $events[$i]['contname'] = $prepFunction($tmp['contname']);
1194 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
1195 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
1196 $events[$i]['fee'] = $prepFunction($tmp['fee']);
1197 $loc = unserialize($tmp['location']);
1198 $events[$i]['location'] = $prepFunction($loc['event_location']);
1199 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
1200 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
1201 $events[$i]['city'] = $prepFunction($loc['event_city']);
1202 $events[$i]['state'] = $prepFunction($loc['event_state']);
1203 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
1205 $i++;
1207 unset($tmp);
1208 $result->Close();
1209 return $events;
1213 function getBlockTime($time) {
1215 if ($time == 0 || strlen($time) == 0) {
1217 return "all_day";
1219 $ts = strtotime($time);
1220 $half = 0;
1221 $minutes = date("i",$ts);
1222 $hour = date("H",$ts);
1223 if ($minutes >= 30)
1224 $half = 1;
1225 $blocknum = (($hour * 2) +$half);
1226 return strval($blocknum);
1229 /*==========================
1230 * Gather up all the Events matching the arguements
1231 * Arguements can be:
1232 * start = starting date in m/d/Y format
1233 * end = ending date in m/d/Y format
1234 * viewtype = day|week|month|year
1235 * provider_id = array of numeric IDs <-- specified by JRM
1236 *========================== */
1237 function &postcalendar_userapi_pcGetEvents($args)
1239 $s_keywords = $s_category = $s_topic = '';
1240 extract($args);
1242 $date =postcalendar_getDate();
1243 $cy = substr($date,0,4);
1244 $cm = substr($date,4,2);
1245 $cd = substr($date,6,2);
1246 if(isset($start) && isset($end)) {
1247 // parse start date
1248 list($sm,$sd,$sy) = explode('/',$start);
1249 // parse end date
1250 list($em,$ed,$ey) = explode('/',$end);
1252 $s = (int) "$sy$sm$sd";
1253 if($s > $date) {
1254 $cy = $sy;
1255 $cm = $sm;
1256 $cd = $sd;
1258 $start_date = Date_Calc::dateFormat($sd,$sm,$sy,'%Y-%m-%d');
1259 $end_date = Date_Calc::dateFormat($ed,$em,$ey,'%Y-%m-%d');
1260 } else {
1261 // missing start OR end date, set them to the current date
1262 $sm = $em = $cm;
1263 $sd = $ed = $cd;
1264 $sy = $cy;
1265 $ey = $cy+2;
1266 $start_date = $sy.'-'.$sm.'-'.$sd;
1267 $end_date = $ey.'-'.$em.'-'.$ed;
1270 if ($faFlag && !isset($events)) {
1271 $a = array('faFlag' => true,'start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, 'provider_id' => $provider_id, 'event_status' => $event_status);
1272 $events = pnModAPIFunc(__POSTCALENDAR__,'user','<strong></strong>pcQueryEventsFA',$a);
1274 elseif ($collideFlag && !isset($events)) {
1275 $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime);
1276 $events = pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a);
1278 elseif ($listappsFlag && !isset($events)) {
1279 $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords);
1280 $events = pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1282 else if(!isset($events)) {
1283 if(!isset($s_keywords)) $s_keywords = '';
1284 $a = array('start'=>$start_date,'end'=>$end_date,'s_keywords'=>$s_keywords,'s_category'=>$s_category,'s_topic'=>$s_topic,'viewtype'=>$viewtype, "sort" => "pc_startTime ASC, a.pc_duration ASC ",'providerID' => $providerID, 'provider_id' => $provider_id);
1285 $events = pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1288 //==============================================================
1289 // Here we build an array consisting of the date ranges
1290 // specific to the current view. This array is then
1291 // used to build the calendar display.
1292 //==============================================================
1293 $days = array();
1294 $sday = Date_Calc::dateToDays($sd,$sm,$sy);
1295 $eday = Date_Calc::dateToDays($ed,$em,$ey);
1296 for($cday = $sday; $cday <= $eday; $cday++) {
1297 $d = Date_Calc::daysToDate($cday,'%d');
1298 $m = Date_Calc::daysToDate($cday,'%m');
1299 $y = Date_Calc::daysToDate($cday,'%Y');
1300 $store_date = Date_Calc::dateFormat($d,$m,$y,'%Y-%m-%d');
1301 $days[$store_date] = array();
1303 $days = calculateEvents($days,$events,$viewtype);
1304 return $days;
1307 //===========================
1308 // Given an array of events, an array of days, and a view type
1309 // fill days with events (recurring is the challenge)
1310 //===========================
1311 function calculateEvents($days,$events,$viewtype) {
1312 $date =postcalendar_getDate();
1313 $cy = substr($date,0,4);
1314 $cm = substr($date,4,2);
1315 $cd = substr($date,6,2);
1317 foreach($events as $event) {
1318 // get the name of the topic
1319 $topicname = pcGetTopicName($event['topic']);
1321 // parse the event start date
1322 list($esY,$esM,$esD) = explode('-',$event['eventDate']);
1324 // grab the recurring specs for the event
1325 $event_recurrspec = @unserialize($event['recurrspec']);
1327 // determine the stop date for this event
1328 if($event['endDate'] == '0000-00-00') {
1329 $stop = $end_date; // <--- this isn't previously defined !!
1330 } else {
1331 $stop = $event['endDate'];
1334 // here the start_date value is set to whatever comes in
1335 // on postcalendar_getDate() which is not always the first
1336 // date of the days array -- JRM
1337 $start_date = "$cy-$cm-$cd";
1339 // here we've made the start_date equal to the first date
1340 // of the days array, makes sense, right? -- JRM
1341 $days_keys = array_keys($days);
1342 $start_date = $days_keys[0];
1344 // Optimization of the stop date to not be much later than required.
1345 $tmpsecs = strtotime($start_date);
1346 if ($viewtype == 'day') $tmpsecs += 3 * 24 * 3600;
1347 else if ($viewtype == 'week') $tmpsecs += 9 * 24 * 3600;
1348 else if ($viewtype == 'month') $tmpsecs += 34 * 24 * 3600;
1349 else $tmpsecs += 367 * 24 * 3600;
1350 $tmp = date('Y-m-d', $tmpsecs);
1351 if ($stop > $tmp) $stop = $tmp;
1353 $eventD = $event['eventDate'];
1354 $eventS = $event['startTime'];
1356 switch($event['recurrtype']) {
1358 //==============================================================
1359 // Events that do not repeat only have a startday
1360 //==============================================================
1361 case NO_REPEAT :
1363 if(isset($days[$event['eventDate']])) {
1364 array_push($days[$event['eventDate']],$event);
1365 if ($viewtype == "week") {
1366 //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."<br />";
1367 fillBlocks($eventD,$days);
1368 //echo "for $eventD loading " . getBlockTime($eventS) . "<br /><br />";
1369 $gbt = getBlockTime($eventS);
1370 $days[$eventD]['blocks'][$gbt][$eventD][] = $event;
1371 //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . " <br />";
1372 //echo "begin printing blocks for $eventD<br />";
1373 //print_r($days[$eventD]['blocks']);
1374 //echo "end printing blocks<br />";
1378 break;
1380 //==============================================================
1381 // Find events that repeat at a certain frequency
1382 // Every,Every Other,Every Third,Every Fourth
1383 // Day,Week,Month,Year,MWF,TR,M-F,SS
1384 //==============================================================
1385 case REPEAT :
1387 $rfreq = $event_recurrspec['event_repeat_freq'];
1388 $rtype = $event_recurrspec['event_repeat_freq_type'];
1389 $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt
1391 // we should bring the event up to date to make this a tad bit faster
1392 // any ideas on how to do that, exactly??? dateToDays probably.
1393 $nm = $esM; $ny = $esY; $nd = $esD;
1394 $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d');
1395 while($occurance < $start_date) {
1396 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1397 list($ny,$nm,$nd) = explode('-',$occurance);
1399 while($occurance <= $stop) {
1400 if(isset($days[$occurance])) {
1401 // check for date exceptions before pushing the event into the days array -- JRM
1402 $excluded = false;
1403 if (isset($exdate)) {
1404 foreach (explode(",", $exdate) as $exception) {
1405 // occurrance format == yyyy-mm-dd
1406 // exception format == yyyymmdd
1407 if (preg_replace("/-/", "", $occurance) == $exception) {
1408 $excluded = true;
1413 // push event into the days array
1414 if ($excluded == false) array_push($days[$occurance],$event);
1416 if ($viewtype == "week") {
1417 fillBlocks($occurance, $days);
1418 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1419 $gbt = getBlockTime($eventS);
1420 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1421 //echo "begin printing blocks for $eventD<br />";
1422 //print_r($days[$occurance]['blocks']);
1423 //echo "end printing blocks<br />";
1426 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1427 list($ny,$nm,$nd) = explode('-',$occurance);
1429 break;
1431 //==============================================================
1432 // Find events that repeat on certain parameters
1433 // On 1st,2nd,3rd,4th,Last
1434 // Sun,Mon,Tue,Wed,Thu,Fri,Sat
1435 // Every N Months
1436 //==============================================================
1437 case REPEAT_ON :
1439 $rfreq = $event_recurrspec['event_repeat_on_freq'];
1440 $rnum = $event_recurrspec['event_repeat_on_num'];
1441 $rday = $event_recurrspec['event_repeat_on_day'];
1442 $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt
1444 //==============================================================
1445 // Populate - Enter data into the event array
1446 //==============================================================
1447 $nm = $esM; $ny = $esY; $nd = $esD;
1448 // make us current
1449 while($ny < $cy) {
1450 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1451 list($ny,$nm,$nd) = explode('-',$occurance);
1454 // populate the event array
1455 while($ny <= $cy) {
1456 $dnum = $rnum; // get day event repeats on
1457 do {
1458 $occurance = Date_Calc::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d");
1459 } while($occurance === -1);
1461 if(isset($days[$occurance]) && $occurance <= $stop) {
1462 // check for date exceptions before pushing the event into the days array -- JRM
1463 $excluded = false;
1464 if (isset($exdate)) {
1465 foreach (explode(",", $exdate) as $exception) {
1466 // occurrance format == yyyy-mm-dd
1467 // exception format == yyyymmdd
1468 if (preg_replace("/-/", "", $occurance) == $exception) {
1469 $excluded = true;
1474 // push event into the days array
1475 if ($excluded == false) array_push($days[$occurance],$event);
1477 if ($viewtype == "week") {
1478 fillBlocks($occurance,$days);
1479 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1480 $gbt = getBlockTime($eventS);
1481 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1484 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1485 list($ny,$nm,$nd) = explode('-',$occurance);
1488 break;
1490 } // <- end of switch($event['recurrtype'])
1491 } // <- end of foreach($events as $event)
1492 return $days;
1495 function fillBlocks($td,$ar) {
1496 if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) {
1497 $ar[$td]['blocks'] = array();
1498 for ($j=0;$j<48;$j++)
1499 $ar[strval($td)]['blocks'][strval($j)] = array();
1500 $ar[strval($td)]['blocks']["all_day"] = array();