Add facilities filter in calendar view.
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnuserapi.php
blob2aa2241312191121678f2e61ccbcaabd174d7793
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 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
33 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
34 require_once("modules/$pcDir/common.api.php");
35 unset($pcModInfo,$pcDir);
37 function postcalendar_userapi_getLongDayName($args)
39 extract($args); unset($args);
40 if(!isset($Date)) { return false; }
41 $pc_long_day = array(_CALLONGFIRSTDAY,
42 _CALLONGSECONDDAY,
43 _CALLONGTHIRDDAY,
44 _CALLONGFOURTHDAY,
45 _CALLONGFIFTHDAY,
46 _CALLONGSIXTHDAY,
47 _CALLONGSEVENTHDAY);
48 return $pc_long_day[Date("w",$Date)];
51 /**
52 * postcalendar_userapi_buildView
54 * Builds the calendar display
55 * @param string $Date mm/dd/yyyy format (we should use timestamps)
56 * @return string generated html output
57 * @access public
59 function postcalendar_userapi_buildView($args)
61 $print = pnVarCleanFromInput('print');
62 $show_days = pnVarCleanFromInput('show_days');
63 extract($args); unset($args);
64 $schedule_start = $GLOBALS[schedule_start];
65 $schedule_end = $GLOBALS[schedule_end];
67 // $times is an array of associative arrays, where each sub-array
68 // has keys 'hour', 'minute' and 'mer'.
70 $times = array();
72 // For each hour in the schedule...
74 for($blocknum = $schedule_start; $blocknum <= $schedule_end; $blocknum++){
75 $mer = ($blocknum >= 12) ? 'pm' : 'am';
77 // $minute is an array of time slot strings within this hour.
78 $minute = array('00');
80 for($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) {
81 if($minutes <= '9'){
82 $under_ten = "0" . $minutes;
83 array_push($minute, "$under_ten");
85 else if($minutes >= '60') {
86 break;
88 else {
89 array_push($minute, "$minutes");
93 foreach($minute as $m ){
94 array_push($times, array("hour"=>$blocknum, "minute"=>$m, "mer"=>$mer));
98 //=================================================================
99 // get the module's information
100 //=================================================================
101 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
102 $pcDir = $modinfo['directory'];
103 unset($modinfo);
105 //=================================================================
106 // grab the for post variable
107 //=================================================================
108 // $pc_username = pnVarCleanFromInput('pc_username');
109 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
110 $category = pnVarCleanFromInput('pc_category');
111 $topic = pnVarCleanFromInput('pc_topic');
113 //=================================================================
114 // set the correct date
115 //=================================================================
116 $Date =& postcalendar_getDate();
118 //=================================================================
119 // get the current view
120 //=================================================================
121 if(!isset($viewtype)) { $viewtype = 'month'; }
123 //=================================================================
124 // Find out what Template we're using
125 //=================================================================
126 $template_name = _SETTING_TEMPLATE;
127 if(!isset($template_name)) { $template_name = 'default'; }
129 //=================================================================
130 // Find out what Template View to use
131 //=================================================================
132 $template_view = pnVarCleanFromInput('tplview');
133 if(!isset($template_view)) { $template_view = 'default'; }
135 //=================================================================
136 // See if the template view exists
137 //=================================================================
138 if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) {
139 $template_view_load = 'default';
140 } else {
141 $template_view_load = pnVarPrepForOS($template_view);
144 //=================================================================
145 // Grab the current theme information
146 //=================================================================
147 pnThemeLoad(pnUserGetTheme());
148 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2;
150 //=================================================================
151 // Insert necessary JavaScript into the page
152 //=================================================================
153 $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup');
155 //=================================================================
156 // Setup Smarty Template Engine
157 //=================================================================
158 $tpl =& new pcSmarty();
160 //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) {
161 //diable caching completely
162 if (true) {
163 //=================================================================
164 // Let's just finish setting things up
165 //=================================================================
166 $the_year = substr($Date,0,4);
167 $the_month = substr($Date,4,2);
168 $the_day = substr($Date,6,2);
169 $last_day = Date_Calc::daysInMonth($the_month,$the_year);
171 //=================================================================
172 // populate the template object with information for
173 // Month Names, Long Day Names and Short Day Names
174 // as translated in the language files
175 // (may be adding more here soon - based on need)
176 //=================================================================
177 $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN,
178 _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC);
180 $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT,
181 _CALTUESDAYSHORT, _CALWEDNESDAYSHORT,
182 _CALTHURSDAYSHORT, _CALFRIDAYSHORT,
183 _CALSATURDAYSHORT);
185 $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY,
186 _CALTUESDAY, _CALWEDNESDAY,
187 _CALTHURSDAY, _CALFRIDAY,
188 _CALSATURDAY);
189 //=================================================================
190 // here we need to set up some information for later
191 // variable creation. This helps us establish the correct
192 // date ranges for each view. There may be a better way
193 // to handle all this, but my brain hurts, so your comments
194 // are very appreciated and welcomed.
195 //=================================================================
196 switch (_SETTING_FIRST_DAY_WEEK)
198 case _IS_MONDAY:
199 $pc_array_pos = 1;
200 $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year));
201 $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year));
202 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
203 if($end_dow != 0) {
204 $the_last_day = $last_day+(7-$end_dow);
205 } else {
206 $the_last_day = $last_day;
208 break;
209 case _IS_SATURDAY:
210 $pc_array_pos = 6;
211 $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year));
212 $week_day = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year));
213 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
214 if($end_dow == 6) {
215 $the_last_day = $last_day+6;
216 } elseif($end_dow != 5) {
217 $the_last_day = $last_day+(5-$end_dow);
218 } else {
219 $the_last_day = $last_day;
221 break;
222 case _IS_SUNDAY:
223 default:
224 $pc_array_pos = 0;
225 $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
226 $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year));
227 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
228 if($end_dow != 6) {
229 $the_last_day = $last_day+(6-$end_dow);
230 } else {
231 $the_last_day = $last_day;
233 break;
236 // passing the times array to the tpl the times array is for the days schedule
237 $tpl->assign_by_ref("times",$times);
238 // load the table width to the template
239 // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']);
241 //=================================================================
242 // Week View is a bit of a pain in the ass, so we need to
243 // do some extra setup for that view. This section will
244 // find the correct starting and ending dates for a given
245 // seven day period, based on the day of the week the
246 // calendar is setup to run under (Sunday, Saturday, Monday)
247 //=================================================================
248 $first_day_of_week = sprintf('%02d',$the_day-$week_day);
249 $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
250 list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day);
251 $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
252 array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year)));
253 $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
254 list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day);
255 $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
256 array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year)));
258 //=================================================================
259 // Setup some information so we know the actual month's dates
260 // also get today's date for later use and highlighting
261 //=================================================================
262 $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year));
263 $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year));
264 $today_date = postcalendar_today('%Y-%m-%d');
266 //=================================================================
267 // Setup the starting and ending date ranges for pcGetEvents()
268 //=================================================================
269 switch($viewtype) {
270 case 'day' :
271 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
272 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
273 break;
274 case 'week' :
275 $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year";
276 $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year";
277 $calendarView = Date_Calc::getCalendarWeek($week_first_day_date,
278 $week_first_day_month,
279 $week_first_day_year,
280 '%Y-%m-%d');
281 break;
282 case 'month' :
283 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year));
284 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year));
285 $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d');
286 break;
287 case 'year' :
288 $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year));
289 $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1));
290 $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d');
291 break;
294 //=================================================================
295 // Load the events
296 //=================================================================
297 if($viewtype != 'year') {
298 $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype));
299 } else {
300 $eventsByDate = array();
303 //=================================================================
304 // Create an array with the day names in the correct order
305 //=================================================================
306 $daynames = array();
307 $numDays = count($pc_long_day_names);
308 for($i=0; $i < $numDays; $i++) {
309 if($pc_array_pos >= $numDays) {
310 $pc_array_pos = 0;
312 array_push($daynames,$pc_long_day_names[$pc_array_pos]);
313 $pc_array_pos++;
315 unset($numDays);
316 $sdaynames = array();
317 $numDays = count($pc_short_day_names);
318 for($i=0; $i < $numDays; $i++) {
319 if($pc_array_pos >= $numDays) {
320 $pc_array_pos = 0;
322 array_push($sdaynames,$pc_short_day_names[$pc_array_pos]);
323 $pc_array_pos++;
325 unset($numDays);
327 //=================================================================
328 // Prepare some values for the template
329 //=================================================================
330 $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d');
331 $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d');
333 $pc_prev = pnModURL(__POSTCALENDAR__,'user','view',
334 array('tplview'=>$template_view,
335 'viewtype'=>'month',
336 'Date'=>$prev_month,
337 'pc_username'=>$pc_username,
338 'pc_category'=>$category,
339 'pc_topic'=>$topic));
341 $pc_next = pnModURL(__POSTCALENDAR__,'user','view',
342 array('tplview'=>$template_view,
343 'viewtype'=>'month',
344 'Date'=>$next_month,
345 'pc_username'=>$pc_username,
346 'pc_category'=>$category,
347 'pc_topic'=>$topic));
349 $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d');
350 $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d');
351 $pc_prev_day = pnModURL(__POSTCALENDAR__,'user','view',
352 array('tplview'=>$template_view,
353 'viewtype'=>'day',
354 'Date'=>$prev_day,
355 'pc_username'=>$pc_username,
356 'pc_category'=>$category,
357 'pc_topic'=>$topic));
359 $pc_next_day = pnModURL(__POSTCALENDAR__,'user','view',
360 array('tplview'=>$template_view,
361 'viewtype'=>'day',
362 'Date'=>$next_day,
363 'pc_username'=>$pc_username,
364 'pc_category'=>$category,
365 'pc_topic'=>$topic));
367 $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year));
368 $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year));
369 $pc_prev_week = pnModURL(__POSTCALENDAR__,'user','view',
370 array('viewtype'=>'week',
371 'Date'=>$prev_week,
372 'pc_username'=>$pc_username,
373 'pc_category'=>$category,
374 'pc_topic'=>$topic));
375 $pc_next_week = pnModURL(__POSTCALENDAR__,'user','view',
376 array('viewtype'=>'week',
377 'Date'=>$next_week,
378 'pc_username'=>$pc_username,
379 'pc_category'=>$category,
380 'pc_topic'=>$topic));
382 $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1));
383 $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1));
384 $pc_prev_year = pnModURL(__POSTCALENDAR__,'user','view',
385 array('viewtype'=>'year',
386 'Date'=>$prev_year,
387 'pc_username'=>$pc_username,
388 'pc_category'=>$category,
389 'pc_topic'=>$topic));
390 $pc_next_year = pnModURL(__POSTCALENDAR__,'user','view',
391 array('viewtype'=>'year',
392 'Date'=>$next_year,
393 'pc_username'=>$pc_username,
394 'pc_category'=>$category,
395 'pc_topic'=>$topic));
397 //=================================================================
398 // Populate the template
399 //=================================================================
400 $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
402 if(isset($calendarView)) {
403 $tpl->assign_by_ref('CAL_FORMAT',$calendarView);
406 if($viewtype == "week") {
407 $last_blocks = array();
408 foreach($eventsByDate as $cdate => $day) {
409 $tblock = array_reverse($day['blocks']);
410 $last_blocks[$cdate] = count($tblock) -1;
411 for ($i=0;$i<count($tblock);$i++) {
412 if (!empty($tblock[$i])) {
413 $last_blocks[$cdate] = count($tblock) - $i;
414 break;
418 $tpl->assign("last_blocks",$last_blocks);
421 $tpl->assign('STYLE',$GLOBALS['style']);
422 $tpl->assign('show_days',$show_days);
423 $provinfo = getProviderInfo();
424 $single = array();
426 // filter the display on the requested username, the provinfo array is
427 // used to build columns in the week view.
429 foreach($provinfo as $provider) {
430 if(is_array($pc_username)){
431 foreach($pc_username as $uname) {
432 if (!empty($pc_username) && $provider['username'] == $uname) {
433 array_push($single,$provider);
437 else {
438 if (!empty($pc_username) && $provider['username'] == $pc_username) {
439 array_push($single,$provider);
443 if ($single != null) {
444 $provinfo = $single;
447 //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other");
448 $tpl->assign_by_ref('providers', $provinfo);
450 if (pnVarCleanFromInput("show_days") != 1) {
451 $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1");
454 $tpl->assign('interval', $GLOBALS['calendar_interval']);
455 $tpl->assign_by_ref('VIEW_TYPE',$viewtype);
456 $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names);
457 $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names);
458 $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names);
459 $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames);
460 $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames);
461 $tpl->assign_by_ref('A_EVENTS',$eventsByDate);
462 $tpl->assign_by_ref('A_CATEGORY',$all_categories);
463 $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev);
464 $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next);
465 $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day);
466 $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day);
467 $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week);
468 $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week);
469 $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year);
470 $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year);
471 $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start);
472 $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end);
473 $tpl->assign_by_ref('TODAY_DATE',$today_date);
474 $tpl->assign_by_ref('DATE',$Date);
475 $tpl->assign_by_ref('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__,'user','submit'));
476 $tpl->assign_by_ref('interval',$intervals);
479 //=================================================================
480 // Parse the template
481 //=================================================================
482 $template = "$template_name/views/$viewtype/$template_view_load.html";
483 if(!$print) {
484 $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
485 $output .= $tpl->fetch($template,$cacheid); // cache id
486 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
487 } else {
488 $theme = pnUserGetTheme();
489 echo "<html><head>";
490 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
491 echo "<style type=\"text/css\">\n";
492 echo "@import url(\"themes/$theme/style/style.css\"); ";
493 echo "</style>\n";
494 echo "</head><body>\n";
495 echo $output;
496 $tpl->display($template,$cacheid);
497 echo postcalendar_footer();
498 echo "\n</body></html>";
499 session_write_close();
500 exit;
502 //=================================================================
503 // Return the output
504 //=================================================================
505 return $output;
509 * postcalendar_userapi_eventPreview
510 * Creates the detailed event display and outputs html.
511 * Accepts an array of key/value pairs
512 * @param array $event array of event details from the form
513 * @return string html output
514 * @access public
516 function postcalendar_userapi_eventPreview($args)
518 // get the theme globals :: is there a better way to do this?
519 pnThemeLoad(pnUserGetTheme());
520 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
521 global $textcolor1, $textcolor2;
523 extract($args); unset($args);
524 $uid = pnUserGetVar('uid');
525 //=================================================================
526 // Setup Smarty Template Engine
527 //=================================================================
528 $tpl =& new pcSmarty();
529 $tpl->caching = false;
530 // add preceding zeros
531 $event_starttimeh = sprintf('%02d',$event_starttimeh);
532 $event_starttimem = sprintf('%02d',$event_starttimem);
533 $event_startday = sprintf('%02d',$event_startday);
534 $event_startmonth = sprintf('%02d',$event_startmonth);
535 $event_endday = sprintf('%02d',$event_endday);
536 $event_endmonth = sprintf('%02d',$event_endmonth);
538 if(!(bool)_SETTING_TIME_24HOUR) {
539 if($event_startampm == _PM_VAL) {
540 if($event_starttimeh != 12) {
541 $event_starttimeh+=12;
543 } elseif($event_startampm == _AM_VAL) {
544 if($event_starttimeh == 12) {
545 $event_starttimeh = 00;
550 $event_startampm." - ";
551 $startTime = $event_starttimeh.':'.$event_starttimem.' ';
553 $event = array();
554 $event['eid'] = '';
555 $event['uname'] = $uname;
556 $event['catid'] = $event_category;
557 if($pc_html_or_text == 'html') {
558 $prepFunction = 'pcVarPrepHTMLDisplay';
559 } else {
560 $prepFunction = 'pcVarPrepForDisplay';
562 $event['title'] = $prepFunction($event_subject);
563 $event['hometext'] = $prepFunction($event_desc);
564 $event['desc'] = $event['hometext'];
565 $event['date'] = $event_startyear.$event_startmonth.$event_startday;
566 $event['duration'] = $event_duration;
567 $event['duration_hours'] = $event_dur_hours;
568 $event['duration_minutes'] = $event_dur_minutes;
569 $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
570 $event['startTime'] = $startTime;
571 $event['recurrtype'] = '';
572 $event['recurrfreq'] = '';
573 $event['recurrspec'] = $event_recurrspec;
574 $event['topic'] = $event_topic;
575 $event['alldayevent'] = $event_allday;
576 $event['conttel'] = $prepFunction($event_conttel);
577 $event['contname'] = $prepFunction($event_contname);
578 $event['contemail'] = $prepFunction($event_contemail);
579 $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website));
580 $event['fee'] = $prepFunction($event_fee);
581 $event['location'] = $prepFunction($event_location);
582 $event['street1'] = $prepFunction($event_street1);
583 $event['street2'] = $prepFunction($event_street2);
584 $event['city'] = $prepFunction($event_city);
585 $event['state'] = $prepFunction($event_state);
586 $event['postal'] = $prepFunction($event_postal);
588 //=================================================================
589 // get event's topic information
590 //=================================================================
591 if(_SETTING_DISPLAY_TOPICS) {
592 list($dbconn) = pnDBGetConn();
593 $pntable = pnDBGetTables();
594 $topics_table = $pntable['topics'];
595 $topics_column = $pntable['topics_column'];
596 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
597 FROM $topics_table
598 WHERE $topics_column[topicid] = $event[topic]
599 LIMIT 1";
600 $topic_result = $dbconn->Execute($topicsql);
601 list($event['topictext'],$event['topicimg']) = $topic_result->fields;
602 $topic_result->Close();
603 } else {
604 $event['topictext'] = $event['topicimg'] = '';
606 //=================================================================
607 // Find out what Template we're using
608 //=================================================================
609 $template_name = _SETTING_TEMPLATE;
610 if(!isset($template_name)) {
611 $template_name = 'default';
613 //=================================================================
614 // populate the template
615 //=================================================================
616 if(!empty($event['location']) || !empty($event['street1']) ||
617 !empty($event['street2']) || !empty($event['city']) ||
618 !empty($event['state']) || !empty($event['postal'])) {
619 $tpl->assign('LOCATION_INFO',true);
620 } else {
621 $tpl->assign('LOCATION_INFO',false);
623 if(!empty($event['contname']) || !empty($event['contemail']) ||
624 !empty($event['conttel']) || !empty($event['website'])) {
625 $tpl->assign('CONTACT_INFO',true);
626 } else {
627 $tpl->assign('CONTACT_INFO',false);
629 $tpl->assign_by_ref('A_EVENT',$event);
630 $tpl->assign('STYLE',$GLOBALS['style']);
631 //=================================================================
632 // Parse the template
633 //=================================================================
634 $output = "\n\n<!-- POSTCALENDAR HTTP://WWW.BAHRAINI.TV -->\n\n";
635 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE START -->\n\n";
636 $output .= $tpl->fetch($template_name.'/user/preview.html');
637 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE END -->\n\n";
639 return $output;
643 * checkEventCollision
644 * Returns an array containing any events that collide with the specified event
645 * @params array(key=>value)
646 * @return array $events[][]
648 function checkEventCollision($edata) {
650 extract($edata);
651 $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear);
652 $edate = $sdate;
653 //hour from forms is 12 not 24 format, convert here
654 if($event_startampm == 2 && $event_starttimeh != 12)
655 $event_starttimeh += 12;
656 elseif ($event_startampm == 1 && $event_starttimeh == 12)
657 $event_starttimeh -= 12;
659 $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00'));
660 $etime = date("H:i:00",$event_duration + strtotime($stime));
661 //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
662 $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime);
663 $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
664 //print_r($eventsByDate);
665 $collisions = array();
666 foreach ($eventsByDate as $day) {
667 foreach ($day as $event) {
668 if ($event['duration'] == 0 && $event['alldayevent'] == 0) {
669 continue;
671 elseif($event['alldayevent'] == 1) {
672 $collisions[] = $event;
674 $festart = strtotime($event['startTime']);
675 $feend = strtotime($event['startTime'] + $event['duration']);
676 $estart = strtotime($stime);
677 $eend = strtotime($etime);
679 //echo "festart = $festart feend = $feend estart = $estart eend = $eend<br />";
680 if ($festart < $eend && $feend > $estart) {
681 $collisions[] = $event;
683 elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) {
684 $collisions[] = $event;
686 elseif ($festart >= $estart && $festart < $eend) {
687 $collisions[] = $event;
691 //foreach ($collisions as $collide) {
692 // echo "collided: " . $collide['title'] . "<br />";
694 return $collisions;
698 * postcalendar_userapi_pcQueryEventsFA
699 * Returns an array containing the event's information for first available queiries
700 * @params array(key=>value)
701 * @params string key eventstatus
702 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
703 * @return array $events[][]
705 function &postcalendar_userapi_pcQueryEventsFA($args) {
707 $end = '0000-00-00';
708 extract($args);
709 $eventstatus = 1;
710 if (is_numeric($event_status))
711 $eventstatus = $event_status;
713 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
714 list($sy,$sm,$sd) = explode('-',$start);
716 list($dbconn) = pnDBGetConn();
717 $pntable = pnDBGetTables();
718 // link to the events tables
719 $table = $pntable['postcalendar_events'];
720 $cattable = $pntable['postcalendar_categories'];
722 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " .
723 "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " .
724 "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " .
725 "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " .
726 "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " .
727 "a.pc_prefcatid, " .
728 "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " .
729 "concat(u.fname,' ',u.lname) as provider_name, " .
730 "concat(pd.fname,' ',pd.lname) as patient_name, " .
731 "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob " .
732 "FROM ( $table AS a, $cattable AS b ) " .
733 "LEFT JOIN users as u ON a.pc_aid = u.id " .
734 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
735 "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " .
736 "WHERE b.pc_catid = a.pc_catid " .
737 "AND a.pc_eventstatus = $eventstatus " .
738 "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " .
739 "AND a.pc_eventDate <= '$end' " .
740 "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')";
742 //======================================================================
743 // START SEARCH FUNCTIONALITY
744 //======================================================================
745 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
746 if(!empty($s_category)) $sql .= "AND ($s_category) ";
747 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
748 if(!empty($collide_etime) && !empty($collide_stime)) {
749 $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL ";
751 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
752 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
753 //======================================================================
754 // Search sort and limitation
755 //======================================================================
756 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC";
757 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
758 //======================================================================
759 // END SEARCH FUNCTIONALITY
760 //======================================================================
761 //echo "<Br />sql: $sql<br />";
762 $result = $dbconn->Execute($sql);
763 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
765 // put the information into an array for easy access
766 $events = array();
767 // return an empty array if we don't have any results
768 if(!isset($result)) { return $events; }
770 for($i=0; !$result->EOF; $result->MoveNext()) {
772 // get the results from the query
773 if(isset($tmp)) { unset($tmp); } $tmp = array();
774 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
775 $tmp['title'], $tmp['time'], $tmp['hometext'],
776 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
777 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
778 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
779 $tmp['location'], $tmp['conttel'], $tmp['contname'],
780 $tmp['contemail'], $tmp['website'], $tmp['fee'],
781 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
782 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
783 $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'],
784 $tmp['owner_name'], $tmp['patient_dob']) = $result->fields;
786 // grab the name of the topic
787 $topicname = pcGetTopicName($tmp['topic']);
788 // get the user id of event's author
789 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
790 // check the current event's permissions
791 // the user does not have permission to view this event
792 // if any of the following evaluate as false
793 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
794 continue;
795 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
796 continue;
797 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
798 continue;
799 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
800 continue;
801 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
802 continue;
805 // add event to the array if we passed the permissions check
806 // this is the common information
807 $events[$i]['eid'] = $tmp['eid'];
808 $events[$i]['uname'] = $tmp['uname'];
809 $events[$i]['uid'] = $cuserid;
810 $events[$i]['catid'] = $tmp['catid'];
811 $events[$i]['time'] = $tmp['time'];
812 $events[$i]['eventDate'] = $tmp['eventDate'];
813 $events[$i]['duration'] = $tmp['duration'];
814 // there has to be a more intelligent way to do this
815 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
816 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
817 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
818 $events[$i]['endDate'] = $tmp['endDate'];
819 $events[$i]['startTime'] = $tmp['startTime'];
820 $events[$i]['recurrtype'] = $tmp['recurrtype'];
821 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
822 $events[$i]['recurrspec'] = $tmp['recurrspec'];
824 $rspecs = unserialize($tmp['recurrspec']);
825 $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
826 $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
827 $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
828 $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
829 $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
831 $events[$i]['topic'] = $tmp['topic'];
832 $events[$i]['alldayevent'] = $tmp['alldayevent'];
833 $events[$i]['catcolor'] = $tmp['catcolor'];
834 $events[$i]['catname'] = $tmp['catname'];
835 $events[$i]['catdesc'] = $tmp['catdesc'];
836 $events[$i]['pid'] = $tmp['pid'];
837 $events[$i]['patient_name']= $tmp['patient_name'];
838 $events[$i]['provider_name'] = $tmp['provider_name'];
839 $events[$i]['owner_name'] = $tmp['owner_name'];
840 $events[$i]['patient_dob'] = $tmp['patient_dob'];
841 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
842 $events[$i]['sharing'] = $tmp['sharing'];
843 $events[$i]['prefcatid'] = $tmp['prefcatid'];
844 $events[$i]['aid'] = $tmp['aid'];
845 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
846 if($events[$i]['intervals'] == 0)
847 $events[$i]['intervals'] = 1;
848 // is this a public event to be shown as busy?
849 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
850 // make it not display any information
851 $events[$i]['title'] = _USER_BUSY_TITLE;
852 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
853 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
854 $events[$i]['conttel'] = '';
855 $events[$i]['contname'] = '';
856 $events[$i]['contemail'] = '';
857 $events[$i]['website'] = '';
858 $events[$i]['fee'] = '';
859 $events[$i]['location'] = '';
860 $events[$i]['street1'] = '';
861 $events[$i]['street2'] = '';
862 $events[$i]['city'] = '';
863 $events[$i]['state'] = '';
864 $events[$i]['postal'] = '';
865 } else {
866 $display_type = substr($tmp['hometext'],0,6);
867 if($display_type == ':text:') {
868 $prepFunction = 'pcVarPrepForDisplay';
869 $tmp['hometext'] = substr($tmp['hometext'],6);
870 } elseif($display_type == ':html:') {
871 $prepFunction = 'pcVarPrepHTMLDisplay';
872 $tmp['hometext'] = substr($tmp['hometext'],6);
873 } else {
874 $prepFunction = 'pcVarPrepHTMLDisplay';
876 unset($display_type);
877 $events[$i]['title'] = $prepFunction($tmp['title']);
878 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
879 $events[$i]['desc'] = $events[$i]['hometext'];
880 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
881 $events[$i]['contname'] = $prepFunction($tmp['contname']);
882 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
883 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
884 $events[$i]['fee'] = $prepFunction($tmp['fee']);
885 $loc = unserialize($tmp['location']);
886 $events[$i]['location'] = $prepFunction($loc['event_location']);
887 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
888 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
889 $events[$i]['city'] = $prepFunction($loc['event_city']);
890 $events[$i]['state'] = $prepFunction($loc['event_state']);
891 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
893 $i++;
895 unset($tmp);
896 $result->Close();
897 return $events;
902 * postcalendar_userapi_pcQueryEvents
903 * Returns an array containing the event's information
904 * @params array(key=>value)
905 * @params string key eventstatus
906 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
907 * @return array $events[][]
909 function &postcalendar_userapi_pcQueryEvents($args)
911 $end = '0000-00-00';
912 extract($args);
914 // echo "<!-- args = "; print_r($args); echo " -->\n"; // debugging
916 // $pc_username = pnVarCleanFromInput('pc_username');
917 $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19
918 if (empty($pc_username) || is_array($pc_username)) {
919 $pc_username = "__PC_ALL__";
922 // echo "<!-- pc_username: $pc_username -->\n"; // debugging
924 $topic = pnVarCleanFromInput('pc_topic');
925 $category = pnVarCleanFromInput('pc_category');
927 if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) {
928 if($pc_username=='__PC_ALL__' || $pc_username == -1) {
929 $ruserid = -1;
930 } else {
931 $ruserid = getIDfromUser($pc_username);
935 if(!isset($eventstatus)) { $eventstatus = 1; }
936 // sanity check on eventstatus
937 if((int)$eventstatus < -1 || (int)$eventstatus > 1) { $eventstatus = 1; }
938 if(!isset($start)) { $start = Date_Calc::dateNow('%Y-%m-%d'); }
939 list($sy,$sm,$sd) = explode('-',$start);
941 list($dbconn) = pnDBGetConn();
942 $pntable = pnDBGetTables();
943 // link to the events tables
944 $table = $pntable['postcalendar_events'];
945 $cattable = $pntable['postcalendar_categories'];
946 $topictable = $pntable['postcalendar_topics'];
948 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " .
949 "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " .
950 "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " .
951 "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " .
952 "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " .
953 "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " .
954 "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " .
955 "concat(u.fname,' ',u.lname) as provider_name, " .
956 "concat(pd.lname,', ',pd.fname) as patient_name, " .
957 "concat(u2.fname, ' ', u2.lname) as owner_name, " .
958 "DOB as patient_dob, pd.pubpid " .
959 "FROM ( $table AS a, $cattable AS b ) " .
960 "LEFT JOIN users as u ON a.pc_aid = u.id " .
961 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
962 "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " .
963 "WHERE b.pc_catid = a.pc_catid " .
964 "AND a.pc_eventstatus = $eventstatus " .
965 "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " .
966 "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " .
967 "a.pc_eventDate <= '$end')) ";
969 //==================================
970 //FACILITY FILTERING (lemonsoftware)
971 if ( $pc_facility ) {
972 $sql .= " AND a.pc_facility = $pc_facility ";
974 //EOS FACILITY FILTERING (lemonsoftware)
975 //==================================
978 // The above 3 lines replaced these:
979 // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00')
980 // AND a.pc_eventDate <= '$end' ";
982 if(!empty($providerID))
984 $ruserid = $providerID;
987 if(isset($ruserid)) {
988 // get all events for the specified username
989 if($ruserid == -1) {
990 $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY . "' ";
991 $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC . "') ";
992 } else {
993 $sql .= "AND a.pc_aid = " . $ruserid . " ";
995 } elseif(!pnUserLoggedIn()) {
996 // get all events for anonymous users
997 $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL . "' ";
998 } else {
999 // get all events for logged in user plus global events
1000 $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL . "') ";
1003 //======================================================================
1004 // START SEARCH FUNCTIONALITY
1005 //======================================================================
1006 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
1007 if(!empty($s_category)) $sql .= "AND ($s_category) ";
1008 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
1009 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
1010 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
1012 //======================================================================
1013 // Search sort and limitation
1014 //======================================================================
1015 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC";
1016 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
1018 //======================================================================
1019 // END SEARCH FUNCTIONALITY
1020 //======================================================================
1021 //echo "sq: $sql<br />";
1023 // echo "<!-- " . $sql . " -->\n"; // debugging
1025 $result = $dbconn->Execute($sql);
1026 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
1028 // put the information into an array for easy access
1029 $events = array();
1030 // return an empty array if we don't have any results
1031 if(!isset($result)) { return $events; }
1033 for($i=0; !$result->EOF; $result->MoveNext()) {
1035 // WHY are we using an array for intermediate storage??? -- Rod
1037 // get the results from the query
1038 if(isset($tmp)) { unset($tmp); } $tmp = array();
1039 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
1040 $tmp['title'], $tmp['time'], $tmp['hometext'],
1041 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
1042 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
1043 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
1044 $tmp['location'], $tmp['conttel'], $tmp['contname'],
1045 $tmp['contemail'], $tmp['website'], $tmp['fee'],
1046 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
1047 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
1048 $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'],
1049 $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'],
1050 $tmp['pubpid']) = $result->fields;
1052 // grab the name of the topic
1053 $topicname = pcGetTopicName($tmp['topic']);
1054 // get the user id of event's author
1055 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
1056 // check the current event's permissions
1057 // the user does not have permission to view this event
1058 // if any of the following evaluate as false
1059 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW)) {
1060 continue;
1061 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW)) {
1062 continue;
1063 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW)) {
1064 continue;
1065 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW)) {
1066 continue;
1067 } elseif($tmp['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
1068 continue;
1071 // add event to the array if we passed the permissions check
1072 // this is the common information
1074 $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span
1075 print_r($events[$i]['intervals']);
1077 $events[$i]['eid'] = $tmp['eid'];
1078 $events[$i]['uname'] = $tmp['uname'];
1079 $events[$i]['uid'] = $cuserid;
1080 $events[$i]['catid'] = $tmp['catid'];
1081 $events[$i]['time'] = $tmp['time'];
1082 $events[$i]['eventDate'] = $tmp['eventDate'];
1083 $events[$i]['duration'] = $tmp['duration'];
1084 // there has to be a more intelligent way to do this
1085 @list($events[$i]['duration_hours'],$dmin) = @explode('.',($tmp['duration']/60/60));
1086 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1087 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1088 $events[$i]['endDate'] = $tmp['endDate'];
1089 $events[$i]['startTime'] = $tmp['startTime'];
1090 $events[$i]['recurrtype'] = $tmp['recurrtype'];
1091 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
1092 $events[$i]['recurrspec'] = $tmp['recurrspec'];
1093 $events[$i]['topic'] = $tmp['topic'];
1094 $events[$i]['alldayevent'] = $tmp['alldayevent'];
1095 $events[$i]['catcolor'] = $tmp['catcolor'];
1096 $events[$i]['catname'] = $tmp['catname'];
1097 $events[$i]['catdesc'] = $tmp['catdesc'];
1098 $events[$i]['pid'] = $tmp['pid'];
1099 $events[$i]['apptstatus'] = $tmp['apptstatus'];
1100 $events[$i]['pubpid'] = $tmp['pubpid'];
1101 $events[$i]['patient_name']= $tmp['patient_name'];
1102 $events[$i]['provider_name'] = $tmp['provider_name'];
1103 $events[$i]['owner_name'] = $tmp['owner_name'];
1104 $events[$i]['patient_dob'] = $tmp['patient_dob'];
1105 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
1106 $events[$i]['sharing'] = $tmp['sharing'];
1107 $events[$i]['prefcatid'] = $tmp['prefcatid'];
1108 $events[$i]['aid'] = $tmp['aid'];
1109 $events[$i]['topictext'] = $topicname;
1110 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
1111 if($events[$i]['intervals'] == 0)
1112 $events[$i]['intervals'] = 1;
1113 // is this a public event to be shown as busy?
1114 if($tmp['sharing'] == SHARING_BUSY && $cuserid != $userid) {
1115 // make it not display any information
1116 $events[$i]['title'] = _USER_BUSY_TITLE;
1117 $events[$i]['hometext'] = _USER_BUSY_MESSAGE;
1118 $events[$i]['desc'] = _USER_BUSY_MESSAGE;
1119 $events[$i]['conttel'] = '';
1120 $events[$i]['contname'] = '';
1121 $events[$i]['contemail'] = '';
1122 $events[$i]['website'] = '';
1123 $events[$i]['fee'] = '';
1124 $events[$i]['location'] = '';
1125 $events[$i]['street1'] = '';
1126 $events[$i]['street2'] = '';
1127 $events[$i]['city'] = '';
1128 $events[$i]['state'] = '';
1129 $events[$i]['postal'] = '';
1130 } else {
1131 $display_type = substr($tmp['hometext'],0,6);
1132 if($display_type == ':text:') {
1133 $prepFunction = 'pcVarPrepForDisplay';
1134 $tmp['hometext'] = substr($tmp['hometext'],6);
1135 } elseif($display_type == ':html:') {
1136 $prepFunction = 'pcVarPrepHTMLDisplay';
1137 $tmp['hometext'] = substr($tmp['hometext'],6);
1138 } else {
1139 $prepFunction = 'pcVarPrepHTMLDisplay';
1141 unset($display_type);
1142 $events[$i]['title'] = $prepFunction($tmp['title']);
1143 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
1144 $events[$i]['desc'] = $events[$i]['hometext'];
1145 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
1146 $events[$i]['contname'] = $prepFunction($tmp['contname']);
1147 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
1148 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
1149 $events[$i]['fee'] = $prepFunction($tmp['fee']);
1150 $loc = unserialize($tmp['location']);
1151 $events[$i]['location'] = $prepFunction($loc['event_location']);
1152 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
1153 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
1154 $events[$i]['city'] = $prepFunction($loc['event_city']);
1155 $events[$i]['state'] = $prepFunction($loc['event_state']);
1156 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
1158 $i++;
1160 unset($tmp);
1161 $result->Close();
1162 return $events;
1166 function getBlockTime($time) {
1168 if ($time == 0 || strlen($time) == 0) {
1170 return "all_day";
1172 $ts = strtotime($time);
1173 $half = 0;
1174 $minutes = date("i",$ts);
1175 $hour = date("H",$ts);
1176 if ($minutes >= 30)
1177 $half = 1;
1178 $blocknum = (($hour * 2) +$half);
1179 return strval($blocknum);
1182 function &postcalendar_userapi_pcGetEvents($args)
1184 $s_keywords = $s_category = $s_topic = '';
1185 extract($args);
1187 $date =& postcalendar_getDate();
1188 $cy = substr($date,0,4);
1189 $cm = substr($date,4,2);
1190 $cd = substr($date,6,2);
1191 if(isset($start) && isset($end)) {
1192 // parse start date
1193 list($sm,$sd,$sy) = explode('/',$start);
1194 // parse end date
1195 list($em,$ed,$ey) = explode('/',$end);
1197 $s = (int) "$sy$sm$sd";
1198 if($s > $date) {
1199 $cy = $sy;
1200 $cm = $sm;
1201 $cd = $sd;
1203 $start_date = Date_Calc::dateFormat($sd,$sm,$sy,'%Y-%m-%d');
1204 $end_date = Date_Calc::dateFormat($ed,$em,$ey,'%Y-%m-%d');
1205 } else {
1206 $sm = $em = $cm;
1207 $sd = $ed = $cd;
1208 $sy = $cy;
1209 $ey = $cy+2;
1210 $start_date = $sy.'-'.$sm.'-'.$sd;
1211 $end_date = $ey.'-'.$em.'-'.$ed;
1213 if ($faFlag && !isset($events)) {
1214 $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);
1215 //print_r($a);
1216 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a);
1218 elseif ($collideFlag && !isset($events)) {
1220 $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime);
1221 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEventsFA',$a);
1223 elseif ($listappsFlag && !isset($events)) {
1225 $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords);
1226 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1228 else if(!isset($events)) {
1229 if(!isset($s_keywords)) $s_keywords = '';
1230 $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);
1231 $events =& pnModAPIFunc(__POSTCALENDAR__,'user','pcQueryEvents',$a);
1234 //==============================================================
1235 // Here we build an array consisting of the date ranges
1236 // specific to the current view. This array is then
1237 // used to build the calendar display.
1238 //==============================================================
1239 $days = array();
1240 $sday = Date_Calc::dateToDays($sd,$sm,$sy);
1241 $eday = Date_Calc::dateToDays($ed,$em,$ey);
1242 for($cday = $sday; $cday <= $eday; $cday++) {
1243 $d = Date_Calc::daysToDate($cday,'%d');
1244 $m = Date_Calc::daysToDate($cday,'%m');
1245 $y = Date_Calc::daysToDate($cday,'%Y');
1246 $store_date = Date_Calc::dateFormat($d,$m,$y,'%Y-%m-%d');
1247 $days[$store_date] = array();
1250 $days = calculateEvents($days,$events,$viewtype);
1251 return $days;
1254 function calculateEvents($days,$events,$viewtype) {
1255 $date =& postcalendar_getDate();
1256 $cy = substr($date,0,4);
1257 $cm = substr($date,4,2);
1258 $cd = substr($date,6,2);
1260 foreach($events as $event) {
1261 // get the name of the topic
1262 $topicname = pcGetTopicName($event['topic']);
1264 // parse the event start date
1265 list($esY,$esM,$esD) = explode('-',$event['eventDate']);
1266 // grab the recurring specs for the event
1267 $event_recurrspec = @unserialize($event['recurrspec']);
1268 // determine the stop date for this event
1269 if($event['endDate'] == '0000-00-00') {
1270 $stop = $end_date;
1271 } else {
1272 $stop = $event['endDate'];
1275 $eventD = $event['eventDate'];
1276 $eventS = $event['startTime'];
1278 switch($event['recurrtype']) {
1279 //==============================================================
1280 // Events that do not repeat only have a startday
1281 //==============================================================
1282 case NO_REPEAT :
1284 if(isset($days[$event['eventDate']])) {
1285 array_push($days[$event['eventDate']],$event);
1286 if ($viewtype == "week") {
1287 //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."<br />";
1289 fillBlocks($eventD,&$days);
1290 //echo "for $eventD loading " . getBlockTime($eventS) . "<br /><br />";
1291 $gbt = getBlockTime($eventS);
1292 $days[$eventD]['blocks'][$gbt][$eventD][] = $event;
1293 //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . " <br />";
1294 //echo "begin printing blocks for $eventD<br />";
1295 //print_r($days[$eventD]['blocks']);
1296 //echo "end printing blocks<br />";
1300 break;
1301 //==============================================================
1302 // Find events that repeat at a certain frequency
1303 // Every,Every Other,Every Third,Every Fourth
1304 // Day,Week,Month,Year,MWF,TR,M-F,SS
1305 //==============================================================
1306 case REPEAT :
1307 $rfreq = $event_recurrspec['event_repeat_freq'];
1308 $rtype = $event_recurrspec['event_repeat_freq_type'];
1309 // we should bring the event up to date to make this a tad bit faster
1310 // any ideas on how to do that, exactly??? dateToDays probably.
1311 $nm = $esM; $ny = $esY; $nd = $esD;
1312 $occurance = Date_Calc::dateFormat($nd,$nm,$ny,'%Y-%m-%d');
1313 while($occurance < $start_date) {
1314 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1315 list($ny,$nm,$nd) = explode('-',$occurance);
1317 while($occurance <= $stop) {
1318 if(isset($days[$occurance])) {
1319 array_push($days[$occurance],$event);
1320 if ($viewtype == "week") {
1321 fillBlocks($occurance,&$days);
1322 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1323 $gbt = getBlockTime($eventS);
1324 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1325 //echo "begin printing blocks for $eventD<br />";
1326 //print_r($days[$occurance]['blocks']);
1327 //echo "end printing blocks<br />";
1330 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1331 list($ny,$nm,$nd) = explode('-',$occurance);
1333 break;
1335 //==============================================================
1336 // Find events that repeat on certain parameters
1337 // On 1st,2nd,3rd,4th,Last
1338 // Sun,Mon,Tue,Wed,Thu,Fri,Sat
1339 // Every N Months
1340 //==============================================================
1341 case REPEAT_ON :
1342 $rfreq = $event_recurrspec['event_repeat_on_freq'];
1343 $rnum = $event_recurrspec['event_repeat_on_num'];
1344 $rday = $event_recurrspec['event_repeat_on_day'];
1346 //==============================================================
1347 // Populate - Enter data into the event array
1348 //==============================================================
1349 $nm = $esM; $ny = $esY; $nd = $esD;
1350 // make us current
1352 while($ny < $cy) {
1354 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1355 list($ny,$nm,$nd) = explode('-',$occurance);
1358 // populate the event array
1359 while($ny <= $cy) {
1361 $dnum = $rnum; // get day event repeats on
1362 do {
1363 $occurance = Date_Calc::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d");
1364 } while($occurance === -1);
1365 if(isset($days[$occurance]) && $occurance <= $stop) {
1366 array_push($days[$occurance],$event);
1367 if ($viewtype == "week") {
1368 fillBlocks($occurance,&$days);
1369 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1370 $gbt = getBlockTime($eventS);
1371 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1374 $occurance = date('Y-m-d',mktime(0,0,0,$nm+$rfreq,$nd,$ny));
1375 list($ny,$nm,$nd) = explode('-',$occurance);
1377 break;
1378 } // <- end of switch($event['recurrtype'])
1379 } // <- end of foreach($events as $event)
1380 return $days;
1383 function fillBlocks($td,&$ar) {
1384 if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) {
1385 $ar[$td]['blocks'] = array();
1386 for ($j=0;$j<48;$j++)
1387 $ar[strval($td)]['blocks'][strval($j)] = array();
1388 $ar[strval($td)]['blocks']["all_day"] = array();
1395 * __increment()
1396 * returns the next valid date for an event based on the
1397 * current day,month,year,freq and type
1398 * @private
1399 * @returns string YYYY-MM-DD
1401 function &__increment($d,$m,$y,$f,$t)
1403 if($t == REPEAT_EVERY_DAY) {
1404 return date('Y-m-d',mktime(0,0,0,$m,($d+$f),$y));
1405 } elseif($t == REPEAT_EVERY_WORK_DAY) {
1406 //echo "special occurance<br />";
1407 $beginday = date("D",mktime(0,0,0,$m,$d,$y));
1408 $dayincrement = 1;
1409 if ($beginday == "Fri") {
1410 $dayincrement = 3;
1412 elseif ($beginday == "Sat") {
1413 $dayincrement = 2;
1415 return date('Y-m-d',mktime(0,0,0,$m,($d+$dayincrement),$y));
1417 } elseif($t == REPEAT_EVERY_WEEK) {
1418 return date('Y-m-d',mktime(0,0,0,$m,($d+(7*$f)),$y));
1419 } elseif($t == REPEAT_EVERY_MONTH) {
1420 return date('Y-m-d',mktime(0,0,0,($m+$f),$d,$y));
1421 } elseif($t == REPEAT_EVERY_YEAR) {
1422 return date('Y-m-d',mktime(0,0,0,$m,$d,($y+$f)));