5 * PostCalendar::PostNuke Events Calendar Module
6 * Copyright (C) 2002 The PostCalendar Team
7 * http://postcalendar.tv
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * To read the license please read the docs/license.txt or visit
24 * http://www.gnu.org/copyleft/gpl.html
28 //=================================================================
29 // define constants used to make the code more readable
30 //=================================================================
31 define('_IS_SUNDAY', 0);
32 define('_IS_MONDAY', 1);
33 define('_IS_SATURDAY', 6);
36 define('_ACTION_DELETE', 4);
37 define('_ACTION_EDIT', 2);
38 define('_EVENT_TEMPLATE', 8);
39 define('_EVENT_TEMPORARY', -9);
40 define('_EVENT_APPROVED', 1);
41 define('_EVENT_QUEUED', 0);
42 define('_EVENT_HIDDEN', -1);
44 define('NO_REPEAT', 0);
46 define('REPEAT_ON', 2);
48 define('REPEAT_EVERY', 1);
49 define('REPEAT_EVERY_OTHER', 2);
50 define('REPEAT_EVERY_THIRD', 3);
51 define('REPEAT_EVERY_FOURTH', 4);
52 // $event_repeat_freq_type
53 define('REPEAT_EVERY_DAY', 0);
54 define('REPEAT_EVERY_WEEK', 1);
55 define('REPEAT_EVERY_MONTH', 2);
56 define('REPEAT_EVERY_YEAR', 3);
57 define('REPEAT_EVERY_WORK_DAY',4);
58 // $event_repeat_on_num
59 define('REPEAT_ON_1ST', 1);
60 define('REPEAT_ON_2ND', 2);
61 define('REPEAT_ON_3RD', 3);
62 define('REPEAT_ON_4TH', 4);
63 define('REPEAT_ON_LAST', 5);
64 // $event_repeat_on_day
65 define('REPEAT_ON_SUN', 0);
66 define('REPEAT_ON_MON', 1);
67 define('REPEAT_ON_TUE', 2);
68 define('REPEAT_ON_WED', 3);
69 define('REPEAT_ON_THU', 4);
70 define('REPEAT_ON_FRI', 5);
71 define('REPEAT_ON_SAT', 6);
72 // $event_repeat_on_freq
73 define('REPEAT_ON_MONTH', 1);
74 define('REPEAT_ON_2MONTH', 2);
75 define('REPEAT_ON_3MONTH', 3);
76 define('REPEAT_ON_4MONTH', 4);
77 define('REPEAT_ON_6MONTH', 6);
78 define('REPEAT_ON_YEAR', 12);
79 // event sharing values
80 define('SHARING_PRIVATE', 0);
81 define('SHARING_PUBLIC', 1);
82 define('SHARING_BUSY', 2);
83 define('SHARING_GLOBAL', 3);
85 define('_ADMIN_ACTION_APPROVE', 0);
86 define('_ADMIN_ACTION_HIDE', 1);
87 define('_ADMIN_ACTION_EDIT', 2);
88 define('_ADMIN_ACTION_VIEW', 3);
89 define('_ADMIN_ACTION_DELETE', 4);
90 //=================================================================
91 // Get the global PostCalendar config settings
92 // This will save us a lot of time and DB queries later
93 //=================================================================
94 define('_SETTING_USE_POPUPS', pnModGetVar(__POSTCALENDAR__
,'pcUsePopups'));
95 define('_SETTING_USE_INT_DATES', pnModGetVar(__POSTCALENDAR__
,'pcUseInternationalDates'));
96 define('_SETTING_OPEN_NEW_WINDOW', pnModGetVar(__POSTCALENDAR__
,'pcEventsOpenInNewWindow'));
97 define('_SETTING_DAY_HICOLOR', pnModGetVar(__POSTCALENDAR__
,'pcDayHighlightColor'));
98 define('_SETTING_FIRST_DAY_WEEK', pnModGetVar(__POSTCALENDAR__
,'pcFirstDayOfWeek'));
99 define('_SETTING_DATE_FORMAT', pnModGetVar(__POSTCALENDAR__
,'pcEventDateFormat'));
100 define('_SETTING_TIME_24HOUR', pnModGetVar(__POSTCALENDAR__
,'pcTime24Hours'));
101 define('_SETTING_DIRECT_SUBMIT', pnModGetVar(__POSTCALENDAR__
,'pcAllowDirectSubmit'));
102 define('_SETTING_DISPLAY_TOPICS', pnModGetVar(__POSTCALENDAR__
,'pcDisplayTopics'));
103 define('_SETTING_ALLOW_GLOBAL', pnModGetVar(__POSTCALENDAR__
,'pcAllowSiteWide'));
104 define('_SETTING_ALLOW_USER_CAL', pnModGetVar(__POSTCALENDAR__
,'pcAllowUserCalendar'));
105 define('_SETTING_TIME_INCREMENT', pnModGetVar(__POSTCALENDAR__
,'pcTimeIncrement'));
106 define('_SETTING_HOW_MANY_EVENTS', pnModGetVar(__POSTCALENDAR__
,'pcListHowManyEvents'));
107 define('_SETTING_TEMPLATE', pnModGetVar(__POSTCALENDAR__
,'pcTemplate'));
108 define('_SETTING_EVENTS_IN_YEAR', pnModGetVar(__POSTCALENDAR__
,'pcShowEventsInYear'));
109 define('_SETTING_USE_CACHE', pnModGetVar(__POSTCALENDAR__
,'pcUseCache'));
110 define('_SETTING_CACHE_LIFETIME', pnModGetVar(__POSTCALENDAR__
,'pcCacheLifetime'));
111 define('_SETTING_DEFAULT_VIEW', pnModGetVar(__POSTCALENDAR__
,'pcDefaultView'));
112 define('_SETTING_SAFE_MODE', pnModGetVar(__POSTCALENDAR__
,'pcSafeMode'));
113 define('_SETTING_NOTIFY_ADMIN', pnModGetVar(__POSTCALENDAR__
,'pcNotifyAdmin'));
114 define('_SETTING_NOTIFY_EMAIL', pnModGetVar(__POSTCALENDAR__
,'pcNotifyEmail'));
115 //=================================================================
116 // Make checking basic permissions easier
117 //=================================================================
118 define('PC_ACCESS_ADMIN', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADMIN
));
119 define('PC_ACCESS_DELETE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_DELETE
));
120 define('PC_ACCESS_ADD', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADD
));
121 define('PC_ACCESS_EDIT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_EDIT
));
122 define('PC_ACCESS_MODERATE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_MODERATE
));
123 define('PC_ACCESS_COMMENT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_COMMENT
));
124 define('PC_ACCESS_READ', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_READ
));
125 define('PC_ACCESS_OVERVIEW', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_OVERVIEW
));
126 define('PC_ACCESS_NONE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_NONE
));
127 //=========================================================================
128 // Require and Setup utility classes and functions
129 //=========================================================================
130 define('DATE_CALC_BEGIN_WEEKDAY', _SETTING_FIRST_DAY_WEEK
);
131 require_once("modules/$pcDir/pnincludes/Date/Calc.php");
132 //=========================================================================
133 // grab the global language file
134 //=========================================================================
135 $userlang = pnUserGetLang();
136 if(file_exists("modules/$pcDir/pnlang/$userlang/global.php")) {
137 require_once("modules/$pcDir/pnlang/$userlang/global.php");
139 require_once("modules/$pcDir/pnlang/eng/global.php");
142 //=========================================================================
143 // Setup Smarty defines
144 //=========================================================================
145 if(!class_exists('Smarty')) {
146 define('_PC_SMARTY_LOADED',true);
147 define('SMARTY_DIR',"modules/$pcDir/pnincludes/Smarty/");
148 require_once(SMARTY_DIR
.'/Smarty.class.php');
150 require_once("modules/$pcDir/pcSmarty.class.php");
151 //=========================================================================
152 // utility functions for postcalendar
153 //=========================================================================
154 function pcDebugVar($in)
157 if(is_array($in)) print_r($in);
161 function &pcVarPrepForDisplay($s) {
162 $s = nl2br(pnVarPrepForDisplay(postcalendar_removeScriptTags($s)));
163 $s = preg_replace('/&(#)?([0-9a-z]+);/i','&\\1\\2;',$s);
166 function &pcVarPrepHTMLDisplay($s) {
167 return pnVarPrepHTMLDisplay(postcalendar_removeScriptTags($s));
169 function pcGetTopicName($topicid)
171 list($dbconn) = pnDBGetConn();
172 $pntable = pnDBGetTables();
174 $topics_table = $pntable['topics'];
175 $topics_column = &$pntable['topics_column'];
176 $sql = "SELECT $topics_column[topicname]
178 WHERE $topics_column[topicid] = '$topicid'";
179 $result = $dbconn->Execute($sql);
180 if($result === false) return '';
181 else return $result->fields
[0];
183 function &postcalendar_makeValidURL($s)
185 if(empty($s)) return '';
186 if(!preg_match('|^http[s]?:\/\/|i',$s)) {
191 function postcalendar_removeScriptTags($in)
193 return preg_replace("/<script.*?>(.*?)<\/script>/","",$in);
195 function &postcalendar_getDate($format='%Y%m%d')
197 list($Date,$jumpday,$jumpmonth,$jumpyear) = pnVarCleanFromInput('Date','jumpday','jumpmonth','jumpyear');
199 // if we still don't have a date then calculate it
201 if (pnUserLoggedIn()) {
202 $time +
= (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
204 // check the jump menu
205 if(!isset($jumpday)) $jumpday = strftime('%d',$time);
206 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time);
207 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time);
208 // create the correct date string
209 $Date = (int) "$jumpyear$jumpmonth$jumpday";
211 $y = substr($Date,0,4);
212 $m = substr($Date,4,2);
213 $d = substr($Date,6,2);
214 return strftime($format,mktime(0,0,0,$m,$d,$y));
217 function &postcalendar_today($format='%Y%m%d')
220 if (pnUserLoggedIn()) {
221 $time +
= (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
223 return strftime($format,$time);
227 * postcalendar_adminapi_pageSetup()
229 * sets up any necessary javascript for the page
230 * @return string javascript to insert into the page
232 function postcalendar_adminapi_pageSetup() { return postcalendar_userapi_pageSetup(); }
234 * postcalendar_userapi_pageSetup()
236 * sets up any necessary javascript for the page
237 * @return string javascript to insert into the page
239 function postcalendar_userapi_pageSetup()
242 // load the DHTML JavaScript code and insert it into the page
243 if(_SETTING_USE_POPUPS
) { $output .= postcalendar_userapi_loadPopups(); }
244 // insert the js popup code into the page (find better code)
245 if(_SETTING_OPEN_NEW_WINDOW
) { $output .= postcalendar_userapi_jsPopup(); }
249 * postcalendar_userapi_jsPopup
250 * Creates the necessary javascript code for a popup window
252 function postcalendar_userapi_jsPopup()
253 { if(defined('_POSTCALENDAR_JSPOPUPS_LOADED')) {
254 // only put the script on the page once
257 define('_POSTCALENDAR_JSPOPUPS_LOADED',true);
259 // build the correct link
260 $js_link = "'index.php?module=".__POSTCALENDAR__
."&type=user&func=view&viewtype=details&eid='+eid+'&Date='+date+'&popup=1'";
261 $js_window_options = 'toolbar=no,'
273 <script language="javascript">
275 function opencal(eid,date) {
276 window.name='csCalendar';
277 w = window.open($js_link,'PostCalendarEvents','$js_window_options');
287 * postcalendar_userapi_loadPopups
288 * Creates the necessary javascript code for mouseover dHTML popups
290 function postcalendar_userapi_loadPopups()
291 { if(defined('_POSTCALENDAR_LOADPOPUPS_LOADED')) {
292 // only put the script on the page once
295 define('_POSTCALENDAR_LOADPOPUPS_LOADED',true);
297 // get the theme globals :: is there a better way to do this?
298 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
299 global $textcolor1, $textcolor2;
301 // lets get the module's information
302 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
303 $pcDir = pnVarPrepForOS($modinfo['directory']);
306 $close = _PC_OL_CLOSE
;
310 <script language="JavaScript">
311 <!-- overLIB configuration -->
312 ol_fgcolor = "$bgcolor1";
313 ol_bgcolor = "$bgcolor2";
314 ol_textcolor = "$textcolor2";
315 ol_capcolor = "$textcolor2";
316 ol_closecolor = "$textcolor2";
317 ol_textfont = "Verdana,Arial,Helvetica";
318 ol_captionfont = "Verdana,Arial,Helvetica";
334 ol_fgbackground = "";
335 ol_bgbackground = "";
340 ol_capicon = "$capicon";
344 <div id="overDiv" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:1000;"></div>
345 <script language="JavaScript" src="modules/$pcDir/pnincludes/overlib_mini.js">
346 <!-- overLIB (c) Erik Bosrup -->
354 * postcalendar_adminapi_getmonthname()
356 * Returns the month name translated for the user's current language
358 * @param array $args['Date'] number of month to return
359 * @return string month name in user's language
361 function postcalendar_adminapi_getmonthname($args) { return postcalendar_userapi_getmonthname($args); }
363 * postcalendar_userapi_getmonthname()
365 * Returns the month name translated for the user's current language
367 * @param array $args['Date'] date to return month name of
368 * @return string month name in user's language
370 function postcalendar_userapi_getmonthname($args)
372 extract($args); unset($args);
373 if(!isset($Date)) { return false; }
374 $month_name = array('01' => _CALJAN
, '02' => _CALFEB
, '03' => _CALMAR
,
375 '04' => _CALAPR
, '05' => _CALMAY
, '06' => _CALJUN
,
376 '07' => _CALJUL
, '08' => _CALAUG
, '09' => _CALSEP
,
377 '10' => _CALOCT
, '11' => _CALNOV
, '12' => _CALDEC
);
378 return $month_name[date('m',$Date)];
381 * Returns an array of form data for FormSelectMultiple
383 function postcalendar_adminapi_buildTimeSelect($args) { return postcalendar_userapi_buildTimeSelect($args); }
384 function postcalendar_userapi_buildTimeSelect($args)
386 $inc = _SETTING_TIME_INCREMENT
;
387 extract($args); unset($args);
388 $output = array('h'=>array(),'m'=>array());
389 if((bool)_SETTING_TIME_24HOUR
) {
393 $hselected = $hselected > 12 ?
$hselected-=12 : $hselected;
395 for($c=0,$h=$start; $h<=$end; $h++
,$c++
) {
396 $hour = sprintf('%02d',$h);
397 $output['h'][$c]['id'] = pnVarPrepForStore($h);
398 $output['h'][$c]['selected'] = $hselected == $hour;
399 $output['h'][$c]['name'] = pnVarPrepForDisplay($hour);
401 for($c=0,$m=0; $m<=(60-$inc);$m+
=$inc,$c++
) {
402 $min = sprintf('%02d',$m);
403 $output['m'][$c]['id'] = pnVarPrepForStore($m);
404 $output['m'][$c]['selected'] = $mselected == $min;
405 $output['m'][$c]['name'] = pnVarPrepForDisplay($min);
410 * Returns an array of form data for FormSelectMultiple
412 function postcalendar_adminapi_buildMonthSelect($args) { return postcalendar_userapi_buildMonthSelect($args); }
413 function postcalendar_userapi_buildMonthSelect($args)
415 extract($args); unset($args);
416 if(!isset($pc_month)) { $pc_month = Date_Calc
::getMonth(); }
417 // create the return object to be inserted into the form
419 if(!isset($selected)) $selected = '';
420 for ($c=0,$i=1;$i<=12;$i++
,$c++
) {
421 if ($selected) { $sel = $selected == $i ?
true : false; }
422 elseif ($i == $pc_month) { $sel = true; }
423 else { $sel = false; }
424 $output[$c]['id'] = sprintf('%02d',$i);
425 $output[$c]['selected'] = $sel;
426 $output[$c]['name'] = postcalendar_userapi_getmonthname(array('Date'=>mktime(0,0,0,$i,15)));
432 * Returns an array of form data for FormSelectMultiple
434 function postcalendar_adminapi_buildDaySelect($args) { return postcalendar_userapi_buildDaySelect($args); }
435 function postcalendar_userapi_buildDaySelect($args)
437 extract($args); unset($args);
438 if(!isset($pc_day)) { $pc_day = Date_Calc
::getDay(); }
439 // create the return object to be inserted into the form
441 if(!isset($selected)) $selected = '';
442 for($c=0,$i=1; $i<=31; $i++
,$c++
) {
443 if ($selected) { $sel = $selected == $i ?
true : false; }
444 elseif ($i == $pc_day) { $sel = true; }
445 else { $sel = false; }
446 $output[$c]['id'] = sprintf('%02d',$i);
447 $output[$c]['selected'] = $sel;
448 $output[$c]['name'] = sprintf('%02d',$i);
454 * Returns an array of form data for FormSelectMultiple
456 function postcalendar_adminapi_buildYearSelect($args) { return postcalendar_userapi_buildYearSelect($args); }
457 function postcalendar_userapi_buildYearSelect($args)
459 extract($args); unset($args);
460 if(!isset($pc_year)) { $pc_year = date('Y'); }
461 // create the return object to be inserted into the form
463 // we want the list to contain 10 years before today and 30 years after
464 // maybe this will eventually become a user defined value
465 $pc_start_year = date('Y') - 1;
466 $pc_end_year = date('Y') +
30;
467 if(!isset($selected)) $selected = '';
468 for($c=0,$i=$pc_start_year; $i<=$pc_end_year; $i++
,$c++
) {
469 if ($selected) { $sel = $selected == $i ?
true : false; }
470 elseif ($i == $pc_year) { $sel = true; }
471 else { $sel = false; }
472 $output[$c]['id'] = sprintf('%04d',$i);
473 $output[$c]['selected'] = $sel;
474 $output[$c]['name'] = sprintf('%04d',$i);
479 function &postcalendar_adminapi_getCategories() { return postcalendar_userapi_getCategories(); }
480 function &postcalendar_userapi_getCategories()
482 list($dbconn) = pnDBGetConn();
483 $pntable = pnDBGetTables();
484 $cat_table = $pntable['postcalendar_categories'];
485 $sql = "SELECT pc_catid,pc_catname,pc_catcolor,pc_catdesc,
486 pc_recurrtype,pc_recurrspec,pc_recurrfreq,pc_duration,
487 pc_dailylimit,pc_end_date_flag,pc_end_date_type,pc_end_date_freq,
488 pc_end_all_day FROM $cat_table
489 ORDER BY pc_catname";
490 $result = $dbconn->Execute($sql);
492 if($dbconn->ErrorNo() != 0) { return array(); }
493 if(!isset($result)) { return array(); }
495 $categories = array();
496 for($i=0; !$result->EOF
; $result->MoveNext()) {
497 list($catid,$catname,$catcolor,$catdesc,
498 $rtype,$rspec,$rfreq,$duration,$limit,$end_date_flag,
499 $end_date_type,$end_date_freq,$end_all_day) = $result->fields
;
500 // check the category's permissions
501 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW
)) {
504 $categories[$i]['id'] = $catid;
505 $categories[$i]['name'] = $catname;
506 $categories[$i]['color'] = $catcolor;
507 $categories[$i]['desc'] = $catdesc;
508 $categories[$i]['event_repeat'] = $rtype;
509 $rspecs = unserialize($rspec);
510 $categories[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
511 $categories[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
512 $categories[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
513 $categories[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
514 $categories[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
515 $categories[$i]['event_recurrspec'] = $rspecs;
516 $categories[$i]['event_duration'] = $duration;
517 $categories[$i]['event_durationh'] = (int)($duration/(60 * 60)); //seconds divided by 60 seconds * 60 minutes;
518 $categories[$i]['event_durationm'] = ($duration%
(60 * 60))/60;
519 $categories[$i]['end_date_flag'] = $end_date_flag;
520 $categories[$i]['end_date_type'] = $end_date_type;
521 $categories[$i]['end_date_freq'] = $end_date_freq;
522 $categories[$i]['end_all_day'] = $end_all_day;
523 $categories[$i++
]['dailylimit'] = $limit;
530 function &postcalendar_adminapi_getTopics() { return postcalendar_userapi_getTopics(); }
531 function &postcalendar_userapi_getTopics()
533 list($dbconn) = pnDBGetConn();
534 $pntable = pnDBGetTables();
535 $topics_table = $pntable['topics'];
536 $topics_column = &$pntable['topics_column'];
537 $sql = "SELECT $topics_column[topicid], $topics_column[topictext], $topics_column[topicname]
539 ORDER BY $topics_column[topictext]";
540 $topiclist = $dbconn->Execute($sql);
541 if($dbconn->ErrorNo() != 0) {
546 for(;!$topiclist->EOF
;$topiclist->MoveNext()) {
547 // check topic permissions
548 if(pnSecAuthAction(0,'PostCalendar::Topic',$topiclist->fields
[2].'::'.$topiclist->fields
[0],ACCESS_OVERVIEW
)) {
549 list($data[$i]['id'], $data[$i]['text'], $data[$i++
]['name']) = $topiclist->fields
;
557 * postcalendar_adminapi_submitEvent()
559 * @param $args array of event data
560 * @return bool true on success : false on failure;
562 function postcalendar_adminapi_submitEvent($args) { return postcalendar_userapi_submitEvent($args); }
564 * postcalendar_userapi_submitEvent()
566 * @param $args array of event data
567 * @return bool true on success : false on failure;
569 function postcalendar_userapi_submitEvent($args)
571 extract($args); unset($args);
573 list($dbconn) = pnDBGetConn();
574 $pntable = pnDBGetTables();
576 // determine if the event is to be published immediately or not
577 //also whether is a special system only event i.e. _EVENT_TEMPORARY
578 if (empty($event_status)) {
579 if( (bool) _SETTING_DIRECT_SUBMIT ||
(bool) PC_ACCESS_ADMIN ||
($event_sharing != SHARING_GLOBAL
) ) {
580 $event_status = _EVENT_APPROVED
;
582 $event_status = _EVENT_QUEUED
;
585 elseif ($event_status == _EVENT_TEMPORARY
) {
586 $event_status = _EVENT_TEMPORARY
;
589 $event_status = _EVENT_QUEUED
;
593 // set up some vars for the insert statement
594 $startDate = $event_startyear.'-'.$event_startmonth.'-'.$event_startday;
595 if($event_endtype == 1) {
596 $endDate = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
598 $endDate = '0000-00-00';
601 if(!isset($event_allday)) $event_allday = 0;
602 if((bool)_SETTING_TIME_24HOUR
) {
603 $startTime = $event_starttimeh.':'.$event_starttimem.':00';
605 if($event_startampm == _AM_VAL
) {
606 $event_starttimeh = $event_starttimeh == 12 ?
'00' : $event_starttimeh;
608 $event_starttimeh = $event_starttimeh != 12 ?
$event_starttimeh+
=12 : $event_starttimeh;
610 $startTime = sprintf('%02d',$event_starttimeh).':'.sprintf('%02d',$event_starttimem).':00';
612 if ($event_allday == 1) {
613 $endTime = "24:00:00";
616 $endTime = date("H:i:00",($event_duration +
strtotime($startTime)));
619 // get rid of variables we no longer need to save memory
620 unset($event_startyear,$event_startmonth,$event_startday,$event_endyear,$event_endmonth,
621 $event_endday,$event_starttimeh,$event_starttimem);
623 //pennfirm users need to be able to enter apps for different providers, this isn't aoplicable
624 /*if(pnUserLoggedIn()) {
625 $event_userid = pnUserGetVar('uid');
631 if($pc_html_or_text == 'html') {
632 $event_desc = ':html:'.$event_desc;
634 $event_desc = ':text:'.$event_desc;
636 list($event_subject,$event_desc,$event_topic,$startDate,$endDate,
637 $event_repeat,$startTime,$event_allday,$event_category,
638 $event_location_info,$event_conttel,$event_contname,
639 $event_contemail,$event_website,$event_fee,$event_status,
640 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
641 $pc_event_id) = @pnVarPrepForStore
($event_subject,$event_desc,$event_topic,$startDate,$endDate,
642 $event_repeat,$startTime,$event_allday,$event_category,
643 $event_location_info,$event_conttel,$event_contname,
644 $event_contemail,$event_website,$event_fee,$event_status,
645 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
648 if(!isset($is_update)) { $is_update = false; }
650 $sql = "UPDATE $pntable[postcalendar_events]
651 SET pc_title = '$event_subject',
652 pc_hometext = '$event_desc',
653 pc_topic = '$event_topic',
654 pc_eventDate = '$startDate',
655 pc_endDate = '$endDate',
656 pc_recurrtype = '$event_repeat',
657 pc_startTime = '$startTime',
658 pc_endTime = '$endTime',
659 pc_alldayevent = '$event_allday',
660 pc_catid = '$event_category',
661 pc_location = '$event_location_info',
662 pc_conttel = '$event_conttel',
663 pc_contname = '$event_contname',
664 pc_contemail = '$event_contemail',
665 pc_website = '$event_website',
666 pc_fee = '$event_fee',
667 pc_eventstatus = '$event_status',
668 pc_recurrspec = '$event_recurrspec',
669 pc_duration = '$event_duration',
670 pc_sharing = '$event_sharing',
671 pc_aid = '$event_userid',
672 pc_pid = '$event_pid'
673 WHERE pc_eid = '$pc_event_id'";
675 $pc_event_id = $dbconn->GenId($pntable['postcalendar_events']);
676 $sql = "INSERT INTO $pntable[postcalendar_events] (
708 " . $_SESSION['authUserID'] . ",
716 '$event_location_info',
730 $result = $dbconn->Execute($sql);
731 if($result === false) {
734 if((bool)$is_update) {
737 $eid = $dbconn->PO_Insert_ID($pntable['postcalendar_events'],'pc_eid');
739 pc_notify($eid,$is_update);
744 function pc_notify($eid,$is_update)
746 if(!(bool)_SETTING_NOTIFY_ADMIN
) { return true; }
748 $subject = _PC_NOTIFY_SUBJECT
;
750 if((bool)$is_update) {
751 $message = _PC_NOTIFY_UPDATE_MSG
;
753 $message = _PC_NOTIFY_NEW_MSG
;
756 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
757 $modversion = pnVarPrepForOS($modinfo['version']);
760 $message .= pnModURL(__POSTCALENDAR__
,'admin','adminevents',array('pc_event_id'=>$eid,'action'=>_ADMIN_ACTION_VIEW
));
761 $message .= "\n\n\n\n";
762 $message .= "----\n";
763 $message .= "PostCalendar $modversion\n";
764 $message .= "http://www.postcalendar.tv";
766 mail(_SETTING_NOTIFY_EMAIL
,$subject,$message,
767 "From: " . _SETTING_NOTIFY_EMAIL
. "\r\n"
768 ."X-Mailer: PHP/" . phpversion() . "\r\n"
769 ."X-Mailer: PostCalendar/$modversion" );
775 function findFirstAvailable($period) {
779 $available_times = array();
780 foreach ($period as $date => $day) {
781 //echo "begin free times for $date:<br />";
782 $ffid_res = findFirstInDay($day,$date);
783 foreach($ffid_res as $times) {
784 //echo "starting: " . date("h:i:s A",$times['startTime']) . " long: " . $times['duration'] . "<br />";
785 $available_times[$date][] = $times;
786 //echo "count of times is:" . count($available_times) . "<br />";
788 //echo "end free times for $date";
791 return $available_times;
794 function findFirstInDay($day,$date) {
799 foreach ($day as $event) {
800 //echo "event is: " . $event['title'] . " cat is: " .$event['catid'] . " event date is: " . $date . "<br />";
802 if ($event['catid'] == 2) { //catid 2 is reserved to represent "In Office" events, id 3 is "Out Of Office"
803 $intime = $event['startTime'];
804 //echo "setting in: $intime<br />";
806 elseif ($event['catid'] == 3) {
808 $outtime = $event['startTime'];
809 //echo "setting out: $outtime<br />";
812 if ($intime == false or $outtime == false) {
816 //echo "increment is: " . _SETTING_TIME_INCREMENT . "<br />";
817 $inc = (_SETTING_TIME_INCREMENT
* 60);
819 $intime_sec = date("U",strtotime($date . " " . $intime));
820 $outtime_sec = date("U",strtotime($date . " " . $outtime));
821 $free_time = $intime_sec;
824 for ($i = $intime_sec; $i < $outtime_sec; $i +
= $inc) {
825 //echo "time is now: " . date("h:i:s A",$i) . "<br />";
826 $closest_start = $outtime_sec;
828 foreach($day as $event) {
829 if ($event['catid'] != 2) {
831 $estart = dtSec($date,$event['startTime']) ;
832 $eend = dtSecDur($date, $event['startTime'], $event['duration']);
834 if ($eend < $intime_sec or $estart > $outtime_sec) {
835 //event ends before intime or starts after outtime we don't care move on;
838 elseif ($eend < $i ) {
839 //event ended before time currently being evaluated, we don't care move on;
842 elseif ($estart < $i and $eend > $i) {
843 //event occupies part of the time we are looking at, look at another time
846 elseif ($estart >= $i) {
847 //echo "tin: " . date("h:i:s A",$i) . " estart: " . date("h:i:s A",$estart) . "<br />";
849 //echo "ev: " . $event['title'] . " s at:" . date("h:i:s A",$estart) . " e at: " . date("h:i:s A",$eend) ." <br />";
850 //some amount of time is free set closest time
851 $oldfreetime = $closest_start - $i;
852 $newfreetime = $estart - $i;
854 //echo "old free: " . $oldfreetime . "<br />";
855 //echo "new free: " . $newfreetime . "<br />";
856 //echo "duration is: " . ($estart - $i) . " cs:$estart i:$i<br />";
857 if ($newfreetime < $oldfreetime && ($estart - $i) != 0) {
859 $closest_start = $estart;
861 //echo "set time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
862 if ($i < ($eend - $inc))
865 elseif($newfreetime <= $oldfreetime && $oldfreetime == ($outtime_sec - $i)) {
867 $closest_start = $estart;
869 //echo "time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
870 if ($i < ($eend - $inc))
874 //echo "closest start: " . date("h:i:s A",$closest_start) . "<br />";
881 if ($closest_start > ($intime_sec +
60)) {
882 //echo "free time is: " . date("h:i:s A",$free_time) . "<br />";
883 //echo "next app is: " . date("h:i:s A",$closest_start) . "<br />";
884 $duration = ($closest_start - $free_time);
885 //echo "duration is: $duration<br />";
886 //we allow for 0 duration events so other things such as overlap and actual times can be calculated
887 //this happens because people want to be able to set 8:00 - 8:15 and 8:15 - 8:30 without a conflict
888 //even though that is technially impossible, so we pretend, however here we weed out the 0
889 //length blocks so that won't be seen
890 $date_sec = strtotime ($date);
892 $times[] = array ("startTime" => $free_time, "endTime" => ($date_sec+
$duration));
900 function dtSec ($date, $time) {
901 return date("U",strtotime($date . " " . $time));
904 function dtSecDur ($date, $time, $dur) {
905 $time_sec = date("U",strtotime($date . " " . $time));
906 return $time_sec +
$dur;
910 * postcalendar_adminapi_buildSubmitForm()
911 * create event submit form
913 function postcalendar_adminapi_buildSubmitForm($args) { return postcalendar_userapi_buildSubmitForm($args,true); }
915 * postcalendar_userapi_buildSubmitForm()
916 * create event submit form
918 function postcalendar_userapi_buildSubmitForm($args,$admin=false)
920 $_SESSION['category'] = "";
921 if(!PC_ACCESS_ADD
) { return _POSTCALENDARNOAUTH
; }
922 extract($args); unset($args);
923 //since we seem to clobber category
925 $output =& new pnHTML();
926 $output->SetInputMode(_PNH_VERBATIMINPUT
);
928 $tpl =& new pcSmarty();
929 $tpl->caching
= false;
931 $template_name = pnModGetVar(__POSTCALENDAR__
,'pcTemplate');
933 if(!isset($template_name)) {
934 $template_name ='default';
937 //=================================================================
938 // Setup the correct config file path for the templates
939 //=================================================================
940 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
941 $modir = pnVarPrepForOS($modinfo['directory']);
942 $modname = $modinfo['displayname'];
943 $all_categories =& pnModAPIFunc(__POSTCALENDAR__
,'user','getCategories');
944 //print_r($all_categories);
946 $tpl->config_dir
= "modules/$modir/pntemplates/$template_name/config/";
947 //=================================================================
949 //=================================================================
952 $tpl->assign('webroot', $GLOBALS['web_root']);
953 $tpl->assign_by_ref('TPL_NAME',$template_name);
954 $tpl->assign('FUNCTION',pnVarCleanFromInput('func'));
955 $tpl->assign_by_ref('ModuleName', $modname);
956 $tpl->assign_by_ref('ModuleDirectory', $modir);
957 $tpl->assign_by_ref('category',$all_categories);
958 $tpl->assign('NewEventHeader', _PC_NEW_EVENT_HEADER
);
959 $tpl->assign('EventTitle', _PC_EVENT_TITLE
);
960 $tpl->assign('Required', _PC_REQUIRED
);
961 $tpl->assign('DateTimeTitle', _PC_DATE_TIME
);
962 $tpl->assign('AlldayEventTitle', _PC_ALLDAY_EVENT
);
963 $tpl->assign('TimedEventTitle', _PC_TIMED_EVENT
);
964 $tpl->assign('TimedDurationTitle', _PC_TIMED_DURATION
);
965 $tpl->assign('TimedDurationHoursTitle', _PC_TIMED_DURATION_HOURS
);
966 $tpl->assign('TimedDurationMinutesTitle',_PC_TIMED_DURATION_MINUTES
);
967 $tpl->assign('EventDescTitle', _PC_EVENT_DESC
);
969 //the double book variable comes from the eventdata array that is
970 //passed here and extracted, injection is not an issue here
971 if (is_numeric($double_book)) {
972 $tpl->assign('double_book', $double_book);
975 //pennfirm begin patient info handling
976 $ProviderID = pnVarCleanFromInput("provider_id");
977 if (is_numeric($ProviderID)) {
978 $tpl->assign('ProviderID', $ProviderID);
979 $tpl->assign('provider_id', $ProviderID);
981 elseif(is_numeric($event_userid) && $event_userid != 0) {
982 $tpl->assign('ProviderID', $event_userid);
983 $tpl->assign('provider_id', $event_userid);
986 if ($_SESSION['userauthorized'] == 1)
987 $tpl->assign('ProviderID', $_SESSION['authUserID']);
989 $tpl->assign('ProviderID', "");
991 $provinfo = getProviderInfo();
992 $tpl->assign('providers', $provinfo);
993 $PatientID = pnVarCleanFromInput("patient_id");
994 if (is_numeric($PatientID)) {
995 $tpl->assign('PatientList', getPatientPID($PatientID));
997 elseif (is_numeric($event_pid)) {
998 $tpl->assign('PatientList', getPatientPID($event_pid));
1001 $tpl->assign('PatientList', getPatientPID());
1003 $tpl->assign('event_pid', $event_pid);
1004 $tpl->assign('event_aid', $event_aid);
1005 $tpl->assign('event_category', pnVarCleanFromInput("event_category"));
1007 if(empty($event_patient_name))
1009 $patient_data = getPatientData($event_pid, $given = "lname, fname");
1010 $event_patient_name = $patient_data['lname'].", ".$patient_data['fname'];
1012 $tpl->assign('patient_value', $event_patient_name);
1014 //=================================================================
1015 // PARSE INPUT_EVENT_TITLE
1016 //=================================================================
1017 $tpl->assign('InputEventTitle', 'event_subject');
1018 $tpl->assign('ValueEventTitle', pnVarPrepForDisplay($event_subject));
1020 //=================================================================
1021 // PARSE SELECT_DATE_TIME
1022 //=================================================================
1024 // It seems that with Mozilla at least, <select> fields that are disabled
1025 // do not get passed as form data. Therefore we ignore $double_book so
1026 // that the fields will not be disabled. -- Rod 2005-03-22
1028 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1029 if(_SETTING_USE_INT_DATES
) {
1030 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1031 $formdata = $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1032 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1033 $formdata .= $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1035 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1036 $formdata = $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1037 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1038 $formdata .= $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1040 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_startyear));
1041 $formdata .= $output->FormSelectMultiple('event_startyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1042 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1043 $tpl->assign('SelectDateTime', $formdata);
1044 $tpl->assign('InputAllday', 'event_allday');
1045 $tpl->assign('ValueAllday', '1');
1046 $tpl->assign('SelectedAllday', $event_allday==1 ?
'checked':'');
1047 $tpl->assign('InputTimed', 'event_allday');
1048 $tpl->assign('ValueTimed', '0');
1049 $tpl->assign('SelectedTimed', $event_allday==0 ?
'checked':'');
1050 $tpl->assign('STYLE',$GLOBALS['style']);
1052 //=================================================================
1053 // PARSE SELECT_END_DATE_TIME
1054 //=================================================================
1055 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1056 //if there is no end date we want the box to read todays date instead of jan 01 1994 :)
1057 if($event_endmonth == 0 && $event_endday ==0 && $event_endyear ==0){
1058 $event_endmonth =$month;
1059 $event_endday = $day ;
1060 $event_endyear = $year;
1062 if(_SETTING_USE_INT_DATES
) {
1063 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1065 $formdata = $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1066 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1067 $formdata .= $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1070 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1071 $formdata = $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1072 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1073 $formdata .= $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1075 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_endyear));
1076 $formdata .= $output->FormSelectMultiple('event_endyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1077 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1078 $tpl->assign('SelectEndDate', $formdata);
1079 //=================================================================
1080 // PARSE SELECT_TIMED_EVENT
1081 //=================================================================
1082 $stimes = pnModAPIFunc(__POSTCALENDAR__
,'user','buildTimeSelect',array('hselected'=>$event_starttimeh,'mselected'=>$event_starttimem));
1083 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1084 $timed_hours = $output->FormSelectMultiple('event_starttimeh', $stimes['h'],0,1,"","",false,/* $double_book*/ '');
1085 $timed_minutes = $output->FormSelectMultiple('event_starttimem', $stimes['m'],0,1,"","",false,/* $double_book*/ '');
1086 if(!_SETTING_TIME_24HOUR
) {
1088 $ampm[0]['id'] = pnVarPrepForStore(_AM_VAL
);
1089 $ampm[0]['name'] = pnVarPrepForDisplay(_PC_AM
);
1090 $ampm[1]['id'] = pnVarPrepForStore(_PM_VAL
);
1091 $ampm[1]['name'] = pnVarPrepForDisplay(_PC_PM
);
1092 if($event_startampm == "AM" ||
$event_startampm == _AM_VAL
)
1094 $ampm[0]['selected'] = 1;
1098 $ampm[1]['selected'] = 1;
1100 $timed_ampm = $output->FormSelectMultiple('event_startampm', $ampm,0,1,"","",false,/* $double_book*/ '');
1104 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1105 $tpl->assign('SelectTimedHours', $timed_hours);
1106 $tpl->assign('SelectTimedMinutes', $timed_minutes);
1107 $tpl->assign('SelectTimedAMPM', $timed_ampm);
1108 $tpl->assign('event_startday', $event_startday);
1109 $tpl->assign('event_startmonth', $event_startmonth);
1110 $tpl->assign('event_startyear', $event_startyear);
1111 $tpl->assign('event_starttimeh', $event_starttimeh);
1112 $tpl->assign('event_starttimem', $event_starttimem);
1113 $tpl->assign('event_startampm', $event_startampm);
1114 $tpl->assign('event_dur_hours', $event_dur_hours);
1115 $tpl->assign('event_dur_minutes', $event_dur_minutes);
1117 //=================================================================
1118 // PARSE SELECT_DURATION
1119 //=================================================================
1120 $event_dur_hours = (int) $event_dur_hours;
1122 for($i=0; $i<=24; $i+
=1) {
1123 $TimedDurationHours[$i] = array('value'=>$i,
1124 'selected'=>($event_dur_hours==$i ?
'selected':''),
1125 'name'=>sprintf('%02d',$i));
1128 $tpl->assign('TimedDurationHours',$TimedDurationHours);
1129 $tpl->assign('InputTimedDurationHours', 'event_dur_hours');
1130 $found_time = false;
1131 for($i=0; $i<60; $i+
=_SETTING_TIME_INCREMENT
) {
1132 $TimedDurationMinutes[$i] = array('value'=>$i,
1133 'selected'=>($event_dur_minutes==$i ?
'selected':''),
1134 'name'=>sprintf('%02d',$i));
1135 if( $TimedDurationMinutes[$i]['selected'] == 'selected' )
1140 $TimedDurationMinutes[$i] = array('value'=>$event_dur_minutes,
1141 'selected'=>'selected',
1142 'name'=>sprintf('%02d',$event_dur_minutes));
1143 $tpl->assign('TimedDurationMinutes',$TimedDurationMinutes);
1144 $tpl->assign('hidden_event_dur_minutes',$event_dur_minutes);
1145 $tpl->assign('InputTimedDurationMinutes', 'event_dur_minutes');
1146 //=================================================================
1147 // PARSE INPUT_EVENT_DESC
1148 //=================================================================
1149 $tpl->assign('InputEventDesc', 'event_desc');
1150 if(empty($pc_html_or_text)) {
1151 $display_type = substr($event_desc,0,6);
1152 if($display_type == ':text:') {
1153 $pc_html_or_text = 'text';
1154 $event_desc = substr($event_desc,6);
1155 } elseif($display_type == ':html:') {
1156 $pc_html_or_text = 'html';
1157 $event_desc = substr($event_desc,6);
1159 $pc_html_or_text = 'text';
1161 unset($display_type);
1163 $tpl->assign('ValueEventDesc', pnVarPrepForDisplay($event_desc));
1164 $eventHTMLorText = "<select name=\"pc_html_or_text\">";
1165 if($pc_html_or_text == 'text') {
1166 $eventHTMLorText .= "<option value=\"text\" selected=\"selected\">"._PC_SUBMIT_TEXT
."</option>";
1168 $eventHTMLorText .= "<option value=\"text\">"._PC_SUBMIT_TEXT
."</option>";
1170 if($pc_html_or_text == 'html') {
1171 $eventHTMLorText .= "<option value=\"html\" selected=\"selected\">"._PC_SUBMIT_HTML
."</option>";
1173 $eventHTMLorText .= "<option value=\"html\">"._PC_SUBMIT_HTML
."</option>";
1175 $eventHTMLorText .= "</select>";
1176 $tpl->assign('EventHTMLorText',$eventHTMLorText);
1177 //=================================================================
1178 // PARSE select_event_topic_block
1179 //=================================================================
1180 $tpl->assign('displayTopics',_SETTING_DISPLAY_TOPICS
);
1181 if((bool)_SETTING_DISPLAY_TOPICS
) {
1182 $a_topics =& postcalendar_userapi_getTopics();
1184 foreach($a_topics as $topic) {
1185 array_push($topics,array('value'=>$topic['id'],
1186 'selected'=>($topic['id']==$event_topic ?
'selected':''),
1187 'name'=>$topic['text']));
1190 // only show this if we have topics to show
1191 if(count($topics) > 0) {
1192 $tpl->assign('topics',$topics);
1193 $tpl->assign('EventTopicTitle', _PC_EVENT_TOPIC
);
1194 $tpl->assign('InputEventTopic', 'event_topic');
1197 //=================================================================
1198 // PARSE select_event_type_block
1199 //=================================================================
1200 $categories = array();
1201 foreach($all_categories as $category) {
1202 array_push($categories,array('value'=>$category['id'],
1203 'selected'=>($category['id']==$event_category ?
'selected' : ''),
1204 'name'=>$category['name'],
1205 'color'=>$category['color'],
1206 'desc'=>$category['desc']));
1208 // only show this if we have categories to show
1209 // you should ALWAYS have at least one valid category
1210 if(count($categories) > 0) {
1211 $tpl->assign('categories',$categories);
1212 $tpl->assign('EventCategoriesTitle', _PC_EVENT_CATEGORY
);
1213 $tpl->assign('InputEventCategory', 'event_category');
1214 $tpl->assign('hidden_event_category', $event_category);
1216 //=================================================================
1217 // PARSE event_sharing_block
1218 //=================================================================
1220 if(_SETTING_ALLOW_USER_CAL
) {
1221 array_push($data,array(SHARING_PRIVATE
,_PC_SHARE_PRIVATE
));
1222 array_push($data,array(SHARING_PUBLIC
,_PC_SHARE_PUBLIC
));
1223 array_push($data,array(SHARING_BUSY
,_PC_SHARE_SHOWBUSY
));
1225 if(pnSecAuthAction(0,'PostCalendar::', '::', ACCESS_ADMIN
) || _SETTING_ALLOW_GLOBAL ||
!_SETTING_ALLOW_USER_CAL
) {
1226 array_push($data,array(SHARING_GLOBAL
,_PC_SHARE_GLOBAL
));
1229 foreach($data as $cell) {
1230 array_push($sharing,array('value'=>$cell[0],
1231 'selected'=>((int) $event_sharing == $cell[0] ?
'selected' : ''),
1235 //pennfirm get list of providers from openemr code in calendar.inc
1236 $tpl->assign("user",getCalendarProviderInfo());
1239 $tpl->assign('sharing',$sharing);
1240 $tpl->assign('EventSharingTitle', _PC_SHARING
);
1241 $tpl->assign('InputEventSharing','event_sharing');
1242 //=================================================================
1243 // location information
1244 //=================================================================
1245 $tpl->assign('EventLocationTitle', _PC_EVENT_LOCATION
);
1246 $tpl->assign('InputLocation', 'event_location');
1247 $tpl->assign('ValueLocation', pnVarPrepForDisplay($event_location));
1248 $tpl->assign('EventStreetTitle', _PC_EVENT_STREET
);
1249 $tpl->assign('InputStreet1', 'event_street1');
1250 $tpl->assign('ValueStreet1', pnVarPrepForDisplay($event_street1));
1251 $tpl->assign('InputStreet2', 'event_street2');
1252 $tpl->assign('ValueStreet2', pnVarPrepForDisplay($event_street2));
1253 $tpl->assign('EventCityTitle', _PC_EVENT_CITY
);
1254 $tpl->assign('InputCity', 'event_city');
1255 $tpl->assign('ValueCity', pnVarPrepForDisplay($event_city));
1256 $tpl->assign('EventStateTitle', _PC_EVENT_STATE
);
1257 $tpl->assign('InputState', 'event_state');
1258 $tpl->assign('ValueState', pnVarPrepForDisplay($event_state));
1259 $tpl->assign('EventPostalTitle', _PC_EVENT_POSTAL
);
1260 $tpl->assign('InputPostal', 'event_postal');
1261 $tpl->assign('ValuePostal', pnVarPrepForDisplay($event_postal));
1262 //=================================================================
1263 // contact information
1264 //=================================================================
1265 $tpl->assign('EventContactTitle', _PC_EVENT_CONTACT
);
1266 $tpl->assign('InputContact', 'event_contname');
1267 $tpl->assign('ValueContact', pnVarPrepForDisplay($event_contname));
1268 $tpl->assign('EventPhoneTitle', _PC_EVENT_PHONE
);
1269 $tpl->assign('InputPhone', 'event_conttel');
1270 $tpl->assign('ValuePhone', pnVarPrepForDisplay($event_conttel));
1271 $tpl->assign('EventEmailTitle', _PC_EVENT_EMAIL
);
1272 $tpl->assign('InputEmail', 'event_contemail');
1273 $tpl->assign('ValueEmail', pnVarPrepForDisplay($event_contemail));
1274 $tpl->assign('EventWebsiteTitle', _PC_EVENT_WEBSITE
);
1275 $tpl->assign('InputWebsite', 'event_website');
1276 $tpl->assign('ValueWebsite', pnVarPrepForDisplay($event_website));
1277 $tpl->assign('EventFeeTitle', _PC_EVENT_FEE
);
1278 $tpl->assign('InputFee', 'event_fee');
1279 $tpl->assign('ValueFee', pnVarPrepForDisplay($event_fee));
1280 //=================================================================
1281 // Repeating Information
1282 //=================================================================
1283 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER
);
1284 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT
);
1285 $tpl->assign('RepeatTitle', _PC_REPEAT
);
1286 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON
);
1287 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH
);
1288 $tpl->assign('EndDateTitle', _PC_END_DATE
);
1289 $tpl->assign('NoEndDateTitle', _PC_NO_END
);
1290 $tpl->assign('InputNoRepeat', 'event_repeat');
1291 $tpl->assign('ValueNoRepeat', '0');
1292 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ?
'checked':'');
1293 $tpl->assign('InputRepeat', 'event_repeat');
1294 $tpl->assign('ValueRepeat', '1');
1295 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ?
'checked':'');
1298 $in = array(_PC_EVERY
,_PC_EVERY_OTHER
,_PC_EVERY_THIRD
,_PC_EVERY_FOURTH
);
1299 $keys = array(REPEAT_EVERY
,REPEAT_EVERY_OTHER
,REPEAT_EVERY_THIRD
,REPEAT_EVERY_FOURTH
);
1300 $repeat_freq = array();
1301 foreach($in as $k=>$v) {
1302 array_push($repeat_freq,array('value'=>$keys[$k],
1303 'selected'=>($keys[$k]==$event_repeat_freq?
'selected':''),
1306 $tpl->assign('InputRepeatFreq','event_repeat_freq');
1307 if(empty($event_repeat_freq) ||
$event_repeat_freq < 1) $event_repeat_freq = 1;
1308 $tpl->assign('InputRepeatFreqVal',$event_repeat_freq);
1309 $tpl->assign('repeat_freq',$repeat_freq);
1311 $in = array(_PC_EVERY_DAY
,_PC_EVERY_WORKDAY
,_PC_EVERY_WEEK
,_PC_EVERY_MONTH
,_PC_EVERY_YEAR
);
1312 $keys = array(REPEAT_EVERY_DAY
,REPEAT_EVERY_WORK_DAY
,REPEAT_EVERY_WEEK
,REPEAT_EVERY_MONTH
,REPEAT_EVERY_YEAR
);
1313 $repeat_freq_type = array();
1314 foreach($in as $k=>$v) {
1315 array_push($repeat_freq_type,array('value'=>$keys[$k],
1316 'selected'=>($keys[$k]==$event_repeat_freq_type?
'selected':''),
1319 $tpl->assign('InputRepeatFreqType','event_repeat_freq_type');
1320 $tpl->assign('repeat_freq_type',$repeat_freq_type);
1322 $tpl->assign('InputRepeatOn', 'event_repeat');
1323 $tpl->assign('ValueRepeatOn', '2');
1324 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ?
'checked':'');
1327 $in = array(_PC_EVERY_1ST
,_PC_EVERY_2ND
,_PC_EVERY_3RD
,_PC_EVERY_4TH
,_PC_EVERY_LAST
);
1328 $keys = array(REPEAT_ON_1ST
,REPEAT_ON_2ND
,REPEAT_ON_3RD
,REPEAT_ON_4TH
,REPEAT_ON_LAST
);
1329 $repeat_on_num = array();
1330 foreach($in as $k=>$v) {
1331 array_push($repeat_on_num,array('value'=>$keys[$k],
1332 'selected'=>($keys[$k]==$event_repeat_on_num?
'selected':''),
1335 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1336 $tpl->assign('repeat_on_num',$repeat_on_num);
1339 $in = array(_PC_EVERY_SUN
,_PC_EVERY_MON
,_PC_EVERY_TUE
,_PC_EVERY_WED
,_PC_EVERY_THU
,_PC_EVERY_FRI
,_PC_EVERY_SAT
);
1340 $keys = array(REPEAT_ON_SUN
,REPEAT_ON_MON
,REPEAT_ON_TUE
,REPEAT_ON_WED
,REPEAT_ON_THU
,REPEAT_ON_FRI
,REPEAT_ON_SAT
);
1341 $repeat_on_day = array();
1342 foreach($in as $k=>$v) {
1343 array_push($repeat_on_day,array('value'=>$keys[$k],
1344 'selected'=>($keys[$k]==$event_repeat_on_day ?
'selected' : ''),
1347 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1348 $tpl->assign('repeat_on_day',$repeat_on_day);
1351 $in = array(_PC_OF_EVERY_MONTH
,_PC_OF_EVERY_2MONTH
,_PC_OF_EVERY_3MONTH
,_PC_OF_EVERY_4MONTH
,_PC_OF_EVERY_6MONTH
,_PC_OF_EVERY_YEAR
);
1352 $keys = array(REPEAT_ON_MONTH
,REPEAT_ON_2MONTH
,REPEAT_ON_3MONTH
,REPEAT_ON_4MONTH
,REPEAT_ON_6MONTH
,REPEAT_ON_YEAR
);
1353 $repeat_on_freq = array();
1354 foreach($in as $k=>$v) {
1355 array_push($repeat_on_freq,array('value'=>$keys[$k],
1356 'selected'=>($keys[$k] == $event_repeat_on_freq ?
'selected' : ''),
1359 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1360 if(empty($event_repeat_on_freq) ||
$event_repeat_on_freq < 1) $event_repeat_on_freq = 1;
1361 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1362 $tpl->assign('repeat_on_freq',$repeat_on_freq);
1363 $tpl->assign('MonthsTitle',_PC_MONTHS
);
1365 //=================================================================
1366 // PARSE INPUT_END_DATE
1367 //=================================================================
1368 $tpl->assign('InputEndOn', 'event_endtype');
1369 $tpl->assign('ValueEndOn', '1');
1370 $tpl->assign('SelectedEndOn', (int) $event_endtype==1 ?
'checked':'');
1371 //=================================================================
1372 // PARSE INPUT_NO_END
1373 //=================================================================
1374 $tpl->assign('InputNoEnd', 'event_endtype');
1375 $tpl->assign('ValueNoEnd', '0');
1376 $tpl->assign('SelectedNoEnd', (int) $event_endtype==0 ?
'checked':'');
1377 $qstring = preg_replace("/provider_id=[0-9]*[&]{0,1}/","",$_SERVER['QUERY_STRING']);
1378 $tpl->assign('qstring', $qstring);
1380 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1381 $authkey = $output->FormHidden('authid',pnSecGenAuthKey());
1382 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1384 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1385 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1386 $form_hidden .= "<input type=\"hidden\" name=\"category\" value=\"$cat\" />";
1387 if(isset($data_loaded)) {
1388 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1389 $tpl->assign('FormHidden',$form_hidden);
1391 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1392 '.$authkey.'<input type="submit" name="submit" value="go">' ;
1393 $tpl->assign('FormSubmit',$form_submit);
1395 // do not cache this page
1397 $output->Text($tpl->fetch($template_name.'/admin/submit.html'));
1399 //check flag no_nav, if true use much smaller submit form for find_patient.php, etc
1400 elseif (pnVarCleanFromInput("no_nav") == 1) {
1401 $output->Text($tpl->fetch($template_name.'/user/submit_no_nav.html'));
1403 $output->Text($tpl->fetch($template_name.'/user/submit.html'));
1405 $output->Text(postcalendar_footer());
1406 return $output->GetOutput();
1409 function &postcalendar_userapi_pcGetEventDetails($eid)
1415 list($dbconn) = pnDBGetConn();
1416 $pntable = pnDBGetTables();
1418 // link to the events tables
1419 $table = $pntable['postcalendar_events'];
1420 $cattable = $pntable['postcalendar_categories'];
1422 $sql = "SELECT DISTINCT e.pc_eid,
1450 FROM $table e, $cattable c
1451 LEFT JOIN patient_data as pd on pd.pid = e.pc_pid
1452 WHERE e.pc_eid = '$eid' AND c.pc_catid = e.pc_catid";
1454 $result = $dbconn->Execute($sql);
1455 if($dbconn->ErrorNo() != 0) {
1456 die ($dbconn->ErrorMsg());
1459 if(!isset($result)) {
1462 list($event['eid'], $event['uname'], $event['catid'],
1463 $event['title'], $event['time'], $event['hometext'],
1464 $event['eventDate'], $event['duration'], $event['endDate'],
1465 $event['startTime'], $event['recurrtype'], $event['recurrfreq'],
1466 $event['recurrspec'], $event['topic'], $event['alldayevent'],
1467 $event['location'], $event['conttel'], $event['contname'],
1468 $event['contemail'], $event['website'], $event['fee'], $event['sharing'],
1469 $event['catcolor'], $event['catname'], $event['catdesc'], $event['pid'], $event['aid'],$event['pubpid']) = $result->fields
;
1470 // there has to be a more intelligent way to do this
1471 @list
($event['duration_hours'],$dmin) = @explode
('.',($event['duration']/60/60));
1472 $event['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1473 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1475 //pennfirm fix to reflect openemr user/informant
1476 $userid = pnUserGetVar('uid');
1478 // get the user id of event's author
1479 $users = pnUserGetAll();
1480 foreach($users as $user) {
1481 if($user['uname'] == $event['uname']) {
1482 $cuserid = $user['uid'];
1488 // is this a public event to be shown as busy?
1489 if($event['sharing'] == SHARING_PRIVATE
&& $cuserid != $userid) {
1490 // they are not supposed to see this
1492 } elseif($event['sharing'] == SHARING_BUSY
&& $cuserid != $userid) {
1493 // make it not display any information
1494 $event['title'] = _USER_BUSY_TITLE
;
1495 $event['hometext'] = _USER_BUSY_MESSAGE
;
1496 $event['location'] = '';
1497 $event['conttel'] = '';
1498 $event['contname'] = '';
1499 $event['contemail'] = '';
1500 $event['website'] = '';
1503 $event['title'] = $event['title'];
1504 $event['hometext'] = $event['hometext'];
1505 $event['location'] = $event['location'];
1506 $event['conttel'] = $event['conttel'];
1507 $event['contname'] = $event['contname'];
1508 $event['contemail'] = $event['contemail'];
1509 $event['website'] = $event['website'];
1510 $event['fee'] = $event['fee'];
1512 $event['desc'] = $event['hometext'];
1513 $event['website'] = $event['website'];
1514 if (!empty($event['pid']))
1515 $event['patient_name'] = getPatientName($event['pid']);
1516 if (empty($event['aid']))
1523 * postcalendar_userapi_eventDetail
1524 * Creates the detailed event display and outputs html.
1525 * Accepts an array of key/value pairs
1526 * @param int $eid the id of the event to display
1527 * @return string html output
1530 function postcalendar_adminapi_eventDetail($args) { return postcalendar_userapi_eventDetail($args,true); }
1531 function postcalendar_userapi_eventDetail($args,$admin=false)
1533 if(!(bool)PC_ACCESS_READ
) { return _POSTCALENDARNOAUTH
; }
1534 // get the theme globals :: is there a better way to do this?
1535 pnThemeLoad(pnUserGetTheme());
1536 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
1537 global $textcolor1, $textcolor2;
1538 $popup = pnVarCleanFromInput('popup');
1539 extract($args); unset($args);
1540 if(!isset($cacheid)) $cacheid = null;
1544 if(!isset($nopop)) {
1548 $uid = pnUserGetVar('uid');
1549 //=================================================================
1550 // Find out what Template we're using
1551 //=================================================================
1552 $template_name = _SETTING_TEMPLATE
;
1553 if(!isset($template_name)) {
1554 $template_name = 'default';
1556 //=================================================================
1557 // Setup Smarty Template Engine
1558 //=================================================================
1559 $tpl =& new pcSmarty();
1562 $template = $template_name.'/admin/details.html';
1563 $args['cacheid'] = '';
1565 $Date =& postcalendar_getDate();
1566 $tpl->caching
= false;
1568 $template = $template_name.'/user/details.html';
1571 if(!$tpl->is_cached($template,$cacheid)) {
1572 // let's get the DB information
1573 list($dbconn) = pnDBGetConn();
1574 $pntable = pnDBGetTables();
1575 // get the event's information
1576 $event =& postcalendar_userapi_pcGetEventDetails($eid);
1577 // if the above is false, it's a private event for another user
1578 // we should not diplay this - so we just exit gracefully
1579 if($event === false) { return false; }
1580 //=================================================================
1581 // get event's topic information
1582 //=================================================================
1583 $topics_table = $pntable['topics'];
1584 $topics_column = $pntable['topics_column'];
1585 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
1587 WHERE $topics_column[topicid] = $event[topic]
1589 $topic_result = $dbconn->Execute($topicsql);
1590 list($event['topictext'],$event['topicimg']) = $topic_result->fields
;
1591 $location = unserialize($event['location']);
1592 $event['location'] = $location['event_location'];
1593 $event['street1'] = $location['event_street1'];
1594 $event['street2'] = $location['event_street2'];
1595 $event['city'] = $location['event_city'];
1596 $event['state'] = $location['event_state'];
1597 $event['postal'] = $location['event_postal'];
1598 $event['date'] = str_replace('-','',$Date);
1599 //=================================================================
1600 // populate the template
1601 //=================================================================
1602 if(!empty($event['location']) ||
!empty($event['street1']) ||
1603 !empty($event['street2']) ||
!empty($event['city']) ||
1604 !empty($event['state']) ||
!empty($event['postal'])) {
1605 $tpl->assign('LOCATION_INFO',true);
1607 $tpl->assign('LOCATION_INFO',false);
1609 if(!empty($event['contname']) ||
!empty($event['contemail']) ||
1610 !empty($event['conttel']) ||
!empty($event['website'])) {
1611 $tpl->assign('CONTACT_INFO',true);
1613 $tpl->assign('CONTACT_INFO',false);
1615 $display_type = substr($event['hometext'],0,6);
1616 if($display_type == ':text:') {
1617 $prepFunction = 'pcVarPrepForDisplay';
1618 $event['hometext'] = substr($event['hometext'],6);
1619 } elseif($display_type == ':html:') {
1620 $prepFunction = 'pcVarPrepHTMLDisplay';
1621 $event['hometext'] = substr($event['hometext'],6);
1623 $prepFunction = 'pcVarPrepHTMLDisplay';
1625 unset($display_type);
1626 // prep the vars for output
1627 $event['title'] =& $prepFunction($event['title']);
1628 $event['hometext'] =& $prepFunction($event['hometext']);
1629 $event['desc'] =& $event['hometext'];
1630 $event['conttel'] =& $prepFunction($event['conttel']);
1631 $event['contname'] =& $prepFunction($event['contname']);
1632 $event['contemail'] =& $prepFunction($event['contemail']);
1633 $event['website'] =& $prepFunction(postcalendar_makeValidURL($event['website']));
1634 $event['fee'] =& $prepFunction($event['fee']);
1635 $event['location'] =& $prepFunction($event['location']);
1636 $event['street1'] =& $prepFunction($event['street1']);
1637 $event['street2'] =& $prepFunction($event['street2']);
1638 $event['city'] =& $prepFunction($event['city']);
1639 $event['state'] =& $prepFunction($event['state']);
1640 $event['postal'] =& $prepFunction($event['postal']);
1642 $tpl->assign_by_ref('A_EVENT',$event);
1643 //=================================================================
1644 // populate the template $ADMIN_OPTIONS
1645 //=================================================================
1647 if(_SETTING_OPEN_NEW_WINDOW
) {
1648 $target = 'target="csCalendar"';
1651 $admin_edit_url = $admin_delete_url = '';
1652 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN
)) {
1653 $admin_edit_url = pnModURL(__POSTCALENDAR__
,'admin','submit',array('pc_event_id'=>$eid));
1654 $admin_delete_url = pnModURL(__POSTCALENDAR__
,'admin','adminevents',array('action'=>_ACTION_DELETE
,'pc_event_id'=>$eid));
1656 $user_edit_url = $user_delete_url = '';
1657 if(pnUserLoggedIn()) {
1658 $logged_in_uname = $_SESSION['authUser'];
1660 $logged_in_uname = '';
1665 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADD
) && validateGroupStatus($logged_in_uname,getUsername($event['uname']))) {
1667 $user_edit_url = pnModURL(__POSTCALENDAR__
,'user','submit',array('pc_event_id'=>$eid));
1668 $user_delete_url = pnModURL(__POSTCALENDAR__
,'user','delete',array('pc_event_id'=>$eid));
1671 $tpl->assign('STYLE',$GLOBALS['style']);
1672 $tpl->assign_by_ref('ADMIN_TARGET',$target);
1673 $tpl->assign_by_ref('ADMIN_EDIT',$admin_edit_url);
1674 $tpl->assign_by_ref('ADMIN_DELETE',$admin_delete_url);
1675 $tpl->assign_by_ref('USER_TARGET',$target);
1676 $tpl->assign_by_ref('USER_EDIT',$user_edit_url);
1677 $tpl->assign_by_ref('USER_DELETE',$user_delete_url);
1678 $tpl->assign_by_ref('USER_CAN_EDIT',$can_edit);
1680 //=================================================================
1681 // Parse the template
1682 //=================================================================
1683 if($popup != 1 && $print != 1) {
1684 $output = "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1685 $output .= $tpl->fetch($template,$cacheid);
1686 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1688 $theme = pnUserGetTheme();
1689 echo "<html><head>";
1690 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
1691 echo "<style type=\"text/css\">\n";
1692 echo "@import url(\"themes/$theme/style/style.css\"); ";
1694 echo "</head><body>\n";
1695 $tpl->display($template,$cacheid);
1696 echo postcalendar_footer();
1697 echo "\n</body></html>";
1698 session_write_close();
1705 function postcalendar_footer()
1707 // lets get the module's information
1708 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
1709 //$footer = "<p align=\"right\"><a href=\"http://www.postcalendar.tv\">PostCalendar v$modinfo[version]</a></p>";
1714 function postcalendar_smarty_pc_sort_day($params, &$smarty)
1719 $smarty->trigger_error("sort_array: missing 'var' parameter");
1723 if (!in_array('value', array_keys($params))) {
1724 $smarty->trigger_error("sort_array: missing 'value' parameter");
1728 if (!in_array('order', array_keys($params))) {
1732 if (!in_array('inc', array_keys($params))) {
1736 if (!in_array('start', array_keys($params))) {
1740 list($sh,$sm) = explode(':',$start);
1743 if (!in_array('end', array_keys($params))) {
1747 list($eh,$em) = explode(':',$end);
1750 if(strtolower($order) == 'asc') $function = 'sort_byTimeA';
1751 if(strtolower($order) == 'desc') $function = 'sort_byTimeD';
1753 foreach($value as $events) {
1754 usort($events,$function);
1755 $newArray = $events;
1758 // here we want to create an intelligent array of
1759 // columns and rows to build a nice day view
1760 $ch = $sh; $cm = $sm;
1761 while("$ch:$cm" <= "$eh:$em") {
1762 $hours["$ch:$cm"] = array();
1766 $ch = sprintf('%02d',$ch+
1);
1770 $alldayevents = array();
1771 foreach($newArray as $event) {
1772 list($sh,$sm,$ss) = explode(':',$event['startTime']);
1773 $eh = sprintf('%02d',$sh +
$event['duration_hours']);
1774 $em = sprintf('%02d',$sm +
$event['duration_minutes']);
1776 if($event['alldayevent']) {
1777 // we need an entire column . save till later
1778 $alldayevents[] = $event;
1780 //find open time slots - avoid overlapping
1782 $ch = $sh; $cm = $sm;
1783 //what times do we need?
1784 while("$ch:$cm" < "$eh:$em") {
1785 $needed[] = "$ch:$cm";
1789 $ch = sprintf('%02d',$ch+
1);
1793 foreach($needed as $time) {
1795 $hours[$time][] = $event;
1796 $key = count($hours[$time])-1;
1798 $hours[$time][$key] = 'continued';
1804 //pcDebugVar($hours);
1805 $smarty->assign_by_ref($var,$hours);
1808 function sort_byCategoryA($a,$b) {
1809 if($a['catname'] < $b['catname']) return -1;
1810 elseif($a['catname'] > $b['catname']) return 1;
1812 function sort_byCategoryD($a,$b) {
1813 if($a['catname'] < $b['catname']) return 1;
1814 elseif($a['catname'] > $b['catname']) return -1;
1816 function sort_byTitleA($a,$b) {
1817 if($a['title'] < $b['title']) return -1;
1818 elseif($a['title'] > $b['title']) return 1;
1820 function sort_byTitleD($a,$b) {
1821 if($a['title'] < $b['title']) return 1;
1822 elseif($a['title'] > $b['title']) return -1;
1824 function sort_byTimeA($a,$b) {
1825 if($a['startTime'] < $b['startTime']) return -1;
1826 elseif($a['startTime'] > $b['startTime']) return 1;
1828 function sort_byTimeD($a,$b) {
1829 if($a['startTime'] < $b['startTime']) return 1;
1830 elseif($a['startTime'] > $b['startTime']) return -1;
1834 * @param s string text to clean
1835 * @return string cleaned up text
1837 function pc_clean($s)
1839 $display_type = substr($s,0,6);
1840 if($display_type == ':text:') {
1842 } elseif($display_type == ':html:') {
1845 unset($display_type);
1846 $s = preg_replace('/[\r|\n]/i','',$s);
1847 $s = str_replace("'","\'",$s);
1848 $s = str_replace('"','"',$s);
1849 // ok, now we need to break really long lines
1850 // we only want to break at spaces to allow for
1851 // correct interpretation of special characters
1852 $tmp = explode(' ',$s);
1853 return join("'+' ",$tmp);
1856 function &postcalendar_adminapi_getCategoryLimits() { return postcalendar_userapi_getCategoryLimits(); }
1857 function &postcalendar_userapi_getCategoryLimits()
1859 list($dbconn) = pnDBGetConn();
1860 $pntable = pnDBGetTables();
1861 $cat_table = $pntable['postcalendar_limits'];
1862 $sql = "SELECT pc_limitid,pc_catid,pc_starttime,pc_endtime,
1863 pc_limit FROM $cat_table
1864 ORDER BY pc_limitid";
1865 $result = $dbconn->Execute($sql);
1867 if($dbconn->ErrorNo() != 0) { return array(); }
1868 if(!isset($result)) { return array(); }
1871 for($i=0; !$result->EOF
; $result->MoveNext()) {
1872 list($limitid,$catid,$startTime,$endTime,$limit) = $result->fields
;
1873 // check the category's permissions
1874 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW
)) {
1877 $limits[$i]['limitid'] = $limitid;
1878 $limits[$i]['catid'] = $catid;
1879 $limits[$i]['startTime']= $startTime;
1880 $limits[$i]['endTime'] = $endTime;
1881 $limits[$i++
]['limit'] = $limit;