Phyaura Calendar speed inhancement
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnuserapi.php
blob8eba1c7a52d84e5805dd4227e4120fae08f9b39b
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 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
34 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
35 require_once("modules/$pcDir/common.api.php");
36 unset($pcModInfo,$pcDir);
38 function postcalendar_userapi_getLongDayName($args)
40 extract($args); unset($args);
41 if(!isset($Date)) { return false; }
42 $pc_long_day = array(_CALLONGFIRSTDAY,
43 _CALLONGSECONDDAY,
44 _CALLONGTHIRDDAY,
45 _CALLONGFOURTHDAY,
46 _CALLONGFIFTHDAY,
47 _CALLONGSIXTHDAY,
48 _CALLONGSEVENTHDAY);
49 return $pc_long_day[Date("w",$Date)];
52 /**
53 * postcalendar_userapi_buildView
55 * Builds the calendar display
56 * @param string $Date mm/dd/yyyy format (we should use timestamps)
57 * @return string generated html output
58 * @access public
60 function postcalendar_userapi_buildView($args)
62 $print = pnVarCleanFromInput('print');
63 $show_days = pnVarCleanFromInput('show_days');
64 extract($args); unset($args);
65 $schedule_start = $GLOBALS[schedule_start];
66 $schedule_end = $GLOBALS[schedule_end];
68 // $times is an array of associative arrays, where each sub-array
69 // has keys 'hour', 'minute' and 'mer'.
71 $times = array();
73 // For each hour in the schedule...
75 for($blocknum = $schedule_start; $blocknum <= $schedule_end; $blocknum++){
76 $mer = ($blocknum >= 12) ? 'pm' : 'am';
78 // $minute is an array of time slot strings within this hour.
79 $minute = array('00');
81 for($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) {
82 if($minutes <= '9'){
83 $under_ten = "0" . $minutes;
84 array_push($minute, "$under_ten");
86 else if($minutes >= '60') {
87 break;
89 else {
90 array_push($minute, "$minutes");
94 foreach($minute as $m ){
95 array_push($times, array("hour"=>$blocknum, "minute"=>$m, "mer"=>$mer));
99 //=================================================================
100 // get the module's information
101 //=================================================================
102 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
103 $pcDir = $modinfo['directory'];
104 unset($modinfo);
106 //=================================================================
107 // grab the for post variable
108 //=================================================================
109 // $pc_username = pnVarCleanFromInput('pc_username');
110 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
111 $category = pnVarCleanFromInput('pc_category');
112 $topic = pnVarCleanFromInput('pc_topic');
114 //=================================================================
115 // set the correct date
116 //=================================================================
117 $Date =& postcalendar_getDate();
119 //=================================================================
120 // get the current view
121 //=================================================================
122 if(!isset($viewtype)) { $viewtype = 'month'; }
124 //=================================================================
125 // Find out what Template we're using
126 //=================================================================
127 $template_name = _SETTING_TEMPLATE;
128 if(!isset($template_name)) { $template_name = 'default'; }
130 //=================================================================
131 // Find out what Template View to use
132 //=================================================================
133 $template_view = pnVarCleanFromInput('tplview');
134 if(!isset($template_view)) { $template_view = 'default'; }
136 //=================================================================
137 // See if the template view exists
138 //=================================================================
139 if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) {
140 $template_view_load = 'default';
141 } else {
142 $template_view_load = pnVarPrepForOS($template_view);
145 //=================================================================
146 // Grab the current theme information
147 //=================================================================
148 pnThemeLoad(pnUserGetTheme());
149 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2;
151 //=================================================================
152 // Insert necessary JavaScript into the page
153 //=================================================================
154 $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup');
156 //=================================================================
157 // Setup Smarty Template Engine
158 //=================================================================
159 $tpl = new pcSmarty();
161 //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) {
162 //diable caching completely
163 if (true) {
164 //=================================================================
165 // Let's just finish setting things up
166 //=================================================================
167 $the_year = substr($Date,0,4);
168 $the_month = substr($Date,4,2);
169 $the_day = substr($Date,6,2);
170 $last_day = Date_Calc::daysInMonth($the_month,$the_year);
172 //=================================================================
173 // populate the template object with information for
174 // Month Names, Long Day Names and Short Day Names
175 // as translated in the language files
176 // (may be adding more here soon - based on need)
177 //=================================================================
178 $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN,
179 _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC);
181 $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT,
182 _CALTUESDAYSHORT, _CALWEDNESDAYSHORT,
183 _CALTHURSDAYSHORT, _CALFRIDAYSHORT,
184 _CALSATURDAYSHORT);
186 $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY,
187 _CALTUESDAY, _CALWEDNESDAY,
188 _CALTHURSDAY, _CALFRIDAY,
189 _CALSATURDAY);
190 //=================================================================
191 // here we need to set up some information for later
192 // variable creation. This helps us establish the correct
193 // date ranges for each view. There may be a better way
194 // to handle all this, but my brain hurts, so your comments
195 // are very appreciated and welcomed.
196 //=================================================================
197 switch (_SETTING_FIRST_DAY_WEEK)
199 case _IS_MONDAY:
200 $pc_array_pos = 1;
201 $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year));
202 $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year));
203 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
204 if($end_dow != 0) {
205 $the_last_day = $last_day+(7-$end_dow);
206 } else {
207 $the_last_day = $last_day;
209 break;
210 case _IS_SATURDAY:
211 $pc_array_pos = 6;
212 $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year));
213 $week_day = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year));
214 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
215 if($end_dow == 6) {
216 $the_last_day = $last_day+6;
217 } elseif($end_dow != 5) {
218 $the_last_day = $last_day+(5-$end_dow);
219 } else {
220 $the_last_day = $last_day;
222 break;
223 case _IS_SUNDAY:
224 default:
225 $pc_array_pos = 0;
226 $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
227 $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year));
228 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
229 if($end_dow != 6) {
230 $the_last_day = $last_day+(6-$end_dow);
231 } else {
232 $the_last_day = $last_day;
234 break;
237 // passing the times array to the tpl the times array is for the days schedule
238 $tpl->assign_by_ref("times",$times);
239 // load the table width to the template
240 // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']);
242 //=================================================================
243 // Week View is a bit of a pain in the ass, so we need to
244 // do some extra setup for that view. This section will
245 // find the correct starting and ending dates for a given
246 // seven day period, based on the day of the week the
247 // calendar is setup to run under (Sunday, Saturday, Monday)
248 //=================================================================
249 $first_day_of_week = sprintf('%02d',$the_day-$week_day);
250 $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
251 list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day);
252 $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
253 array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year)));
254 $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
255 list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day);
256 $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
257 array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year)));
259 $week_view_start = date('Y-m-d',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
260 $week_view_end = date('Y-m-d',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
262 //=================================================================
263 // Setup some information so we know the actual month's dates
264 // also get today's date for later use and highlighting
265 //=================================================================
266 $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year));
267 $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year));
268 $today_date = postcalendar_today('%Y-%m-%d');
270 //=================================================================
271 // Setup the starting and ending date ranges for pcGetEvents()
272 //=================================================================
273 switch($viewtype) {
274 case 'day' :
275 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
276 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
277 break;
278 case 'week' :
279 $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year";
280 $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year";
281 $calendarView = Date_Calc::getCalendarWeek($week_first_day_date,
282 $week_first_day_month,
283 $week_first_day_year,
284 '%Y-%m-%d');
285 break;
286 case 'month' :
287 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year));
288 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year));
289 $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d');
290 break;
291 case 'year' :
292 $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year));
293 $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1));
294 $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d');
295 break;
299 //=================================================================
300 // Identify the Providers whose schedules we should load
301 //=================================================================
303 //==================================
304 //FACILITY FILTERING (CHEMED)
305 if ( $_SESSION['pc_facility'] ) {
306 $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
307 } else {
308 $provinfo = getProviderInfo();
310 //EOS FACILITY FILTERING (CHEMED)
311 //==================================
313 $single = array();
314 $provIDs = array(); // array of numeric provider IDs
316 // filter the display on the requested username, the provinfo array is
317 // used to build columns in the week view.
319 foreach($provinfo as $provider) {
320 if(is_array($pc_username)){
321 foreach($pc_username as $uname) {
322 if (!empty($pc_username) && $provider['username'] == $uname) {
323 array_push($single,$provider);
324 array_push($provIDs,$provider['id']);
328 else {
329 if (!empty($pc_username) && $provider['username'] == $pc_username) {
330 array_push($single,$provider);
331 array_push($provIDs,$provider['id']);
335 if ($single != null) {
336 $provinfo = $single;
339 //=================================================================
340 // Load the events
341 //=================================================================
342 if($viewtype != 'year') {
343 $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype, 'provider_id' => $provIDs));
344 } else {
345 $eventsByDate = array();
349 //=================================================================
350 // Create an array with the day names in the correct order
351 //=================================================================
352 $daynames = array();
353 $numDays = count($pc_long_day_names);
354 for($i=0; $i < $numDays; $i++) {
355 if($pc_array_pos >= $numDays) {
356 $pc_array_pos = 0;
358 array_push($daynames,$pc_long_day_names[$pc_array_pos]);
359 $pc_array_pos++;
361 unset($numDays);
362 $sdaynames = array();
363 $numDays = count($pc_short_day_names);
364 for($i=0; $i < $numDays; $i++) {
365 if($pc_array_pos >= $numDays) {
366 $pc_array_pos = 0;
368 array_push($sdaynames,$pc_short_day_names[$pc_array_pos]);
369 $pc_array_pos++;
371 unset($numDays);
373 //=================================================================
374 // Prepare some values for the template
375 //=================================================================
376 $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d');
377 $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d');
379 $pc_prev = pnModURL(__POSTCALENDAR__,'user','view',
380 array('tplview'=>$template_view,
381 'viewtype'=>'month',
382 'Date'=>$prev_month,
383 'pc_username'=>$pc_username,
384 'pc_category'=>$category,
385 'pc_topic'=>$topic));
387 $pc_next = pnModURL(__POSTCALENDAR__,'user','view',
388 array('tplview'=>$template_view,
389 'viewtype'=>'month',
390 'Date'=>$next_month,
391 'pc_username'=>$pc_username,
392 'pc_category'=>$category,
393 'pc_topic'=>$topic));
395 $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d');
396 $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d');
397 $pc_prev_day = pnModURL(__POSTCALENDAR__,'user','view',
398 array('tplview'=>$template_view,
399 'viewtype'=>'day',
400 'Date'=>$prev_day,
401 'pc_username'=>$pc_username,
402 'pc_category'=>$category,
403 'pc_topic'=>$topic));
405 $pc_next_day = pnModURL(__POSTCALENDAR__,'user','view',
406 array('tplview'=>$template_view,
407 'viewtype'=>'day',
408 'Date'=>$next_day,
409 'pc_username'=>$pc_username,
410 'pc_category'=>$category,
411 'pc_topic'=>$topic));
413 $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year));
414 $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year));
415 $pc_prev_week = pnModURL(__POSTCALENDAR__,'user','view',
416 array('viewtype'=>'week',
417 'Date'=>$prev_week,
418 'pc_username'=>$pc_username,
419 'pc_category'=>$category,
420 'pc_topic'=>$topic));
421 $pc_next_week = pnModURL(__POSTCALENDAR__,'user','view',
422 array('viewtype'=>'week',
423 'Date'=>$next_week,
424 'pc_username'=>$pc_username,
425 'pc_category'=>$category,
426 'pc_topic'=>$topic));
428 $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1));
429 $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1));
430 $pc_prev_year = pnModURL(__POSTCALENDAR__,'user','view',
431 array('viewtype'=>'year',
432 'Date'=>$prev_year,
433 'pc_username'=>$pc_username,
434 'pc_category'=>$category,
435 'pc_topic'=>$topic));
436 $pc_next_year = pnModURL(__POSTCALENDAR__,'user','view',
437 array('viewtype'=>'year',
438 'Date'=>$next_year,
439 'pc_username'=>$pc_username,
440 'pc_category'=>$category,
441 'pc_topic'=>$topic));
443 //=================================================================
444 // Populate the template
445 //=================================================================
446 $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
448 if(isset($calendarView)) {
449 $tpl->assign_by_ref('CAL_FORMAT',$calendarView);
452 if ($viewtype == "week") {
453 $last_blocks = array();
454 foreach($eventsByDate as $cdate => $day) {
455 $tblock = array_reverse($day['blocks']);
456 $last_blocks[$cdate] = count($tblock) -1;
457 for ($i=0;$i<count($tblock);$i++) {
458 if (!empty($tblock[$i])) {
459 $last_blocks[$cdate] = count($tblock) - $i;
460 break;
464 $tpl->assign("last_blocks",$last_blocks);
467 $tpl->assign('STYLE',$GLOBALS['style']);
468 $tpl->assign('show_days',$show_days);
470 //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other");
471 $tpl->assign_by_ref('providers', $provinfo);
473 if (pnVarCleanFromInput("show_days") != 1) {
474 $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1");
477 $tpl->assign('interval', $GLOBALS['calendar_interval']);
478 $tpl->assign_by_ref('VIEW_TYPE',$viewtype);
479 $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names);
480 $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names);
481 $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names);
482 $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames);
483 $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames);
484 $tpl->assign_by_ref('A_EVENTS',$eventsByDate);
485 $tpl->assign_by_ref('A_CATEGORY',$all_categories);
486 $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev);
487 $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next);
488 $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day);
489 $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day);
490 $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week);
491 $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week);
492 $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year);
493 $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year);
494 $tpl->assign_by_ref('WEEK_START_DATE',$week_view_start);
495 $tpl->assign_by_ref('WEEK_END_DATE',$week_view_end);
496 $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start);
497 $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end);
498 $tpl->assign_by_ref('TODAY_DATE',$today_date);
499 $tpl->assign_by_ref('DATE',$Date);
500 $tpl->assign_by_ref('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__,'user','submit'));
501 $tpl->assign_by_ref('interval',$intervals);
504 //=================================================================
505 // Parse the template
506 //=================================================================
507 $template = "$template_name/views/$viewtype/$template_view_load.html";
508 if(!$print) {
509 $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
510 $output .= $tpl->fetch($template,$cacheid); // cache id
511 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
512 } else {
513 $theme = pnUserGetTheme();
514 echo "<html><head>";
515 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
516 echo "<style type=\"text/css\">\n";
517 echo "@import url(\"themes/$theme/style/style.css\"); ";
518 echo "</style>\n";
519 echo "</head><body>\n";
520 echo $output;
521 $tpl->display($template,$cacheid);
522 echo postcalendar_footer();
523 echo "\n</body></html>";
524 session_write_close();
525 exit;
527 //=================================================================
528 // Return the output
529 //=================================================================
530 return $output;
534 * postcalendar_userapi_eventPreview
535 * Creates the detailed event display and outputs html.
536 * Accepts an array of key/value pairs
537 * @param array $event array of event details from the form
538 * @return string html output
539 * @access public
541 function postcalendar_userapi_eventPreview($args)
543 // get the theme globals :: is there a better way to do this?
544 pnThemeLoad(pnUserGetTheme());
545 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
546 global $textcolor1, $textcolor2;
548 extract($args); unset($args);
549 $uid = pnUserGetVar('uid');
550 //=================================================================
551 // Setup Smarty Template Engine
552 //=================================================================
553 $tpl = new pcSmarty();
554 $tpl->caching = false;
555 // add preceding zeros
556 $event_starttimeh = sprintf('%02d',$event_starttimeh);
557 $event_starttimem = sprintf('%02d',$event_starttimem);
558 $event_startday = sprintf('%02d',$event_startday);
559 $event_startmonth = sprintf('%02d',$event_startmonth);
560 $event_endday = sprintf('%02d',$event_endday);
561 $event_endmonth = sprintf('%02d',$event_endmonth);
563 if(!(bool)_SETTING_TIME_24HOUR) {
564 if($event_startampm == _PM_VAL) {
565 if($event_starttimeh != 12) {
566 $event_starttimeh+=12;
568 } elseif($event_startampm == _AM_VAL) {
569 if($event_starttimeh == 12) {
570 $event_starttimeh = 00;
575 $event_startampm." - ";
576 $startTime = $event_starttimeh.':'.$event_starttimem.' ';
578 $event = array();
579 $event['eid'] = '';
580 $event['uname'] = $uname;
581 $event['catid'] = $event_category;
582 if($pc_html_or_text == 'html') {
583 $prepFunction = 'pcVarPrepHTMLDisplay';
584 } else {
585 $prepFunction = 'pcVarPrepForDisplay';
587 $event['title'] = $prepFunction($event_subject);
588 $event['hometext'] = $prepFunction($event_desc);
589 $event['desc'] = $event['hometext'];
590 $event['date'] = $event_startyear.$event_startmonth.$event_startday;
591 $event['duration'] = $event_duration;
592 $event['duration_hours'] = $event_dur_hours;
593 $event['duration_minutes'] = $event_dur_minutes;
594 $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
595 $event['startTime'] = $startTime;
596 $event['recurrtype'] = '';
597 $event['recurrfreq'] = '';
598 $event['recurrspec'] = $event_recurrspec;
599 $event['topic'] = $event_topic;
600 $event['alldayevent'] = $event_allday;
601 $event['conttel'] = $prepFunction($event_conttel);
602 $event['contname'] = $prepFunction($event_contname);
603 $event['contemail'] = $prepFunction($event_contemail);
604 $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website));
605 $event['fee'] = $prepFunction($event_fee);
606 $event['location'] = $prepFunction($event_location);
607 $event['street1'] = $prepFunction($event_street1);
608 $event['street2'] = $prepFunction($event_street2);
609 $event['city'] = $prepFunction($event_city);
610 $event['state'] = $prepFunction($event_state);
611 $event['postal'] = $prepFunction($event_postal);
613 //=================================================================
614 // get event's topic information
615 //=================================================================
616 if(_SETTING_DISPLAY_TOPICS) {
617 list($dbconn) = pnDBGetConn();
618 $pntable = pnDBGetTables();
619 $topics_table = $pntable['topics'];
620 $topics_column = $pntable['topics_column'];
621 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
622 FROM $topics_table
623 WHERE $topics_column[topicid] = $event[topic]
624 LIMIT 1";
625 $topic_result = $dbconn->Execute($topicsql);
626 list($event['topictext'],$event['topicimg']) = $topic_result->fields;
627 $topic_result->Close();
628 } else {
629 $event['topictext'] = $event['topicimg'] = '';
631 //=================================================================
632 // Find out what Template we're using
633 //=================================================================
634 $template_name = _SETTING_TEMPLATE;
635 if(!isset($template_name)) {
636 $template_name = 'default';
638 //=================================================================
639 // populate the template
640 //=================================================================
641 if(!empty($event['location']) || !empty($event['street1']) ||
642 !empty($event['street2']) || !empty($event['city']) ||
643 !empty($event['state']) || !empty($event['postal'])) {
644 $tpl->assign('LOCATION_INFO',true);
645 } else {
646 $tpl->assign('LOCATION_INFO',false);
648 if(!empty($event['contname']) || !empty($event['contemail']) ||
649 !empty($event['conttel']) || !empty($event['website'])) {
650 $tpl->assign('CONTACT_INFO',true);
651 } else {
652 $tpl->assign('CONTACT_INFO',false);
654 $tpl->assign_by_ref('A_EVENT',$event);
655 $tpl->assign('STYLE',$GLOBALS['style']);
656 //=================================================================
657 // Parse the template
658 //=================================================================
659 $output = "\n\n<!-- POSTCALENDAR HTTP://WWW.BAHRAINI.TV -->\n\n";
660 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE START -->\n\n";
661 $output .= $tpl->fetch($template_name.'/user/preview.html');
662 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE END -->\n\n";
664 return $output;
668 * checkEventCollision
669 * Returns an array containing any events that collide with the specified event
670 * @params array(key=>value)
671 * @return array $events[][]
673 function checkEventCollision($edata) {
675 extract($edata);
676 $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear);
677 $edate = $sdate;
678 //hour from forms is 12 not 24 format, convert here
679 if($event_startampm == 2 && $event_starttimeh != 12)
680 $event_starttimeh += 12;
681 elseif ($event_startampm == 1 && $event_starttimeh == 12)
682 $event_starttimeh -= 12;
684 $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00'));
685 $etime = date("H:i:00",$event_duration + strtotime($stime));
686 //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
687 $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime);
688 $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
689 //print_r($eventsByDate);
690 $collisions = array();
691 foreach ($eventsByDate as $day) {
692 foreach ($day as $event) {
693 if ($event['duration'] == 0 && $event['alldayevent'] == 0) {
694 continue;
696 elseif($event['alldayevent'] == 1) {
697 $collisions[] = $event;
699 $festart = strtotime($event['startTime']);
700 $feend = strtotime($event['startTime'] + $event['duration']);
701 $estart = strtotime($stime);
702 $eend = strtotime($etime);
704 //echo "festart = $festart feend = $feend estart = $estart eend = $eend<br />";
705 if ($festart < $eend && $feend > $estart) {
706 $collisions[] = $event;
708 elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) {
709 $collisions[] = $event;
711 elseif ($festart >= $estart && $festart < $eend) {
712 $collisions[] = $event;
716 //foreach ($collisions as $collide) {
717 // echo "collided: " . $collide['title'] . "<br />";
719 return $collisions;
723 * postcalendar_userapi_pcQueryEventsFA
724 * Returns an array containing the event's information for first available queiries
725 * @params array(key=>value)
726 * @params string key eventstatus
727 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
728 * @return array $events[][]
730 function &postcalendar_userapi_pcQueryEventsFA($args) {
732 $end = '0000-00-00';
733 extract($args);
734 $eventstatus = 1;
735 if (is_numeric($event_status))
736 $eventstatus = $event_status;
738 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
739 list($sy,$sm,$sd) = explode('-',$start);
741 list($dbconn) = pnDBGetConn();
742 $pntable = pnDBGetTables();
743 // link to the events tables
744 $table = $pntable['postcalendar_events'];
745 $cattable = $pntable['postcalendar_categories'];
747 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " .
748 "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " .
749 "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " .
750 "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " .
751 "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " .
752 "a.pc_prefcatid, " .
753 "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " .
754 "concat(u.fname,' ',u.lname) as provider_name, " .
755 "concat(pd.fname,' ',pd.lname) as patient_name, " .
756 "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob " .
757 "FROM ( $table AS a ) " .
758 "LEFT JOIN $cattable AS b ON b.pc_catid = a.pc_catid " .
759 "LEFT JOIN users as u ON a.pc_aid = u.id " .
760 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
761 "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " .
762 "WHERE a.pc_eventstatus = $eventstatus " .
763 "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " .
764 "AND a.pc_eventDate <= '$end' " .
765 "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')";
767 //======================================================================
768 // START SEARCH FUNCTIONALITY
769 //======================================================================
770 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
771 if(!empty($s_category)) $sql .= "AND ($s_category) ";
772 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
773 if(!empty($collide_etime) && !empty($collide_stime)) {
774 $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL ";
776 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
777 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
778 //======================================================================
779 // Search sort and limitation
780 //======================================================================
781 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC";
782 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
783 //======================================================================
784 // END SEARCH FUNCTIONALITY
785 //======================================================================
786 //echo "<Br />sql: $sql<br />";
787 $result = $dbconn->Execute($sql);
788 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
790 // put the information into an array for easy access
791 $events = array();
792 // return an empty array if we don't have any results
793 if(!isset($result)) { return $events; }
795 for($i=0; !$result->EOF; $result->MoveNext()) {
797 // get the results from the query
798 if(isset($tmp)) { unset($tmp); } $tmp = array();
799 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
800 $tmp['title'], $tmp['time'], $tmp['hometext'],
801 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
802 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
803 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
804 $tmp['location'], $tmp['conttel'], $tmp['contname'],
805 $tmp['contemail'], $tmp['website'], $tmp['fee'],
806 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
807 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
808 $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'],
809 $tmp['owner_name'], $tmp['patient_dob']) = $result->fields;
811 // grab the name of the topic
812 $topicname = pcGetTopicName($tmp['topic']);
813 // get the user id of event's author
814 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
815 // check the current event's permissions
816 // the user does not have permission to view this event
817 // if any of the following evaluate as false
818 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
819 continue;
820 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
821 continue;
822 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
823 continue;
824 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
825 continue;
826 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
827 continue;
830 // add event to the array if we passed the permissions check
831 // this is the common information
832 $events[$i]['eid'] = $tmp['eid'];
833 $events[$i]['uname'] = $tmp['uname'];
834 $events[$i]['uid'] = $cuserid;
835 $events[$i]['catid'] = $tmp['catid'];
836 $events[$i]['time'] = $tmp['time'];
837 $events[$i]['eventDate'] = $tmp['eventDate'];
838 $events[$i]['duration'] = $tmp['duration'];
839 // there has to be a more intelligent way to do this
840 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
841 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
842 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
843 $events[$i]['endDate'] = $tmp['endDate'];
844 $events[$i]['startTime'] = $tmp['startTime'];
845 $events[$i]['recurrtype'] = $tmp['recurrtype'];
846 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
847 $events[$i]['recurrspec'] = $tmp['recurrspec'];
849 $rspecs = unserialize($tmp['recurrspec']);
850 $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
851 $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
852 $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
853 $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
854 $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
856 $events[$i]['topic'] = $tmp['topic'];
857 $events[$i]['alldayevent'] = $tmp['alldayevent'];
858 $events[$i]['catcolor'] = $tmp['catcolor'];
859 $events[$i]['catname'] = $tmp['catname'];
860 $events[$i]['catdesc'] = $tmp['catdesc'];
861 $events[$i]['pid'] = $tmp['pid'];
862 $events[$i]['patient_name']= $tmp['patient_name'];
863 $events[$i]['provider_name'] = $tmp['provider_name'];
864 $events[$i]['owner_name'] = $tmp['owner_name'];
865 $events[$i]['patient_dob'] = $tmp['patient_dob'];
866 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
867 $events[$i]['sharing'] = $tmp['sharing'];
868 $events[$i]['prefcatid'] = $tmp['prefcatid'];
869 $events[$i]['aid'] = $tmp['aid'];
870 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
871 if($events[$i]['intervals'] == 0)
872 $events[$i]['intervals'] = 1;
873 // is this a public event to be shown as busy?
874 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
875 // make it not display any information
876 $events[$i]['title'] = _USER_BUSY_TITLE;
877 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
878 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
879 $events[$i]['conttel'] = '';
880 $events[$i]['contname'] = '';
881 $events[$i]['contemail'] = '';
882 $events[$i]['website'] = '';
883 $events[$i]['fee'] = '';
884 $events[$i]['location'] = '';
885 $events[$i]['street1'] = '';
886 $events[$i]['street2'] = '';
887 $events[$i]['city'] = '';
888 $events[$i]['state'] = '';
889 $events[$i]['postal'] = '';
890 } else {
891 $display_type = substr($tmp['hometext'],0,6);
892 if($display_type == ':text:') {
893 $prepFunction = 'pcVarPrepForDisplay';
894 $tmp['hometext'] = substr($tmp['hometext'],6);
895 } elseif($display_type == ':html:') {
896 $prepFunction = 'pcVarPrepHTMLDisplay';
897 $tmp['hometext'] = substr($tmp['hometext'],6);
898 } else {
899 $prepFunction = 'pcVarPrepHTMLDisplay';
901 unset($display_type);
902 $events[$i]['title'] = $prepFunction($tmp['title']);
903 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
904 $events[$i]['desc'] = $events[$i]['hometext'];
905 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
906 $events[$i]['contname'] = $prepFunction($tmp['contname']);
907 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
908 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
909 $events[$i]['fee'] = $prepFunction($tmp['fee']);
910 $loc = unserialize($tmp['location']);
911 $events[$i]['location'] = $prepFunction($loc['event_location']);
912 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
913 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
914 $events[$i]['city'] = $prepFunction($loc['event_city']);
915 $events[$i]['state'] = $prepFunction($loc['event_state']);
916 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
918 $i++;
920 unset($tmp);
921 $result->Close();
922 return $events;
927 * postcalendar_userapi_pcQueryEvents
928 * INPUT
929 * $args = Array of values possibly containing:
930 * $provider_id = array of provider ID numbers
932 * Returns an array containing the event's information
933 * @params array(key=>value)
934 * @params string key eventstatus
935 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
936 * @return array $events[][]
938 function &postcalendar_userapi_pcQueryEvents($args)
940 $end = '0000-00-00';
941 extract($args);
943 // echo "<!-- args = "; print_r($args); echo " -->\n"; // debugging
945 // $pc_username = pnVarCleanFromInput('pc_username');
946 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
947 if (empty($pc_username) || is_array($pc_username)) {
948 $pc_username = "__PC_ALL__";
951 //echo "DEBUG pc_username: $pc_username \n"; // debugging
953 $topic = pnVarCleanFromInput('pc_topic');
954 $category = pnVarCleanFromInput('pc_category');
955 if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) {
956 if($pc_username=='__PC_ALL__' || $pc_username == -1) {
957 $ruserid = -1;
958 } else {
959 $ruserid = getIDfromUser($pc_username);
963 if(!isset($eventstatus)) { $eventstatus = 1; }
964 // sanity check on eventstatus
965 if((int)$eventstatus < -1 || (int)$eventstatus > 1) { $eventstatus = 1; }
966 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
967 list($sy,$sm,$sd) = explode('-',$start);
969 list($dbconn) = pnDBGetConn();
970 $pntable = pnDBGetTables();
971 // link to the events tables
972 $table = $pntable['postcalendar_events'];
973 $cattable = $pntable['postcalendar_categories'];
974 $topictable = $pntable['postcalendar_topics'];
976 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " .
977 "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " .
978 "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " .
979 "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " .
980 "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " .
981 "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " .
982 "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " .
983 "concat(u.fname,' ',u.lname) as provider_name, " .
984 "concat(pd.lname,', ',pd.fname) as patient_name, " .
985 "concat(u2.fname, ' ', u2.lname) as owner_name, " .
986 "DOB as patient_dob, pd.pubpid " .
987 "FROM ( $table AS a ) " .
988 "LEFT JOIN $cattable AS b ON b.pc_catid = a.pc_catid ".
989 "LEFT JOIN users as u ON a.pc_aid = u.id " .
990 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
991 "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " .
992 "WHERE a.pc_eventstatus = $eventstatus " .
993 "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " .
994 "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " .
995 "a.pc_eventDate <= '$end')) ";
997 //==================================
998 //FACILITY FILTERING (lemonsoftware)(CHEMED)
999 if ( $_SESSION['pc_facility'] ) {
1000 $pc_facility = $_SESSION['pc_facility'];
1001 $sql .= " AND a.pc_facility = $pc_facility "; /*
1002 AND u.facility_id = $pc_facility
1003 AND u2.facility_id = $pc_facility "; */
1005 else if ($pc_facility) {
1006 // pc_facility could be provided in the search arguments -- JRM March 2008
1007 $sql .= " AND a.pc_facility = $pc_facility "; /*.
1008 " AND u.facility_id = $pc_facility".
1009 " AND u2.facility_id = $pc_facility "; */
1011 //EOS FACILITY FILTERING (lemonsoftware)
1012 //==================================
1015 // The above 3 lines replaced these:
1016 // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00')
1017 // AND a.pc_eventDate <= '$end' ";
1019 if(!empty($providerID)) { $ruserid = $providerID; }
1021 // eliminate ruserid if we're trying to query by provider_id -- JRM
1022 if (!empty($provider_id)) { unset($ruserid); }
1024 if(isset($ruserid)) {
1025 // get all events for the specified username
1026 if($ruserid == -1) {
1027 $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY . "' ";
1028 $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC . "') ";
1029 } else {
1030 $sql .= "AND a.pc_aid = " . $ruserid . " ";
1032 } elseif(!pnUserLoggedIn()) {
1033 // get all events for anonymous users
1034 $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL . "' ";
1035 } elseif(!empty($provider_id)) {
1036 // get all events for a variety of provider IDs -- JRM
1037 if ($provider_id[0] != "_ALL_") {
1038 $sql .= "AND a.pc_aid in (" . implode(",", $provider_id). ") ";
1040 } else {
1041 // get all events for logged in user plus global events
1042 $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL . "') ";
1045 //======================================================================
1046 // START SEARCH FUNCTIONALITY
1047 //======================================================================
1048 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
1049 if(!empty($s_category)) $sql .= "AND ($s_category) ";
1050 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
1051 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
1052 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
1054 //======================================================================
1055 // Search sort and limitation
1056 //======================================================================
1057 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC";
1058 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
1060 //======================================================================
1061 // END SEARCH FUNCTIONALITY
1062 //======================================================================
1063 //echo "<br>sq: $sql<br />";
1065 // echo "<!-- " . $sql . " -->\n"; // debugging
1067 $result = $dbconn->Execute($sql);
1068 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
1070 // put the information into an array for easy access
1071 $events = array();
1072 // return an empty array if we don't have any results
1073 if(!isset($result)) { return $events; }
1075 for($i=0; !$result->EOF; $result->MoveNext()) {
1077 // WHY are we using an array for intermediate storage??? -- Rod
1079 // get the results from the query
1080 if(isset($tmp)) { unset($tmp); } $tmp = array();
1081 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
1082 $tmp['title'], $tmp['time'], $tmp['hometext'],
1083 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
1084 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
1085 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
1086 $tmp['location'], $tmp['conttel'], $tmp['contname'],
1087 $tmp['contemail'], $tmp['website'], $tmp['fee'],
1088 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
1089 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
1090 $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'],
1091 $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'],
1092 $tmp['pubpid']) = $result->fields;
1094 // grab the name of the topic
1095 $topicname = pcGetTopicName($tmp['topic']);
1096 // get the user id of event's author
1097 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
1098 // check the current event's permissions
1099 // the user does not have permission to view this event
1100 // if any of the following evaluate as false
1101 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
1102 continue;
1103 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
1104 continue;
1105 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
1106 continue;
1107 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
1108 continue;
1109 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
1110 continue;
1113 // add event to the array if we passed the permissions check
1114 // this is the common information
1116 $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span
1117 print_r($events[$i]['intervals']);
1119 $events[$i]['eid'] = $tmp['eid'];
1120 $events[$i]['uname'] = $tmp['uname'];
1121 $events[$i]['uid'] = $cuserid;
1122 $events[$i]['catid'] = $tmp['catid'];
1123 $events[$i]['time'] = $tmp['time'];
1124 $events[$i]['eventDate'] = $tmp['eventDate'];
1125 $events[$i]['duration'] = $tmp['duration'];
1126 // there has to be a more intelligent way to do this
1127 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
1128 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1129 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1130 $events[$i]['endDate'] = $tmp['endDate'];
1131 $events[$i]['startTime'] = $tmp['startTime'];
1132 $events[$i]['recurrtype'] = $tmp['recurrtype'];
1133 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
1134 $events[$i]['recurrspec'] = $tmp['recurrspec'];
1135 $events[$i]['topic'] = $tmp['topic'];
1136 $events[$i]['alldayevent'] = $tmp['alldayevent'];
1137 $events[$i]['catcolor'] = $tmp['catcolor'];
1138 // Modified 06-2009 by BM to translate the category if applicable
1139 $events[$i]['catname'] = xl_appt_category($tmp['catname']);
1140 $events[$i]['catdesc'] = $tmp['catdesc'];
1141 $events[$i]['pid'] = $tmp['pid'];
1142 $events[$i]['apptstatus'] = $tmp['apptstatus'];
1143 $events[$i]['pubpid'] = $tmp['pubpid'];
1144 $events[$i]['patient_name']= $tmp['patient_name'];
1145 $events[$i]['provider_name'] = $tmp['provider_name'];
1146 $events[$i]['owner_name'] = $tmp['owner_name'];
1147 $events[$i]['patient_dob'] = $tmp['patient_dob'];
1148 $events[$i]['patient_age'] = getPatientAge($tmp['patient_dob']);
1149 $events[$i]['sharing'] = $tmp['sharing'];
1150 $events[$i]['prefcatid'] = $tmp['prefcatid'];
1151 $events[$i]['aid'] = $tmp['aid'];
1152 $events[$i]['topictext'] = $topicname;
1153 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
1154 if($events[$i]['intervals'] == 0)
1155 $events[$i]['intervals'] = 1;
1156 // is this a public event to be shown as busy?
1157 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
1158 // make it not display any information
1159 $events[$i]['title'] = _USER_BUSY_TITLE;
1160 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
1161 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
1162 $events[$i]['conttel'] = '';
1163 $events[$i]['contname'] = '';
1164 $events[$i]['contemail'] = '';
1165 $events[$i]['website'] = '';
1166 $events[$i]['fee'] = '';
1167 $events[$i]['location'] = '';
1168 $events[$i]['street1'] = '';
1169 $events[$i]['street2'] = '';
1170 $events[$i]['city'] = '';
1171 $events[$i]['state'] = '';
1172 $events[$i]['postal'] = '';
1173 } else {
1174 $display_type = substr($tmp['hometext'],0,6);
1175 if($display_type == ':text:') {
1176 $prepFunction = 'pcVarPrepForDisplay';
1177 $tmp['hometext'] = substr($tmp['hometext'],6);
1178 } elseif($display_type == ':html:') {
1179 $prepFunction = 'pcVarPrepHTMLDisplay';
1180 $tmp['hometext'] = substr($tmp['hometext'],6);
1181 } else {
1182 $prepFunction = 'pcVarPrepHTMLDisplay';
1184 unset($display_type);
1185 $events[$i]['title'] = $prepFunction($tmp['title']);
1186 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
1187 $events[$i]['desc'] = $events[$i]['hometext'];
1188 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
1189 $events[$i]['contname'] = $prepFunction($tmp['contname']);
1190 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
1191 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
1192 $events[$i]['fee'] = $prepFunction($tmp['fee']);
1193 $loc = unserialize($tmp['location']);
1194 $events[$i]['location'] = $prepFunction($loc['event_location']);
1195 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
1196 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
1197 $events[$i]['city'] = $prepFunction($loc['event_city']);
1198 $events[$i]['state'] = $prepFunction($loc['event_state']);
1199 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
1201 $i++;
1203 unset($tmp);
1204 $result->Close();
1205 return $events;
1209 function getBlockTime($time) {
1211 if ($time == 0 || strlen($time) == 0) {
1213 return "all_day";
1215 $ts = strtotime($time);
1216 $half = 0;
1217 $minutes = date("i",$ts);
1218 $hour = date("H",$ts);
1219 if ($minutes >= 30)
1220 $half = 1;
1221 $blocknum = (($hour * 2) +$half);
1222 return strval($blocknum);
1225 /*==========================
1226 * Gather up all the Events matching the arguements
1227 * Arguements can be:
1228 * start = starting date in m/d/Y format
1229 * end = ending date in m/d/Y format
1230 * viewtype = day|week|month|year
1231 * provider_id = array of numeric IDs <-- specified by JRM
1232 *========================== */
1233 function &postcalendar_userapi_pcGetEvents($args)
1235 $s_keywords = $s_category = $s_topic = '';
1236 extract($args);
1238 $date =& postcalendar_getDate();
1239 $cy = substr($date,0,4);
1240 $cm = substr($date,4,2);
1241 $cd = substr($date,6,2);
1242 if(isset($start) && isset($end)) {
1243 // parse start date
1244 list($sm,$sd,$sy) = explode('/',$start);
1245 // parse end date
1246 list($em,$ed,$ey) = explode('/',$end);
1248 $s = (int) "$sy$sm$sd";
1249 if($s > $date) {
1250 $cy = $sy;
1251 $cm = $sm;
1252 $cd = $sd;
1254 $start_date = Date_Calc::dateFormat($sd,$sm,$sy,'%Y-%m-%d');
1255 $end_date = Date_Calc::dateFormat($ed,$em,$ey,'%Y-%m-%d');
1256 } else {
1257 // missing start OR end date, set them to the current date
1258 $sm = $em = $cm;
1259 $sd = $ed = $cd;
1260 $sy = $cy;
1261 $ey = $cy+2;
1262 $start_date = $sy.'-'.$sm.'-'.$sd;
1263 $end_date = $ey.'-'.$em.'-'.$ed;
1266 if ($faFlag && !isset($events)) {
1267 $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);
1268 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','<strong></strong>pcQueryEventsFA',$a);
1270 elseif ($collideFlag && !isset($events)) {
1271 $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime);
1272 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a);
1274 elseif ($listappsFlag && !isset($events)) {
1275 $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords);
1276 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1278 else if(!isset($events)) {
1279 if(!isset($s_keywords)) $s_keywords = '';
1280 $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);
1281 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1284 //==============================================================
1285 // Here we build an array consisting of the date ranges
1286 // specific to the current view. This array is then
1287 // used to build the calendar display.
1288 //==============================================================
1289 $days = array();
1290 $sday = Date_Calc::dateToDays($sd,$sm,$sy);
1291 $eday = Date_Calc::dateToDays($ed,$em,$ey);
1292 for($cday = $sday; $cday <= $eday; $cday++) {
1293 $d = Date_Calc::daysToDate($cday,'%d');
1294 $m = Date_Calc::daysToDate($cday,'%m');
1295 $y = Date_Calc::daysToDate($cday,'%Y');
1296 $store_date = Date_Calc::dateFormat($d,$m,$y,'%Y-%m-%d');
1297 $days[$store_date] = array();
1299 $days = calculateEvents($days,$events,$viewtype);
1300 return $days;
1303 //===========================
1304 // Given an array of events, an array of days, and a view type
1305 // fill days with events (recurring is the challenge)
1306 //===========================
1307 function calculateEvents($days,$events,$viewtype) {
1308 $date =& postcalendar_getDate();
1309 $cy = substr($date,0,4);
1310 $cm = substr($date,4,2);
1311 $cd = substr($date,6,2);
1313 foreach($events as $event) {
1314 // get the name of the topic
1315 $topicname = pcGetTopicName($event['topic']);
1317 // parse the event start date
1318 list($esY,$esM,$esD) = explode('-',$event['eventDate']);
1320 // grab the recurring specs for the event
1321 $event_recurrspec = @unserialize($event['recurrspec']);
1323 // determine the stop date for this event
1324 if($event['endDate'] == '0000-00-00') {
1325 $stop = $end_date; // <--- this isn't previously defined !!
1326 } else {
1327 $stop = $event['endDate'];
1330 // here the start_date value is set to whatever comes in
1331 // on postcalendar_getDate() which is not always the first
1332 // date of the days array -- JRM
1333 $start_date = "$cy-$cm-$cd";
1335 // here we've made the start_date equal to the first date
1336 // of the days array, makes sense, right? -- JRM
1337 $days_keys = array_keys($days);
1338 $start_date = $days_keys[0];
1340 // Optimization of the stop date to not be much later than required.
1341 $tmpsecs = strtotime($start_date);
1342 if ($viewtype == 'day') $tmpsecs += 3 * 24 * 3600;
1343 else if ($viewtype == 'week') $tmpsecs += 9 * 24 * 3600;
1344 else if ($viewtype == 'month') $tmpsecs += 34 * 24 * 3600;
1345 else $tmpsecs += 367 * 24 * 3600;
1346 $tmp = date('Y-m-d', $tmpsecs);
1347 if ($stop > $tmp) $stop = $tmp;
1349 $eventD = $event['eventDate'];
1350 $eventS = $event['startTime'];
1352 switch($event['recurrtype']) {
1354 //==============================================================
1355 // Events that do not repeat only have a startday
1356 //==============================================================
1357 case NO_REPEAT :
1359 if(isset($days[$event['eventDate']])) {
1360 array_push($days[$event['eventDate']],$event);
1361 if ($viewtype == "week") {
1362 //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."<br />";
1363 fillBlocks($eventD,&$days);
1364 //echo "for $eventD loading " . getBlockTime($eventS) . "<br /><br />";
1365 $gbt = getBlockTime($eventS);
1366 $days[$eventD]['blocks'][$gbt][$eventD][] = $event;
1367 //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . " <br />";
1368 //echo "begin printing blocks for $eventD<br />";
1369 //print_r($days[$eventD]['blocks']);
1370 //echo "end printing blocks<br />";
1374 break;
1376 //==============================================================
1377 // Find events that repeat at a certain frequency
1378 // Every,Every Other,Every Third,Every Fourth
1379 // Day,Week,Month,Year,MWF,TR,M-F,SS
1380 //==============================================================
1381 case REPEAT :
1383 $rfreq = $event_recurrspec['event_repeat_freq'];
1384 $rtype = $event_recurrspec['event_repeat_freq_type'];
1385 $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt
1387 // we should bring the event up to date to make this a tad bit faster
1388 // any ideas on how to do that, exactly??? dateToDays probably.
1389 $nm = $esM; $ny = $esY; $nd = $esD;
1390 $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d');
1391 while($occurance < $start_date) {
1392 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1393 list($ny,$nm,$nd) = explode('-',$occurance);
1395 while($occurance <= $stop) {
1396 if(isset($days[$occurance])) {
1397 // check for date exceptions before pushing the event into the days array -- JRM
1398 $excluded = false;
1399 if (isset($exdate)) {
1400 foreach (explode(",", $exdate) as $exception) {
1401 // occurrance format == yyyy-mm-dd
1402 // exception format == yyyymmdd
1403 if (preg_replace("/-/", "", $occurance) == $exception) {
1404 $excluded = true;
1409 // push event into the days array
1410 if ($excluded == false) array_push($days[$occurance],$event);
1412 if ($viewtype == "week") {
1413 fillBlocks($occurance, &$days);
1414 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1415 $gbt = getBlockTime($eventS);
1416 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1417 //echo "begin printing blocks for $eventD<br />";
1418 //print_r($days[$occurance]['blocks']);
1419 //echo "end printing blocks<br />";
1422 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1423 list($ny,$nm,$nd) = explode('-',$occurance);
1425 break;
1427 //==============================================================
1428 // Find events that repeat on certain parameters
1429 // On 1st,2nd,3rd,4th,Last
1430 // Sun,Mon,Tue,Wed,Thu,Fri,Sat
1431 // Every N Months
1432 //==============================================================
1433 case REPEAT_ON :
1435 $rfreq = $event_recurrspec['event_repeat_on_freq'];
1436 $rnum = $event_recurrspec['event_repeat_on_num'];
1437 $rday = $event_recurrspec['event_repeat_on_day'];
1438 $exdate = $event_recurrspec['exdate']; // this attribute follows the iCalendar spec http://www.ietf.org/rfc/rfc2445.txt
1440 //==============================================================
1441 // Populate - Enter data into the event array
1442 //==============================================================
1443 $nm = $esM; $ny = $esY; $nd = $esD;
1444 // make us current
1445 while($ny < $cy) {
1446 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1447 list($ny,$nm,$nd) = explode('-',$occurance);
1450 // populate the event array
1451 while($ny <= $cy) {
1452 $dnum = $rnum; // get day event repeats on
1453 do {
1454 $occurance = Date_Calc::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d");
1455 } while($occurance === -1);
1457 if(isset($days[$occurance]) && $occurance <= $stop) {
1458 // check for date exceptions before pushing the event into the days array -- JRM
1459 $excluded = false;
1460 if (isset($exdate)) {
1461 foreach (explode(",", $exdate) as $exception) {
1462 // occurrance format == yyyy-mm-dd
1463 // exception format == yyyymmdd
1464 if (preg_replace("/-/", "", $occurance) == $exception) {
1465 $excluded = true;
1470 // push event into the days array
1471 if ($excluded == false) array_push($days[$occurance],$event);
1473 if ($viewtype == "week") {
1474 fillBlocks($occurance,&$days);
1475 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1476 $gbt = getBlockTime($eventS);
1477 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1480 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1481 list($ny,$nm,$nd) = explode('-',$occurance);
1484 break;
1486 } // <- end of switch($event['recurrtype'])
1487 } // <- end of foreach($events as $event)
1488 return $days;
1491 function fillBlocks($td,&$ar) {
1492 if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) {
1493 $ar[$td]['blocks'] = array();
1494 for ($j=0;$j<48;$j++)
1495 $ar[strval($td)]['blocks'][strval($j)] = array();
1496 $ar[strval($td)]['blocks']["all_day"] = array();
1503 * __increment()
1504 * returns the next valid date for an event based on the
1505 * current day,month,year,freq and type
1506 * @private
1507 * @returns string YYYY-MM-DD
1509 function &__increment($d,$m,$y,$f,$t)
1511 if($t == REPEAT_EVERY_DAY) {
1512 return date('Y-m-d',mktime(0,0,0,$m,($d+$f),$y));
1513 } elseif($t == REPEAT_EVERY_WORK_DAY) {
1514 // a workday is defined as Mon,Tue,Wed,Thu,Fri
1515 // repeating on every or Nth work day means to not include
1516 // weekends (Sat/Sun) in the increment... tricky
1518 // ugh, a day-by-day loop seems necessary here, something where
1519 // we can check to see if the day is a Sat/Sun and increment
1520 // the frequency count so as to ignore the weekend. hmmmm....
1521 $orig_freq = $f;
1522 for ($daycount=1; $daycount<=$orig_freq; $daycount++) {
1523 $nextWorkDOW = date('D',mktime(0,0,0,$m,($d+$daycount),$y));
1524 if ($nextWorkDOW == "Sat") { $f++; }
1525 else if ($nextWorkDOW == "Sun") { $f++; }
1527 // and finally make sure we haven't landed on a Sat/Sun
1528 // adjust as necessary
1529 $nextWorkDOW = date('D',mktime(0,0,0,$m,($d+$f),$y));
1530 if ($nextWorkDOW == "Sat") { $f+=2; }
1531 else if ($nextWorkDOW == "Sun") { $f++; }
1533 return date('Y-m-d',mktime(0,0,0,$m,($d+$f),$y));
1535 } elseif($t == REPEAT_EVERY_WEEK) {
1536 return date('Y-m-d',mktime(0,0,0,$m,($d+(7*$f)),$y));
1537 } elseif($t == REPEAT_EVERY_MONTH) {
1538 return date('Y-m-d',mktime(0,0,0,($m+$f),$d,$y));
1539 } elseif($t == REPEAT_EVERY_YEAR) {
1540 return date('Y-m-d',mktime(0,0,0,$m,$d,($y+$f)));