use calendar widget for date select; remember last viewed calendar date
[openemr.git] / interface / main / calendar / modules / PostCalendar / common.api.php
blob1c0b0145b759599ac4ae5031e58aa281f7887af5
1 <?php
2 /**
3 * $Id$
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);
34 define('_AM_VAL', 1);
35 define('_PM_VAL', 2);
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);
43 // $event_repeat
44 define('NO_REPEAT', 0);
45 define('REPEAT', 1);
46 define('REPEAT_ON', 2);
47 // $event_repeat_freq
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);
84 // admin defines
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");
138 } else {
139 require_once("modules/$pcDir/pnlang/eng/global.php");
141 unset($userlang);
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)
156 echo '<pre>';
157 if(is_array($in)) print_r($in);
158 else echo $in;
159 echo '</pre>';
161 function &pcVarPrepForDisplay($s) {
162 $s = nl2br(pnVarPrepForDisplay(postcalendar_removeScriptTags($s)));
163 $s = preg_replace('/&amp;(#)?([0-9a-z]+);/i','&\\1\\2;',$s);
164 return $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]
177 FROM $topics_table
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)) {
187 $s = 'http://'.$s;
189 return $s;
191 function postcalendar_removeScriptTags($in)
193 return preg_replace("/<script.*?>(.*?)<\/script>/","",$in);
196 function &postcalendar_getDate($format='%Y%m%d')
198 list($Date, $jumpday, $jumpmonth, $jumpyear, $jumpdate) =
199 pnVarCleanFromInput('Date', 'jumpday', 'jumpmonth', 'jumpyear', 'jumpdate');
200 if(!isset($Date)) {
201 // if we still don't have a date then calculate it
202 // check the jump menu, might be a 'jumpdate' input field or m/d/y select lists
203 if ($jumpdate) {
204 $jumpyear = substr($jumpdate,0,4);
205 $jumpmonth = substr($jumpdate,5,2);
206 $jumpday = substr($jumpdate,8,2);
207 } else {
208 if ($_SESSION['lastcaldate']) {
209 $time = strtotime($_SESSION['lastcaldate']);
210 } else {
211 $time = time();
212 if (pnUserLoggedIn())
213 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
215 if(!isset($jumpday)) $jumpday = strftime('%d',$time);
216 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time);
217 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time);
219 // create the correct date string
220 $Date = (int) "$jumpyear$jumpmonth$jumpday";
222 $y = substr($Date,0,4);
223 $m = substr($Date,4,2);
224 $d = substr($Date,6,2);
225 $_SESSION['lastcaldate'] = "$y-$m-$d"; // remember the last chosen date
226 return strftime($format,mktime(0,0,0,$m,$d,$y));
229 function &postcalendar_today($format='%Y%m%d')
231 $time = time();
232 if (pnUserLoggedIn()) {
233 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
235 return strftime($format,$time);
239 * postcalendar_adminapi_pageSetup()
241 * sets up any necessary javascript for the page
242 * @return string javascript to insert into the page
244 function postcalendar_adminapi_pageSetup() { return postcalendar_userapi_pageSetup(); }
246 * postcalendar_userapi_pageSetup()
248 * sets up any necessary javascript for the page
249 * @return string javascript to insert into the page
251 function postcalendar_userapi_pageSetup()
253 $output = '';
254 // load the DHTML JavaScript code and insert it into the page
255 if(_SETTING_USE_POPUPS) { $output .= postcalendar_userapi_loadPopups(); }
256 // insert the js popup code into the page (find better code)
257 if(_SETTING_OPEN_NEW_WINDOW) { $output .= postcalendar_userapi_jsPopup(); }
258 return $output;
261 * postcalendar_userapi_jsPopup
262 * Creates the necessary javascript code for a popup window
264 function postcalendar_userapi_jsPopup()
265 { if(defined('_POSTCALENDAR_JSPOPUPS_LOADED')) {
266 // only put the script on the page once
267 return false;
269 define('_POSTCALENDAR_JSPOPUPS_LOADED',true);
271 // build the correct link
272 $js_link = "'index.php?module=".__POSTCALENDAR__."&type=user&func=view&viewtype=details&eid='+eid+'&Date='+date+'&popup=1'";
273 $js_window_options = 'toolbar=no,'
274 . 'location=no,'
275 . 'directories=no,'
276 . 'status=no,'
277 . 'menubar=no,'
278 . 'scrollbars=yes,'
279 . 'resizable=no,'
280 . 'width=600,'
281 . 'height=300';
283 $output = <<<EOF
285 <script language="javascript">
286 <!--
287 function opencal(eid,date) {
288 window.name='csCalendar';
289 w = window.open($js_link,'PostCalendarEvents','$js_window_options');
291 // -->
292 </script>
294 EOF;
295 return $output;
299 * postcalendar_userapi_loadPopups
300 * Creates the necessary javascript code for mouseover dHTML popups
302 function postcalendar_userapi_loadPopups()
303 { if(defined('_POSTCALENDAR_LOADPOPUPS_LOADED')) {
304 // only put the script on the page once
305 return false;
307 define('_POSTCALENDAR_LOADPOPUPS_LOADED',true);
309 // get the theme globals :: is there a better way to do this?
310 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
311 global $textcolor1, $textcolor2;
313 // lets get the module's information
314 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
315 $pcDir = pnVarPrepForOS($modinfo['directory']);
316 unset($modinfo);
317 $capicon = '';
318 $close = _PC_OL_CLOSE;
320 $output = <<<EOF
322 <script language="JavaScript">
323 <!-- overLIB configuration -->
324 ol_fgcolor = "$bgcolor1";
325 ol_bgcolor = "$bgcolor2";
326 ol_textcolor = "$textcolor2";
327 ol_capcolor = "$textcolor2";
328 ol_closecolor = "$textcolor2";
329 ol_textfont = "Verdana,Arial,Helvetica";
330 ol_captionfont = "Verdana,Arial,Helvetica";
331 ol_captionsize = 2;
332 ol_textsize = 2;
333 ol_border = 2;
334 ol_width = 350;
335 ol_offsetx = 10;
336 ol_offsety = 10;
337 ol_sticky = 0;
338 ol_close = "$close";
339 ol_closeclick = 0;
340 ol_autostatus = 2;
341 ol_snapx = 0;
342 ol_snapy = 0;
343 ol_fixx = -1;
344 ol_fixy = -1;
345 ol_background = "";
346 ol_fgbackground = "";
347 ol_bgbackground = "";
348 ol_padxl = 1;
349 ol_padxr = 1;
350 ol_padyt = 1;
351 ol_padyb = 1;
352 ol_capicon = "$capicon";
353 ol_hauto = 1;
354 ol_vauto = 1;
355 </script>
356 <div id="overDiv" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:1000;"></div>
357 <script language="JavaScript" src="modules/$pcDir/pnincludes/overlib_mini.js">
358 <!-- overLIB (c) Erik Bosrup -->
359 </script>
361 EOF;
362 return $output;
366 * postcalendar_adminapi_getmonthname()
368 * Returns the month name translated for the user's current language
370 * @param array $args['Date'] number of month to return
371 * @return string month name in user's language
373 function postcalendar_adminapi_getmonthname($args) { return postcalendar_userapi_getmonthname($args); }
375 * postcalendar_userapi_getmonthname()
377 * Returns the month name translated for the user's current language
379 * @param array $args['Date'] date to return month name of
380 * @return string month name in user's language
382 function postcalendar_userapi_getmonthname($args)
384 extract($args); unset($args);
385 if(!isset($Date)) { return false; }
386 $month_name = array('01' => _CALJAN, '02' => _CALFEB, '03' => _CALMAR,
387 '04' => _CALAPR, '05' => _CALMAY, '06' => _CALJUN,
388 '07' => _CALJUL, '08' => _CALAUG, '09' => _CALSEP,
389 '10' => _CALOCT, '11' => _CALNOV, '12' => _CALDEC);
390 return $month_name[date('m',$Date)];
393 * Returns an array of form data for FormSelectMultiple
395 function postcalendar_adminapi_buildTimeSelect($args) { return postcalendar_userapi_buildTimeSelect($args); }
396 function postcalendar_userapi_buildTimeSelect($args)
398 $inc = _SETTING_TIME_INCREMENT;
399 extract($args); unset($args);
400 $output = array('h'=>array(),'m'=>array());
401 if((bool)_SETTING_TIME_24HOUR) {
402 $start=0; $end=23;
403 } else {
404 $start=1; $end=12;
405 $hselected = $hselected > 12 ? $hselected-=12 : $hselected;
407 for($c=0,$h=$start; $h<=$end; $h++,$c++) {
408 $hour = sprintf('%02d',$h);
409 $output['h'][$c]['id'] = pnVarPrepForStore($h);
410 $output['h'][$c]['selected'] = $hselected == $hour;
411 $output['h'][$c]['name'] = pnVarPrepForDisplay($hour);
413 for($c=0,$m=0; $m<=(60-$inc);$m+=$inc,$c++) {
414 $min = sprintf('%02d',$m);
415 $output['m'][$c]['id'] = pnVarPrepForStore($m);
416 $output['m'][$c]['selected'] = $mselected == $min;
417 $output['m'][$c]['name'] = pnVarPrepForDisplay($min);
419 return $output;
422 * Returns an array of form data for FormSelectMultiple
424 function postcalendar_adminapi_buildMonthSelect($args) { return postcalendar_userapi_buildMonthSelect($args); }
425 function postcalendar_userapi_buildMonthSelect($args)
427 extract($args); unset($args);
428 if(!isset($pc_month)) { $pc_month = Date_Calc::getMonth(); }
429 // create the return object to be inserted into the form
430 $output = array();
431 if(!isset($selected)) $selected = '';
432 for ($c=0,$i=1;$i<=12;$i++,$c++) {
433 if ($selected) { $sel = $selected == $i ? true : false; }
434 elseif ($i == $pc_month) { $sel = true; }
435 else { $sel = false; }
436 $output[$c]['id'] = sprintf('%02d',$i);
437 $output[$c]['selected'] = $sel;
438 $output[$c]['name'] = postcalendar_userapi_getmonthname(array('Date'=>mktime(0,0,0,$i,15)));
440 return $output;
444 * Returns an array of form data for FormSelectMultiple
446 function postcalendar_adminapi_buildDaySelect($args) { return postcalendar_userapi_buildDaySelect($args); }
447 function postcalendar_userapi_buildDaySelect($args)
449 extract($args); unset($args);
450 if(!isset($pc_day)) { $pc_day = Date_Calc::getDay(); }
451 // create the return object to be inserted into the form
452 $output = array();
453 if(!isset($selected)) $selected = '';
454 for($c=0,$i=1; $i<=31; $i++,$c++) {
455 if ($selected) { $sel = $selected == $i ? true : false; }
456 elseif ($i == $pc_day) { $sel = true; }
457 else { $sel = false; }
458 $output[$c]['id'] = sprintf('%02d',$i);
459 $output[$c]['selected'] = $sel;
460 $output[$c]['name'] = sprintf('%02d',$i);
462 return $output;
466 * Returns an array of form data for FormSelectMultiple
468 function postcalendar_adminapi_buildYearSelect($args) { return postcalendar_userapi_buildYearSelect($args); }
469 function postcalendar_userapi_buildYearSelect($args)
471 extract($args); unset($args);
472 if(!isset($pc_year)) { $pc_year = date('Y'); }
473 // create the return object to be inserted into the form
474 $output = array();
475 // we want the list to contain 10 years before today and 30 years after
476 // maybe this will eventually become a user defined value
477 $pc_start_year = date('Y') - 1;
478 $pc_end_year = date('Y') + 30;
479 if(!isset($selected)) $selected = '';
480 for($c=0,$i=$pc_start_year; $i<=$pc_end_year; $i++,$c++) {
481 if ($selected) { $sel = $selected == $i ? true : false; }
482 elseif ($i == $pc_year) { $sel = true; }
483 else { $sel = false; }
484 $output[$c]['id'] = sprintf('%04d',$i);
485 $output[$c]['selected'] = $sel;
486 $output[$c]['name'] = sprintf('%04d',$i);
488 return $output;
491 function &postcalendar_adminapi_getCategories() { return postcalendar_userapi_getCategories(); }
492 function &postcalendar_userapi_getCategories()
494 list($dbconn) = pnDBGetConn();
495 $pntable = pnDBGetTables();
496 $cat_table = $pntable['postcalendar_categories'];
497 $sql = "SELECT pc_catid,pc_catname,pc_catcolor,pc_catdesc,
498 pc_recurrtype,pc_recurrspec,pc_recurrfreq,pc_duration,
499 pc_dailylimit,pc_end_date_flag,pc_end_date_type,pc_end_date_freq,
500 pc_end_all_day FROM $cat_table
501 ORDER BY pc_catname";
502 $result = $dbconn->Execute($sql);
504 if($dbconn->ErrorNo() != 0) { return array(); }
505 if(!isset($result)) { return array(); }
507 $categories = array();
508 for($i=0; !$result->EOF; $result->MoveNext()) {
509 list($catid,$catname,$catcolor,$catdesc,
510 $rtype,$rspec,$rfreq,$duration,$limit,$end_date_flag,
511 $end_date_type,$end_date_freq,$end_all_day) = $result->fields;
512 // check the category's permissions
513 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW)) {
514 continue;
516 $categories[$i]['id'] = $catid;
517 $categories[$i]['name'] = $catname;
518 $categories[$i]['color'] = $catcolor;
519 $categories[$i]['desc'] = $catdesc;
520 $categories[$i]['event_repeat'] = $rtype;
521 $rspecs = unserialize($rspec);
522 $categories[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
523 $categories[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
524 $categories[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
525 $categories[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
526 $categories[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
527 $categories[$i]['event_recurrspec'] = $rspecs;
528 $categories[$i]['event_duration'] = $duration;
529 $categories[$i]['event_durationh'] = (int)($duration/(60 * 60)); //seconds divided by 60 seconds * 60 minutes;
530 $categories[$i]['event_durationm'] = ($duration%(60 * 60))/60;
531 $categories[$i]['end_date_flag'] = $end_date_flag;
532 $categories[$i]['end_date_type'] = $end_date_type;
533 $categories[$i]['end_date_freq'] = $end_date_freq;
534 $categories[$i]['end_all_day'] = $end_all_day;
535 $categories[$i++]['dailylimit'] = $limit;
538 $result->Close();
539 return $categories;
542 function &postcalendar_adminapi_getTopics() { return postcalendar_userapi_getTopics(); }
543 function &postcalendar_userapi_getTopics()
545 list($dbconn) = pnDBGetConn();
546 $pntable = pnDBGetTables();
547 $topics_table = $pntable['topics'];
548 $topics_column = &$pntable['topics_column'];
549 $sql = "SELECT $topics_column[topicid], $topics_column[topictext], $topics_column[topicname]
550 FROM $topics_table
551 ORDER BY $topics_column[topictext]";
552 $topiclist = $dbconn->Execute($sql);
553 if($dbconn->ErrorNo() != 0) {
554 return false;
556 $data = array();
557 $i=0;
558 for(;!$topiclist->EOF;$topiclist->MoveNext()) {
559 // check topic permissions
560 if(pnSecAuthAction(0,'PostCalendar::Topic',$topiclist->fields[2].'::'.$topiclist->fields[0],ACCESS_OVERVIEW)) {
561 list($data[$i]['id'], $data[$i]['text'], $data[$i++]['name']) = $topiclist->fields;
564 $topiclist->Close();
565 return $data;
569 * postcalendar_adminapi_submitEvent()
570 * submit an event
571 * @param $args array of event data
572 * @return bool true on success : false on failure;
574 function postcalendar_adminapi_submitEvent($args) { return postcalendar_userapi_submitEvent($args); }
576 * postcalendar_userapi_submitEvent()
577 * submit an event
578 * @param $args array of event data
579 * @return bool true on success : false on failure;
581 function postcalendar_userapi_submitEvent($args)
583 extract($args); unset($args);
585 list($dbconn) = pnDBGetConn();
586 $pntable = pnDBGetTables();
588 // determine if the event is to be published immediately or not
589 //also whether is a special system only event i.e. _EVENT_TEMPORARY
590 if (empty($event_status)) {
591 if( (bool) _SETTING_DIRECT_SUBMIT || (bool) PC_ACCESS_ADMIN || ($event_sharing != SHARING_GLOBAL) ) {
592 $event_status = _EVENT_APPROVED;
593 } else {
594 $event_status = _EVENT_QUEUED;
597 elseif ($event_status == _EVENT_TEMPORARY) {
598 $event_status = _EVENT_TEMPORARY;
600 else {
601 $event_status = _EVENT_QUEUED;
605 // set up some vars for the insert statement
606 $startDate = $event_startyear.'-'.$event_startmonth.'-'.$event_startday;
607 if($event_endtype == 1) {
608 $endDate = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
609 } else {
610 $endDate = '0000-00-00';
613 if(!isset($event_allday)) $event_allday = 0;
614 if((bool)_SETTING_TIME_24HOUR) {
615 $startTime = $event_starttimeh.':'.$event_starttimem.':00';
616 } else {
617 if($event_startampm == _AM_VAL) {
618 $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
619 } else {
620 $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
622 $startTime = sprintf('%02d',$event_starttimeh).':'.sprintf('%02d',$event_starttimem).':00';
624 if ($event_allday == 1) {
625 $endTime = "24:00:00";
627 else {
628 $endTime = date("H:i:00",($event_duration + strtotime($startTime)));
631 // get rid of variables we no longer need to save memory
632 unset($event_startyear,$event_startmonth,$event_startday,$event_endyear,$event_endmonth,
633 $event_endday,$event_starttimeh,$event_starttimem);
635 //pennfirm users need to be able to enter apps for different providers, this isn't aoplicable
636 /*if(pnUserLoggedIn()) {
637 $event_userid = pnUserGetVar('uid');
638 } else {
639 $event_userid = 0;
643 if($pc_html_or_text == 'html') {
644 $event_desc = ':html:'.$event_desc;
645 } else {
646 $event_desc = ':text:'.$event_desc;
648 list($event_subject,$event_desc,$event_topic,$startDate,$endDate,
649 $event_repeat,$startTime,$event_allday,$event_category,
650 $event_location_info,$event_conttel,$event_contname,
651 $event_contemail,$event_website,$event_fee,$event_status,
652 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
653 $pc_event_id) = @pnVarPrepForStore($event_subject,$event_desc,$event_topic,$startDate,$endDate,
654 $event_repeat,$startTime,$event_allday,$event_category,
655 $event_location_info,$event_conttel,$event_contname,
656 $event_contemail,$event_website,$event_fee,$event_status,
657 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
658 $pc_event_id);
660 if(!isset($is_update)) { $is_update = false; }
661 if($is_update) {
662 $sql = "UPDATE $pntable[postcalendar_events]
663 SET pc_title = '$event_subject',
664 pc_hometext = '$event_desc',
665 pc_topic = '$event_topic',
666 pc_eventDate = '$startDate',
667 pc_endDate = '$endDate',
668 pc_recurrtype = '$event_repeat',
669 pc_startTime = '$startTime',
670 pc_endTime = '$endTime',
671 pc_alldayevent = '$event_allday',
672 pc_catid = '$event_category',
673 pc_location = '$event_location_info',
674 pc_conttel = '$event_conttel',
675 pc_contname = '$event_contname',
676 pc_contemail = '$event_contemail',
677 pc_website = '$event_website',
678 pc_fee = '$event_fee',
679 pc_eventstatus = '$event_status',
680 pc_recurrspec = '$event_recurrspec',
681 pc_duration = '$event_duration',
682 pc_sharing = '$event_sharing',
683 pc_aid = '$event_userid',
684 pc_pid = '$event_pid'
685 WHERE pc_eid = '$pc_event_id'";
686 } else {
687 $pc_event_id = $dbconn->GenId($pntable['postcalendar_events']);
688 $sql = "INSERT INTO $pntable[postcalendar_events] (
689 pc_eid,
690 pc_title,
691 pc_time,
692 pc_hometext,
693 pc_topic,
694 pc_informant,
695 pc_eventDate,
696 pc_endDate,
697 pc_recurrtype,
698 pc_startTime,
699 pc_endTime,
700 pc_alldayevent,
701 pc_catid,
702 pc_location,
703 pc_conttel,
704 pc_contname,
705 pc_contemail,
706 pc_website,
707 pc_fee,
708 pc_eventstatus,
709 pc_recurrspec,
710 pc_duration,
711 pc_sharing,
712 pc_aid,
713 pc_pid)
714 VALUES (
715 '$pc_event_id',
716 '$event_subject',
717 NOW(),
718 '$event_desc',
719 '$event_topic',
720 " . $_SESSION['authUserID'] . ",
721 '$startDate',
722 '$endDate',
723 '$event_repeat',
724 '$startTime',
725 '$endTime',
726 '$event_allday',
727 '$event_category',
728 '$event_location_info',
729 '$event_conttel',
730 '$event_contname',
731 '$event_contemail',
732 '$event_website',
733 '$event_fee',
734 '$event_status',
735 '$event_recurrspec',
736 '$event_duration',
737 '$event_sharing',
738 '$event_userid',
739 '$event_pid'
742 $result = $dbconn->Execute($sql);
743 if($result === false) {
744 return false;
745 } else {
746 if((bool)$is_update) {
747 $eid = $pc_event_id;
748 } else {
749 $eid = $dbconn->PO_Insert_ID($pntable['postcalendar_events'],'pc_eid');
751 pc_notify($eid,$is_update);
752 return true;
756 function pc_notify($eid,$is_update)
758 if(!(bool)_SETTING_NOTIFY_ADMIN) { return true; }
760 $subject = _PC_NOTIFY_SUBJECT;
762 if((bool)$is_update) {
763 $message = _PC_NOTIFY_UPDATE_MSG;
764 } else {
765 $message = _PC_NOTIFY_NEW_MSG;
768 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
769 $modversion = pnVarPrepForOS($modinfo['version']);
770 unset($modinfo);
772 $message .= pnModURL(__POSTCALENDAR__,'admin','adminevents',array('pc_event_id'=>$eid,'action'=>_ADMIN_ACTION_VIEW));
773 $message .= "\n\n\n\n";
774 $message .= "----\n";
775 $message .= "PostCalendar $modversion\n";
776 $message .= "http://www.postcalendar.tv";
778 mail(_SETTING_NOTIFY_EMAIL,$subject,$message,
779 "From: " . _SETTING_NOTIFY_EMAIL . "\r\n"
780 ."X-Mailer: PHP/" . phpversion() . "\r\n"
781 ."X-Mailer: PostCalendar/$modversion" );
783 return true;
787 function findFirstAvailable($period) {
788 //print_r($period);
790 $day_date = "";
791 $available_times = array();
792 foreach ($period as $date => $day) {
793 //echo "begin free times for $date:<br />";
794 $ffid_res = findFirstInDay($day,$date);
795 foreach($ffid_res as $times) {
796 //echo "starting: " . date("h:i:s A",$times['startTime']) . " long: " . $times['duration'] . "<br />";
797 $available_times[$date][] = $times;
798 //echo "count of times is:" . count($available_times) . "<br />";
800 //echo "end free times for $date";
803 return $available_times;
806 function findFirstInDay($day,$date) {
807 $stack = array();
808 $lastcat = 3;
809 $intime = false;
810 $outtime = false;
811 foreach ($day as $event) {
812 //echo "event is: " . $event['title'] . " cat is: " .$event['catid'] . " event date is: " . $date . "<br />";
814 if ($event['catid'] == 2) { //catid 2 is reserved to represent "In Office" events, id 3 is "Out Of Office"
815 $intime = $event['startTime'];
816 //echo "setting in: $intime<br />";
818 elseif ($event['catid'] == 3) {
820 $outtime = $event['startTime'];
821 //echo "setting out: $outtime<br />";
824 if ($intime == false or $outtime == false) {
825 return array();
828 //echo "increment is: " . _SETTING_TIME_INCREMENT . "<br />";
829 $inc = (_SETTING_TIME_INCREMENT * 60);
830 //$inc = 60;
831 $intime_sec = date("U",strtotime($date . " " . $intime));
832 $outtime_sec = date("U",strtotime($date . " " . $outtime));
833 $free_time = $intime_sec;
835 $times = array();
836 for ($i = $intime_sec; $i < $outtime_sec; $i += $inc) {
837 //echo "time is now: " . date("h:i:s A",$i) . "<br />";
838 $closest_start = $outtime_sec;
839 $timeclear = false;
840 foreach($day as $event) {
841 if ($event['catid'] != 2) {
843 $estart = dtSec($date,$event['startTime']) ;
844 $eend = dtSecDur($date, $event['startTime'], $event['duration']);
846 if ($eend < $intime_sec or $estart > $outtime_sec) {
847 //event ends before intime or starts after outtime we don't care move on;
848 continue;
850 elseif ($eend < $i ) {
851 //event ended before time currently being evaluated, we don't care move on;
852 continue;
854 elseif ($estart < $i and $eend > $i) {
855 //event occupies part of the time we are looking at, look at another time
856 continue;
858 elseif ($estart >= $i) {
859 //echo "tin: " . date("h:i:s A",$i) . " estart: " . date("h:i:s A",$estart) . "<br />";
861 //echo "ev: " . $event['title'] . " s at:" . date("h:i:s A",$estart) . " e at: " . date("h:i:s A",$eend) ." <br />";
862 //some amount of time is free set closest time
863 $oldfreetime = $closest_start - $i;
864 $newfreetime = $estart - $i;
866 //echo "old free: " . $oldfreetime . "<br />";
867 //echo "new free: " . $newfreetime . "<br />";
868 //echo "duration is: " . ($estart - $i) . " cs:$estart i:$i<br />";
869 if ($newfreetime < $oldfreetime && ($estart - $i) != 0) {
870 $free_time = $i;
871 $closest_start = $estart;
873 //echo "set time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
874 if ($i < ($eend - $inc))
875 $i = ($eend - $inc);
877 elseif($newfreetime <= $oldfreetime && $oldfreetime == ($outtime_sec - $i)) {
878 $free_time = $i;
879 $closest_start = $estart;
881 //echo "time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
882 if ($i < ($eend - $inc))
883 $i = ($eend - $inc);
886 //echo "closest start: " . date("h:i:s A",$closest_start) . "<br />";
893 if ($closest_start > ($intime_sec + 60)) {
894 //echo "free time is: " . date("h:i:s A",$free_time) . "<br />";
895 //echo "next app is: " . date("h:i:s A",$closest_start) . "<br />";
896 $duration = ($closest_start - $free_time);
897 //echo "duration is: $duration<br />";
898 //we allow for 0 duration events so other things such as overlap and actual times can be calculated
899 //this happens because people want to be able to set 8:00 - 8:15 and 8:15 - 8:30 without a conflict
900 //even though that is technially impossible, so we pretend, however here we weed out the 0
901 //length blocks so that won't be seen
902 $date_sec = strtotime ($date);
903 if ($duration > 0) {
904 $times[] = array ("startTime" => $free_time, "endTime" => ($date_sec+$duration));
908 return $times;
912 function dtSec ($date, $time) {
913 return date("U",strtotime($date . " " . $time));
916 function dtSecDur ($date, $time, $dur) {
917 $time_sec = date("U",strtotime($date . " " . $time));
918 return $time_sec + $dur;
922 * postcalendar_adminapi_buildSubmitForm()
923 * create event submit form
925 function postcalendar_adminapi_buildSubmitForm($args) { return postcalendar_userapi_buildSubmitForm($args,true); }
927 * postcalendar_userapi_buildSubmitForm()
928 * create event submit form
930 function postcalendar_userapi_buildSubmitForm($args,$admin=false)
932 $_SESSION['category'] = "";
933 if(!PC_ACCESS_ADD) { return _POSTCALENDARNOAUTH; }
934 extract($args); unset($args);
935 //since we seem to clobber category
936 $cat = $category;
937 $output =& new pnHTML();
938 $output->SetInputMode(_PNH_VERBATIMINPUT);
939 // set up Smarty
940 $tpl =& new pcSmarty();
941 $tpl->caching = false;
943 $template_name = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
945 if(!isset($template_name)) {
946 $template_name ='default';
949 //=================================================================
950 // Setup the correct config file path for the templates
951 //=================================================================
952 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
953 $modir = pnVarPrepForOS($modinfo['directory']);
954 $modname = $modinfo['displayname'];
955 $all_categories =& pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
956 //print_r($all_categories);
957 unset($modinfo);
958 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
959 //=================================================================
960 // PARSE MAIN
961 //=================================================================
964 $tpl->assign('webroot', $GLOBALS['web_root']);
965 $tpl->assign_by_ref('TPL_NAME',$template_name);
966 $tpl->assign('FUNCTION',pnVarCleanFromInput('func'));
967 $tpl->assign_by_ref('ModuleName', $modname);
968 $tpl->assign_by_ref('ModuleDirectory', $modir);
969 $tpl->assign_by_ref('category',$all_categories);
970 $tpl->assign('NewEventHeader', _PC_NEW_EVENT_HEADER);
971 $tpl->assign('EventTitle', _PC_EVENT_TITLE);
972 $tpl->assign('Required', _PC_REQUIRED);
973 $tpl->assign('DateTimeTitle', _PC_DATE_TIME);
974 $tpl->assign('AlldayEventTitle', _PC_ALLDAY_EVENT);
975 $tpl->assign('TimedEventTitle', _PC_TIMED_EVENT);
976 $tpl->assign('TimedDurationTitle', _PC_TIMED_DURATION);
977 $tpl->assign('TimedDurationHoursTitle', _PC_TIMED_DURATION_HOURS);
978 $tpl->assign('TimedDurationMinutesTitle',_PC_TIMED_DURATION_MINUTES);
979 $tpl->assign('EventDescTitle', _PC_EVENT_DESC);
981 //the double book variable comes from the eventdata array that is
982 //passed here and extracted, injection is not an issue here
983 if (is_numeric($double_book)) {
984 $tpl->assign('double_book', $double_book);
987 //pennfirm begin patient info handling
988 $ProviderID = pnVarCleanFromInput("provider_id");
989 if (is_numeric($ProviderID)) {
990 $tpl->assign('ProviderID', $ProviderID);
991 $tpl->assign('provider_id', $ProviderID);
993 elseif(is_numeric($event_userid) && $event_userid != 0) {
994 $tpl->assign('ProviderID', $event_userid);
995 $tpl->assign('provider_id', $event_userid);
997 else {
998 if ($_SESSION['userauthorized'] == 1)
999 $tpl->assign('ProviderID', $_SESSION['authUserID']);
1000 else
1001 $tpl->assign('ProviderID', "");
1003 $provinfo = getProviderInfo();
1004 $tpl->assign('providers', $provinfo);
1005 $PatientID = pnVarCleanFromInput("patient_id");
1006 if (is_numeric($PatientID)) {
1007 $tpl->assign('PatientList', getPatientPID($PatientID));
1009 elseif (is_numeric($event_pid)) {
1010 $tpl->assign('PatientList', getPatientPID($event_pid));
1012 else {
1013 $tpl->assign('PatientList', getPatientPID());
1015 $tpl->assign('event_pid', $event_pid);
1016 $tpl->assign('event_aid', $event_aid);
1017 $tpl->assign('event_category', pnVarCleanFromInput("event_category"));
1019 if(empty($event_patient_name))
1021 $patient_data = getPatientData($event_pid, $given = "lname, fname");
1022 $event_patient_name = $patient_data['lname'].", ".$patient_data['fname'];
1024 $tpl->assign('patient_value', $event_patient_name);
1026 //=================================================================
1027 // PARSE INPUT_EVENT_TITLE
1028 //=================================================================
1029 $tpl->assign('InputEventTitle', 'event_subject');
1030 $tpl->assign('ValueEventTitle', pnVarPrepForDisplay($event_subject));
1032 //=================================================================
1033 // PARSE SELECT_DATE_TIME
1034 //=================================================================
1036 // It seems that with Mozilla at least, <select> fields that are disabled
1037 // do not get passed as form data. Therefore we ignore $double_book so
1038 // that the fields will not be disabled. -- Rod 2005-03-22
1040 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1041 if(_SETTING_USE_INT_DATES) {
1042 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1043 $formdata = $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1044 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1045 $formdata .= $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1046 } else {
1047 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_startmonth));
1048 $formdata = $output->FormSelectMultiple('event_startmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1049 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_startday));
1050 $formdata .= $output->FormSelectMultiple('event_startday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1052 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_startyear));
1053 $formdata .= $output->FormSelectMultiple('event_startyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1054 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1055 $tpl->assign('SelectDateTime', $formdata);
1056 $tpl->assign('InputAllday', 'event_allday');
1057 $tpl->assign('ValueAllday', '1');
1058 $tpl->assign('SelectedAllday', $event_allday==1 ? 'checked':'');
1059 $tpl->assign('InputTimed', 'event_allday');
1060 $tpl->assign('ValueTimed', '0');
1061 $tpl->assign('SelectedTimed', $event_allday==0 ? 'checked':'');
1062 $tpl->assign('STYLE',$GLOBALS['style']);
1064 //=================================================================
1065 // PARSE SELECT_END_DATE_TIME
1066 //=================================================================
1067 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1068 //if there is no end date we want the box to read todays date instead of jan 01 1994 :)
1069 if($event_endmonth == 0 && $event_endday ==0 && $event_endyear ==0){
1070 $event_endmonth =$month;
1071 $event_endday = $day ;
1072 $event_endyear = $year;
1074 if(_SETTING_USE_INT_DATES) {
1075 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1077 $formdata = $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1078 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1079 $formdata .= $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1080 } else {
1082 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildMonthSelect',array('pc_month'=>$month,'selected'=>$event_endmonth));
1083 $formdata = $output->FormSelectMultiple('event_endmonth', $sel_data,0,1,"","",false,/* $double_book*/ '');
1084 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildDaySelect',array('pc_day'=>$day,'selected'=>$event_endday));
1085 $formdata .= $output->FormSelectMultiple('event_endday', $sel_data,0,1,"","",false,/* $double_book*/ '');
1087 $sel_data = pnModAPIFunc(__POSTCALENDAR__,'user','buildYearSelect',array('pc_year'=>$year,'selected'=>$event_endyear));
1088 $formdata .= $output->FormSelectMultiple('event_endyear', $sel_data,0,1,"","",false,/* $double_book*/ '');
1089 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1090 $tpl->assign('SelectEndDate', $formdata);
1091 //=================================================================
1092 // PARSE SELECT_TIMED_EVENT
1093 //=================================================================
1094 $stimes = pnModAPIFunc(__POSTCALENDAR__,'user','buildTimeSelect',array('hselected'=>$event_starttimeh,'mselected'=>$event_starttimem));
1095 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1096 $timed_hours = $output->FormSelectMultiple('event_starttimeh', $stimes['h'],0,1,"","",false,/* $double_book*/ '');
1097 $timed_minutes = $output->FormSelectMultiple('event_starttimem', $stimes['m'],0,1,"","",false,/* $double_book*/ '');
1098 if(!_SETTING_TIME_24HOUR) {
1099 $ampm = array();
1100 $ampm[0]['id'] = pnVarPrepForStore(_AM_VAL);
1101 $ampm[0]['name'] = pnVarPrepForDisplay(_PC_AM);
1102 $ampm[1]['id'] = pnVarPrepForStore(_PM_VAL);
1103 $ampm[1]['name'] = pnVarPrepForDisplay(_PC_PM);
1104 if($event_startampm == "AM" || $event_startampm == _AM_VAL)
1106 $ampm[0]['selected'] = 1;
1108 else
1110 $ampm[1]['selected'] = 1;
1112 $timed_ampm = $output->FormSelectMultiple('event_startampm', $ampm,0,1,"","",false,/* $double_book*/ '');
1113 } else {
1114 $timed_ampm = '';
1116 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1117 $tpl->assign('SelectTimedHours', $timed_hours);
1118 $tpl->assign('SelectTimedMinutes', $timed_minutes);
1119 $tpl->assign('SelectTimedAMPM', $timed_ampm);
1120 $tpl->assign('event_startday', $event_startday);
1121 $tpl->assign('event_startmonth', $event_startmonth);
1122 $tpl->assign('event_startyear', $event_startyear);
1123 $tpl->assign('event_starttimeh', $event_starttimeh);
1124 $tpl->assign('event_starttimem', $event_starttimem);
1125 $tpl->assign('event_startampm', $event_startampm);
1126 $tpl->assign('event_dur_hours', $event_dur_hours);
1127 $tpl->assign('event_dur_minutes', $event_dur_minutes);
1129 //=================================================================
1130 // PARSE SELECT_DURATION
1131 //=================================================================
1132 $event_dur_hours = (int) $event_dur_hours;
1134 for($i=0; $i<=24; $i+=1) {
1135 $TimedDurationHours[$i] = array('value'=>$i,
1136 'selected'=>($event_dur_hours==$i ? 'selected':''),
1137 'name'=>sprintf('%02d',$i));
1140 $tpl->assign('TimedDurationHours',$TimedDurationHours);
1141 $tpl->assign('InputTimedDurationHours', 'event_dur_hours');
1142 $found_time = false;
1143 for($i=0; $i<60; $i+=_SETTING_TIME_INCREMENT) {
1144 $TimedDurationMinutes[$i] = array('value'=>$i,
1145 'selected'=>($event_dur_minutes==$i ? 'selected':''),
1146 'name'=>sprintf('%02d',$i));
1147 if( $TimedDurationMinutes[$i]['selected'] == 'selected' )
1148 $found_time = true;
1151 if(!$found_time)
1152 $TimedDurationMinutes[$i] = array('value'=>$event_dur_minutes,
1153 'selected'=>'selected',
1154 'name'=>sprintf('%02d',$event_dur_minutes));
1155 $tpl->assign('TimedDurationMinutes',$TimedDurationMinutes);
1156 $tpl->assign('hidden_event_dur_minutes',$event_dur_minutes);
1157 $tpl->assign('InputTimedDurationMinutes', 'event_dur_minutes');
1158 //=================================================================
1159 // PARSE INPUT_EVENT_DESC
1160 //=================================================================
1161 $tpl->assign('InputEventDesc', 'event_desc');
1162 if(empty($pc_html_or_text)) {
1163 $display_type = substr($event_desc,0,6);
1164 if($display_type == ':text:') {
1165 $pc_html_or_text = 'text';
1166 $event_desc = substr($event_desc,6);
1167 } elseif($display_type == ':html:') {
1168 $pc_html_or_text = 'html';
1169 $event_desc = substr($event_desc,6);
1170 } else {
1171 $pc_html_or_text = 'text';
1173 unset($display_type);
1175 $tpl->assign('ValueEventDesc', pnVarPrepForDisplay($event_desc));
1176 $eventHTMLorText = "<select name=\"pc_html_or_text\">";
1177 if($pc_html_or_text == 'text') {
1178 $eventHTMLorText .= "<option value=\"text\" selected=\"selected\">"._PC_SUBMIT_TEXT."</option>";
1179 } else {
1180 $eventHTMLorText .= "<option value=\"text\">"._PC_SUBMIT_TEXT."</option>";
1182 if($pc_html_or_text == 'html') {
1183 $eventHTMLorText .= "<option value=\"html\" selected=\"selected\">"._PC_SUBMIT_HTML."</option>";
1184 } else {
1185 $eventHTMLorText .= "<option value=\"html\">"._PC_SUBMIT_HTML."</option>";
1187 $eventHTMLorText .= "</select>";
1188 $tpl->assign('EventHTMLorText',$eventHTMLorText);
1189 //=================================================================
1190 // PARSE select_event_topic_block
1191 //=================================================================
1192 $tpl->assign('displayTopics',_SETTING_DISPLAY_TOPICS);
1193 if((bool)_SETTING_DISPLAY_TOPICS) {
1194 $a_topics =& postcalendar_userapi_getTopics();
1195 $topics = array();
1196 foreach($a_topics as $topic) {
1197 array_push($topics,array('value'=>$topic['id'],
1198 'selected'=>($topic['id']==$event_topic ? 'selected':''),
1199 'name'=>$topic['text']));
1201 unset($a_topics);
1202 // only show this if we have topics to show
1203 if(count($topics) > 0) {
1204 $tpl->assign('topics',$topics);
1205 $tpl->assign('EventTopicTitle', _PC_EVENT_TOPIC);
1206 $tpl->assign('InputEventTopic', 'event_topic');
1209 //=================================================================
1210 // PARSE select_event_type_block
1211 //=================================================================
1212 $categories = array();
1213 foreach($all_categories as $category) {
1214 array_push($categories,array('value'=>$category['id'],
1215 'selected'=>($category['id']==$event_category ? 'selected' : ''),
1216 'name'=>$category['name'],
1217 'color'=>$category['color'],
1218 'desc'=>$category['desc']));
1220 // only show this if we have categories to show
1221 // you should ALWAYS have at least one valid category
1222 if(count($categories) > 0) {
1223 $tpl->assign('categories',$categories);
1224 $tpl->assign('EventCategoriesTitle', _PC_EVENT_CATEGORY);
1225 $tpl->assign('InputEventCategory', 'event_category');
1226 $tpl->assign('hidden_event_category', $event_category);
1228 //=================================================================
1229 // PARSE event_sharing_block
1230 //=================================================================
1231 $data = array();
1232 if(_SETTING_ALLOW_USER_CAL) {
1233 array_push($data,array(SHARING_PRIVATE,_PC_SHARE_PRIVATE));
1234 array_push($data,array(SHARING_PUBLIC,_PC_SHARE_PUBLIC));
1235 array_push($data,array(SHARING_BUSY,_PC_SHARE_SHOWBUSY));
1237 if(pnSecAuthAction(0,'PostCalendar::', '::', ACCESS_ADMIN) || _SETTING_ALLOW_GLOBAL || !_SETTING_ALLOW_USER_CAL) {
1238 array_push($data,array(SHARING_GLOBAL,_PC_SHARE_GLOBAL));
1240 $sharing = array();
1241 foreach($data as $cell) {
1242 array_push($sharing,array('value'=>$cell[0],
1243 'selected'=>((int) $event_sharing == $cell[0] ? 'selected' : ''),
1244 'name'=>$cell[1]));
1247 //pennfirm get list of providers from openemr code in calendar.inc
1248 $tpl->assign("user",getCalendarProviderInfo());
1251 $tpl->assign('sharing',$sharing);
1252 $tpl->assign('EventSharingTitle', _PC_SHARING);
1253 $tpl->assign('InputEventSharing','event_sharing');
1254 //=================================================================
1255 // location information
1256 //=================================================================
1257 $tpl->assign('EventLocationTitle', _PC_EVENT_LOCATION);
1258 $tpl->assign('InputLocation', 'event_location');
1259 $tpl->assign('ValueLocation', pnVarPrepForDisplay($event_location));
1260 $tpl->assign('EventStreetTitle', _PC_EVENT_STREET);
1261 $tpl->assign('InputStreet1', 'event_street1');
1262 $tpl->assign('ValueStreet1', pnVarPrepForDisplay($event_street1));
1263 $tpl->assign('InputStreet2', 'event_street2');
1264 $tpl->assign('ValueStreet2', pnVarPrepForDisplay($event_street2));
1265 $tpl->assign('EventCityTitle', _PC_EVENT_CITY);
1266 $tpl->assign('InputCity', 'event_city');
1267 $tpl->assign('ValueCity', pnVarPrepForDisplay($event_city));
1268 $tpl->assign('EventStateTitle', _PC_EVENT_STATE);
1269 $tpl->assign('InputState', 'event_state');
1270 $tpl->assign('ValueState', pnVarPrepForDisplay($event_state));
1271 $tpl->assign('EventPostalTitle', _PC_EVENT_POSTAL);
1272 $tpl->assign('InputPostal', 'event_postal');
1273 $tpl->assign('ValuePostal', pnVarPrepForDisplay($event_postal));
1274 //=================================================================
1275 // contact information
1276 //=================================================================
1277 $tpl->assign('EventContactTitle', _PC_EVENT_CONTACT);
1278 $tpl->assign('InputContact', 'event_contname');
1279 $tpl->assign('ValueContact', pnVarPrepForDisplay($event_contname));
1280 $tpl->assign('EventPhoneTitle', _PC_EVENT_PHONE);
1281 $tpl->assign('InputPhone', 'event_conttel');
1282 $tpl->assign('ValuePhone', pnVarPrepForDisplay($event_conttel));
1283 $tpl->assign('EventEmailTitle', _PC_EVENT_EMAIL);
1284 $tpl->assign('InputEmail', 'event_contemail');
1285 $tpl->assign('ValueEmail', pnVarPrepForDisplay($event_contemail));
1286 $tpl->assign('EventWebsiteTitle', _PC_EVENT_WEBSITE);
1287 $tpl->assign('InputWebsite', 'event_website');
1288 $tpl->assign('ValueWebsite', pnVarPrepForDisplay($event_website));
1289 $tpl->assign('EventFeeTitle', _PC_EVENT_FEE);
1290 $tpl->assign('InputFee', 'event_fee');
1291 $tpl->assign('ValueFee', pnVarPrepForDisplay($event_fee));
1292 //=================================================================
1293 // Repeating Information
1294 //=================================================================
1295 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
1296 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
1297 $tpl->assign('RepeatTitle', _PC_REPEAT);
1298 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
1299 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
1300 $tpl->assign('EndDateTitle', _PC_END_DATE);
1301 $tpl->assign('NoEndDateTitle', _PC_NO_END);
1302 $tpl->assign('InputNoRepeat', 'event_repeat');
1303 $tpl->assign('ValueNoRepeat', '0');
1304 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
1305 $tpl->assign('InputRepeat', 'event_repeat');
1306 $tpl->assign('ValueRepeat', '1');
1307 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
1309 unset($in);
1310 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
1311 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
1312 $repeat_freq = array();
1313 foreach($in as $k=>$v) {
1314 array_push($repeat_freq,array('value'=>$keys[$k],
1315 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
1316 'name'=>$v));
1318 $tpl->assign('InputRepeatFreq','event_repeat_freq');
1319 if(empty($event_repeat_freq) || $event_repeat_freq < 1) $event_repeat_freq = 1;
1320 $tpl->assign('InputRepeatFreqVal',$event_repeat_freq);
1321 $tpl->assign('repeat_freq',$repeat_freq);
1322 unset($in);
1323 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
1324 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
1325 $repeat_freq_type = array();
1326 foreach($in as $k=>$v) {
1327 array_push($repeat_freq_type,array('value'=>$keys[$k],
1328 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
1329 'name'=>$v));
1331 $tpl->assign('InputRepeatFreqType','event_repeat_freq_type');
1332 $tpl->assign('repeat_freq_type',$repeat_freq_type);
1334 $tpl->assign('InputRepeatOn', 'event_repeat');
1335 $tpl->assign('ValueRepeatOn', '2');
1336 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
1338 unset($in);
1339 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
1340 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
1341 $repeat_on_num = array();
1342 foreach($in as $k=>$v) {
1343 array_push($repeat_on_num,array('value'=>$keys[$k],
1344 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
1345 'name'=>$v));
1347 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1348 $tpl->assign('repeat_on_num',$repeat_on_num);
1350 unset($in);
1351 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
1352 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
1353 $repeat_on_day = array();
1354 foreach($in as $k=>$v) {
1355 array_push($repeat_on_day,array('value'=>$keys[$k],
1356 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
1357 'name'=>$v));
1359 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1360 $tpl->assign('repeat_on_day',$repeat_on_day);
1362 unset($in);
1363 $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);
1364 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
1365 $repeat_on_freq = array();
1366 foreach($in as $k=>$v) {
1367 array_push($repeat_on_freq,array('value'=>$keys[$k],
1368 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
1369 'name'=>$v));
1371 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1372 if(empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) $event_repeat_on_freq = 1;
1373 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1374 $tpl->assign('repeat_on_freq',$repeat_on_freq);
1375 $tpl->assign('MonthsTitle',_PC_MONTHS);
1377 //=================================================================
1378 // PARSE INPUT_END_DATE
1379 //=================================================================
1380 $tpl->assign('InputEndOn', 'event_endtype');
1381 $tpl->assign('ValueEndOn', '1');
1382 $tpl->assign('SelectedEndOn', (int) $event_endtype==1 ? 'checked':'');
1383 //=================================================================
1384 // PARSE INPUT_NO_END
1385 //=================================================================
1386 $tpl->assign('InputNoEnd', 'event_endtype');
1387 $tpl->assign('ValueNoEnd', '0');
1388 $tpl->assign('SelectedNoEnd', (int) $event_endtype==0 ? 'checked':'');
1389 $qstring = preg_replace("/provider_id=[0-9]*[&]{0,1}/","",$_SERVER['QUERY_STRING']);
1390 $tpl->assign('qstring', $qstring);
1392 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1393 $authkey = $output->FormHidden('authid',pnSecGenAuthKey());
1394 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1396 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1397 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1398 $form_hidden .= "<input type=\"hidden\" name=\"category\" value=\"$cat\" />";
1399 if(isset($data_loaded)) {
1400 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1401 $tpl->assign('FormHidden',$form_hidden);
1403 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1404 '.$authkey.'<input type="submit" name="submit" value="go">' ;
1405 $tpl->assign('FormSubmit',$form_submit);
1407 // do not cache this page
1408 if($admin) {
1409 $output->Text($tpl->fetch($template_name.'/admin/submit.html'));
1411 //check flag no_nav, if true use much smaller submit form for find_patient.php, etc
1412 elseif (pnVarCleanFromInput("no_nav") == 1) {
1413 $output->Text($tpl->fetch($template_name.'/user/submit_no_nav.html'));
1414 } else {
1415 $output->Text($tpl->fetch($template_name.'/user/submit.html'));
1417 $output->Text(postcalendar_footer());
1418 return $output->GetOutput();
1421 function &postcalendar_userapi_pcGetEventDetails($eid)
1424 if(!isset($eid)) {
1425 return false;
1427 list($dbconn) = pnDBGetConn();
1428 $pntable = pnDBGetTables();
1430 // link to the events tables
1431 $table = $pntable['postcalendar_events'];
1432 $cattable = $pntable['postcalendar_categories'];
1434 $sql = "SELECT DISTINCT e.pc_eid,
1435 e.pc_informant,
1436 e.pc_catid,
1437 e.pc_title,
1438 e.pc_time,
1439 e.pc_hometext,
1440 e.pc_eventDate,
1441 e.pc_duration,
1442 e.pc_endDate,
1443 e.pc_startTime,
1444 e.pc_recurrtype,
1445 e.pc_recurrfreq,
1446 e.pc_recurrspec,
1447 e.pc_topic,
1448 e.pc_alldayevent,
1449 e.pc_location,
1450 e.pc_conttel,
1451 e.pc_contname,
1452 e.pc_contemail,
1453 e.pc_website,
1454 e.pc_fee,
1455 e.pc_sharing,
1456 c.pc_catcolor,
1457 c.pc_catname,
1458 c.pc_catdesc,
1459 e.pc_pid,
1460 e.pc_aid,
1461 pd.pubpid
1462 FROM $table e, $cattable c
1463 LEFT JOIN patient_data as pd on pd.pid = e.pc_pid
1464 WHERE e.pc_eid = '$eid' AND c.pc_catid = e.pc_catid";
1466 $result = $dbconn->Execute($sql);
1467 if($dbconn->ErrorNo() != 0) {
1468 die ($dbconn->ErrorMsg());
1470 $event = array();
1471 if(!isset($result)) {
1472 return $event;
1474 list($event['eid'], $event['uname'], $event['catid'],
1475 $event['title'], $event['time'], $event['hometext'],
1476 $event['eventDate'], $event['duration'], $event['endDate'],
1477 $event['startTime'], $event['recurrtype'], $event['recurrfreq'],
1478 $event['recurrspec'], $event['topic'], $event['alldayevent'],
1479 $event['location'], $event['conttel'], $event['contname'],
1480 $event['contemail'], $event['website'], $event['fee'], $event['sharing'],
1481 $event['catcolor'], $event['catname'], $event['catdesc'], $event['pid'], $event['aid'],$event['pubpid']) = $result->fields;
1482 // there has to be a more intelligent way to do this
1483 @list($event['duration_hours'],$dmin) = @explode('.',($event['duration']/60/60));
1484 $event['duration_minutes'] = substr(sprintf('%.2f','.' . 60*($dmin/100)),2,2);
1485 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1486 $result->Close();
1487 //pennfirm fix to reflect openemr user/informant
1488 $userid = pnUserGetVar('uid');
1490 // get the user id of event's author
1491 $users = pnUserGetAll();
1492 foreach($users as $user) {
1493 if($user['uname'] == $event['uname']) {
1494 $cuserid = $user['uid'];
1495 break;
1498 unset($users);
1500 // is this a public event to be shown as busy?
1501 if($event['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
1502 // they are not supposed to see this
1503 return false;
1504 } elseif($event['sharing'] == SHARING_BUSY && $cuserid != $userid) {
1505 // make it not display any information
1506 $event['title'] = _USER_BUSY_TITLE;
1507 $event['hometext'] = _USER_BUSY_MESSAGE;
1508 $event['location'] = '';
1509 $event['conttel'] = '';
1510 $event['contname'] = '';
1511 $event['contemail'] = '';
1512 $event['website'] = '';
1513 $event['fee'] = '';
1514 } else {
1515 $event['title'] = $event['title'];
1516 $event['hometext'] = $event['hometext'];
1517 $event['location'] = $event['location'];
1518 $event['conttel'] = $event['conttel'];
1519 $event['contname'] = $event['contname'];
1520 $event['contemail'] = $event['contemail'];
1521 $event['website'] = $event['website'];
1522 $event['fee'] = $event['fee'];
1524 $event['desc'] = $event['hometext'];
1525 $event['website'] = $event['website'];
1526 if (!empty($event['pid']))
1527 $event['patient_name'] = getPatientName($event['pid']);
1528 if (empty($event['aid']))
1529 $event['aid']= -1;
1531 return $event;
1535 * postcalendar_userapi_eventDetail
1536 * Creates the detailed event display and outputs html.
1537 * Accepts an array of key/value pairs
1538 * @param int $eid the id of the event to display
1539 * @return string html output
1540 * @access public
1542 function postcalendar_adminapi_eventDetail($args) { return postcalendar_userapi_eventDetail($args,true); }
1543 function postcalendar_userapi_eventDetail($args,$admin=false)
1545 if(!(bool)PC_ACCESS_READ) { return _POSTCALENDARNOAUTH; }
1546 // get the theme globals :: is there a better way to do this?
1547 pnThemeLoad(pnUserGetTheme());
1548 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
1549 global $textcolor1, $textcolor2;
1550 $popup = pnVarCleanFromInput('popup');
1551 extract($args); unset($args);
1552 if(!isset($cacheid)) $cacheid = null;
1553 if(!isset($eid)) {
1554 return false;
1556 if(!isset($nopop)) {
1557 $nopop = false;
1560 $uid = pnUserGetVar('uid');
1561 //=================================================================
1562 // Find out what Template we're using
1563 //=================================================================
1564 $template_name = _SETTING_TEMPLATE;
1565 if(!isset($template_name)) {
1566 $template_name = 'default';
1568 //=================================================================
1569 // Setup Smarty Template Engine
1570 //=================================================================
1571 $tpl =& new pcSmarty();
1573 if($admin) {
1574 $template = $template_name.'/admin/details.html';
1575 $args['cacheid'] = '';
1576 $print=0;
1577 $Date =& postcalendar_getDate();
1578 $tpl->caching = false;
1579 } else {
1580 $template = $template_name.'/user/details.html';
1583 if(!$tpl->is_cached($template,$cacheid)) {
1584 // let's get the DB information
1585 list($dbconn) = pnDBGetConn();
1586 $pntable = pnDBGetTables();
1587 // get the event's information
1588 $event =& postcalendar_userapi_pcGetEventDetails($eid);
1589 // if the above is false, it's a private event for another user
1590 // we should not diplay this - so we just exit gracefully
1591 if($event === false) { return false; }
1592 //=================================================================
1593 // get event's topic information
1594 //=================================================================
1595 $topics_table = $pntable['topics'];
1596 $topics_column = $pntable['topics_column'];
1597 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
1598 FROM $topics_table
1599 WHERE $topics_column[topicid] = $event[topic]
1600 LIMIT 1";
1601 $topic_result = $dbconn->Execute($topicsql);
1602 list($event['topictext'],$event['topicimg']) = $topic_result->fields;
1603 $location = unserialize($event['location']);
1604 $event['location'] = $location['event_location'];
1605 $event['street1'] = $location['event_street1'];
1606 $event['street2'] = $location['event_street2'];
1607 $event['city'] = $location['event_city'];
1608 $event['state'] = $location['event_state'];
1609 $event['postal'] = $location['event_postal'];
1610 $event['date'] = str_replace('-','',$Date);
1611 //=================================================================
1612 // populate the template
1613 //=================================================================
1614 if(!empty($event['location']) || !empty($event['street1']) ||
1615 !empty($event['street2']) || !empty($event['city']) ||
1616 !empty($event['state']) || !empty($event['postal'])) {
1617 $tpl->assign('LOCATION_INFO',true);
1618 } else {
1619 $tpl->assign('LOCATION_INFO',false);
1621 if(!empty($event['contname']) || !empty($event['contemail']) ||
1622 !empty($event['conttel']) || !empty($event['website'])) {
1623 $tpl->assign('CONTACT_INFO',true);
1624 } else {
1625 $tpl->assign('CONTACT_INFO',false);
1627 $display_type = substr($event['hometext'],0,6);
1628 if($display_type == ':text:') {
1629 $prepFunction = 'pcVarPrepForDisplay';
1630 $event['hometext'] = substr($event['hometext'],6);
1631 } elseif($display_type == ':html:') {
1632 $prepFunction = 'pcVarPrepHTMLDisplay';
1633 $event['hometext'] = substr($event['hometext'],6);
1634 } else {
1635 $prepFunction = 'pcVarPrepHTMLDisplay';
1637 unset($display_type);
1638 // prep the vars for output
1639 $event['title'] =& $prepFunction($event['title']);
1640 $event['hometext'] =& $prepFunction($event['hometext']);
1641 $event['desc'] =& $event['hometext'];
1642 $event['conttel'] =& $prepFunction($event['conttel']);
1643 $event['contname'] =& $prepFunction($event['contname']);
1644 $event['contemail'] =& $prepFunction($event['contemail']);
1645 $event['website'] =& $prepFunction(postcalendar_makeValidURL($event['website']));
1646 $event['fee'] =& $prepFunction($event['fee']);
1647 $event['location'] =& $prepFunction($event['location']);
1648 $event['street1'] =& $prepFunction($event['street1']);
1649 $event['street2'] =& $prepFunction($event['street2']);
1650 $event['city'] =& $prepFunction($event['city']);
1651 $event['state'] =& $prepFunction($event['state']);
1652 $event['postal'] =& $prepFunction($event['postal']);
1654 $tpl->assign_by_ref('A_EVENT',$event);
1655 //=================================================================
1656 // populate the template $ADMIN_OPTIONS
1657 //=================================================================
1658 $target='';
1659 if(_SETTING_OPEN_NEW_WINDOW) {
1660 $target = 'target="csCalendar"';
1663 $admin_edit_url = $admin_delete_url = '';
1664 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN)) {
1665 $admin_edit_url = pnModURL(__POSTCALENDAR__,'admin','submit',array('pc_event_id'=>$eid));
1666 $admin_delete_url = pnModURL(__POSTCALENDAR__,'admin','adminevents',array('action'=>_ACTION_DELETE,'pc_event_id'=>$eid));
1668 $user_edit_url = $user_delete_url = '';
1669 if(pnUserLoggedIn()) {
1670 $logged_in_uname = $_SESSION['authUser'];
1671 } else {
1672 $logged_in_uname = '';
1676 $can_edit = false;
1677 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADD) && validateGroupStatus($logged_in_uname,getUsername($event['uname']))) {
1679 $user_edit_url = pnModURL(__POSTCALENDAR__,'user','submit',array('pc_event_id'=>$eid));
1680 $user_delete_url = pnModURL(__POSTCALENDAR__,'user','delete',array('pc_event_id'=>$eid));
1681 $can_edit = true;
1683 $tpl->assign('STYLE',$GLOBALS['style']);
1684 $tpl->assign_by_ref('ADMIN_TARGET',$target);
1685 $tpl->assign_by_ref('ADMIN_EDIT',$admin_edit_url);
1686 $tpl->assign_by_ref('ADMIN_DELETE',$admin_delete_url);
1687 $tpl->assign_by_ref('USER_TARGET',$target);
1688 $tpl->assign_by_ref('USER_EDIT',$user_edit_url);
1689 $tpl->assign_by_ref('USER_DELETE',$user_delete_url);
1690 $tpl->assign_by_ref('USER_CAN_EDIT',$can_edit);
1692 //=================================================================
1693 // Parse the template
1694 //=================================================================
1695 if($popup != 1 && $print != 1) {
1696 $output = "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1697 $output .= $tpl->fetch($template,$cacheid);
1698 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1699 } else {
1700 $theme = pnUserGetTheme();
1701 echo "<html><head>";
1702 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
1703 echo "<style type=\"text/css\">\n";
1704 echo "@import url(\"themes/$theme/style/style.css\"); ";
1705 echo "</style>\n";
1706 echo "</head><body>\n";
1707 $tpl->display($template,$cacheid);
1708 echo postcalendar_footer();
1709 echo "\n</body></html>";
1710 session_write_close();
1711 exit;
1714 return $output;
1717 function postcalendar_footer()
1719 // lets get the module's information
1720 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1721 //$footer = "<p align=\"right\"><a href=\"http://www.postcalendar.tv\">PostCalendar v$modinfo[version]</a></p>";
1722 $footer = "";
1723 return $footer;
1726 function postcalendar_smarty_pc_sort_day($params, &$smarty)
1728 extract($params);
1730 if (empty($var)) {
1731 $smarty->trigger_error("sort_array: missing 'var' parameter");
1732 return;
1735 if (!in_array('value', array_keys($params))) {
1736 $smarty->trigger_error("sort_array: missing 'value' parameter");
1737 return;
1740 if (!in_array('order', array_keys($params))) {
1741 $order = 'asc';
1744 if (!in_array('inc', array_keys($params))) {
1745 $inc = '15';
1748 if (!in_array('start', array_keys($params))) {
1749 $sh = '08';
1750 $sm = '00';
1751 } else {
1752 list($sh,$sm) = explode(':',$start);
1755 if (!in_array('end', array_keys($params))) {
1756 $eh = '21';
1757 $em = '00';
1758 } else {
1759 list($eh,$em) = explode(':',$end);
1762 if(strtolower($order) == 'asc') $function = 'sort_byTimeA';
1763 if(strtolower($order) == 'desc') $function = 'sort_byTimeD';
1765 foreach($value as $events) {
1766 usort($events,$function);
1767 $newArray = $events;
1770 // here we want to create an intelligent array of
1771 // columns and rows to build a nice day view
1772 $ch = $sh; $cm = $sm;
1773 while("$ch:$cm" <= "$eh:$em") {
1774 $hours["$ch:$cm"] = array();
1775 $cm += $inc;
1776 if($cm >= 60) {
1777 $cm = '00';
1778 $ch = sprintf('%02d',$ch+1);
1782 $alldayevents = array();
1783 foreach($newArray as $event) {
1784 list($sh,$sm,$ss) = explode(':',$event['startTime']);
1785 $eh = sprintf('%02d',$sh + $event['duration_hours']);
1786 $em = sprintf('%02d',$sm + $event['duration_minutes']);
1788 if($event['alldayevent']) {
1789 // we need an entire column . save till later
1790 $alldayevents[] = $event;
1791 } else {
1792 //find open time slots - avoid overlapping
1793 $needed = array();
1794 $ch = $sh; $cm = $sm;
1795 //what times do we need?
1796 while("$ch:$cm" < "$eh:$em") {
1797 $needed[] = "$ch:$cm";
1798 $cm += $inc;
1799 if($cm >= 60) {
1800 $cm = '00';
1801 $ch = sprintf('%02d',$ch+1);
1804 $i = 0;
1805 foreach($needed as $time) {
1806 if($i==0) {
1807 $hours[$time][] = $event;
1808 $key = count($hours[$time])-1;
1809 } else {
1810 $hours[$time][$key] = 'continued';
1812 $i++;
1816 //pcDebugVar($hours);
1817 $smarty->assign_by_ref($var,$hours);
1820 function sort_byCategoryA($a,$b) {
1821 if($a['catname'] < $b['catname']) return -1;
1822 elseif($a['catname'] > $b['catname']) return 1;
1824 function sort_byCategoryD($a,$b) {
1825 if($a['catname'] < $b['catname']) return 1;
1826 elseif($a['catname'] > $b['catname']) return -1;
1828 function sort_byTitleA($a,$b) {
1829 if($a['title'] < $b['title']) return -1;
1830 elseif($a['title'] > $b['title']) return 1;
1832 function sort_byTitleD($a,$b) {
1833 if($a['title'] < $b['title']) return 1;
1834 elseif($a['title'] > $b['title']) return -1;
1836 function sort_byTimeA($a,$b) {
1837 if($a['startTime'] < $b['startTime']) return -1;
1838 elseif($a['startTime'] > $b['startTime']) return 1;
1840 function sort_byTimeD($a,$b) {
1841 if($a['startTime'] < $b['startTime']) return 1;
1842 elseif($a['startTime'] > $b['startTime']) return -1;
1845 * pc_clean
1846 * @param s string text to clean
1847 * @return string cleaned up text
1849 function pc_clean($s)
1851 $display_type = substr($s,0,6);
1852 if($display_type == ':text:') {
1853 $s = substr($s,6);
1854 } elseif($display_type == ':html:') {
1855 $s = substr($s,6);
1857 unset($display_type);
1858 $s = preg_replace('/[\r|\n]/i','',$s);
1859 $s = str_replace("'","\'",$s);
1860 $s = str_replace('"','&quot;',$s);
1861 // ok, now we need to break really long lines
1862 // we only want to break at spaces to allow for
1863 // correct interpretation of special characters
1864 $tmp = explode(' ',$s);
1865 return join("'+' ",$tmp);
1868 function &postcalendar_adminapi_getCategoryLimits() { return postcalendar_userapi_getCategoryLimits(); }
1869 function &postcalendar_userapi_getCategoryLimits()
1871 list($dbconn) = pnDBGetConn();
1872 $pntable = pnDBGetTables();
1873 $cat_table = $pntable['postcalendar_limits'];
1874 $sql = "SELECT pc_limitid,pc_catid,pc_starttime,pc_endtime,
1875 pc_limit FROM $cat_table
1876 ORDER BY pc_limitid";
1877 $result = $dbconn->Execute($sql);
1879 if($dbconn->ErrorNo() != 0) { return array(); }
1880 if(!isset($result)) { return array(); }
1882 $limits = array();
1883 for($i=0; !$result->EOF; $result->MoveNext()) {
1884 list($limitid,$catid,$startTime,$endTime,$limit) = $result->fields;
1885 // check the category's permissions
1886 if (!pnSecAuthAction(0,'PostCalendar::Category',"$catname::$catid",ACCESS_OVERVIEW)) {
1887 continue;
1889 $limits[$i]['limitid'] = $limitid;
1890 $limits[$i]['catid'] = $catid;
1891 $limits[$i]['startTime']= $startTime;
1892 $limits[$i]['endTime'] = $endTime;
1893 $limits[$i++]['limit'] = $limit;
1895 $result->Close();
1896 return $limits;