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('TYPE_ON_PATIENT', 0);
86 define('TYPE_ON_PROVIDER', 1);
88 define('_ADMIN_ACTION_APPROVE', 0);
89 define('_ADMIN_ACTION_HIDE', 1);
90 define('_ADMIN_ACTION_EDIT', 2);
91 define('_ADMIN_ACTION_VIEW', 3);
92 define('_ADMIN_ACTION_DELETE', 4);
93 //=================================================================
94 // Get the global PostCalendar config settings
95 // This will save us a lot of time and DB queries later
96 //=================================================================
97 define('_SETTING_USE_POPUPS', pnModGetVar(__POSTCALENDAR__
,'pcUsePopups'));
98 define('_SETTING_USE_INT_DATES', pnModGetVar(__POSTCALENDAR__
,'pcUseInternationalDates'));
99 define('_SETTING_OPEN_NEW_WINDOW', pnModGetVar(__POSTCALENDAR__
,'pcEventsOpenInNewWindow'));
100 define('_SETTING_DAY_HICOLOR', pnModGetVar(__POSTCALENDAR__
,'pcDayHighlightColor'));
101 define('_SETTING_FIRST_DAY_WEEK', pnModGetVar(__POSTCALENDAR__
,'pcFirstDayOfWeek'));
102 define('_SETTING_DATE_FORMAT', pnModGetVar(__POSTCALENDAR__
,'pcEventDateFormat'));
103 define('_SETTING_TIME_24HOUR', pnModGetVar(__POSTCALENDAR__
,'pcTime24Hours'));
104 define('_SETTING_DIRECT_SUBMIT', pnModGetVar(__POSTCALENDAR__
,'pcAllowDirectSubmit'));
105 define('_SETTING_DISPLAY_TOPICS', pnModGetVar(__POSTCALENDAR__
,'pcDisplayTopics'));
106 define('_SETTING_ALLOW_GLOBAL', pnModGetVar(__POSTCALENDAR__
,'pcAllowSiteWide'));
107 define('_SETTING_ALLOW_USER_CAL', pnModGetVar(__POSTCALENDAR__
,'pcAllowUserCalendar'));
108 define('_SETTING_TIME_INCREMENT', pnModGetVar(__POSTCALENDAR__
,'pcTimeIncrement'));
109 define('_SETTING_HOW_MANY_EVENTS', pnModGetVar(__POSTCALENDAR__
,'pcListHowManyEvents'));
110 define('_SETTING_TEMPLATE', pnModGetVar(__POSTCALENDAR__
,'pcTemplate'));
111 define('_SETTING_EVENTS_IN_YEAR', pnModGetVar(__POSTCALENDAR__
,'pcShowEventsInYear'));
112 define('_SETTING_USE_CACHE', pnModGetVar(__POSTCALENDAR__
,'pcUseCache'));
113 define('_SETTING_CACHE_LIFETIME', pnModGetVar(__POSTCALENDAR__
,'pcCacheLifetime'));
114 define('_SETTING_DEFAULT_VIEW', pnModGetVar(__POSTCALENDAR__
,'pcDefaultView'));
115 define('_SETTING_SAFE_MODE', pnModGetVar(__POSTCALENDAR__
,'pcSafeMode'));
116 define('_SETTING_NOTIFY_ADMIN', pnModGetVar(__POSTCALENDAR__
,'pcNotifyAdmin'));
117 define('_SETTING_NOTIFY_EMAIL', pnModGetVar(__POSTCALENDAR__
,'pcNotifyEmail'));
118 //=================================================================
119 // Make checking basic permissions easier
120 //=================================================================
121 define('PC_ACCESS_ADMIN', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADMIN
));
122 define('PC_ACCESS_DELETE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_DELETE
));
123 define('PC_ACCESS_ADD', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADD
));
124 define('PC_ACCESS_EDIT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_EDIT
));
125 define('PC_ACCESS_MODERATE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_MODERATE
));
126 define('PC_ACCESS_COMMENT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_COMMENT
));
127 define('PC_ACCESS_READ', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_READ
));
128 define('PC_ACCESS_OVERVIEW', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_OVERVIEW
));
129 define('PC_ACCESS_NONE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_NONE
));
130 //=========================================================================
131 // Require and Setup utility classes and functions
132 //=========================================================================
133 define('DATE_CALC_BEGIN_WEEKDAY', _SETTING_FIRST_DAY_WEEK
);
134 require_once("modules/$pcDir/pnincludes/Date/Calc.php");
135 //=========================================================================
136 // grab the global language file
137 //=========================================================================
138 $userlang = pnUserGetLang();
139 if(file_exists("modules/$pcDir/pnlang/$userlang/global.php")) {
140 require_once("modules/$pcDir/pnlang/$userlang/global.php");
142 require_once("modules/$pcDir/pnlang/eng/global.php");
145 //=========================================================================
146 // Setup Smarty defines
147 //=========================================================================
148 if(!class_exists('Smarty')) {
149 define('_PC_SMARTY_LOADED',true);
150 define('SMARTY_DIR',"modules/$pcDir/pnincludes/Smarty/");
151 require_once(SMARTY_DIR
.'/Smarty.class.php');
153 require_once("modules/$pcDir/pcSmarty.class.php");
154 //=========================================================================
155 // utility functions for postcalendar
156 //=========================================================================
157 function pcDebugVar($in)
160 if(is_array($in)) print_r($in);
164 function &pcVarPrepForDisplay($s) {
165 $s = nl2br(pnVarPrepForDisplay(postcalendar_removeScriptTags($s)));
166 $s = preg_replace('/&(#)?([0-9a-z]+);/i','&\\1\\2;',$s);
169 function &pcVarPrepHTMLDisplay($s) {
170 return pnVarPrepHTMLDisplay(postcalendar_removeScriptTags($s));
172 function pcGetTopicName($topicid)
174 list($dbconn) = pnDBGetConn();
175 $pntable = pnDBGetTables();
177 $topics_table = $pntable['topics'];
178 $topics_column = &$pntable['topics_column'];
179 $sql = "SELECT $topics_column[topicname]
181 WHERE $topics_column[topicid] = '$topicid'";
182 $result = $dbconn->Execute($sql);
183 if($result === false) return '';
184 else return $result->fields
[0];
186 function &postcalendar_makeValidURL($s)
188 if(empty($s)) return '';
189 if(!preg_match('|^http[s]?:\/\/|i',$s)) {
194 function postcalendar_removeScriptTags($in)
196 return preg_replace("/<script.*?>(.*?)<\/script>/","",$in);
199 function postcalendar_getDate($format='%Y%m%d')
201 list($Date, $jumpday, $jumpmonth, $jumpyear, $jumpdate) =
202 pnVarCleanFromInput('Date', 'jumpday', 'jumpmonth', 'jumpyear', 'jumpdate');
204 // if we still don't have a date then calculate it
205 // check the jump menu, might be a 'jumpdate' input field or m/d/y select lists
207 $jumpyear = substr($jumpdate,0,4);
208 $jumpmonth = substr($jumpdate,5,2);
209 $jumpday = substr($jumpdate,8,2);
211 if ($_SESSION['lastcaldate']) {
212 $time = strtotime($_SESSION['lastcaldate']);
215 if (pnUserLoggedIn())
216 $time +
= (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
218 if(!isset($jumpday)) $jumpday = strftime('%d',$time);
219 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time);
220 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time);
222 // create the correct date string
223 $Date = (int) "$jumpyear$jumpmonth$jumpday";
225 $y = substr($Date,0,4);
226 $m = substr($Date,4,2);
227 $d = substr($Date,6,2);
228 $_SESSION['lastcaldate'] = "$y-$m-$d"; // remember the last chosen date
229 return strftime($format,mktime(0,0,0,$m,$d,$y));
232 function &postcalendar_today($format='%Y%m%d')
235 if (pnUserLoggedIn()) {
236 $time +
= (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
238 return strftime($format,$time);
242 * postcalendar_adminapi_pageSetup()
244 * sets up any necessary javascript for the page
245 * @return string javascript to insert into the page
247 function postcalendar_adminapi_pageSetup() { return postcalendar_userapi_pageSetup(); }
249 * postcalendar_userapi_pageSetup()
251 * sets up any necessary javascript for the page
252 * @return string javascript to insert into the page
254 function postcalendar_userapi_pageSetup()
257 // load the DHTML JavaScript code and insert it into the page
258 if(_SETTING_USE_POPUPS
) { $output .= postcalendar_userapi_loadPopups(); }
259 // insert the js popup code into the page (find better code)
260 if(_SETTING_OPEN_NEW_WINDOW
) { $output .= postcalendar_userapi_jsPopup(); }
264 * postcalendar_userapi_jsPopup
265 * Creates the necessary javascript code for a popup window
267 function postcalendar_userapi_jsPopup()
268 { if(defined('_POSTCALENDAR_JSPOPUPS_LOADED')) {
269 // only put the script on the page once
272 define('_POSTCALENDAR_JSPOPUPS_LOADED',true);
274 // build the correct link
275 $js_link = "'index.php?module=".__POSTCALENDAR__
."&type=user&func=view&viewtype=details&eid='+eid+'&Date='+date+'&popup=1'";
276 $js_window_options = 'toolbar=no,'
288 <script language="javascript">
290 function opencal(eid,date) {
291 window.name='csCalendar';
292 w = window.open($js_link,'PostCalendarEvents','$js_window_options');
302 * postcalendar_userapi_loadPopups
303 * Creates the necessary javascript code for mouseover dHTML popups
305 function postcalendar_userapi_loadPopups()
306 { if(defined('_POSTCALENDAR_LOADPOPUPS_LOADED')) {
307 // only put the script on the page once
310 define('_POSTCALENDAR_LOADPOPUPS_LOADED',true);
312 // get the theme globals :: is there a better way to do this?
313 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
314 global $textcolor1, $textcolor2;
316 // lets get the module's information
317 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
318 $pcDir = pnVarPrepForOS($modinfo['directory']);
321 $close = _PC_OL_CLOSE
;
325 <script language="JavaScript">
326 <!-- overLIB configuration -->
327 ol_fgcolor = "$bgcolor1";
328 ol_bgcolor = "$bgcolor2";
329 ol_textcolor = "$textcolor2";
330 ol_capcolor = "$textcolor2";
331 ol_closecolor = "$textcolor2";
332 ol_textfont = "Verdana,Arial,Helvetica";
333 ol_captionfont = "Verdana,Arial,Helvetica";
349 ol_fgbackground = "";
350 ol_bgbackground = "";
355 ol_capicon = "$capicon";
359 <div id="overDiv" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:1000;"></div>
360 <script language="JavaScript" src="modules/$pcDir/pnincludes/overlib_mini.js">
361 <!-- overLIB (c) Erik Bosrup -->
369 * postcalendar_adminapi_getmonthname()
371 * Returns the month name translated for the user's current language
373 * @param array $args['Date'] number of month to return
374 * @return string month name in user's language
376 function postcalendar_adminapi_getmonthname($args) { return postcalendar_userapi_getmonthname($args); }
378 * postcalendar_userapi_getmonthname()
380 * Returns the month name translated for the user's current language
382 * @param array $args['Date'] date to return month name of
383 * @return string month name in user's language
385 function postcalendar_userapi_getmonthname($args)
387 extract($args); unset($args);
388 if(!isset($Date)) { return false; }
389 $month_name = array('01' => _CALJAN
, '02' => _CALFEB
, '03' => _CALMAR
,
390 '04' => _CALAPR
, '05' => _CALMAY
, '06' => _CALJUN
,
391 '07' => _CALJUL
, '08' => _CALAUG
, '09' => _CALSEP
,
392 '10' => _CALOCT
, '11' => _CALNOV
, '12' => _CALDEC
);
393 return $month_name[date('m',$Date)];
396 * Returns an array of form data for FormSelectMultiple
398 function postcalendar_adminapi_buildTimeSelect($args) { return postcalendar_userapi_buildTimeSelect($args); }
399 function postcalendar_userapi_buildTimeSelect($args)
401 $inc = _SETTING_TIME_INCREMENT
;
402 extract($args); unset($args);
403 $output = array('h'=>array(),'m'=>array());
404 if((bool)_SETTING_TIME_24HOUR
) {
408 $hselected = $hselected > 12 ?
$hselected-=12 : $hselected;
410 for($c=0,$h=$start; $h<=$end; $h++
,$c++
) {
411 $hour = sprintf('%02d',$h);
412 $output['h'][$c]['id'] = pnVarPrepForStore($h);
413 $output['h'][$c]['selected'] = $hselected == $hour;
414 $output['h'][$c]['name'] = pnVarPrepForDisplay($hour);
416 for($c=0,$m=0; $m<=(60-$inc);$m+
=$inc,$c++
) {
417 $min = sprintf('%02d',$m);
418 $output['m'][$c]['id'] = pnVarPrepForStore($m);
419 $output['m'][$c]['selected'] = $mselected == $min;
420 $output['m'][$c]['name'] = pnVarPrepForDisplay($min);
425 * Returns an array of form data for FormSelectMultiple
427 function postcalendar_adminapi_buildMonthSelect($args) { return postcalendar_userapi_buildMonthSelect($args); }
428 function postcalendar_userapi_buildMonthSelect($args)
430 extract($args); unset($args);
431 if(!isset($pc_month)) { $pc_month = Date_Calc
::getMonth(); }
432 // create the return object to be inserted into the form
434 if(!isset($selected)) $selected = '';
435 for ($c=0,$i=1;$i<=12;$i++
,$c++
) {
436 if ($selected) { $sel = $selected == $i ?
true : false; }
437 elseif ($i == $pc_month) { $sel = true; }
438 else { $sel = false; }
439 $output[$c]['id'] = sprintf('%02d',$i);
440 $output[$c]['selected'] = $sel;
441 $output[$c]['name'] = postcalendar_userapi_getmonthname(array('Date'=>mktime(0,0,0,$i,15)));
447 * Returns an array of form data for FormSelectMultiple
449 function postcalendar_adminapi_buildDaySelect($args) { return postcalendar_userapi_buildDaySelect($args); }
450 function postcalendar_userapi_buildDaySelect($args)
452 extract($args); unset($args);
453 if(!isset($pc_day)) { $pc_day = Date_Calc
::getDay(); }
454 // create the return object to be inserted into the form
456 if(!isset($selected)) $selected = '';
457 for($c=0,$i=1; $i<=31; $i++
,$c++
) {
458 if ($selected) { $sel = $selected == $i ?
true : false; }
459 elseif ($i == $pc_day) { $sel = true; }
460 else { $sel = false; }
461 $output[$c]['id'] = sprintf('%02d',$i);
462 $output[$c]['selected'] = $sel;
463 $output[$c]['name'] = sprintf('%02d',$i);
469 * Returns an array of form data for FormSelectMultiple
471 function postcalendar_adminapi_buildYearSelect($args) { return postcalendar_userapi_buildYearSelect($args); }
472 function postcalendar_userapi_buildYearSelect($args)
474 extract($args); unset($args);
475 if(!isset($pc_year)) { $pc_year = date('Y'); }
476 // create the return object to be inserted into the form
478 // we want the list to contain 10 years before today and 30 years after
479 // maybe this will eventually become a user defined value
480 $pc_start_year = date('Y') - 1;
481 $pc_end_year = date('Y') +
30;
482 if(!isset($selected)) $selected = '';
483 for($c=0,$i=$pc_start_year; $i<=$pc_end_year; $i++
,$c++
) {
484 if ($selected) { $sel = $selected == $i ?
true : false; }
485 elseif ($i == $pc_year) { $sel = true; }
486 else { $sel = false; }
487 $output[$c]['id'] = sprintf('%04d',$i);
488 $output[$c]['selected'] = $sel;
489 $output[$c]['name'] = sprintf('%04d',$i);
494 function &postcalendar_adminapi_getCategories() { return postcalendar_userapi_getCategories(); }
495 function &postcalendar_userapi_getCategories()
497 list($dbconn) = pnDBGetConn();
498 $pntable = pnDBGetTables();
499 $cat_table = $pntable['postcalendar_categories'];
500 $sql = "SELECT pc_catid,pc_catname,pc_catcolor,pc_catdesc,
501 pc_recurrtype,pc_recurrspec,pc_recurrfreq,pc_duration,
502 pc_dailylimit,pc_end_date_flag,pc_end_date_type,pc_end_date_freq,
503 pc_end_all_day,pc_cattype FROM $cat_table
504 ORDER BY pc_catname";
505 $result = $dbconn->Execute($sql);
507 if($dbconn->ErrorNo() != 0) { return array(); }
508 if(!isset($result)) { return array(); }
510 $categories = array();
511 for($i=0; !$result->EOF
; $result->MoveNext()) {
512 list($catid,$catname,$catcolor,$catdesc,
513 $rtype,$rspec,$rfreq,$duration,$limit,$end_date_flag,
514 $end_date_type,$end_date_freq,$end_all_day,$cattype) = $result->fields
;
515 // check the category's permissions
516 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW
)) {
519 $categories[$i]['id'] = $catid;
520 $categories[$i]['name'] = $catname;
521 $categories[$i]['color'] = $catcolor;
522 $categories[$i]['desc'] = $catdesc;
523 $categories[$i]['value_cat_type'] = $cattype;
524 $categories[$i]['event_repeat'] = $rtype;
525 $rspecs = unserialize($rspec);
526 $categories[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
527 $categories[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
528 $categories[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
529 $categories[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
530 $categories[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
531 $categories[$i]['event_recurrspec'] = $rspecs;
532 $categories[$i]['event_duration'] = $duration;
533 $categories[$i]['event_durationh'] = (int)($duration/(60 * 60)); //seconds divided by 60 seconds * 60 minutes;
534 $categories[$i]['event_durationm'] = ($duration%
(60 * 60))/60;
535 $categories[$i]['end_date_flag'] = $end_date_flag;
536 $categories[$i]['end_date_type'] = $end_date_type;
537 $categories[$i]['end_date_freq'] = $end_date_freq;
538 $categories[$i]['end_all_day'] = $end_all_day;
539 $categories[$i++
]['dailylimit'] = $limit;
546 function &postcalendar_adminapi_getTopics() { return postcalendar_userapi_getTopics(); }
547 function &postcalendar_userapi_getTopics()
549 list($dbconn) = pnDBGetConn();
550 $pntable = pnDBGetTables();
551 $topics_table = $pntable['topics'];
552 $topics_column = &$pntable['topics_column'];
553 $sql = "SELECT $topics_column[topicid], $topics_column[topictext], $topics_column[topicname]
555 ORDER BY $topics_column[topictext]";
556 $topiclist = $dbconn->Execute($sql);
557 if($dbconn->ErrorNo() != 0) {
562 for(;!$topiclist->EOF
;$topiclist->MoveNext()) {
563 // check topic permissions
564 if(pnSecAuthAction(0,'PostCalendar::Topic',$topiclist->fields
[2].'::'.$topiclist->fields
[0],ACCESS_OVERVIEW
)) {
565 list($data[$i]['id'], $data[$i]['text'], $data[$i++
]['name']) = $topiclist->fields
;
573 * postcalendar_adminapi_submitEvent()
575 * @param $args array of event data
576 * @return bool true on success : false on failure;
578 function postcalendar_adminapi_submitEvent($args) { return postcalendar_userapi_submitEvent($args); }
580 * postcalendar_userapi_submitEvent()
582 * @param $args array of event data
583 * @return bool true on success : false on failure;
585 function postcalendar_userapi_submitEvent($args)
587 extract($args); unset($args);
589 list($dbconn) = pnDBGetConn();
590 $pntable = pnDBGetTables();
592 // determine if the event is to be published immediately or not
593 //also whether is a special system only event i.e. _EVENT_TEMPORARY
594 if (empty($event_status)) {
595 if( (bool) _SETTING_DIRECT_SUBMIT ||
(bool) PC_ACCESS_ADMIN ||
($event_sharing != SHARING_GLOBAL
) ) {
596 $event_status = _EVENT_APPROVED
;
598 $event_status = _EVENT_QUEUED
;
601 elseif ($event_status == _EVENT_TEMPORARY
) {
602 $event_status = _EVENT_TEMPORARY
;
605 $event_status = _EVENT_QUEUED
;
609 // set up some vars for the insert statement
610 $startDate = $event_startyear.'-'.$event_startmonth.'-'.$event_startday;
611 if($event_endtype == 1) {
612 $endDate = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
614 $endDate = '0000-00-00';
617 if(!isset($event_allday)) $event_allday = 0;
618 if((bool)_SETTING_TIME_24HOUR
) {
619 $startTime = $event_starttimeh.':'.$event_starttimem.':00';
621 if($event_startampm == _AM_VAL
) {
622 $event_starttimeh = $event_starttimeh == 12 ?
'00' : $event_starttimeh;
624 $event_starttimeh = $event_starttimeh != 12 ?
$event_starttimeh+
=12 : $event_starttimeh;
626 $startTime = sprintf('%02d',$event_starttimeh).':'.sprintf('%02d',$event_starttimem).':00';
628 if ($event_allday == 1) {
629 $endTime = "24:00:00";
632 $endTime = date("H:i:00",($event_duration +
strtotime($startTime)));
635 // get rid of variables we no longer need to save memory
636 unset($event_startyear,$event_startmonth,$event_startday,$event_endyear,$event_endmonth,
637 $event_endday,$event_starttimeh,$event_starttimem);
639 //pennfirm users need to be able to enter apps for different providers, this isn't aoplicable
640 /*if(pnUserLoggedIn()) {
641 $event_userid = pnUserGetVar('uid');
647 if($pc_html_or_text == 'html') {
648 $event_desc = ':html:'.$event_desc;
650 $event_desc = ':text:'.$event_desc;
652 list($event_subject,$event_desc,$event_topic,$startDate,$endDate,
653 $event_repeat,$startTime,$event_allday,$event_category,
654 $event_location_info,$event_conttel,$event_contname,
655 $event_contemail,$event_website,$event_fee,$event_status,
656 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
657 $pc_event_id) = @pnVarPrepForStore
($event_subject,$event_desc,$event_topic,$startDate,$endDate,
658 $event_repeat,$startTime,$event_allday,$event_category,
659 $event_location_info,$event_conttel,$event_contname,
660 $event_contemail,$event_website,$event_fee,$event_status,
661 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
664 if(!isset($is_update)) { $is_update = false; }
666 $sql = "UPDATE $pntable[postcalendar_events]
667 SET pc_title = '$event_subject',
668 pc_hometext = '$event_desc',
669 pc_topic = '$event_topic',
670 pc_eventDate = '$startDate',
671 pc_endDate = '$endDate',
672 pc_recurrtype = '$event_repeat',
673 pc_startTime = '$startTime',
674 pc_endTime = '$endTime',
675 pc_alldayevent = '$event_allday',
676 pc_catid = '$event_category',
677 pc_location = '$event_location_info',
678 pc_conttel = '$event_conttel',
679 pc_contname = '$event_contname',
680 pc_contemail = '$event_contemail',
681 pc_website = '$event_website',
682 pc_fee = '$event_fee',
683 pc_eventstatus = '$event_status',
684 pc_recurrspec = '$event_recurrspec',
685 pc_duration = '$event_duration',
686 pc_sharing = '$event_sharing',
687 pc_aid = '$event_userid',
688 pc_pid = '$event_pid'
689 WHERE pc_eid = '$pc_event_id'";
691 $pc_event_id = $dbconn->GenId($pntable['postcalendar_events']);
692 $sql = "INSERT INTO $pntable[postcalendar_events] (
724 " . $_SESSION['authUserID'] . ",
732 '$event_location_info',
746 $result = $dbconn->Execute($sql);
747 if($result === false) {
750 if((bool)$is_update) {
753 $eid = $dbconn->PO_Insert_ID($pntable['postcalendar_events'],'pc_eid');
755 pc_notify($eid,$is_update);
760 function pc_notify($eid,$is_update)
762 if(!(bool)_SETTING_NOTIFY_ADMIN
) { return true; }
764 $subject = _PC_NOTIFY_SUBJECT
;
766 if((bool)$is_update) {
767 $message = _PC_NOTIFY_UPDATE_MSG
;
769 $message = _PC_NOTIFY_NEW_MSG
;
772 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
773 $modversion = pnVarPrepForOS($modinfo['version']);
776 $message .= pnModURL(__POSTCALENDAR__
,'admin','adminevents',array('pc_event_id'=>$eid,'action'=>_ADMIN_ACTION_VIEW
));
777 $message .= "\n\n\n\n";
778 $message .= "----\n";
779 $message .= "PostCalendar $modversion\n";
780 $message .= "http://www.postcalendar.tv";
782 mail(_SETTING_NOTIFY_EMAIL
,$subject,$message,
783 "From: " . _SETTING_NOTIFY_EMAIL
. "\r\n"
784 ."X-Mailer: PHP/" . phpversion() . "\r\n"
785 ."X-Mailer: PostCalendar/$modversion" );
791 function findFirstAvailable($period) {
795 $available_times = array();
796 foreach ($period as $date => $day) {
797 //echo "begin free times for $date:<br />";
798 $ffid_res = findFirstInDay($day,$date);
799 foreach($ffid_res as $times) {
800 //echo "starting: " . date("h:i:s A",$times['startTime']) . " long: " . $times['duration'] . "<br />";
801 $available_times[$date][] = $times;
802 //echo "count of times is:" . count($available_times) . "<br />";
804 //echo "end free times for $date";
807 return $available_times;
810 function findFirstInDay($day,$date) {
815 foreach ($day as $event) {
816 //echo "event is: " . $event['title'] . " cat is: " .$event['catid'] . " event date is: " . $date . "<br />";
818 if ($event['catid'] == 2) { //catid 2 is reserved to represent "In Office" events, id 3 is "Out Of Office"
819 $intime = $event['startTime'];
820 //echo "setting in: $intime<br />";
822 elseif ($event['catid'] == 3) {
824 $outtime = $event['startTime'];
825 //echo "setting out: $outtime<br />";
828 if ($intime == false or $outtime == false) {
832 //echo "increment is: " . _SETTING_TIME_INCREMENT . "<br />";
833 $inc = (_SETTING_TIME_INCREMENT
* 60);
835 $intime_sec = date("U",strtotime($date . " " . $intime));
836 $outtime_sec = date("U",strtotime($date . " " . $outtime));
837 $free_time = $intime_sec;
840 for ($i = $intime_sec; $i < $outtime_sec; $i +
= $inc) {
841 //echo "time is now: " . date("h:i:s A",$i) . "<br />";
842 $closest_start = $outtime_sec;
844 foreach($day as $event) {
845 if ($event['catid'] != 2) {
847 $estart = dtSec($date,$event['startTime']) ;
848 $eend = dtSecDur($date, $event['startTime'], $event['duration']);
850 if ($eend < $intime_sec or $estart > $outtime_sec) {
851 //event ends before intime or starts after outtime we don't care move on;
854 elseif ($eend < $i ) {
855 //event ended before time currently being evaluated, we don't care move on;
858 elseif ($estart < $i and $eend > $i) {
859 //event occupies part of the time we are looking at, look at another time
862 elseif ($estart >= $i) {
863 //echo "tin: " . date("h:i:s A",$i) . " estart: " . date("h:i:s A",$estart) . "<br />";
865 //echo "ev: " . $event['title'] . " s at:" . date("h:i:s A",$estart) . " e at: " . date("h:i:s A",$eend) ." <br />";
866 //some amount of time is free set closest time
867 $oldfreetime = $closest_start - $i;
868 $newfreetime = $estart - $i;
870 //echo "old free: " . $oldfreetime . "<br />";
871 //echo "new free: " . $newfreetime . "<br />";
872 //echo "duration is: " . ($estart - $i) . " cs:$estart i:$i<br />";
873 if ($newfreetime < $oldfreetime && ($estart - $i) != 0) {
875 $closest_start = $estart;
877 //echo "set time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
878 if ($i < ($eend - $inc))
881 elseif($newfreetime <= $oldfreetime && $oldfreetime == ($outtime_sec - $i)) {
883 $closest_start = $estart;
885 //echo "time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
886 if ($i < ($eend - $inc))
890 //echo "closest start: " . date("h:i:s A",$closest_start) . "<br />";
897 if ($closest_start > ($intime_sec +
60)) {
898 //echo "free time is: " . date("h:i:s A",$free_time) . "<br />";
899 //echo "next app is: " . date("h:i:s A",$closest_start) . "<br />";
900 $duration = ($closest_start - $free_time);
901 //echo "duration is: $duration<br />";
902 //we allow for 0 duration events so other things such as overlap and actual times can be calculated
903 //this happens because people want to be able to set 8:00 - 8:15 and 8:15 - 8:30 without a conflict
904 //even though that is technially impossible, so we pretend, however here we weed out the 0
905 //length blocks so that won't be seen
906 $date_sec = strtotime ($date);
908 $times[] = array ("startTime" => $free_time, "endTime" => ($date_sec+
$duration));
916 function dtSec ($date, $time) {
917 return date("U",strtotime($date . " " . $time));
920 function dtSecDur ($date, $time, $dur) {
921 $time_sec = date("U",strtotime($date . " " . $time));
922 return $time_sec +
$dur;
926 * postcalendar_adminapi_buildSubmitForm()
927 * create event submit form
929 function postcalendar_adminapi_buildSubmitForm($args) { return postcalendar_userapi_buildSubmitForm($args,true); }
931 * postcalendar_userapi_buildSubmitForm()
932 * create event submit form
934 function postcalendar_userapi_buildSubmitForm($args,$admin=false)
936 $_SESSION['category'] = "";
937 if(!PC_ACCESS_ADD
) { return _POSTCALENDARNOAUTH
; }
938 extract($args); unset($args);
939 //since we seem to clobber category
941 $output = new pnHTML();
942 $output->SetInputMode(_PNH_VERBATIMINPUT
);
944 $tpl = new pcSmarty();
945 $tpl->caching
= false;
947 $template_name = pnModGetVar(__POSTCALENDAR__
,'pcTemplate');
949 if(!isset($template_name)) {
950 $template_name ='default';
953 //=================================================================
954 // Setup the correct config file path for the templates
955 //=================================================================
956 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
957 $modir = pnVarPrepForOS($modinfo['directory']);
958 $modname = $modinfo['displayname'];
959 $all_categories =& pnModAPIFunc(__POSTCALENDAR__
,'user','getCategories');
960 //print_r($all_categories);
962 $tpl->config_dir
= "modules/$modir/pntemplates/$template_name/config/";
963 //=================================================================
965 //=================================================================
968 $tpl->assign('webroot', $GLOBALS['web_root']);
969 $tpl->assign_by_ref('TPL_NAME',$template_name);
970 $tpl->assign('FUNCTION',pnVarCleanFromInput('func'));
971 $tpl->assign_by_ref('ModuleName', $modname);
972 $tpl->assign_by_ref('ModuleDirectory', $modir);
973 $tpl->assign_by_ref('category',$all_categories);
974 $tpl->assign('NewEventHeader', _PC_NEW_EVENT_HEADER
);
975 $tpl->assign('EventTitle', _PC_EVENT_TITLE
);
976 $tpl->assign('Required', _PC_REQUIRED
);
977 $tpl->assign('DateTimeTitle', _PC_DATE_TIME
);
978 $tpl->assign('AlldayEventTitle', _PC_ALLDAY_EVENT
);
979 $tpl->assign('TimedEventTitle', _PC_TIMED_EVENT
);
980 $tpl->assign('TimedDurationTitle', _PC_TIMED_DURATION
);
981 $tpl->assign('TimedDurationHoursTitle', _PC_TIMED_DURATION_HOURS
);
982 $tpl->assign('TimedDurationMinutesTitle',_PC_TIMED_DURATION_MINUTES
);
983 $tpl->assign('EventDescTitle', _PC_EVENT_DESC
);
985 //the double book variable comes from the eventdata array that is
986 //passed here and extracted, injection is not an issue here
987 if (is_numeric($double_book)) {
988 $tpl->assign('double_book', $double_book);
991 //pennfirm begin patient info handling
992 $ProviderID = pnVarCleanFromInput("provider_id");
993 if (is_numeric($ProviderID)) {
994 $tpl->assign('ProviderID', $ProviderID);
995 $tpl->assign('provider_id', $ProviderID);
997 elseif(is_numeric($event_userid) && $event_userid != 0) {
998 $tpl->assign('ProviderID', $event_userid);
999 $tpl->assign('provider_id', $event_userid);
1002 if ($_SESSION['userauthorized'] == 1)
1003 $tpl->assign('ProviderID', $_SESSION['authUserID']);
1005 $tpl->assign('ProviderID', "");
1007 $provinfo = getProviderInfo();
1008 $tpl->assign('providers', $provinfo);
1009 $PatientID = pnVarCleanFromInput("patient_id");
1011 // limit the number of results returned by getPatientPID
1012 // this helps to prevent the server from stalling on a request with
1013 // no PID and thousands of PIDs in the database -- JRM
1014 // the function getPatientPID($pid, $given, $orderby, $limit, $start) <-- defined in library/patient.inc
1016 if (is_numeric($PatientID)) {
1017 $tpl->assign('PatientList', getPatientPID(array('pid'=>$PatientID, 'limit'=>$plistlimit)));
1019 elseif (is_numeric($event_pid)) {
1020 $tpl->assign('PatientList', getPatientPID(array('pid'=>$event_pid, 'limit'=>$plistlimit)));
1023 $tpl->assign('PatientList', getPatientPID(array('limit' =>$plistlimit)));
1026 $tpl->assign('event_pid', $event_pid);
1027 $tpl->assign('event_aid', $event_aid);
1028 $tpl->assign('event_category', pnVarCleanFromInput("event_category"));
1030 if(empty($event_patient_name))
1032 $patient_data = getPatientData($event_pid, $given = "lname, fname");
1033 $event_patient_name = $patient_data['lname'].", ".$patient_data['fname'];
1035 $tpl->assign('patient_value', $event_patient_name);
1037 //=================================================================
1038 // PARSE INPUT_EVENT_TITLE
1039 //=================================================================
1040 $tpl->assign('InputEventTitle', 'event_subject');
1041 $tpl->assign('ValueEventTitle', pnVarPrepForDisplay($event_subject));
1043 //=================================================================
1044 // PARSE SELECT_DATE_TIME
1045 //=================================================================
1047 // It seems that with Mozilla at least, <select> fields that are disabled
1048 // do not get passed as form data. Therefore we ignore $double_book so
1049 // that the fields will not be disabled. -- Rod 2005-03-22
1051 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1052 if(_SETTING_USE_INT_DATES
) {
1053 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1054 $formdata = $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1055 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1056 $formdata .= $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1058 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1059 $formdata = $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1060 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1061 $formdata .= $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1063 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_startyear));
1064 $formdata .= $output->FormSelectMultiple('event_startyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1065 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1066 $tpl->assign('SelectDateTime', $formdata);
1067 $tpl->assign('InputAllday', 'event_allday');
1068 $tpl->assign('ValueAllday', '1');
1069 $tpl->assign('SelectedAllday', $event_allday==1 ?
'checked':'');
1070 $tpl->assign('InputTimed', 'event_allday');
1071 $tpl->assign('ValueTimed', '0');
1072 $tpl->assign('SelectedTimed', $event_allday==0 ?
'checked':'');
1073 $tpl->assign('STYLE',$GLOBALS['style']);
1075 //=================================================================
1076 // PARSE SELECT_END_DATE_TIME
1077 //=================================================================
1078 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1079 //if there is no end date we want the box to read todays date instead of jan 01 1994 :)
1080 if($event_endmonth == 0 && $event_endday ==0 && $event_endyear ==0){
1081 $event_endmonth =$month;
1082 $event_endday = $day ;
1083 $event_endyear = $year;
1085 if(_SETTING_USE_INT_DATES
) {
1086 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1088 $formdata = $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1089 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1090 $formdata .= $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1093 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1094 $formdata = $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1095 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1096 $formdata .= $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1098 $sel_data = pnModAPIFunc(__POSTCALENDAR__
,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_endyear));
1099 $formdata .= $output->FormSelectMultiple('event_endyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1100 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1101 $tpl->assign('SelectEndDate', $formdata);
1102 //=================================================================
1103 // PARSE SELECT_TIMED_EVENT
1104 //=================================================================
1105 $stimes = pnModAPIFunc(__POSTCALENDAR__
,'user','buildTimeSelect',array('hselected'=>$event_starttimeh,'mselected'=>$event_starttimem));
1106 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1107 $timed_hours = $output->FormSelectMultiple('event_starttimeh', $stimes['h'],0,1,"","",false,/* $double_book*/ '');
1108 $timed_minutes = $output->FormSelectMultiple('event_starttimem', $stimes['m'],0,1,"","",false,/* $double_book*/ '');
1109 if(!_SETTING_TIME_24HOUR
) {
1111 $ampm[0]['id'] = pnVarPrepForStore(_AM_VAL
);
1112 $ampm[0]['name'] = pnVarPrepForDisplay(_PC_AM
);
1113 $ampm[1]['id'] = pnVarPrepForStore(_PM_VAL
);
1114 $ampm[1]['name'] = pnVarPrepForDisplay(_PC_PM
);
1115 if($event_startampm == "AM" ||
$event_startampm == _AM_VAL
)
1117 $ampm[0]['selected'] = 1;
1121 $ampm[1]['selected'] = 1;
1123 $timed_ampm = $output->FormSelectMultiple('event_startampm', $ampm,0,1,"","",false,/* $double_book*/ '');
1127 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1128 $tpl->assign('SelectTimedHours', $timed_hours);
1129 $tpl->assign('SelectTimedMinutes', $timed_minutes);
1130 $tpl->assign('SelectTimedAMPM', $timed_ampm);
1131 $tpl->assign('event_startday', $event_startday);
1132 $tpl->assign('event_startmonth', $event_startmonth);
1133 $tpl->assign('event_startyear', $event_startyear);
1134 $tpl->assign('event_starttimeh', $event_starttimeh);
1135 $tpl->assign('event_starttimem', $event_starttimem);
1136 $tpl->assign('event_startampm', $event_startampm);
1137 $tpl->assign('event_dur_hours', $event_dur_hours);
1138 $tpl->assign('event_dur_minutes', $event_dur_minutes);
1140 //=================================================================
1141 // PARSE SELECT_DURATION
1142 //=================================================================
1143 $event_dur_hours = (int) $event_dur_hours;
1145 for($i=0; $i<=24; $i+
=1) {
1146 $TimedDurationHours[$i] = array('value'=>$i,
1147 'selected'=>($event_dur_hours==$i ?
'selected':''),
1148 'name'=>sprintf('%02d',$i));
1151 $tpl->assign('TimedDurationHours',$TimedDurationHours);
1152 $tpl->assign('InputTimedDurationHours', 'event_dur_hours');
1153 $found_time = false;
1154 for($i=0; $i<60; $i+
=_SETTING_TIME_INCREMENT
) {
1155 $TimedDurationMinutes[$i] = array('value'=>$i,
1156 'selected'=>($event_dur_minutes==$i ?
'selected':''),
1157 'name'=>sprintf('%02d',$i));
1158 if( $TimedDurationMinutes[$i]['selected'] == 'selected' )
1163 $TimedDurationMinutes[$i] = array('value'=>$event_dur_minutes,
1164 'selected'=>'selected',
1165 'name'=>sprintf('%02d',$event_dur_minutes));
1166 $tpl->assign('TimedDurationMinutes',$TimedDurationMinutes);
1167 $tpl->assign('hidden_event_dur_minutes',$event_dur_minutes);
1168 $tpl->assign('InputTimedDurationMinutes', 'event_dur_minutes');
1169 //=================================================================
1170 // PARSE INPUT_EVENT_DESC
1171 //=================================================================
1172 $tpl->assign('InputEventDesc', 'event_desc');
1173 if(empty($pc_html_or_text)) {
1174 $display_type = substr($event_desc,0,6);
1175 if($display_type == ':text:') {
1176 $pc_html_or_text = 'text';
1177 $event_desc = substr($event_desc,6);
1178 } elseif($display_type == ':html:') {
1179 $pc_html_or_text = 'html';
1180 $event_desc = substr($event_desc,6);
1182 $pc_html_or_text = 'text';
1184 unset($display_type);
1186 $tpl->assign('ValueEventDesc', pnVarPrepForDisplay($event_desc));
1187 $eventHTMLorText = "<select name=\"pc_html_or_text\">";
1188 if($pc_html_or_text == 'text') {
1189 $eventHTMLorText .= "<option value=\"text\" selected=\"selected\">"._PC_SUBMIT_TEXT
."</option>";
1191 $eventHTMLorText .= "<option value=\"text\">"._PC_SUBMIT_TEXT
."</option>";
1193 if($pc_html_or_text == 'html') {
1194 $eventHTMLorText .= "<option value=\"html\" selected=\"selected\">"._PC_SUBMIT_HTML
."</option>";
1196 $eventHTMLorText .= "<option value=\"html\">"._PC_SUBMIT_HTML
."</option>";
1198 $eventHTMLorText .= "</select>";
1199 $tpl->assign('EventHTMLorText',$eventHTMLorText);
1200 //=================================================================
1201 // PARSE select_event_topic_block
1202 //=================================================================
1203 $tpl->assign('displayTopics',_SETTING_DISPLAY_TOPICS
);
1204 if((bool)_SETTING_DISPLAY_TOPICS
) {
1205 $a_topics =& postcalendar_userapi_getTopics();
1207 foreach($a_topics as $topic) {
1208 array_push($topics,array('value'=>$topic['id'],
1209 'selected'=>($topic['id']==$event_topic ?
'selected':''),
1210 'name'=>$topic['text']));
1213 // only show this if we have topics to show
1214 if(count($topics) > 0) {
1215 $tpl->assign('topics',$topics);
1216 $tpl->assign('EventTopicTitle', _PC_EVENT_TOPIC
);
1217 $tpl->assign('InputEventTopic', 'event_topic');
1220 //=================================================================
1221 // PARSE select_event_type_block
1222 //=================================================================
1223 $categories = array();
1224 foreach($all_categories as $category) {
1225 array_push($categories,array('value'=>$category['id'],
1226 'selected'=>($category['id']==$event_category ?
'selected' : ''),
1227 'name'=>$category['name'],
1228 'color'=>$category['color'],
1229 'desc'=>$category['desc']));
1231 // only show this if we have categories to show
1232 // you should ALWAYS have at least one valid category
1233 if(count($categories) > 0) {
1234 $tpl->assign('categories',$categories);
1235 $tpl->assign('EventCategoriesTitle', _PC_EVENT_CATEGORY
);
1236 $tpl->assign('InputEventCategory', 'event_category');
1237 $tpl->assign('hidden_event_category', $event_category);
1239 //=================================================================
1240 // PARSE event_sharing_block
1241 //=================================================================
1243 if(_SETTING_ALLOW_USER_CAL
) {
1244 array_push($data,array(SHARING_PRIVATE
,_PC_SHARE_PRIVATE
));
1245 array_push($data,array(SHARING_PUBLIC
,_PC_SHARE_PUBLIC
));
1246 array_push($data,array(SHARING_BUSY
,_PC_SHARE_SHOWBUSY
));
1248 if(pnSecAuthAction(0,'PostCalendar::', '::', ACCESS_ADMIN
) || _SETTING_ALLOW_GLOBAL ||
!_SETTING_ALLOW_USER_CAL
) {
1249 array_push($data,array(SHARING_GLOBAL
,_PC_SHARE_GLOBAL
));
1252 foreach($data as $cell) {
1253 array_push($sharing,array('value'=>$cell[0],
1254 'selected'=>((int) $event_sharing == $cell[0] ?
'selected' : ''),
1258 //pennfirm get list of providers from openemr code in calendar.inc
1259 $tpl->assign("user",getCalendarProviderInfo());
1262 $tpl->assign('sharing',$sharing);
1263 $tpl->assign('EventSharingTitle', _PC_SHARING
);
1264 $tpl->assign('InputEventSharing','event_sharing');
1265 //=================================================================
1266 // location information
1267 //=================================================================
1268 $tpl->assign('EventLocationTitle', _PC_EVENT_LOCATION
);
1269 $tpl->assign('InputLocation', 'event_location');
1270 $tpl->assign('ValueLocation', pnVarPrepForDisplay($event_location));
1271 $tpl->assign('EventStreetTitle', _PC_EVENT_STREET
);
1272 $tpl->assign('InputStreet1', 'event_street1');
1273 $tpl->assign('ValueStreet1', pnVarPrepForDisplay($event_street1));
1274 $tpl->assign('InputStreet2', 'event_street2');
1275 $tpl->assign('ValueStreet2', pnVarPrepForDisplay($event_street2));
1276 $tpl->assign('EventCityTitle', _PC_EVENT_CITY
);
1277 $tpl->assign('InputCity', 'event_city');
1278 $tpl->assign('ValueCity', pnVarPrepForDisplay($event_city));
1279 $tpl->assign('EventStateTitle', _PC_EVENT_STATE
);
1280 $tpl->assign('InputState', 'event_state');
1281 $tpl->assign('ValueState', pnVarPrepForDisplay($event_state));
1282 $tpl->assign('EventPostalTitle', _PC_EVENT_POSTAL
);
1283 $tpl->assign('InputPostal', 'event_postal');
1284 $tpl->assign('ValuePostal', pnVarPrepForDisplay($event_postal));
1285 //=================================================================
1286 // contact information
1287 //=================================================================
1288 $tpl->assign('EventContactTitle', _PC_EVENT_CONTACT
);
1289 $tpl->assign('InputContact', 'event_contname');
1290 $tpl->assign('ValueContact', pnVarPrepForDisplay($event_contname));
1291 $tpl->assign('EventPhoneTitle', _PC_EVENT_PHONE
);
1292 $tpl->assign('InputPhone', 'event_conttel');
1293 $tpl->assign('ValuePhone', pnVarPrepForDisplay($event_conttel));
1294 $tpl->assign('EventEmailTitle', _PC_EVENT_EMAIL
);
1295 $tpl->assign('InputEmail', 'event_contemail');
1296 $tpl->assign('ValueEmail', pnVarPrepForDisplay($event_contemail));
1297 $tpl->assign('EventWebsiteTitle', _PC_EVENT_WEBSITE
);
1298 $tpl->assign('InputWebsite', 'event_website');
1299 $tpl->assign('ValueWebsite', pnVarPrepForDisplay($event_website));
1300 $tpl->assign('EventFeeTitle', _PC_EVENT_FEE
);
1301 $tpl->assign('InputFee', 'event_fee');
1302 $tpl->assign('ValueFee', pnVarPrepForDisplay($event_fee));
1303 //=================================================================
1304 // Repeating Information
1305 //=================================================================
1306 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER
);
1307 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT
);
1308 $tpl->assign('RepeatTitle', _PC_REPEAT
);
1309 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON
);
1310 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH
);
1311 $tpl->assign('EndDateTitle', _PC_END_DATE
);
1312 $tpl->assign('NoEndDateTitle', _PC_NO_END
);
1313 $tpl->assign('InputNoRepeat', 'event_repeat');
1314 $tpl->assign('ValueNoRepeat', '0');
1315 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ?
'checked':'');
1316 $tpl->assign('InputRepeat', 'event_repeat');
1317 $tpl->assign('ValueRepeat', '1');
1318 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ?
'checked':'');
1321 $in = array(_PC_EVERY
,_PC_EVERY_OTHER
,_PC_EVERY_THIRD
,_PC_EVERY_FOURTH
);
1322 $keys = array(REPEAT_EVERY
,REPEAT_EVERY_OTHER
,REPEAT_EVERY_THIRD
,REPEAT_EVERY_FOURTH
);
1323 $repeat_freq = array();
1324 foreach($in as $k=>$v) {
1325 array_push($repeat_freq,array('value'=>$keys[$k],
1326 'selected'=>($keys[$k]==$event_repeat_freq?
'selected':''),
1329 $tpl->assign('InputRepeatFreq','event_repeat_freq');
1330 if(empty($event_repeat_freq) ||
$event_repeat_freq < 1) $event_repeat_freq = 1;
1331 $tpl->assign('InputRepeatFreqVal',$event_repeat_freq);
1332 $tpl->assign('repeat_freq',$repeat_freq);
1334 $in = array(_PC_EVERY_DAY
,_PC_EVERY_WORKDAY
,_PC_EVERY_WEEK
,_PC_EVERY_MONTH
,_PC_EVERY_YEAR
);
1335 $keys = array(REPEAT_EVERY_DAY
,REPEAT_EVERY_WORK_DAY
,REPEAT_EVERY_WEEK
,REPEAT_EVERY_MONTH
,REPEAT_EVERY_YEAR
);
1336 $repeat_freq_type = array();
1337 foreach($in as $k=>$v) {
1338 array_push($repeat_freq_type,array('value'=>$keys[$k],
1339 'selected'=>($keys[$k]==$event_repeat_freq_type?
'selected':''),
1342 $tpl->assign('InputRepeatFreqType','event_repeat_freq_type');
1343 $tpl->assign('repeat_freq_type',$repeat_freq_type);
1345 $tpl->assign('InputRepeatOn', 'event_repeat');
1346 $tpl->assign('ValueRepeatOn', '2');
1347 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ?
'checked':'');
1350 $in = array(_PC_EVERY_1ST
,_PC_EVERY_2ND
,_PC_EVERY_3RD
,_PC_EVERY_4TH
,_PC_EVERY_LAST
);
1351 $keys = array(REPEAT_ON_1ST
,REPEAT_ON_2ND
,REPEAT_ON_3RD
,REPEAT_ON_4TH
,REPEAT_ON_LAST
);
1352 $repeat_on_num = array();
1353 foreach($in as $k=>$v) {
1354 array_push($repeat_on_num,array('value'=>$keys[$k],
1355 'selected'=>($keys[$k]==$event_repeat_on_num?
'selected':''),
1358 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1359 $tpl->assign('repeat_on_num',$repeat_on_num);
1362 $in = array(_PC_EVERY_SUN
,_PC_EVERY_MON
,_PC_EVERY_TUE
,_PC_EVERY_WED
,_PC_EVERY_THU
,_PC_EVERY_FRI
,_PC_EVERY_SAT
);
1363 $keys = array(REPEAT_ON_SUN
,REPEAT_ON_MON
,REPEAT_ON_TUE
,REPEAT_ON_WED
,REPEAT_ON_THU
,REPEAT_ON_FRI
,REPEAT_ON_SAT
);
1364 $repeat_on_day = array();
1365 foreach($in as $k=>$v) {
1366 array_push($repeat_on_day,array('value'=>$keys[$k],
1367 'selected'=>($keys[$k]==$event_repeat_on_day ?
'selected' : ''),
1370 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1371 $tpl->assign('repeat_on_day',$repeat_on_day);
1374 $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
);
1375 $keys = array(REPEAT_ON_MONTH
,REPEAT_ON_2MONTH
,REPEAT_ON_3MONTH
,REPEAT_ON_4MONTH
,REPEAT_ON_6MONTH
,REPEAT_ON_YEAR
);
1376 $repeat_on_freq = array();
1377 foreach($in as $k=>$v) {
1378 array_push($repeat_on_freq,array('value'=>$keys[$k],
1379 'selected'=>($keys[$k] == $event_repeat_on_freq ?
'selected' : ''),
1382 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1383 if(empty($event_repeat_on_freq) ||
$event_repeat_on_freq < 1) $event_repeat_on_freq = 1;
1384 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1385 $tpl->assign('repeat_on_freq',$repeat_on_freq);
1386 $tpl->assign('MonthsTitle',_PC_MONTHS
);
1388 //=================================================================
1389 // PARSE INPUT_END_DATE
1390 //=================================================================
1391 $tpl->assign('InputEndOn', 'event_endtype');
1392 $tpl->assign('ValueEndOn', '1');
1393 $tpl->assign('SelectedEndOn', (int) $event_endtype==1 ?
'checked':'');
1394 //=================================================================
1395 // PARSE INPUT_NO_END
1396 //=================================================================
1397 $tpl->assign('InputNoEnd', 'event_endtype');
1398 $tpl->assign('ValueNoEnd', '0');
1399 $tpl->assign('SelectedNoEnd', (int) $event_endtype==0 ?
'checked':'');
1400 $qstring = preg_replace("/provider_id=[0-9]*[&]{0,1}/","",$_SERVER['QUERY_STRING']);
1401 $tpl->assign('qstring', $qstring);
1403 $output->SetOutputMode(_PNH_RETURNOUTPUT
);
1404 $authkey = $output->FormHidden('authid',pnSecGenAuthKey());
1405 $output->SetOutputMode(_PNH_KEEPOUTPUT
);
1407 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1408 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1409 $form_hidden .= "<input type=\"hidden\" name=\"category\" value=\"$cat\" />";
1410 if(isset($data_loaded)) {
1411 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1412 $tpl->assign('FormHidden',$form_hidden);
1414 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1415 '.$authkey.'<input type="submit" name="submit" value="go">' ;
1416 $tpl->assign('FormSubmit',$form_submit);
1418 // do not cache this page
1420 $output->Text($tpl->fetch($template_name.'/admin/submit.html'));
1422 //check flag no_nav, if true use much smaller submit form for find_patient.php, etc
1423 elseif (pnVarCleanFromInput("no_nav") == 1) {
1424 $output->Text($tpl->fetch($template_name.'/user/submit_no_nav.html'));
1426 $output->Text($tpl->fetch($template_name.'/user/submit.html'));
1428 $output->Text(postcalendar_footer());
1429 return $output->GetOutput();
1432 function &postcalendar_userapi_pcGetEventDetails($eid)
1438 list($dbconn) = pnDBGetConn();
1439 $pntable = pnDBGetTables();
1441 // link to the events tables
1442 $table = $pntable['postcalendar_events'];
1443 $cattable = $pntable['postcalendar_categories'];
1445 $sql = "SELECT DISTINCT e.pc_eid,
1473 FROM ($table e, $cattable c)
1474 LEFT JOIN patient_data as pd ON (pd.pid = e.pc_pid)
1475 WHERE (e.pc_eid = '$eid' AND c.pc_catid = e.pc_catid)";
1477 $result = $dbconn->Execute($sql);
1478 if($dbconn->ErrorNo() != 0) {
1479 die ($dbconn->ErrorMsg());
1482 if(!isset($result)) {
1485 list($event['eid'], $event['uname'], $event['catid'],
1486 $event['title'], $event['time'], $event['hometext'],
1487 $event['eventDate'], $event['duration'], $event['endDate'],
1488 $event['startTime'], $event['recurrtype'], $event['recurrfreq'],
1489 $event['recurrspec'], $event['topic'], $event['alldayevent'],
1490 $event['location'], $event['conttel'], $event['contname'],
1491 $event['contemail'], $event['website'], $event['fee'], $event['sharing'],
1492 $event['catcolor'], $event['catname'], $event['catdesc'], $event['pid'], $event['aid'],$event['pubpid']) = $result->fields
;
1493 // there has to be a more intelligent way to do this
1494 @list
($event['duration_hours'],$dmin) = @explode
('.',($event['duration']/60/60));
1495 $event['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1496 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1498 //pennfirm fix to reflect openemr user/informant
1499 $userid = pnUserGetVar('uid');
1501 // get the user id of event's author
1502 $users = pnUserGetAll();
1503 foreach($users as $user) {
1504 if($user['uname'] == $event['uname']) {
1505 $cuserid = $user['uid'];
1511 // is this a public event to be shown as busy?
1512 if($event['sharing'] == SHARING_PRIVATE
&& $cuserid != $userid) {
1513 // they are not supposed to see this
1515 } elseif($event['sharing'] == SHARING_BUSY
&& $cuserid != $userid) {
1516 // make it not display any information
1517 $event['title'] = _USER_BUSY_TITLE
;
1518 $event['hometext'] = _USER_BUSY_MESSAGE
;
1519 $event['location'] = '';
1520 $event['conttel'] = '';
1521 $event['contname'] = '';
1522 $event['contemail'] = '';
1523 $event['website'] = '';
1526 $event['title'] = $event['title'];
1527 $event['hometext'] = $event['hometext'];
1528 $event['location'] = $event['location'];
1529 $event['conttel'] = $event['conttel'];
1530 $event['contname'] = $event['contname'];
1531 $event['contemail'] = $event['contemail'];
1532 $event['website'] = $event['website'];
1533 $event['fee'] = $event['fee'];
1535 $event['desc'] = $event['hometext'];
1536 $event['website'] = $event['website'];
1537 if (!empty($event['pid']))
1538 $event['patient_name'] = getPatientName($event['pid']);
1539 if (empty($event['aid']))
1546 * postcalendar_userapi_eventDetail
1547 * Creates the detailed event display and outputs html.
1548 * Accepts an array of key/value pairs
1549 * @param int $eid the id of the event to display
1550 * @return string html output
1553 function postcalendar_adminapi_eventDetail($args) { return postcalendar_userapi_eventDetail($args,true); }
1554 function postcalendar_userapi_eventDetail($args,$admin=false)
1556 if(!(bool)PC_ACCESS_READ
) { return _POSTCALENDARNOAUTH
; }
1557 // get the theme globals :: is there a better way to do this?
1558 pnThemeLoad(pnUserGetTheme());
1559 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
1560 global $textcolor1, $textcolor2;
1561 $popup = pnVarCleanFromInput('popup');
1562 extract($args); unset($args);
1563 if(!isset($cacheid)) $cacheid = null;
1567 if(!isset($nopop)) {
1571 $uid = pnUserGetVar('uid');
1572 //=================================================================
1573 // Find out what Template we're using
1574 //=================================================================
1575 $template_name = _SETTING_TEMPLATE
;
1576 if(!isset($template_name)) {
1577 $template_name = 'default';
1579 //=================================================================
1580 // Setup Smarty Template Engine
1581 //=================================================================
1582 $tpl = new pcSmarty();
1585 $template = $template_name.'/admin/details.html';
1586 $args['cacheid'] = '';
1588 $Date =& postcalendar_getDate();
1589 $tpl->caching
= false;
1591 $template = $template_name.'/user/details.html';
1594 if(!$tpl->is_cached($template,$cacheid)) {
1595 // let's get the DB information
1596 list($dbconn) = pnDBGetConn();
1597 $pntable = pnDBGetTables();
1598 // get the event's information
1599 $event =& postcalendar_userapi_pcGetEventDetails($eid);
1600 // if the above is false, it's a private event for another user
1601 // we should not diplay this - so we just exit gracefully
1602 if($event === false) { return false; }
1603 //=================================================================
1604 // get event's topic information
1605 //=================================================================
1606 $topics_table = $pntable['topics'];
1607 $topics_column = $pntable['topics_column'];
1608 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
1610 WHERE $topics_column[topicid] = $event[topic]
1612 $topic_result = $dbconn->Execute($topicsql);
1613 list($event['topictext'],$event['topicimg']) = $topic_result->fields
;
1614 $location = unserialize($event['location']);
1615 $event['location'] = $location['event_location'];
1616 $event['street1'] = $location['event_street1'];
1617 $event['street2'] = $location['event_street2'];
1618 $event['city'] = $location['event_city'];
1619 $event['state'] = $location['event_state'];
1620 $event['postal'] = $location['event_postal'];
1621 $event['date'] = str_replace('-','',$Date);
1622 //=================================================================
1623 // populate the template
1624 //=================================================================
1625 if(!empty($event['location']) ||
!empty($event['street1']) ||
1626 !empty($event['street2']) ||
!empty($event['city']) ||
1627 !empty($event['state']) ||
!empty($event['postal'])) {
1628 $tpl->assign('LOCATION_INFO',true);
1630 $tpl->assign('LOCATION_INFO',false);
1632 if(!empty($event['contname']) ||
!empty($event['contemail']) ||
1633 !empty($event['conttel']) ||
!empty($event['website'])) {
1634 $tpl->assign('CONTACT_INFO',true);
1636 $tpl->assign('CONTACT_INFO',false);
1638 $display_type = substr($event['hometext'],0,6);
1639 if($display_type == ':text:') {
1640 $prepFunction = 'pcVarPrepForDisplay';
1641 $event['hometext'] = substr($event['hometext'],6);
1642 } elseif($display_type == ':html:') {
1643 $prepFunction = 'pcVarPrepHTMLDisplay';
1644 $event['hometext'] = substr($event['hometext'],6);
1646 $prepFunction = 'pcVarPrepHTMLDisplay';
1648 unset($display_type);
1649 // prep the vars for output
1650 $event['title'] =& $prepFunction($event['title']);
1651 $event['hometext'] =& $prepFunction($event['hometext']);
1652 $event['desc'] =& $event['hometext'];
1653 $event['conttel'] =& $prepFunction($event['conttel']);
1654 $event['contname'] =& $prepFunction($event['contname']);
1655 $event['contemail'] =& $prepFunction($event['contemail']);
1656 $event['website'] =& $prepFunction(postcalendar_makeValidURL($event['website']));
1657 $event['fee'] =& $prepFunction($event['fee']);
1658 $event['location'] =& $prepFunction($event['location']);
1659 $event['street1'] =& $prepFunction($event['street1']);
1660 $event['street2'] =& $prepFunction($event['street2']);
1661 $event['city'] =& $prepFunction($event['city']);
1662 $event['state'] =& $prepFunction($event['state']);
1663 $event['postal'] =& $prepFunction($event['postal']);
1665 $tpl->assign_by_ref('A_EVENT',$event);
1666 //=================================================================
1667 // populate the template $ADMIN_OPTIONS
1668 //=================================================================
1670 if(_SETTING_OPEN_NEW_WINDOW
) {
1671 $target = 'target="csCalendar"';
1674 $admin_edit_url = $admin_delete_url = '';
1675 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN
)) {
1676 $admin_edit_url = pnModURL(__POSTCALENDAR__
,'admin','submit',array('pc_event_id'=>$eid));
1677 $admin_delete_url = pnModURL(__POSTCALENDAR__
,'admin','adminevents',array('action'=>_ACTION_DELETE
,'pc_event_id'=>$eid));
1679 $user_edit_url = $user_delete_url = '';
1680 if(pnUserLoggedIn()) {
1681 $logged_in_uname = $_SESSION['authUser'];
1683 $logged_in_uname = '';
1688 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADD
) && validateGroupStatus($logged_in_uname,getUsername($event['uname']))) {
1690 $user_edit_url = pnModURL(__POSTCALENDAR__
,'user','submit',array('pc_event_id'=>$eid));
1691 $user_delete_url = pnModURL(__POSTCALENDAR__
,'user','delete',array('pc_event_id'=>$eid));
1694 $tpl->assign('STYLE',$GLOBALS['style']);
1695 $tpl->assign_by_ref('ADMIN_TARGET',$target);
1696 $tpl->assign_by_ref('ADMIN_EDIT',$admin_edit_url);
1697 $tpl->assign_by_ref('ADMIN_DELETE',$admin_delete_url);
1698 $tpl->assign_by_ref('USER_TARGET',$target);
1699 $tpl->assign_by_ref('USER_EDIT',$user_edit_url);
1700 $tpl->assign_by_ref('USER_DELETE',$user_delete_url);
1701 $tpl->assign_by_ref('USER_CAN_EDIT',$can_edit);
1703 //=================================================================
1704 // Parse the template
1705 //=================================================================
1706 if($popup != 1 && $print != 1) {
1707 $output = "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1708 $output .= $tpl->fetch($template,$cacheid);
1709 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1711 $theme = pnUserGetTheme();
1712 echo "<html><head>";
1713 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
1714 echo "<style type=\"text/css\">\n";
1715 echo "@import url(\"themes/$theme/style/style.css\"); ";
1717 echo "</head><body>\n";
1718 $tpl->display($template,$cacheid);
1719 echo postcalendar_footer();
1720 echo "\n</body></html>";
1721 session_write_close();
1728 function postcalendar_footer()
1730 // lets get the module's information
1731 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__
));
1732 //$footer = "<p align=\"right\"><a href=\"http://www.postcalendar.tv\">PostCalendar v$modinfo[version]</a></p>";
1737 function postcalendar_smarty_pc_sort_day($params, &$smarty)
1742 $smarty->trigger_error("sort_array: missing 'var' parameter");
1746 if (!in_array('value', array_keys($params))) {
1747 $smarty->trigger_error("sort_array: missing 'value' parameter");
1751 if (!in_array('order', array_keys($params))) {
1755 if (!in_array('inc', array_keys($params))) {
1759 if (!in_array('start', array_keys($params))) {
1763 list($sh,$sm) = explode(':',$start);
1766 if (!in_array('end', array_keys($params))) {
1770 list($eh,$em) = explode(':',$end);
1773 if(strtolower($order) == 'asc') $function = 'sort_byTimeA';
1774 if(strtolower($order) == 'desc') $function = 'sort_byTimeD';
1776 foreach($value as $events) {
1777 usort($events,$function);
1778 $newArray = $events;
1781 // here we want to create an intelligent array of
1782 // columns and rows to build a nice day view
1783 $ch = $sh; $cm = $sm;
1784 while("$ch:$cm" <= "$eh:$em") {
1785 $hours["$ch:$cm"] = array();
1789 $ch = sprintf('%02d',$ch+
1);
1793 $alldayevents = array();
1794 foreach($newArray as $event) {
1795 list($sh,$sm,$ss) = explode(':',$event['startTime']);
1796 $eh = sprintf('%02d',$sh +
$event['duration_hours']);
1797 $em = sprintf('%02d',$sm +
$event['duration_minutes']);
1799 if($event['alldayevent']) {
1800 // we need an entire column . save till later
1801 $alldayevents[] = $event;
1803 //find open time slots - avoid overlapping
1805 $ch = $sh; $cm = $sm;
1806 //what times do we need?
1807 while("$ch:$cm" < "$eh:$em") {
1808 $needed[] = "$ch:$cm";
1812 $ch = sprintf('%02d',$ch+
1);
1816 foreach($needed as $time) {
1818 $hours[$time][] = $event;
1819 $key = count($hours[$time])-1;
1821 $hours[$time][$key] = 'continued';
1827 //pcDebugVar($hours);
1828 $smarty->assign_by_ref($var,$hours);
1831 function sort_byCategoryA($a,$b) {
1832 if($a['catname'] < $b['catname']) return -1;
1833 elseif($a['catname'] > $b['catname']) return 1;
1835 function sort_byCategoryD($a,$b) {
1836 if($a['catname'] < $b['catname']) return 1;
1837 elseif($a['catname'] > $b['catname']) return -1;
1839 function sort_byTitleA($a,$b) {
1840 if($a['title'] < $b['title']) return -1;
1841 elseif($a['title'] > $b['title']) return 1;
1843 function sort_byTitleD($a,$b) {
1844 if($a['title'] < $b['title']) return 1;
1845 elseif($a['title'] > $b['title']) return -1;
1847 function sort_byTimeA($a,$b) {
1848 if($a['startTime'] < $b['startTime']) return -1;
1849 elseif($a['startTime'] > $b['startTime']) return 1;
1851 function sort_byTimeD($a,$b) {
1852 if($a['startTime'] < $b['startTime']) return 1;
1853 elseif($a['startTime'] > $b['startTime']) return -1;
1857 * @param s string text to clean
1858 * @return string cleaned up text
1860 function pc_clean($s)
1862 $display_type = substr($s,0,6);
1863 if($display_type == ':text:') {
1865 } elseif($display_type == ':html:') {
1868 unset($display_type);
1869 $s = preg_replace('/[\r|\n]/i','',$s);
1870 $s = str_replace("'","\'",$s);
1871 $s = str_replace('"','"',$s);
1872 // ok, now we need to break really long lines
1873 // we only want to break at spaces to allow for
1874 // correct interpretation of special characters
1875 $tmp = explode(' ',$s);
1876 return join("'+' ",$tmp);
1879 function &postcalendar_adminapi_getCategoryLimits() { return postcalendar_userapi_getCategoryLimits(); }
1880 function &postcalendar_userapi_getCategoryLimits()
1882 list($dbconn) = pnDBGetConn();
1883 $pntable = pnDBGetTables();
1884 $cat_table = $pntable['postcalendar_limits'];
1885 $sql = "SELECT pc_limitid,pc_catid,pc_starttime,pc_endtime,
1886 pc_limit FROM $cat_table
1887 ORDER BY pc_limitid";
1888 $result = $dbconn->Execute($sql);
1890 if($dbconn->ErrorNo() != 0) { return array(); }
1891 if(!isset($result)) { return array(); }
1894 for($i=0; !$result->EOF
; $result->MoveNext()) {
1895 list($limitid,$catid,$startTime,$endTime,$limit) = $result->fields
;
1896 // check the category's permissions
1897 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW
)) {
1900 $limits[$i]['limitid'] = $limitid;
1901 $limits[$i]['catid'] = $catid;
1902 $limits[$i]['startTime']= $startTime;
1903 $limits[$i]['endTime'] = $endTime;
1904 $limits[$i++
]['limit'] = $limit;