2 @define
('__POSTCALENDAR__','PostCalendar');
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
,
48 return $pc_long_day[Date("w",$Date)];
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
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'.
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']) {
82 $under_ten = "0" . $minutes;
83 array_push($minute, "$under_ten");
85 else if($minutes >= '60') {
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'];
105 //=================================================================
106 // grab the for post variable
107 //=================================================================
108 $pc_username = pnVarCleanFromInput('pc_username');
109 $category = pnVarCleanFromInput('pc_category');
110 $topic = pnVarCleanFromInput('pc_topic');
112 //=================================================================
113 // set the correct date
114 //=================================================================
115 $Date =& postcalendar_getDate();
117 //=================================================================
118 // get the current view
119 //=================================================================
120 if(!isset($viewtype)) { $viewtype = 'month'; }
122 //=================================================================
123 // Find out what Template we're using
124 //=================================================================
125 $template_name = _SETTING_TEMPLATE
;
126 if(!isset($template_name)) { $template_name = 'default'; }
128 //=================================================================
129 // Find out what Template View to use
130 //=================================================================
131 $template_view = pnVarCleanFromInput('tplview');
132 if(!isset($template_view)) { $template_view = 'default'; }
134 //=================================================================
135 // See if the template view exists
136 //=================================================================
137 if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) {
138 $template_view_load = 'default';
140 $template_view_load = pnVarPrepForOS($template_view);
143 //=================================================================
144 // Grab the current theme information
145 //=================================================================
146 pnThemeLoad(pnUserGetTheme());
147 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2;
149 //=================================================================
150 // Insert necessary JavaScript into the page
151 //=================================================================
152 $output = pnModAPIFunc(__POSTCALENDAR__
, 'user', 'pageSetup');
154 //=================================================================
155 // Setup Smarty Template Engine
156 //=================================================================
157 $tpl =& new pcSmarty();
159 //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) {
160 //diable caching completely
162 //=================================================================
163 // Let's just finish setting things up
164 //=================================================================
165 $the_year = substr($Date,0,4);
166 $the_month = substr($Date,4,2);
167 $the_day = substr($Date,6,2);
168 $last_day = Date_Calc
::daysInMonth($the_month,$the_year);
170 //=================================================================
171 // populate the template object with information for
172 // Month Names, Long Day Names and Short Day Names
173 // as translated in the language files
174 // (may be adding more here soon - based on need)
175 //=================================================================
176 $pc_month_names = array(_CALJAN
,_CALFEB
,_CALMAR
,_CALAPR
,_CALMAY
,_CALJUN
,
177 _CALJUL
,_CALAUG
,_CALSEP
,_CALOCT
,_CALNOV
,_CALDEC
);
179 $pc_short_day_names = array(_CALSUNDAYSHORT
, _CALMONDAYSHORT
,
180 _CALTUESDAYSHORT
, _CALWEDNESDAYSHORT
,
181 _CALTHURSDAYSHORT
, _CALFRIDAYSHORT
,
184 $pc_long_day_names = array(_CALSUNDAY
, _CALMONDAY
,
185 _CALTUESDAY
, _CALWEDNESDAY
,
186 _CALTHURSDAY
, _CALFRIDAY
,
188 //=================================================================
189 // here we need to set up some information for later
190 // variable creation. This helps us establish the correct
191 // date ranges for each view. There may be a better way
192 // to handle all this, but my brain hurts, so your comments
193 // are very appreciated and welcomed.
194 //=================================================================
195 switch (_SETTING_FIRST_DAY_WEEK
)
199 $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year));
200 $week_day = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year));
201 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
203 $the_last_day = $last_day+
(7-$end_dow);
205 $the_last_day = $last_day;
210 $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year));
211 $week_day = date('w',mktime(0,0,0,$the_month,$the_day+
1,$the_year));
212 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
214 $the_last_day = $last_day+
6;
215 } elseif($end_dow != 5) {
216 $the_last_day = $last_day+
(5-$end_dow);
218 $the_last_day = $last_day;
224 $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
225 $week_day = date('w',mktime(0,0,0,$the_month,$the_day,$the_year));
226 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
228 $the_last_day = $last_day+
(6-$end_dow);
230 $the_last_day = $last_day;
235 // passing the times array to the tpl the times array is for the days schedule
236 $tpl->assign_by_ref("times",$times);
237 // load the table width to the template
238 // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']);
240 //=================================================================
241 // Week View is a bit of a pain in the ass, so we need to
242 // do some extra setup for that view. This section will
243 // find the correct starting and ending dates for a given
244 // seven day period, based on the day of the week the
245 // calendar is setup to run under (Sunday, Saturday, Monday)
246 //=================================================================
247 $first_day_of_week = sprintf('%02d',$the_day-$week_day);
248 $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
249 list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day);
250 $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__
, 'user', 'getmonthname',
251 array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year)));
252 $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+
6,$the_year));
253 list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day);
254 $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__
, 'user', 'getmonthname',
255 array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year)));
257 //=================================================================
258 // Setup some information so we know the actual month's dates
259 // also get today's date for later use and highlighting
260 //=================================================================
261 $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year));
262 $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year));
263 $today_date = postcalendar_today('%Y-%m-%d');
265 //=================================================================
266 // Setup the starting and ending date ranges for pcGetEvents()
267 //=================================================================
270 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
271 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
274 $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year";
275 $ending_date = "$week_last_day_month/$week_last_day_date/$week_last_day_year";
276 $calendarView = Date_Calc
::getCalendarWeek($week_first_day_date,
277 $week_first_day_month,
278 $week_first_day_year,
282 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year));
283 $ending_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year));
284 $calendarView = Date_Calc
::getCalendarMonth($the_month, $the_year, '%Y-%m-%d');
287 $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year));
288 $ending_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year+
1));
289 $calendarView = Date_Calc
::getCalendarYear($the_year, '%Y-%m-%d');
293 //=================================================================
295 //=================================================================
296 if($viewtype != 'year') {
297 $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date, 'viewtype' => $viewtype));
299 $eventsByDate = array();
302 //=================================================================
303 // Create an array with the day names in the correct order
304 //=================================================================
306 $numDays = count($pc_long_day_names);
307 for($i=0; $i < $numDays; $i++
) {
308 if($pc_array_pos >= $numDays) {
311 array_push($daynames,$pc_long_day_names[$pc_array_pos]);
315 $sdaynames = array();
316 $numDays = count($pc_short_day_names);
317 for($i=0; $i < $numDays; $i++
) {
318 if($pc_array_pos >= $numDays) {
321 array_push($sdaynames,$pc_short_day_names[$pc_array_pos]);
326 //=================================================================
327 // Prepare some values for the template
328 //=================================================================
329 $prev_month = Date_Calc
::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d');
330 $next_month = Date_Calc
::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d');
332 $pc_prev = pnModURL(__POSTCALENDAR__
,'user','view',
333 array('tplview'=>$template_view,
336 'pc_username'=>$pc_username,
337 'pc_category'=>$category,
338 'pc_topic'=>$topic));
340 $pc_next = pnModURL(__POSTCALENDAR__
,'user','view',
341 array('tplview'=>$template_view,
344 'pc_username'=>$pc_username,
345 'pc_category'=>$category,
346 'pc_topic'=>$topic));
348 $prev_day = Date_Calc
::prevDay($the_day,$the_month,$the_year,'%Y%m%d');
349 $next_day = Date_Calc
::nextDay($the_day,$the_month,$the_year,'%Y%m%d');
350 $pc_prev_day = pnModURL(__POSTCALENDAR__
,'user','view',
351 array('tplview'=>$template_view,
354 'pc_username'=>$pc_username,
355 'pc_category'=>$category,
356 'pc_topic'=>$topic));
358 $pc_next_day = pnModURL(__POSTCALENDAR__
,'user','view',
359 array('tplview'=>$template_view,
362 'pc_username'=>$pc_username,
363 'pc_category'=>$category,
364 'pc_topic'=>$topic));
366 $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year));
367 $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+
1,$week_last_day_year));
368 $pc_prev_week = pnModURL(__POSTCALENDAR__
,'user','view',
369 array('viewtype'=>'week',
371 'pc_username'=>$pc_username,
372 'pc_category'=>$category,
373 'pc_topic'=>$topic));
374 $pc_next_week = pnModURL(__POSTCALENDAR__
,'user','view',
375 array('viewtype'=>'week',
377 'pc_username'=>$pc_username,
378 'pc_category'=>$category,
379 'pc_topic'=>$topic));
381 $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1));
382 $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+
1));
383 $pc_prev_year = pnModURL(__POSTCALENDAR__
,'user','view',
384 array('viewtype'=>'year',
386 'pc_username'=>$pc_username,
387 'pc_category'=>$category,
388 'pc_topic'=>$topic));
389 $pc_next_year = pnModURL(__POSTCALENDAR__
,'user','view',
390 array('viewtype'=>'year',
392 'pc_username'=>$pc_username,
393 'pc_category'=>$category,
394 'pc_topic'=>$topic));
396 //=================================================================
397 // Populate the template
398 //=================================================================
399 $all_categories = pnModAPIFunc(__POSTCALENDAR__
,'user','getCategories');
401 if(isset($calendarView)) {
402 $tpl->assign_by_ref('CAL_FORMAT',$calendarView);
405 if($viewtype == "week") {
406 $last_blocks = array();
407 foreach($eventsByDate as $cdate => $day) {
408 $tblock = array_reverse($day['blocks']);
409 $last_blocks[$cdate] = count($tblock) -1;
410 for ($i=0;$i<count($tblock);$i++
) {
411 if (!empty($tblock[$i])) {
412 $last_blocks[$cdate] = count($tblock) - $i;
417 $tpl->assign("last_blocks",$last_blocks);
420 $tpl->assign('STYLE',$GLOBALS['style']);
421 $tpl->assign('show_days',$show_days);
422 $provinfo = getProviderInfo();
425 // filter the display on the requested username, the provinfo array is
426 // used to build columns in the week view.
428 foreach($provinfo as $provider) {
429 if(is_array($pc_username)){
430 foreach($pc_username as $uname) {
431 if (!empty($pc_username) && $provider['username'] == $uname) {
432 array_push($single,$provider);
437 if (!empty($pc_username) && $provider['username'] == $pc_username) {
438 array_push($single,$provider);
442 if ($single != null) {
446 //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other");
447 $tpl->assign_by_ref('providers', $provinfo);
449 if (pnVarCleanFromInput("show_days") != 1) {
450 $tpl->assign('showdaysurl',"index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1");
453 $tpl->assign('interval', $GLOBALS['calendar_interval']);
454 $tpl->assign_by_ref('VIEW_TYPE',$viewtype);
455 $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names);
456 $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names);
457 $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names);
458 $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames);
459 $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames);
460 $tpl->assign_by_ref('A_EVENTS',$eventsByDate);
461 $tpl->assign_by_ref('A_CATEGORY',$all_categories);
462 $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev);
463 $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next);
464 $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day);
465 $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day);
466 $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week);
467 $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week);
468 $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year);
469 $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year);
470 $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start);
471 $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end);
472 $tpl->assign_by_ref('TODAY_DATE',$today_date);
473 $tpl->assign_by_ref('DATE',$Date);
474 $tpl->assign_by_ref('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__
,'user','submit'));
475 $tpl->assign_by_ref('interval',$intervals);
478 //=================================================================
479 // Parse the template
480 //=================================================================
481 $template = "$template_name/views/$viewtype/$template_view_load.html";
483 $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
484 $output .= $tpl->fetch($template,$cacheid); // cache id
485 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
487 $theme = pnUserGetTheme();
489 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
490 echo "<style type=\"text/css\">\n";
491 echo "@import url(\"themes/$theme/style/style.css\"); ";
493 echo "</head><body>\n";
495 $tpl->display($template,$cacheid);
496 echo postcalendar_footer();
497 echo "\n</body></html>";
498 session_write_close();
501 //=================================================================
503 //=================================================================
508 * postcalendar_userapi_eventPreview
509 * Creates the detailed event display and outputs html.
510 * Accepts an array of key/value pairs
511 * @param array $event array of event details from the form
512 * @return string html output
515 function postcalendar_userapi_eventPreview($args)
517 // get the theme globals :: is there a better way to do this?
518 pnThemeLoad(pnUserGetTheme());
519 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
520 global $textcolor1, $textcolor2;
522 extract($args); unset($args);
523 $uid = pnUserGetVar('uid');
524 //=================================================================
525 // Setup Smarty Template Engine
526 //=================================================================
527 $tpl =& new pcSmarty();
528 $tpl->caching
= false;
529 // add preceding zeros
530 $event_starttimeh = sprintf('%02d',$event_starttimeh);
531 $event_starttimem = sprintf('%02d',$event_starttimem);
532 $event_startday = sprintf('%02d',$event_startday);
533 $event_startmonth = sprintf('%02d',$event_startmonth);
534 $event_endday = sprintf('%02d',$event_endday);
535 $event_endmonth = sprintf('%02d',$event_endmonth);
537 if(!(bool)_SETTING_TIME_24HOUR
) {
538 if($event_startampm == _PM_VAL
) {
539 if($event_starttimeh != 12) {
540 $event_starttimeh+
=12;
542 } elseif($event_startampm == _AM_VAL
) {
543 if($event_starttimeh == 12) {
544 $event_starttimeh = 00;
549 $event_startampm." - ";
550 $startTime = $event_starttimeh.':'.$event_starttimem.' ';
554 $event['uname'] = $uname;
555 $event['catid'] = $event_category;
556 if($pc_html_or_text == 'html') {
557 $prepFunction = 'pcVarPrepHTMLDisplay';
559 $prepFunction = 'pcVarPrepForDisplay';
561 $event['title'] = $prepFunction($event_subject);
562 $event['hometext'] = $prepFunction($event_desc);
563 $event['desc'] = $event['hometext'];
564 $event['date'] = $event_startyear.$event_startmonth.$event_startday;
565 $event['duration'] = $event_duration;
566 $event['duration_hours'] = $event_dur_hours;
567 $event['duration_minutes'] = $event_dur_minutes;
568 $event['endDate'] = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
569 $event['startTime'] = $startTime;
570 $event['recurrtype'] = '';
571 $event['recurrfreq'] = '';
572 $event['recurrspec'] = $event_recurrspec;
573 $event['topic'] = $event_topic;
574 $event['alldayevent'] = $event_allday;
575 $event['conttel'] = $prepFunction($event_conttel);
576 $event['contname'] = $prepFunction($event_contname);
577 $event['contemail'] = $prepFunction($event_contemail);
578 $event['website'] = $prepFunction(postcalendar_makeValidURL($event_website));
579 $event['fee'] = $prepFunction($event_fee);
580 $event['location'] = $prepFunction($event_location);
581 $event['street1'] = $prepFunction($event_street1);
582 $event['street2'] = $prepFunction($event_street2);
583 $event['city'] = $prepFunction($event_city);
584 $event['state'] = $prepFunction($event_state);
585 $event['postal'] = $prepFunction($event_postal);
587 //=================================================================
588 // get event's topic information
589 //=================================================================
590 if(_SETTING_DISPLAY_TOPICS
) {
591 list($dbconn) = pnDBGetConn();
592 $pntable = pnDBGetTables();
593 $topics_table = $pntable['topics'];
594 $topics_column = $pntable['topics_column'];
595 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
597 WHERE $topics_column[topicid] = $event[topic]
599 $topic_result = $dbconn->Execute($topicsql);
600 list($event['topictext'],$event['topicimg']) = $topic_result->fields
;
601 $topic_result->Close();
603 $event['topictext'] = $event['topicimg'] = '';
605 //=================================================================
606 // Find out what Template we're using
607 //=================================================================
608 $template_name = _SETTING_TEMPLATE
;
609 if(!isset($template_name)) {
610 $template_name = 'default';
612 //=================================================================
613 // populate the template
614 //=================================================================
615 if(!empty($event['location']) ||
!empty($event['street1']) ||
616 !empty($event['street2']) ||
!empty($event['city']) ||
617 !empty($event['state']) ||
!empty($event['postal'])) {
618 $tpl->assign('LOCATION_INFO',true);
620 $tpl->assign('LOCATION_INFO',false);
622 if(!empty($event['contname']) ||
!empty($event['contemail']) ||
623 !empty($event['conttel']) ||
!empty($event['website'])) {
624 $tpl->assign('CONTACT_INFO',true);
626 $tpl->assign('CONTACT_INFO',false);
628 $tpl->assign_by_ref('A_EVENT',$event);
629 $tpl->assign('STYLE',$GLOBALS['style']);
630 //=================================================================
631 // Parse the template
632 //=================================================================
633 $output = "\n\n<!-- POSTCALENDAR HTTP://WWW.BAHRAINI.TV -->\n\n";
634 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE START -->\n\n";
635 $output .= $tpl->fetch($template_name.'/user/preview.html');
636 $output .= "\n\n<!-- POSTCALENDAR TEMPLATE END -->\n\n";
642 * checkEventCollision
643 * Returns an array containing any events that collide with the specified event
644 * @params array(key=>value)
645 * @return array $events[][]
647 function checkEventCollision($edata) {
650 $sdate = ($event_startmonth.'/'.$event_startday.'/'.$event_startyear);
652 //hour from forms is 12 not 24 format, convert here
653 if($event_startampm == 2 && $event_starttimeh != 12)
654 $event_starttimeh +
= 12;
655 elseif ($event_startampm == 1 && $event_starttimeh == 12)
656 $event_starttimeh -= 12;
658 $stime = date("H:i:00",strtotime($event_starttimeh.':'.$event_starttimem.':00'));
659 $etime = date("H:i:00",$event_duration +
strtotime($stime));
660 //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
661 $a = array('collideFlag' => true,'start'=>$edate,'end'=>$sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime);
662 $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
663 //print_r($eventsByDate);
664 $collisions = array();
665 foreach ($eventsByDate as $day) {
666 foreach ($day as $event) {
667 if ($event['duration'] == 0 && $event['alldayevent'] == 0) {
670 elseif($event['alldayevent'] == 1) {
671 $collisions[] = $event;
673 $festart = strtotime($event['startTime']);
674 $feend = strtotime($event['startTime'] +
$event['duration']);
675 $estart = strtotime($stime);
676 $eend = strtotime($etime);
678 //echo "festart = $festart feend = $feend estart = $estart eend = $eend<br />";
679 if ($festart < $eend && $feend > $estart) {
680 $collisions[] = $event;
682 elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) {
683 $collisions[] = $event;
685 elseif ($festart >= $estart && $festart < $eend) {
686 $collisions[] = $event;
690 //foreach ($collisions as $collide) {
691 // echo "collided: " . $collide['title'] . "<br />";
697 * postcalendar_userapi_pcQueryEventsFA
698 * Returns an array containing the event's information for first available queiries
699 * @params array(key=>value)
700 * @params string key eventstatus
701 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
702 * @return array $events[][]
704 function &postcalendar_userapi_pcQueryEventsFA($args) {
709 if (is_numeric($event_status))
710 $eventstatus = $event_status;
712 if(!isset($start)) { $start = Date_Calc
::dateNow('%Y-%m-%d'); }
713 list($sy,$sm,$sd) = explode('-',$start);
715 list($dbconn) = pnDBGetConn();
716 $pntable = pnDBGetTables();
717 // link to the events tables
718 $table = $pntable['postcalendar_events'];
719 $cattable = $pntable['postcalendar_categories'];
721 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, a.pc_title, " .
722 "a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, a.pc_endDate, " .
723 "a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, a.pc_recurrspec, " .
724 "a.pc_topic, a.pc_alldayevent, a.pc_location, a.pc_conttel, " .
725 "a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, a.pc_sharing, " .
727 "b.pc_catcolor, b.pc_catname, b.pc_catdesc, a.pc_pid, a.pc_aid, " .
728 "concat(u.fname,' ',u.lname) as provider_name, " .
729 "concat(pd.fname,' ',pd.lname) as patient_name, " .
730 "concat(u2.fname, ' ', u2.lname) as owner_name, pd.DOB as patient_dob " .
731 "FROM ( $table AS a, $cattable AS b ) " .
732 "LEFT JOIN users as u ON a.pc_aid = u.id " .
733 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
734 "LEFT JOIN patient_data as pd ON a.pc_pid=pd.pid " .
735 "WHERE b.pc_catid = a.pc_catid " .
736 "AND a.pc_eventstatus = $eventstatus " .
737 "AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00') " .
738 "AND a.pc_eventDate <= '$end' " .
739 "AND (a.pc_aid = '" . $provider_id . "' OR a.pc_aid = '')";
741 //======================================================================
742 // START SEARCH FUNCTIONALITY
743 //======================================================================
744 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
745 if(!empty($s_category)) $sql .= "AND ($s_category) ";
746 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
747 if(!empty($collide_etime) && !empty($collide_stime)) {
748 $sql .= "AND NOT ((pc_endTime <= '$collide_stime') OR (pc_startTime >= '$collide_etime')) AND pc_endTime IS NOT NULL ";
750 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
751 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
752 //======================================================================
753 // Search sort and limitation
754 //======================================================================
755 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_startTime ASC";
756 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
757 //======================================================================
758 // END SEARCH FUNCTIONALITY
759 //======================================================================
760 //echo "<Br />sql: $sql<br />";
761 $result = $dbconn->Execute($sql);
762 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
764 // put the information into an array for easy access
766 // return an empty array if we don't have any results
767 if(!isset($result)) { return $events; }
769 for($i=0; !$result->EOF
; $result->MoveNext()) {
771 // get the results from the query
772 if(isset($tmp)) { unset($tmp); } $tmp = array();
773 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
774 $tmp['title'], $tmp['time'], $tmp['hometext'],
775 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
776 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
777 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
778 $tmp['location'], $tmp['conttel'], $tmp['contname'],
779 $tmp['contemail'], $tmp['website'], $tmp['fee'],
780 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
781 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
782 $tmp['aid'], $tmp['provider_name'], $tmp['patient_name'],
783 $tmp['owner_name'], $tmp['patient_dob']) = $result->fields
;
785 // grab the name of the topic
786 $topicname = pcGetTopicName($tmp['topic']);
787 // get the user id of event's author
788 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
789 // check the current event's permissions
790 // the user does not have permission to view this event
791 // if any of the following evaluate as false
792 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW
)) {
794 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW
)) {
796 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW
)) {
798 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW
)) {
800 } elseif($tmp['sharing'] == SHARING_PRIVATE
&& $cuserid != $userid) {
804 // add event to the array if we passed the permissions check
805 // this is the common information
806 $events[$i]['eid'] = $tmp['eid'];
807 $events[$i]['uname'] = $tmp['uname'];
808 $events[$i]['uid'] = $cuserid;
809 $events[$i]['catid'] = $tmp['catid'];
810 $events[$i]['time'] = $tmp['time'];
811 $events[$i]['eventDate'] = $tmp['eventDate'];
812 $events[$i]['duration'] = $tmp['duration'];
813 // there has to be a more intelligent way to do this
814 @list
($events[$i]['duration_hours'],$dmin) = @explode
('.',($tmp['duration']/60/60));
815 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
816 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
817 $events[$i]['endDate'] = $tmp['endDate'];
818 $events[$i]['startTime'] = $tmp['startTime'];
819 $events[$i]['recurrtype'] = $tmp['recurrtype'];
820 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
821 $events[$i]['recurrspec'] = $tmp['recurrspec'];
823 $rspecs = unserialize($tmp['recurrspec']);
824 $events[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
825 $events[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
826 $events[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
827 $events[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
828 $events[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
830 $events[$i]['topic'] = $tmp['topic'];
831 $events[$i]['alldayevent'] = $tmp['alldayevent'];
832 $events[$i]['catcolor'] = $tmp['catcolor'];
833 $events[$i]['catname'] = $tmp['catname'];
834 $events[$i]['catdesc'] = $tmp['catdesc'];
835 $events[$i]['pid'] = $tmp['pid'];
836 $events[$i]['patient_name']= $tmp['patient_name'];
837 $events[$i]['provider_name'] = $tmp['provider_name'];
838 $events[$i]['owner_name'] = $tmp['owner_name'];
839 $events[$i]['patient_dob'] = $tmp['patient_dob'];
840 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
841 $events[$i]['sharing'] = $tmp['sharing'];
842 $events[$i]['prefcatid'] = $tmp['prefcatid'];
843 $events[$i]['aid'] = $tmp['aid'];
844 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
845 if($events[$i]['intervals'] == 0)
846 $events[$i]['intervals'] = 1;
847 // is this a public event to be shown as busy?
848 if($tmp['sharing'] == SHARING_BUSY
&& $cuserid != $userid) {
849 // make it not display any information
850 $events[$i]['title'] = _USER_BUSY_TITLE
;
851 $events[$i]['hometext'] = _USER_BUSY_MESSAGE
;
852 $events[$i]['desc'] = _USER_BUSY_MESSAGE
;
853 $events[$i]['conttel'] = '';
854 $events[$i]['contname'] = '';
855 $events[$i]['contemail'] = '';
856 $events[$i]['website'] = '';
857 $events[$i]['fee'] = '';
858 $events[$i]['location'] = '';
859 $events[$i]['street1'] = '';
860 $events[$i]['street2'] = '';
861 $events[$i]['city'] = '';
862 $events[$i]['state'] = '';
863 $events[$i]['postal'] = '';
865 $display_type = substr($tmp['hometext'],0,6);
866 if($display_type == ':text:') {
867 $prepFunction = 'pcVarPrepForDisplay';
868 $tmp['hometext'] = substr($tmp['hometext'],6);
869 } elseif($display_type == ':html:') {
870 $prepFunction = 'pcVarPrepHTMLDisplay';
871 $tmp['hometext'] = substr($tmp['hometext'],6);
873 $prepFunction = 'pcVarPrepHTMLDisplay';
875 unset($display_type);
876 $events[$i]['title'] = $prepFunction($tmp['title']);
877 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
878 $events[$i]['desc'] = $events[$i]['hometext'];
879 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
880 $events[$i]['contname'] = $prepFunction($tmp['contname']);
881 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
882 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
883 $events[$i]['fee'] = $prepFunction($tmp['fee']);
884 $loc = unserialize($tmp['location']);
885 $events[$i]['location'] = $prepFunction($loc['event_location']);
886 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
887 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
888 $events[$i]['city'] = $prepFunction($loc['event_city']);
889 $events[$i]['state'] = $prepFunction($loc['event_state']);
890 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
901 * postcalendar_userapi_pcQueryEvents
902 * Returns an array containing the event's information
903 * @params array(key=>value)
904 * @params string key eventstatus
905 * @params int value -1 == hidden ; 0 == queued ; 1 == approved
906 * @return array $events[][]
908 function &postcalendar_userapi_pcQueryEvents($args)
913 // echo "<!-- args = "; print_r($args); echo " -->\n"; // debugging
915 $pc_username = pnVarCleanFromInput('pc_username');
916 if (empty($pc_username) ||
is_array($pc_username)) {
917 $pc_username = "__PC_ALL__";
920 // echo "<!-- pc_username: $pc_username -->\n"; // debugging
922 $topic = pnVarCleanFromInput('pc_topic');
923 $category = pnVarCleanFromInput('pc_category');
925 if(!empty($pc_username) && (strtolower($pc_username) != 'anonymous')) {
926 if($pc_username=='__PC_ALL__' ||
$pc_username == -1) {
929 $ruserid = getIDfromUser($pc_username);
933 if(!isset($eventstatus)) { $eventstatus = 1; }
934 // sanity check on eventstatus
935 if((int)$eventstatus < -1 ||
(int)$eventstatus > 1) { $eventstatus = 1; }
936 if(!isset($start)) { $start = Date_Calc
::dateNow('%Y-%m-%d'); }
937 list($sy,$sm,$sd) = explode('-',$start);
939 list($dbconn) = pnDBGetConn();
940 $pntable = pnDBGetTables();
941 // link to the events tables
942 $table = $pntable['postcalendar_events'];
943 $cattable = $pntable['postcalendar_categories'];
944 $topictable = $pntable['postcalendar_topics'];
946 $sql = "SELECT DISTINCT a.pc_eid, a.pc_informant, a.pc_catid, " .
947 "a.pc_title, a.pc_time, a.pc_hometext, a.pc_eventDate, a.pc_duration, " .
948 "a.pc_endDate, a.pc_startTime, a.pc_recurrtype, a.pc_recurrfreq, " .
949 "a.pc_recurrspec, a.pc_topic, a.pc_alldayevent, a.pc_location, " .
950 "a.pc_conttel, a.pc_contname, a.pc_contemail, a.pc_website, a.pc_fee, " .
951 "a.pc_sharing, a.pc_prefcatid, b.pc_catcolor, b.pc_catname, " .
952 "b.pc_catdesc, a.pc_pid, a.pc_apptstatus, a.pc_aid, " .
953 "concat(u.fname,' ',u.lname) as provider_name, " .
954 "concat(pd.lname,', ',pd.fname) as patient_name, " .
955 "concat(u2.fname, ' ', u2.lname) as owner_name, " .
956 "DOB as patient_dob, pd.pubpid " .
957 "FROM ( $table AS a, $cattable AS b ) " .
958 "LEFT JOIN users as u ON a.pc_aid = u.id " .
959 "LEFT JOIN users as u2 ON a.pc_aid = u2.id " .
960 "LEFT JOIN patient_data as pd ON a.pc_pid = pd.pid " .
961 "WHERE b.pc_catid = a.pc_catid " .
962 "AND a.pc_eventstatus = $eventstatus " .
963 "AND ((a.pc_endDate >= '$start' AND a.pc_eventDate <= '$end') OR " .
964 "(a.pc_endDate = '0000-00-00' AND a.pc_eventDate >= '$start' AND " .
965 "a.pc_eventDate <= '$end')) ";
967 // The above 3 lines replaced these:
968 // AND (a.pc_endDate >= '$start' OR a.pc_endDate = '0000-00-00')
969 // AND a.pc_eventDate <= '$end' ";
971 if(!empty($providerID))
973 $ruserid = $providerID;
976 if(isset($ruserid)) {
977 // get all events for the specified username
979 $sql .= "AND (a.pc_sharing = '" . SHARING_BUSY
. "' ";
980 $sql .= "OR a.pc_sharing = '" . SHARING_PUBLIC
. "') ";
982 $sql .= "AND a.pc_aid = " . $ruserid . " ";
984 } elseif(!pnUserLoggedIn()) {
985 // get all events for anonymous users
986 $sql .= "AND a.pc_sharing = '" . SHARING_GLOBAL
. "' ";
988 // get all events for logged in user plus global events
989 $sql .= "AND (a.pc_aid = " . $_SESSION['authUserID'] . " OR a.pc_sharing = '" . SHARING_GLOBAL
. "') ";
992 //======================================================================
993 // START SEARCH FUNCTIONALITY
994 //======================================================================
995 if(!empty($s_keywords)) $sql .= "AND ($s_keywords) ";
996 if(!empty($s_category)) $sql .= "AND ($s_category) ";
997 if(!empty($s_topic)) $sql .= "AND ($s_topic) ";
998 if(!empty($category)) $sql .= "AND (a.pc_catid = '".pnVarPrepForStore($category)."') ";
999 if(!empty($topic)) $sql .= "AND (a.pc_topic = '".pnVarPrepForStore($topic)."') ";
1001 //======================================================================
1002 // Search sort and limitation
1003 //======================================================================
1004 if(empty($sort)) $sql .= "GROUP BY a.pc_eid ORDER BY a.pc_time DESC";
1005 else $sql .= "GROUP BY a.pc_eid ORDER BY a.$sort";
1007 //======================================================================
1008 // END SEARCH FUNCTIONALITY
1009 //======================================================================
1010 //echo "sq: $sql<br />";
1012 // echo "<!-- " . $sql . " -->\n"; // debugging
1014 $result = $dbconn->Execute($sql);
1015 if($dbconn->ErrorNo() != 0) die ($dbconn->ErrorMsg());
1017 // put the information into an array for easy access
1019 // return an empty array if we don't have any results
1020 if(!isset($result)) { return $events; }
1022 for($i=0; !$result->EOF
; $result->MoveNext()) {
1024 // WHY are we using an array for intermediate storage??? -- Rod
1026 // get the results from the query
1027 if(isset($tmp)) { unset($tmp); } $tmp = array();
1028 list($tmp['eid'], $tmp['uname'], $tmp['catid'],
1029 $tmp['title'], $tmp['time'], $tmp['hometext'],
1030 $tmp['eventDate'], $tmp['duration'], $tmp['endDate'],
1031 $tmp['startTime'], $tmp['recurrtype'], $tmp['recurrfreq'],
1032 $tmp['recurrspec'], $tmp['topic'], $tmp['alldayevent'],
1033 $tmp['location'], $tmp['conttel'], $tmp['contname'],
1034 $tmp['contemail'], $tmp['website'], $tmp['fee'],
1035 $tmp['sharing'], $tmp['prefcatid'], $tmp['catcolor'],
1036 $tmp['catname'], $tmp['catdesc'], $tmp['pid'],
1037 $tmp['apptstatus'], $tmp['aid'], $tmp['provider_name'],
1038 $tmp['patient_name'], $tmp['owner_name'], $tmp['patient_dob'],
1039 $tmp['pubpid']) = $result->fields
;
1041 // grab the name of the topic
1042 $topicname = pcGetTopicName($tmp['topic']);
1043 // get the user id of event's author
1044 $cuserid = @$nuke_users[strtolower($tmp['uname'])];
1045 // check the current event's permissions
1046 // the user does not have permission to view this event
1047 // if any of the following evaluate as false
1048 if(!pnSecAuthAction(0, 'PostCalendar::Event', "$tmp[title]::$tmp[eid]", ACCESS_OVERVIEW
)) {
1050 } elseif(!pnSecAuthAction(0, 'PostCalendar::Category', "$tmp[catname]::$tmp[catid]", ACCESS_OVERVIEW
)) {
1052 } elseif(!pnSecAuthAction(0, 'PostCalendar::User', "$tmp[uname]::$cuserid", ACCESS_OVERVIEW
)) {
1054 } elseif(!pnSecAuthAction(0, 'PostCalendar::Topic', "$topicname::$tmp[topic]", ACCESS_OVERVIEW
)) {
1056 } elseif($tmp['sharing'] == SHARING_PRIVATE
&& $cuserid != $userid) {
1060 // add event to the array if we passed the permissions check
1061 // this is the common information
1063 $events[$i]['intervals'] =($tmp['duration']/60)/ $GLOBALS['day_calandar_interval'];//sets the number of rows this event should span
1064 print_r($events[$i]['intervals']);
1066 $events[$i]['eid'] = $tmp['eid'];
1067 $events[$i]['uname'] = $tmp['uname'];
1068 $events[$i]['uid'] = $cuserid;
1069 $events[$i]['catid'] = $tmp['catid'];
1070 $events[$i]['time'] = $tmp['time'];
1071 $events[$i]['eventDate'] = $tmp['eventDate'];
1072 $events[$i]['duration'] = $tmp['duration'];
1073 // there has to be a more intelligent way to do this
1074 @list
($events[$i]['duration_hours'],$dmin) = @explode
('.',($tmp['duration']/60/60));
1075 $events[$i]['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1076 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1077 $events[$i]['endDate'] = $tmp['endDate'];
1078 $events[$i]['startTime'] = $tmp['startTime'];
1079 $events[$i]['recurrtype'] = $tmp['recurrtype'];
1080 $events[$i]['recurrfreq'] = $tmp['recurrfreq'];
1081 $events[$i]['recurrspec'] = $tmp['recurrspec'];
1082 $events[$i]['topic'] = $tmp['topic'];
1083 $events[$i]['alldayevent'] = $tmp['alldayevent'];
1084 $events[$i]['catcolor'] = $tmp['catcolor'];
1085 $events[$i]['catname'] = $tmp['catname'];
1086 $events[$i]['catdesc'] = $tmp['catdesc'];
1087 $events[$i]['pid'] = $tmp['pid'];
1088 $events[$i]['apptstatus'] = $tmp['apptstatus'];
1089 $events[$i]['pubpid'] = $tmp['pubpid'];
1090 $events[$i]['patient_name']= $tmp['patient_name'];
1091 $events[$i]['provider_name'] = $tmp['provider_name'];
1092 $events[$i]['owner_name'] = $tmp['owner_name'];
1093 $events[$i]['patient_dob'] = $tmp['patient_dob'];
1094 $events[$i]['patient_age'] = date("Y") - substr(($tmp['patient_dob']),0,4);
1095 $events[$i]['sharing'] = $tmp['sharing'];
1096 $events[$i]['prefcatid'] = $tmp['prefcatid'];
1097 $events[$i]['aid'] = $tmp['aid'];
1098 $events[$i]['topictext'] = $topicname;
1099 $events[$i]['intervals'] = ceil(($tmp['duration']/60) / $GLOBALS['calendar_interval']);
1100 if($events[$i]['intervals'] == 0)
1101 $events[$i]['intervals'] = 1;
1102 // is this a public event to be shown as busy?
1103 if($tmp['sharing'] == SHARING_BUSY
&& $cuserid != $userid) {
1104 // make it not display any information
1105 $events[$i]['title'] = _USER_BUSY_TITLE
;
1106 $events[$i]['hometext'] = _USER_BUSY_MESSAGE
;
1107 $events[$i]['desc'] = _USER_BUSY_MESSAGE
;
1108 $events[$i]['conttel'] = '';
1109 $events[$i]['contname'] = '';
1110 $events[$i]['contemail'] = '';
1111 $events[$i]['website'] = '';
1112 $events[$i]['fee'] = '';
1113 $events[$i]['location'] = '';
1114 $events[$i]['street1'] = '';
1115 $events[$i]['street2'] = '';
1116 $events[$i]['city'] = '';
1117 $events[$i]['state'] = '';
1118 $events[$i]['postal'] = '';
1120 $display_type = substr($tmp['hometext'],0,6);
1121 if($display_type == ':text:') {
1122 $prepFunction = 'pcVarPrepForDisplay';
1123 $tmp['hometext'] = substr($tmp['hometext'],6);
1124 } elseif($display_type == ':html:') {
1125 $prepFunction = 'pcVarPrepHTMLDisplay';
1126 $tmp['hometext'] = substr($tmp['hometext'],6);
1128 $prepFunction = 'pcVarPrepHTMLDisplay';
1130 unset($display_type);
1131 $events[$i]['title'] = $prepFunction($tmp['title']);
1132 $events[$i]['hometext'] = $prepFunction($tmp['hometext']);
1133 $events[$i]['desc'] = $events[$i]['hometext'];
1134 $events[$i]['conttel'] = $prepFunction($tmp['conttel']);
1135 $events[$i]['contname'] = $prepFunction($tmp['contname']);
1136 $events[$i]['contemail'] = $prepFunction($tmp['contemail']);
1137 $events[$i]['website'] = $prepFunction(postcalendar_makeValidURL($tmp['website']));
1138 $events[$i]['fee'] = $prepFunction($tmp['fee']);
1139 $loc = unserialize($tmp['location']);
1140 $events[$i]['location'] = $prepFunction($loc['event_location']);
1141 $events[$i]['street1'] = $prepFunction($loc['event_street1']);
1142 $events[$i]['street2'] = $prepFunction($loc['event_street2']);
1143 $events[$i]['city'] = $prepFunction($loc['event_city']);
1144 $events[$i]['state'] = $prepFunction($loc['event_state']);
1145 $events[$i]['postal'] = $prepFunction($loc['event_postal']);
1155 function getBlockTime($time) {
1157 if ($time == 0 ||
strlen($time) == 0) {
1161 $ts = strtotime($time);
1163 $minutes = date("i",$ts);
1164 $hour = date("H",$ts);
1167 $blocknum = (($hour * 2) +
$half);
1168 return strval($blocknum);
1171 function &postcalendar_userapi_pcGetEvents($args)
1173 $s_keywords = $s_category = $s_topic = '';
1176 $date =& postcalendar_getDate();
1177 $cy = substr($date,0,4);
1178 $cm = substr($date,4,2);
1179 $cd = substr($date,6,2);
1180 if(isset($start) && isset($end)) {
1182 list($sm,$sd,$sy) = explode('/',$start);
1184 list($em,$ed,$ey) = explode('/',$end);
1186 $s = (int) "$sy$sm$sd";
1192 $start_date = Date_Calc
::dateFormat($sd,$sm,$sy,'%Y-%m-%d');
1193 $end_date = Date_Calc
::dateFormat($ed,$em,$ey,'%Y-%m-%d');
1199 $start_date = $sy.'-'.$sm.'-'.$sd;
1200 $end_date = $ey.'-'.$em.'-'.$ed;
1202 if ($faFlag && !isset($events)) {
1203 $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);
1205 $events =& pnModAPIFunc(__POSTCALENDAR__
,'user','pcQueryEventsFA',$a);
1207 elseif ($collideFlag && !isset($events)) {
1209 $a = array('collideFlag' => true,'start'=>$start_date,'end'=>$end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime);
1210 $events =& pnModAPIFunc(__POSTCALENDAR__
,'user','pcQueryEventsFA',$a);
1212 elseif ($listappsFlag && !isset($events)) {
1214 $a = array('listappsFlag' => true,'start'=>$start_date,'end'=>$end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords);
1215 $events =& pnModAPIFunc(__POSTCALENDAR__
,'user','pcQueryEvents',$a);
1217 else if(!isset($events)) {
1218 if(!isset($s_keywords)) $s_keywords = '';
1219 $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);
1220 $events =& pnModAPIFunc(__POSTCALENDAR__
,'user','pcQueryEvents',$a);
1223 //==============================================================
1224 // Here we build an array consisting of the date ranges
1225 // specific to the current view. This array is then
1226 // used to build the calendar display.
1227 //==============================================================
1229 $sday = Date_Calc
::dateToDays($sd,$sm,$sy);
1230 $eday = Date_Calc
::dateToDays($ed,$em,$ey);
1231 for($cday = $sday; $cday <= $eday; $cday++
) {
1232 $d = Date_Calc
::daysToDate($cday,'%d');
1233 $m = Date_Calc
::daysToDate($cday,'%m');
1234 $y = Date_Calc
::daysToDate($cday,'%Y');
1235 $store_date = Date_Calc
::dateFormat($d,$m,$y,'%Y-%m-%d');
1236 $days[$store_date] = array();
1239 $days = calculateEvents($days,$events,$viewtype);
1243 function calculateEvents($days,$events,$viewtype) {
1244 $date =& postcalendar_getDate();
1245 $cy = substr($date,0,4);
1246 $cm = substr($date,4,2);
1247 $cd = substr($date,6,2);
1249 foreach($events as $event) {
1250 // get the name of the topic
1251 $topicname = pcGetTopicName($event['topic']);
1253 // parse the event start date
1254 list($esY,$esM,$esD) = explode('-',$event['eventDate']);
1255 // grab the recurring specs for the event
1256 $event_recurrspec = @unserialize
($event['recurrspec']);
1257 // determine the stop date for this event
1258 if($event['endDate'] == '0000-00-00') {
1261 $stop = $event['endDate'];
1264 $eventD = $event['eventDate'];
1265 $eventS = $event['startTime'];
1267 switch($event['recurrtype']) {
1268 //==============================================================
1269 // Events that do not repeat only have a startday
1270 //==============================================================
1273 if(isset($days[$event['eventDate']])) {
1274 array_push($days[$event['eventDate']],$event);
1275 if ($viewtype == "week") {
1276 //echo "non repeating date eventdate: $eventD startime:$eventS block #: " . getBlockTime($eventS) ."<br />";
1278 fillBlocks($eventD,&$days);
1279 //echo "for $eventD loading " . getBlockTime($eventS) . "<br /><br />";
1280 $gbt = getBlockTime($eventS);
1281 $days[$eventD]['blocks'][$gbt][$eventD][] = $event;
1282 //echo "event is: " . print_r($days[$eventD]['blocks'][$gbt],true) . " <br />";
1283 //echo "begin printing blocks for $eventD<br />";
1284 //print_r($days[$eventD]['blocks']);
1285 //echo "end printing blocks<br />";
1290 //==============================================================
1291 // Find events that repeat at a certain frequency
1292 // Every,Every Other,Every Third,Every Fourth
1293 // Day,Week,Month,Year,MWF,TR,M-F,SS
1294 //==============================================================
1296 $rfreq = $event_recurrspec['event_repeat_freq'];
1297 $rtype = $event_recurrspec['event_repeat_freq_type'];
1298 // we should bring the event up to date to make this a tad bit faster
1299 // any ideas on how to do that, exactly??? dateToDays probably.
1300 $nm = $esM; $ny = $esY; $nd = $esD;
1301 $occurance = Date_Calc
::dateFormat($nd,$nm,$ny,'%Y-%m-%d');
1302 while($occurance < $start_date) {
1303 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1304 list($ny,$nm,$nd) = explode('-',$occurance);
1306 while($occurance <= $stop) {
1307 if(isset($days[$occurance])) {
1308 array_push($days[$occurance],$event);
1309 if ($viewtype == "week") {
1310 fillBlocks($occurance,&$days);
1311 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1312 $gbt = getBlockTime($eventS);
1313 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1314 //echo "begin printing blocks for $eventD<br />";
1315 //print_r($days[$occurance]['blocks']);
1316 //echo "end printing blocks<br />";
1319 $occurance =& __increment($nd,$nm,$ny,$rfreq,$rtype);
1320 list($ny,$nm,$nd) = explode('-',$occurance);
1324 //==============================================================
1325 // Find events that repeat on certain parameters
1326 // On 1st,2nd,3rd,4th,Last
1327 // Sun,Mon,Tue,Wed,Thu,Fri,Sat
1329 //==============================================================
1331 $rfreq = $event_recurrspec['event_repeat_on_freq'];
1332 $rnum = $event_recurrspec['event_repeat_on_num'];
1333 $rday = $event_recurrspec['event_repeat_on_day'];
1335 //==============================================================
1336 // Populate - Enter data into the event array
1337 //==============================================================
1338 $nm = $esM; $ny = $esY; $nd = $esD;
1343 $occurance = date('Y-m-d',mktime(0,0,0,$nm+
$rfreq,$nd,$ny));
1344 list($ny,$nm,$nd) = explode('-',$occurance);
1347 // populate the event array
1350 $dnum = $rnum; // get day event repeats on
1352 $occurance = Date_Calc
::NWeekdayOfMonth($dnum--,$rday,$nm,$ny,$format="%Y-%m-%d");
1353 } while($occurance === -1);
1354 if(isset($days[$occurance]) && $occurance <= $stop) {
1355 array_push($days[$occurance],$event);
1356 if ($viewtype == "week") {
1357 fillBlocks($occurance,&$days);
1358 //echo "for $occurance loading " . getBlockTime($eventS) . "<br /><br />";
1359 $gbt = getBlockTime($eventS);
1360 $days[$occurance]['blocks'][$gbt][$occurance][] = $event;
1363 $occurance = date('Y-m-d',mktime(0,0,0,$nm+
$rfreq,$nd,$ny));
1364 list($ny,$nm,$nd) = explode('-',$occurance);
1367 } // <- end of switch($event['recurrtype'])
1368 } // <- end of foreach($events as $event)
1372 function fillBlocks($td,&$ar) {
1373 if (strlen ($td) > 0 && !isset($ar[$td]['blocks'])) {
1374 $ar[$td]['blocks'] = array();
1375 for ($j=0;$j<48;$j++
)
1376 $ar[strval($td)]['blocks'][strval($j)] = array();
1377 $ar[strval($td)]['blocks']["all_day"] = array();
1385 * returns the next valid date for an event based on the
1386 * current day,month,year,freq and type
1388 * @returns string YYYY-MM-DD
1390 function &__increment($d,$m,$y,$f,$t)
1392 if($t == REPEAT_EVERY_DAY
) {
1393 return date('Y-m-d',mktime(0,0,0,$m,($d+
$f),$y));
1394 } elseif($t == REPEAT_EVERY_WORK_DAY
) {
1395 //echo "special occurance<br />";
1396 $beginday = date("D",mktime(0,0,0,$m,$d,$y));
1398 if ($beginday == "Fri") {
1401 elseif ($beginday == "Sat") {
1404 return date('Y-m-d',mktime(0,0,0,$m,($d+
$dayincrement),$y));
1406 } elseif($t == REPEAT_EVERY_WEEK
) {
1407 return date('Y-m-d',mktime(0,0,0,$m,($d+
(7*$f)),$y));
1408 } elseif($t == REPEAT_EVERY_MONTH
) {
1409 return date('Y-m-d',mktime(0,0,0,($m+
$f),$d,$y));
1410 } elseif($t == REPEAT_EVERY_YEAR
) {
1411 return date('Y-m-d',mktime(0,0,0,$m,$d,($y+
$f)));