Highway to PSR2
[openemr.git] / interface / main / calendar / modules / PostCalendar / common.api.php
blob9d9432ef9966b5fb5e24675cc39eb97c12dbc000
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 define('REPEAT_DAYS', 3);
48 // $event_repeat_freq
49 define('REPEAT_EVERY', 1);
50 define('REPEAT_EVERY_OTHER', 2);
51 define('REPEAT_EVERY_THIRD', 3);
52 define('REPEAT_EVERY_FOURTH', 4);
53 // $event_repeat_freq_type
54 define('REPEAT_EVERY_DAY', 0);
55 define('REPEAT_EVERY_WEEK', 1);
56 define('REPEAT_EVERY_MONTH', 2);
57 define('REPEAT_EVERY_YEAR', 3);
58 define('REPEAT_EVERY_WORK_DAY', 4);
59 // $event_repeat_on_num
60 define('REPEAT_ON_1ST', 1);
61 define('REPEAT_ON_2ND', 2);
62 define('REPEAT_ON_3RD', 3);
63 define('REPEAT_ON_4TH', 4);
64 define('REPEAT_ON_LAST', 5);
65 // $event_repeat_on_day
66 define('REPEAT_ON_SUN', 0);
67 define('REPEAT_ON_MON', 1);
68 define('REPEAT_ON_TUE', 2);
69 define('REPEAT_ON_WED', 3);
70 define('REPEAT_ON_THU', 4);
71 define('REPEAT_ON_FRI', 5);
72 define('REPEAT_ON_SAT', 6);
73 // $event_repeat_on_freq
74 define('REPEAT_ON_MONTH', 1);
75 define('REPEAT_ON_2MONTH', 2);
76 define('REPEAT_ON_3MONTH', 3);
77 define('REPEAT_ON_4MONTH', 4);
78 define('REPEAT_ON_6MONTH', 6);
79 define('REPEAT_ON_YEAR', 12);
80 // event sharing values
81 define('SHARING_PRIVATE', 0);
82 define('SHARING_PUBLIC', 1);
83 define('SHARING_BUSY', 2);
84 define('SHARING_GLOBAL', 3);
85 // $cat_type
86 define('TYPE_ON_PATIENT', 0);
87 define('TYPE_ON_PROVIDER', 1);
88 define('TYPE_ON_CLINIC', 2);
89 define('TYPE_ON_THERAPY_GROUP', 3);
90 // admin defines
91 define('_ADMIN_ACTION_APPROVE', 0);
92 define('_ADMIN_ACTION_HIDE', 1);
93 define('_ADMIN_ACTION_EDIT', 2);
94 define('_ADMIN_ACTION_VIEW', 3);
95 define('_ADMIN_ACTION_DELETE', 4);
96 //=================================================================
97 // Get the global PostCalendar config settings
98 // This will save us a lot of time and DB queries later
99 //=================================================================
100 define('_SETTING_USE_POPUPS', pnModGetVar(__POSTCALENDAR__, 'pcUsePopups'));
101 define('_SETTING_USE_INT_DATES', pnModGetVar(__POSTCALENDAR__, 'pcUseInternationalDates'));
102 define('_SETTING_OPEN_NEW_WINDOW', pnModGetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow'));
103 define('_SETTING_DAY_HICOLOR', pnModGetVar(__POSTCALENDAR__, 'pcDayHighlightColor'));
104 define('_SETTING_FIRST_DAY_WEEK', pnModGetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek'));
105 define('_SETTING_DATE_FORMAT', pnModGetVar(__POSTCALENDAR__, 'pcEventDateFormat'));
106 define('_SETTING_TIME_24HOUR', pnModGetVar(__POSTCALENDAR__, 'pcTime24Hours'));
107 define('_SETTING_DIRECT_SUBMIT', pnModGetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit'));
108 define('_SETTING_DISPLAY_TOPICS', pnModGetVar(__POSTCALENDAR__, 'pcDisplayTopics'));
109 define('_SETTING_ALLOW_GLOBAL', pnModGetVar(__POSTCALENDAR__, 'pcAllowSiteWide'));
110 define('_SETTING_ALLOW_USER_CAL', pnModGetVar(__POSTCALENDAR__, 'pcAllowUserCalendar'));
111 define('_SETTING_TIME_INCREMENT', pnModGetVar(__POSTCALENDAR__, 'pcTimeIncrement'));
112 define('_SETTING_HOW_MANY_EVENTS', pnModGetVar(__POSTCALENDAR__, 'pcListHowManyEvents'));
113 define('_SETTING_TEMPLATE', pnModGetVar(__POSTCALENDAR__, 'pcTemplate'));
114 define('_SETTING_EVENTS_IN_YEAR', pnModGetVar(__POSTCALENDAR__, 'pcShowEventsInYear'));
115 define('_SETTING_USE_CACHE', pnModGetVar(__POSTCALENDAR__, 'pcUseCache'));
116 define('_SETTING_CACHE_LIFETIME', pnModGetVar(__POSTCALENDAR__, 'pcCacheLifetime'));
117 define('_SETTING_DEFAULT_VIEW', pnModGetVar(__POSTCALENDAR__, 'pcDefaultView'));
118 define('_SETTING_SAFE_MODE', pnModGetVar(__POSTCALENDAR__, 'pcSafeMode'));
119 define('_SETTING_NOTIFY_ADMIN', pnModGetVar(__POSTCALENDAR__, 'pcNotifyAdmin'));
120 define('_SETTING_NOTIFY_EMAIL', pnModGetVar(__POSTCALENDAR__, 'pcNotifyEmail'));
121 //=================================================================
122 // Make checking basic permissions easier
123 //=================================================================
124 define('PC_ACCESS_ADMIN', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADMIN));
125 define('PC_ACCESS_DELETE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_DELETE));
126 define('PC_ACCESS_ADD', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADD));
127 define('PC_ACCESS_EDIT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_EDIT));
128 define('PC_ACCESS_MODERATE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_MODERATE));
129 define('PC_ACCESS_COMMENT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_COMMENT));
130 define('PC_ACCESS_READ', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_READ));
131 define('PC_ACCESS_OVERVIEW', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_OVERVIEW));
132 define('PC_ACCESS_NONE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_NONE));
133 //=========================================================================
134 // Require and Setup utility classes and functions
135 //=========================================================================
136 define('DATE_CALC_BEGIN_WEEKDAY', _SETTING_FIRST_DAY_WEEK);
137 require_once("modules/$pcDir/pnincludes/Date/Calc.php");
138 //=========================================================================
139 // grab the global language file
140 //=========================================================================
141 $userlang = pnUserGetLang();
142 if (file_exists("modules/$pcDir/pnlang/$userlang/global.php")) {
143 require_once("modules/$pcDir/pnlang/$userlang/global.php");
144 } else {
145 require_once("modules/$pcDir/pnlang/eng/global.php");
148 unset($userlang);
149 //=========================================================================
150 // Setup Smarty defines
151 //=========================================================================
152 require_once("modules/$pcDir/pcSmarty.class.php");
153 //=========================================================================
154 // utility functions for postcalendar
155 //=========================================================================
156 function pcDebugVar($in)
158 echo '<pre>';
159 if (is_array($in)) {
160 print_r($in);
161 } else {
162 echo $in;
165 echo '</pre>';
167 function &pcVarPrepForDisplay($s)
169 $s = nl2br(pnVarPrepForDisplay(postcalendar_removeScriptTags($s)));
170 $s = preg_replace('/&amp;(#)?([0-9a-z]+);/i', '&\\1\\2;', $s);
171 return $s;
173 function &pcVarPrepHTMLDisplay($s)
175 return pnVarPrepHTMLDisplay(postcalendar_removeScriptTags($s));
177 function pcGetTopicName($topicid)
179 list($dbconn) = pnDBGetConn();
180 $pntable = pnDBGetTables();
182 $topics_table = $pntable['topics'];
183 $topics_column = &$pntable['topics_column'];
184 $sql = "SELECT $topics_column[topicname]
185 FROM $topics_table
186 WHERE $topics_column[topicid] = '$topicid'";
187 $result = $dbconn->Execute($sql);
188 if ($result === false) {
189 return '';
190 } else {
191 return $result->fields[0];
194 function &postcalendar_makeValidURL($s)
196 if (empty($s)) {
197 return '';
200 if (!preg_match('|^http[s]?:\/\/|i', $s)) {
201 $s = 'http://'.$s;
204 return $s;
206 function postcalendar_removeScriptTags($in)
208 return preg_replace("/<script.*?>(.*?)<\/script>/", "", $in);
211 function postcalendar_getDate($format = '%Y%m%d')
213 list($Date, $jumpday, $jumpmonth, $jumpyear, $jumpdate) =
214 pnVarCleanFromInput('Date', 'jumpday', 'jumpmonth', 'jumpyear', 'jumpdate');
215 if (!isset($Date)) {
216 // if we still don't have a date then calculate it
217 // check the jump menu, might be a 'jumpdate' input field or m/d/y select lists
218 if ($jumpdate) {
219 $jumpyear = substr($jumpdate, 0, 4);
220 $jumpmonth = substr($jumpdate, 5, 2);
221 $jumpday = substr($jumpdate, 8, 2);
222 } else {
223 if ($_SESSION['lastcaldate']) {
224 $time = strtotime($_SESSION['lastcaldate']);
225 } else {
226 $time = time();
227 if (pnUserLoggedIn()) {
228 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
232 if (!isset($jumpday)) {
233 $jumpday = strftime('%d', $time);
236 if (!isset($jumpmonth)) {
237 $jumpmonth = strftime('%m', $time);
240 if (!isset($jumpyear)) {
241 $jumpyear = strftime('%Y', $time);
245 // create the correct date string
246 $Date = (int) "$jumpyear$jumpmonth$jumpday";
249 $y = substr($Date, 0, 4);
250 $m = substr($Date, 4, 2);
251 $d = substr($Date, 6, 2);
252 $_SESSION['lastcaldate'] = "$y-$m-$d"; // remember the last chosen date
253 return strftime($format, mktime(0, 0, 0, $m, $d, $y));
256 function &postcalendar_today($format = '%Y%m%d')
258 $time = time();
259 if (pnUserLoggedIn()) {
260 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
263 return strftime($format, $time);
267 * postcalendar_adminapi_pageSetup()
269 * sets up any necessary javascript for the page
270 * @return string javascript to insert into the page
272 function postcalendar_adminapi_pageSetup()
274 return postcalendar_userapi_pageSetup();
277 * postcalendar_userapi_pageSetup()
279 * sets up any necessary javascript for the page
280 * @return string javascript to insert into the page
282 function postcalendar_userapi_pageSetup()
284 $output = '';
285 // load the DHTML JavaScript code and insert it into the page
286 if (_SETTING_USE_POPUPS) {
287 $output .= postcalendar_userapi_loadPopups();
290 // insert the js popup code into the page (find better code)
291 if (_SETTING_OPEN_NEW_WINDOW) {
292 $output .= postcalendar_userapi_jsPopup();
295 return $output;
298 * postcalendar_userapi_jsPopup
299 * Creates the necessary javascript code for a popup window
301 function postcalendar_userapi_jsPopup()
303 if (defined('_POSTCALENDAR_JSPOPUPS_LOADED')) {
304 // only put the script on the page once
305 return false;
308 define('_POSTCALENDAR_JSPOPUPS_LOADED', true);
310 // build the correct link
311 $js_link = "'index.php?module=".__POSTCALENDAR__."&type=user&func=view&viewtype=details&eid='+eid+'&Date='+date+'&popup=1'";
312 $js_window_options = 'toolbar=no,'
313 . 'location=no,'
314 . 'directories=no,'
315 . 'status=no,'
316 . 'menubar=no,'
317 . 'scrollbars=yes,'
318 . 'resizable=no,'
319 . 'width=600,'
320 . 'height=300';
322 $output = <<<EOF
324 <script language="javascript">
325 <!--
326 function opencal(eid,date) {
327 window.name='csCalendar';
328 w = window.open($js_link,'PostCalendarEvents','$js_window_options');
330 // -->
331 </script>
333 EOF;
334 return $output;
338 * postcalendar_userapi_loadPopups
339 * Creates the necessary javascript code for mouseover dHTML popups
341 function postcalendar_userapi_loadPopups()
343 if (defined('_POSTCALENDAR_LOADPOPUPS_LOADED')) {
344 // only put the script on the page once
345 return false;
348 define('_POSTCALENDAR_LOADPOPUPS_LOADED', true);
350 // get the theme globals :: is there a better way to do this?
351 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
352 global $textcolor1, $textcolor2;
354 // lets get the module's information
355 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
356 $pcDir = pnVarPrepForOS($modinfo['directory']);
357 unset($modinfo);
358 $capicon = '';
359 $close = _PC_OL_CLOSE;
361 $output = <<<EOF
363 <script language="JavaScript">
364 <!-- overLIB configuration -->
365 ol_fgcolor = "$bgcolor1";
366 ol_bgcolor = "$bgcolor2";
367 ol_textcolor = "$textcolor2";
368 ol_capcolor = "$textcolor2";
369 ol_closecolor = "$textcolor2";
370 ol_textfont = "Verdana,Arial,Helvetica";
371 ol_captionfont = "Verdana,Arial,Helvetica";
372 ol_captionsize = 2;
373 ol_textsize = 2;
374 ol_border = 2;
375 ol_width = 350;
376 ol_offsetx = 10;
377 ol_offsety = 10;
378 ol_sticky = 0;
379 ol_close = "$close";
380 ol_closeclick = 0;
381 ol_autostatus = 2;
382 ol_snapx = 0;
383 ol_snapy = 0;
384 ol_fixx = -1;
385 ol_fixy = -1;
386 ol_background = "";
387 ol_fgbackground = "";
388 ol_bgbackground = "";
389 ol_padxl = 1;
390 ol_padxr = 1;
391 ol_padyt = 1;
392 ol_padyb = 1;
393 ol_capicon = "$capicon";
394 ol_hauto = 1;
395 ol_vauto = 1;
396 </script>
397 <div id="overDiv" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:1000;"></div>
398 <script language="JavaScript" src="modules/$pcDir/pnincludes/overlib_mini.js">
399 <!-- overLIB (c) Erik Bosrup -->
400 </script>
402 EOF;
403 return $output;
407 * postcalendar_adminapi_getmonthname()
409 * Returns the month name translated for the user's current language
411 * @param array $args['Date'] number of month to return
412 * @return string month name in user's language
414 function postcalendar_adminapi_getmonthname($args)
416 return postcalendar_userapi_getmonthname($args);
419 * postcalendar_userapi_getmonthname()
421 * Returns the month name translated for the user's current language
423 * @param array $args['Date'] date to return month name of
424 * @return string month name in user's language
426 function postcalendar_userapi_getmonthname($args)
428 extract($args);
429 unset($args);
430 if (!isset($Date)) {
431 return false;
434 $month_name = array('01' => _CALJAN, '02' => _CALFEB, '03' => _CALMAR,
435 '04' => _CALAPR, '05' => _CALMAY, '06' => _CALJUN,
436 '07' => _CALJUL, '08' => _CALAUG, '09' => _CALSEP,
437 '10' => _CALOCT, '11' => _CALNOV, '12' => _CALDEC);
438 return $month_name[date('m', $Date)];
441 * Returns an array of form data for FormSelectMultiple
443 function postcalendar_adminapi_buildTimeSelect($args)
445 return postcalendar_userapi_buildTimeSelect($args);
447 function postcalendar_userapi_buildTimeSelect($args)
449 $inc = _SETTING_TIME_INCREMENT;
450 extract($args);
451 unset($args);
452 $output = array('h'=>array(),'m'=>array());
453 if ((bool)_SETTING_TIME_24HOUR) {
454 $start=0;
455 $end=23;
456 } else {
457 $start=1;
458 $end=12;
459 $hselected = $hselected > 12 ? $hselected-=12 : $hselected;
462 for ($c=0,$h=$start; $h<=$end; $h++,$c++) {
463 $hour = sprintf('%02d', $h);
464 $output['h'][$c]['id'] = pnVarPrepForStore($h);
465 $output['h'][$c]['selected'] = $hselected == $hour;
466 $output['h'][$c]['name'] = pnVarPrepForDisplay($hour);
469 for ($c=0,$m=0; $m<=(60-$inc); $m+=$inc,$c++) {
470 $min = sprintf('%02d', $m);
471 $output['m'][$c]['id'] = pnVarPrepForStore($m);
472 $output['m'][$c]['selected'] = $mselected == $min;
473 $output['m'][$c]['name'] = pnVarPrepForDisplay($min);
476 return $output;
479 * Returns an array of form data for FormSelectMultiple
481 function postcalendar_adminapi_buildMonthSelect($args)
483 return postcalendar_userapi_buildMonthSelect($args);
485 function postcalendar_userapi_buildMonthSelect($args)
487 extract($args);
488 unset($args);
489 if (!isset($pc_month)) {
490 $pc_month = Date_Calc::getMonth();
493 // create the return object to be inserted into the form
494 $output = array();
495 if (!isset($selected)) {
496 $selected = '';
499 for ($c=0,$i=1; $i<=12; $i++,$c++) {
500 if ($selected) {
501 $sel = $selected == $i ? true : false;
502 } elseif ($i == $pc_month) {
503 $sel = true;
504 } else {
505 $sel = false;
508 $output[$c]['id'] = sprintf('%02d', $i);
509 $output[$c]['selected'] = $sel;
510 $output[$c]['name'] = postcalendar_userapi_getmonthname(array('Date'=>mktime(0, 0, 0, $i, 15)));
513 return $output;
517 * Returns an array of form data for FormSelectMultiple
519 function postcalendar_adminapi_buildDaySelect($args)
521 return postcalendar_userapi_buildDaySelect($args);
523 function postcalendar_userapi_buildDaySelect($args)
525 extract($args);
526 unset($args);
527 if (!isset($pc_day)) {
528 $pc_day = Date_Calc::getDay();
531 // create the return object to be inserted into the form
532 $output = array();
533 if (!isset($selected)) {
534 $selected = '';
537 for ($c=0,$i=1; $i<=31; $i++,$c++) {
538 if ($selected) {
539 $sel = $selected == $i ? true : false;
540 } elseif ($i == $pc_day) {
541 $sel = true;
542 } else {
543 $sel = false;
546 $output[$c]['id'] = sprintf('%02d', $i);
547 $output[$c]['selected'] = $sel;
548 $output[$c]['name'] = sprintf('%02d', $i);
551 return $output;
555 * Returns an array of form data for FormSelectMultiple
557 function postcalendar_adminapi_buildYearSelect($args)
559 return postcalendar_userapi_buildYearSelect($args);
561 function postcalendar_userapi_buildYearSelect($args)
563 extract($args);
564 unset($args);
565 if (!isset($pc_year)) {
566 $pc_year = date('Y');
569 // create the return object to be inserted into the form
570 $output = array();
571 // we want the list to contain 10 years before today and 30 years after
572 // maybe this will eventually become a user defined value
573 $pc_start_year = date('Y') - 1;
574 $pc_end_year = date('Y') + 30;
575 if (!isset($selected)) {
576 $selected = '';
579 for ($c=0,$i=$pc_start_year; $i<=$pc_end_year; $i++,$c++) {
580 if ($selected) {
581 $sel = $selected == $i ? true : false;
582 } elseif ($i == $pc_year) {
583 $sel = true;
584 } else {
585 $sel = false;
588 $output[$c]['id'] = sprintf('%04d', $i);
589 $output[$c]['selected'] = $sel;
590 $output[$c]['name'] = sprintf('%04d', $i);
593 return $output;
596 function &postcalendar_adminapi_getCategories()
598 return postcalendar_userapi_getCategories();
600 function &postcalendar_userapi_getCategories()
602 list($dbconn) = pnDBGetConn();
603 $pntable = pnDBGetTables();
604 $cat_table = $pntable['postcalendar_categories'];
605 $sql = "SELECT pc_catid,pc_catname,pc_catcolor,pc_catdesc,
606 pc_recurrtype,pc_recurrspec,pc_recurrfreq,pc_duration,
607 pc_dailylimit,pc_end_date_flag,pc_end_date_type,pc_end_date_freq,
608 pc_end_all_day,pc_cattype,pc_active,pc_seq,aco_spec FROM $cat_table
609 ORDER BY pc_catname";
610 $result = $dbconn->Execute($sql);
612 if ($dbconn->ErrorNo() != 0) {
613 return array();
616 if (!isset($result)) {
617 return array();
620 $categories = array();
621 for ($i=0; !$result->EOF; $result->MoveNext()) {
622 list($catid,$catname,$catcolor,$catdesc,
623 $rtype,$rspec,$rfreq,$duration,$limit,$end_date_flag,
624 $end_date_type,$end_date_freq,$end_all_day,$cattype,$active,$seq,$aco) = $result->fields;
625 // check the category's permissions
626 if (!pnSecAuthAction(0, 'PostCalendar::Category', "$catname::$catid", ACCESS_OVERVIEW)) {
627 continue;
630 $categories[$i]['id'] = $catid;
631 $categories[$i]['name'] = $catname;
632 $categories[$i]['color'] = $catcolor;
633 $categories[$i]['desc'] = $catdesc;
634 $categories[$i]['value_cat_type'] = $cattype;
635 $categories[$i]['active'] = $active;
636 $categories[$i]['sequence'] = $seq;
637 $categories[$i]['event_repeat'] = $rtype;
638 $rspecs = unserialize($rspec);
639 $categories[$i]['event_repeat_freq'] = $rspecs['event_repeat_freq'];
640 $categories[$i]['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
641 $categories[$i]['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
642 $categories[$i]['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
643 $categories[$i]['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
644 $categories[$i]['event_recurrspec'] = $rspecs;
645 $categories[$i]['event_duration'] = $duration;
646 $categories[$i]['event_durationh'] = (int)($duration/(60 * 60)); //seconds divided by 60 seconds * 60 minutes;
647 $categories[$i]['event_durationm'] = ($duration%(60 * 60))/60;
648 $categories[$i]['end_date_flag'] = $end_date_flag;
649 $categories[$i]['end_date_type'] = $end_date_type;
650 $categories[$i]['end_date_freq'] = $end_date_freq;
651 $categories[$i]['end_all_day'] = $end_all_day;
652 $categories[$i]['aco'] = $aco;
653 $categories[$i++]['dailylimit'] = $limit;
656 $result->Close();
657 return $categories;
660 function &postcalendar_adminapi_getTopics()
662 return postcalendar_userapi_getTopics();
664 function &postcalendar_userapi_getTopics()
666 list($dbconn) = pnDBGetConn();
667 $pntable = pnDBGetTables();
668 $topics_table = $pntable['topics'];
669 $topics_column = &$pntable['topics_column'];
670 $sql = "SELECT $topics_column[topicid], $topics_column[topictext], $topics_column[topicname]
671 FROM $topics_table
672 ORDER BY $topics_column[topictext]";
673 $topiclist = $dbconn->Execute($sql);
674 if ($dbconn->ErrorNo() != 0) {
675 return false;
678 $data = array();
679 $i=0;
680 for (; !$topiclist->EOF; $topiclist->MoveNext()) {
681 // check topic permissions
682 if (pnSecAuthAction(0, 'PostCalendar::Topic', $topiclist->fields[2].'::'.$topiclist->fields[0], ACCESS_OVERVIEW)) {
683 list($data[$i]['id'], $data[$i]['text'], $data[$i++]['name']) = $topiclist->fields;
687 $topiclist->Close();
688 return $data;
692 * postcalendar_adminapi_submitEvent()
693 * submit an event
694 * @param $args array of event data
695 * @return bool true on success : false on failure;
697 function postcalendar_adminapi_submitEvent($args)
699 return postcalendar_userapi_submitEvent($args);
702 * postcalendar_userapi_submitEvent()
703 * submit an event
704 * @param $args array of event data
705 * @return bool true on success : false on failure;
707 function postcalendar_userapi_submitEvent($args)
709 extract($args);
710 unset($args);
712 list($dbconn) = pnDBGetConn();
713 $pntable = pnDBGetTables();
715 // determine if the event is to be published immediately or not
716 //also whether is a special system only event i.e. _EVENT_TEMPORARY
717 if (empty($event_status)) {
718 if ((bool) _SETTING_DIRECT_SUBMIT || (bool) PC_ACCESS_ADMIN || ($event_sharing != SHARING_GLOBAL)) {
719 $event_status = _EVENT_APPROVED;
720 } else {
721 $event_status = _EVENT_QUEUED;
723 } elseif ($event_status == _EVENT_TEMPORARY) {
724 $event_status = _EVENT_TEMPORARY;
725 } else {
726 $event_status = _EVENT_QUEUED;
730 // set up some vars for the insert statement
731 $startDate = $event_startyear.'-'.$event_startmonth.'-'.$event_startday;
732 if ($event_endtype == 1) {
733 $endDate = $event_endyear.'-'.$event_endmonth.'-'.$event_endday;
734 } else {
735 $endDate = '0000-00-00';
738 if (!isset($event_allday)) {
739 $event_allday = 0;
742 if ((bool)_SETTING_TIME_24HOUR) {
743 $startTime = $event_starttimeh.':'.$event_starttimem.':00';
744 } else {
745 if ($event_startampm == _AM_VAL) {
746 $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
747 } else {
748 $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
751 $startTime = sprintf('%02d', $event_starttimeh).':'.sprintf('%02d', $event_starttimem).':00';
754 if ($event_allday == 1) {
755 $endTime = "24:00:00";
756 } else {
757 $endTime = date("H:i:00", ($event_duration + strtotime($startTime)));
760 // get rid of variables we no longer need to save memory
761 unset(
762 $event_startyear,
763 $event_startmonth,
764 $event_startday,
765 $event_endyear,
766 $event_endmonth,
767 $event_endday,
768 $event_starttimeh,
769 $event_starttimem
772 //pennfirm users need to be able to enter apps for different providers, this isn't aoplicable
773 /*if(pnUserLoggedIn()) {
774 $event_userid = pnUserGetVar('uid');
775 } else {
776 $event_userid = 0;
780 if ($pc_html_or_text == 'html') {
781 $event_desc = ':html:'.$event_desc;
782 } else {
783 $event_desc = ':text:'.$event_desc;
786 list($event_subject,$event_desc,$event_topic,$startDate,$endDate,
787 $event_repeat,$startTime,$event_allday,$event_category,
788 $event_location_info,$event_conttel,$event_contname,
789 $event_contemail,$event_website,$event_fee,$event_status,
790 $event_recurrspec,$event_duration,$event_sharing,$event_userid,$event_pid,
791 $pc_event_id) = @pnVarPrepForStore(
792 $event_subject,
793 $event_desc,
794 $event_topic,
795 $startDate,
796 $endDate,
797 $event_repeat,
798 $startTime,
799 $event_allday,
800 $event_category,
801 $event_location_info,
802 $event_conttel,
803 $event_contname,
804 $event_contemail,
805 $event_website,
806 $event_fee,
807 $event_status,
808 $event_recurrspec,
809 $event_duration,
810 $event_sharing,
811 $event_userid,
812 $event_pid,
813 $pc_event_id
816 if (!isset($is_update)) {
817 $is_update = false;
820 if ($is_update) {
821 $sql = "UPDATE $pntable[postcalendar_events]
822 SET pc_title = '$event_subject',
823 pc_hometext = '$event_desc',
824 pc_topic = '$event_topic',
825 pc_eventDate = '$startDate',
826 pc_endDate = '$endDate',
827 pc_recurrtype = '$event_repeat',
828 pc_startTime = '$startTime',
829 pc_endTime = '$endTime',
830 pc_alldayevent = '$event_allday',
831 pc_catid = '$event_category',
832 pc_location = '$event_location_info',
833 pc_conttel = '$event_conttel',
834 pc_contname = '$event_contname',
835 pc_contemail = '$event_contemail',
836 pc_website = '$event_website',
837 pc_fee = '$event_fee',
838 pc_eventstatus = '$event_status',
839 pc_recurrspec = '$event_recurrspec',
840 pc_duration = '$event_duration',
841 pc_sharing = '$event_sharing',
842 pc_aid = '$event_userid',
843 pc_pid = '$event_pid'
844 WHERE pc_eid = '$pc_event_id'";
845 } else {
846 $pc_event_id = $dbconn->GenId($pntable['postcalendar_events']);
847 $sql = "INSERT INTO $pntable[postcalendar_events] (
848 pc_eid,
849 pc_title,
850 pc_time,
851 pc_hometext,
852 pc_topic,
853 pc_informant,
854 pc_eventDate,
855 pc_endDate,
856 pc_recurrtype,
857 pc_startTime,
858 pc_endTime,
859 pc_alldayevent,
860 pc_catid,
861 pc_location,
862 pc_conttel,
863 pc_contname,
864 pc_contemail,
865 pc_website,
866 pc_fee,
867 pc_eventstatus,
868 pc_recurrspec,
869 pc_duration,
870 pc_sharing,
871 pc_aid,
872 pc_pid)
873 VALUES (
874 '$pc_event_id',
875 '$event_subject',
876 NOW(),
877 '$event_desc',
878 '$event_topic',
879 " . $_SESSION['authUserID'] . ",
880 '$startDate',
881 '$endDate',
882 '$event_repeat',
883 '$startTime',
884 '$endTime',
885 '$event_allday',
886 '$event_category',
887 '$event_location_info',
888 '$event_conttel',
889 '$event_contname',
890 '$event_contemail',
891 '$event_website',
892 '$event_fee',
893 '$event_status',
894 '$event_recurrspec',
895 '$event_duration',
896 '$event_sharing',
897 '$event_userid',
898 '$event_pid'
902 $result = $dbconn->Execute($sql);
903 if ($result === false) {
904 return false;
905 } else {
906 if ((bool)$is_update) {
907 $eid = $pc_event_id;
908 } else {
909 $eid = $dbconn->PO_Insert_ID($pntable['postcalendar_events'], 'pc_eid');
912 pc_notify($eid, $is_update);
913 return true;
917 function pc_notify($eid, $is_update)
919 if (!(bool)_SETTING_NOTIFY_ADMIN) {
920 return true;
923 $subject = _PC_NOTIFY_SUBJECT;
925 if ((bool)$is_update) {
926 $message = _PC_NOTIFY_UPDATE_MSG;
927 } else {
928 $message = _PC_NOTIFY_NEW_MSG;
931 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
932 $modversion = pnVarPrepForOS($modinfo['version']);
933 unset($modinfo);
935 $message .= pnModURL(__POSTCALENDAR__, 'admin', 'adminevents', array('pc_event_id'=>$eid,'action'=>_ADMIN_ACTION_VIEW));
936 $message .= "\n\n\n\n";
937 $message .= "----\n";
938 $message .= "PostCalendar $modversion\n";
939 $message .= "http://www.postcalendar.tv";
941 mail(
942 _SETTING_NOTIFY_EMAIL,
943 $subject,
944 $message,
945 "From: " . _SETTING_NOTIFY_EMAIL . "\r\n"
946 ."X-Mailer: PHP/" . phpversion() . "\r\n"
947 ."X-Mailer: PostCalendar/$modversion"
950 return true;
954 function findFirstAvailable($period)
956 //print_r($period);
958 $day_date = "";
959 $available_times = array();
960 foreach ($period as $date => $day) {
961 //echo "begin free times for $date:<br />";
962 $ffid_res = findFirstInDay($day, $date);
963 foreach ($ffid_res as $times) {
964 //echo "starting: " . date("h:i:s A",$times['startTime']) . " long: " . $times['duration'] . "<br />";
965 $available_times[$date][] = $times;
966 //echo "count of times is:" . count($available_times) . "<br />";
969 //echo "end free times for $date";
972 return $available_times;
975 function findFirstInDay($day, $date)
977 $stack = array();
978 $lastcat = 3;
979 $intime = false;
980 $outtime = false;
981 foreach ($day as $event) {
982 //echo "event is: " . $event['title'] . " cat is: " .$event['catid'] . " event date is: " . $date . "<br />";
984 if ($event['catid'] == 2) { //catid 2 is reserved to represent "In Office" events, id 3 is "Out Of Office"
985 $intime = $event['startTime'];
986 //echo "setting in: $intime<br />";
987 } elseif ($event['catid'] == 3) {
988 $outtime = $event['startTime'];
989 //echo "setting out: $outtime<br />";
993 if ($intime == false or $outtime == false) {
994 return array();
997 //echo "increment is: " . _SETTING_TIME_INCREMENT . "<br />";
998 $inc = (_SETTING_TIME_INCREMENT * 60);
999 //$inc = 60;
1000 $intime_sec = date("U", strtotime($date . " " . $intime));
1001 $outtime_sec = date("U", strtotime($date . " " . $outtime));
1002 $free_time = $intime_sec;
1004 $times = array();
1005 for ($i = $intime_sec; $i < $outtime_sec; $i += $inc) {
1006 //echo "time is now: " . date("h:i:s A",$i) . "<br />";
1007 $closest_start = $outtime_sec;
1008 $timeclear = false;
1009 foreach ($day as $event) {
1010 if ($event['catid'] != 2) {
1011 $estart = dtSec($date, $event['startTime']) ;
1012 $eend = dtSecDur($date, $event['startTime'], $event['duration']);
1014 if ($eend < $intime_sec or $estart > $outtime_sec) {
1015 //event ends before intime or starts after outtime we don't care move on;
1016 continue;
1017 } elseif ($eend < $i) {
1018 //event ended before time currently being evaluated, we don't care move on;
1019 continue;
1020 } elseif ($estart < $i and $eend > $i) {
1021 //event occupies part of the time we are looking at, look at another time
1022 continue;
1023 } elseif ($estart >= $i) {
1024 //echo "tin: " . date("h:i:s A",$i) . " estart: " . date("h:i:s A",$estart) . "<br />";
1026 //echo "ev: " . $event['title'] . " s at:" . date("h:i:s A",$estart) . " e at: " . date("h:i:s A",$eend) ." <br />";
1027 //some amount of time is free set closest time
1028 $oldfreetime = $closest_start - $i;
1029 $newfreetime = $estart - $i;
1031 //echo "old free: " . $oldfreetime . "<br />";
1032 //echo "new free: " . $newfreetime . "<br />";
1033 //echo "duration is: " . ($estart - $i) . " cs:$estart i:$i<br />";
1034 if ($newfreetime < $oldfreetime && ($estart - $i) != 0) {
1035 $free_time = $i;
1036 $closest_start = $estart;
1038 //echo "set time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
1039 if ($i < ($eend - $inc)) {
1040 $i = ($eend - $inc);
1042 } elseif ($newfreetime <= $oldfreetime && $oldfreetime == ($outtime_sec - $i)) {
1043 $free_time = $i;
1044 $closest_start = $estart;
1046 //echo "time is " . date("h:i:s A",$i) . " min free: " . (($closest_start - $i)/60) . " " . date("h:i:s A",$closest_start) . "<br />";
1047 if ($i < ($eend - $inc)) {
1048 $i = ($eend - $inc);
1052 //echo "closest start: " . date("h:i:s A",$closest_start) . "<br />";
1057 if ($closest_start > ($intime_sec + 60)) {
1058 //echo "free time is: " . date("h:i:s A",$free_time) . "<br />";
1059 //echo "next app is: " . date("h:i:s A",$closest_start) . "<br />";
1060 $duration = ($closest_start - $free_time);
1061 //echo "duration is: $duration<br />";
1062 //we allow for 0 duration events so other things such as overlap and actual times can be calculated
1063 //this happens because people want to be able to set 8:00 - 8:15 and 8:15 - 8:30 without a conflict
1064 //even though that is technially impossible, so we pretend, however here we weed out the 0
1065 //length blocks so that won't be seen
1066 $date_sec = strtotime($date);
1067 if ($duration > 0) {
1068 $times[] = array ("startTime" => $free_time, "endTime" => ($date_sec+$duration));
1073 return $times;
1076 function dtSec($date, $time)
1078 return date("U", strtotime($date . " " . $time));
1081 function dtSecDur($date, $time, $dur)
1083 $time_sec = date("U", strtotime($date . " " . $time));
1084 return $time_sec + $dur;
1088 * postcalendar_adminapi_buildSubmitForm()
1089 * create event submit form
1091 function postcalendar_adminapi_buildSubmitForm($args)
1093 return postcalendar_userapi_buildSubmitForm($args, true);
1096 * postcalendar_userapi_buildSubmitForm()
1097 * create event submit form
1099 function postcalendar_userapi_buildSubmitForm($args, $admin = false)
1101 $_SESSION['category'] = "";
1102 if (!PC_ACCESS_ADD) {
1103 return _POSTCALENDARNOAUTH;
1106 extract($args);
1107 unset($args);
1108 //since we seem to clobber category
1109 $cat = $category;
1110 $output = new pnHTML();
1111 $output->SetInputMode(_PNH_VERBATIMINPUT);
1112 // set up Smarty
1113 $tpl = new pcSmarty();
1114 $tpl->caching = false;
1116 $template_name = pnModGetVar(__POSTCALENDAR__, 'pcTemplate');
1118 if (!isset($template_name)) {
1119 $template_name ='default';
1122 //=================================================================
1123 // Setup the correct config file path for the templates
1124 //=================================================================
1125 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1126 $modir = pnVarPrepForOS($modinfo['directory']);
1127 $modname = $modinfo['displayname'];
1128 $all_categories =& pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
1129 //print_r($all_categories);
1130 unset($modinfo);
1131 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
1132 //=================================================================
1133 // PARSE MAIN
1134 //=================================================================
1137 $tpl->assign('webroot', $GLOBALS['web_root']);
1138 $tpl->assign_by_ref('TPL_NAME', $template_name);
1139 $tpl->assign('FUNCTION', pnVarCleanFromInput('func'));
1140 $tpl->assign_by_ref('ModuleName', $modname);
1141 $tpl->assign_by_ref('ModuleDirectory', $modir);
1142 $tpl->assign_by_ref('category', $all_categories);
1143 $tpl->assign('NewEventHeader', _PC_NEW_EVENT_HEADER);
1144 $tpl->assign('EventTitle', _PC_EVENT_TITLE);
1145 $tpl->assign('Required', _PC_REQUIRED);
1146 $tpl->assign('DateTimeTitle', _PC_DATE_TIME);
1147 $tpl->assign('AlldayEventTitle', _PC_ALLDAY_EVENT);
1148 $tpl->assign('TimedEventTitle', _PC_TIMED_EVENT);
1149 $tpl->assign('TimedDurationTitle', _PC_TIMED_DURATION);
1150 $tpl->assign('TimedDurationHoursTitle', _PC_TIMED_DURATION_HOURS);
1151 $tpl->assign('TimedDurationMinutesTitle', _PC_TIMED_DURATION_MINUTES);
1152 $tpl->assign('EventDescTitle', _PC_EVENT_DESC);
1154 //the double book variable comes from the eventdata array that is
1155 //passed here and extracted, injection is not an issue here
1156 if (is_numeric($double_book)) {
1157 $tpl->assign('double_book', $double_book);
1160 //pennfirm begin patient info handling
1161 $ProviderID = pnVarCleanFromInput("provider_id");
1162 if (is_numeric($ProviderID)) {
1163 $tpl->assign('ProviderID', $ProviderID);
1164 $tpl->assign('provider_id', $ProviderID);
1165 } elseif (is_numeric($event_userid) && $event_userid != 0) {
1166 $tpl->assign('ProviderID', $event_userid);
1167 $tpl->assign('provider_id', $event_userid);
1168 } else {
1169 if ($_SESSION['userauthorized'] == 1) {
1170 $tpl->assign('ProviderID', $_SESSION['authUserID']);
1171 } else {
1172 $tpl->assign('ProviderID', "");
1176 $provinfo = getProviderInfo();
1177 $tpl->assign('providers', $provinfo);
1178 $PatientID = pnVarCleanFromInput("patient_id");
1180 // limit the number of results returned by getPatientPID
1181 // this helps to prevent the server from stalling on a request with
1182 // no PID and thousands of PIDs in the database -- JRM
1183 // the function getPatientPID($pid, $given, $orderby, $limit, $start) <-- defined in library/patient.inc
1184 $plistlimit = 500;
1185 if (is_numeric($PatientID)) {
1186 $tpl->assign('PatientList', getPatientPID(array('pid'=>$PatientID, 'limit'=>$plistlimit)));
1187 } elseif (is_numeric($event_pid)) {
1188 $tpl->assign('PatientList', getPatientPID(array('pid'=>$event_pid, 'limit'=>$plistlimit)));
1189 } else {
1190 $tpl->assign('PatientList', getPatientPID(array('limit' =>$plistlimit)));
1193 $tpl->assign('event_pid', $event_pid);
1194 $tpl->assign('event_aid', $event_aid);
1195 $tpl->assign('event_category', pnVarCleanFromInput("event_category"));
1197 if (empty($event_patient_name)) {
1198 $patient_data = getPatientData($event_pid, $given = "lname, fname");
1199 $event_patient_name = $patient_data['lname'].", ".$patient_data['fname'];
1202 $tpl->assign('patient_value', $event_patient_name);
1204 //=================================================================
1205 // PARSE INPUT_EVENT_TITLE
1206 //=================================================================
1207 $tpl->assign('InputEventTitle', 'event_subject');
1208 $tpl->assign('ValueEventTitle', pnVarPrepForDisplay($event_subject));
1210 //=================================================================
1211 // PARSE SELECT_DATE_TIME
1212 //=================================================================
1214 // It seems that with Mozilla at least, <select> fields that are disabled
1215 // do not get passed as form data. Therefore we ignore $double_book so
1216 // that the fields will not be disabled. -- Rod 2005-03-22
1218 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1219 if (_SETTING_USE_INT_DATES) {
1220 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildDaySelect', array('pc_day'=>$day,'selected'=>$event_startday));
1221 $formdata = $output->FormSelectMultiple('event_startday', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1222 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildMonthSelect', array('pc_month'=>$month,'selected'=>$event_startmonth));
1223 $formdata .= $output->FormSelectMultiple('event_startmonth', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1224 } else {
1225 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildMonthSelect', array('pc_month'=>$month,'selected'=>$event_startmonth));
1226 $formdata = $output->FormSelectMultiple('event_startmonth', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1227 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildDaySelect', array('pc_day'=>$day,'selected'=>$event_startday));
1228 $formdata .= $output->FormSelectMultiple('event_startday', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1231 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildYearSelect', array('pc_year'=>$year,'selected'=>$event_startyear));
1232 $formdata .= $output->FormSelectMultiple('event_startyear', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1233 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1234 $tpl->assign('SelectDateTime', $formdata);
1235 $tpl->assign('InputAllday', 'event_allday');
1236 $tpl->assign('ValueAllday', '1');
1237 $tpl->assign('SelectedAllday', $event_allday==1 ? 'checked':'');
1238 $tpl->assign('InputTimed', 'event_allday');
1239 $tpl->assign('ValueTimed', '0');
1240 $tpl->assign('SelectedTimed', $event_allday==0 ? 'checked':'');
1241 $tpl->assign('STYLE', $GLOBALS['style']);
1243 //=================================================================
1244 // PARSE SELECT_END_DATE_TIME
1245 //=================================================================
1246 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1247 //if there is no end date we want the box to read todays date instead of jan 01 1994 :)
1248 if ($event_endmonth == 0 && $event_endday ==0 && $event_endyear ==0) {
1249 $event_endmonth =$month;
1250 $event_endday = $day ;
1251 $event_endyear = $year;
1254 if (_SETTING_USE_INT_DATES) {
1255 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildDaySelect', array('pc_day'=>$day,'selected'=>$event_endday));
1257 $formdata = $output->FormSelectMultiple('event_endday', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1258 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildMonthSelect', array('pc_month'=>$month,'selected'=>$event_endmonth));
1259 $formdata .= $output->FormSelectMultiple('event_endmonth', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1260 } else {
1261 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildMonthSelect', array('pc_month'=>$month,'selected'=>$event_endmonth));
1262 $formdata = $output->FormSelectMultiple('event_endmonth', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1263 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildDaySelect', array('pc_day'=>$day,'selected'=>$event_endday));
1264 $formdata .= $output->FormSelectMultiple('event_endday', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1267 $sel_data = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildYearSelect', array('pc_year'=>$year,'selected'=>$event_endyear));
1268 $formdata .= $output->FormSelectMultiple('event_endyear', $sel_data, 0, 1, "", "", false, /* $double_book*/ '');
1269 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1270 $tpl->assign('SelectEndDate', $formdata);
1271 //=================================================================
1272 // PARSE SELECT_TIMED_EVENT
1273 //=================================================================
1274 $stimes = pnModAPIFunc(__POSTCALENDAR__, 'user', 'buildTimeSelect', array('hselected'=>$event_starttimeh,'mselected'=>$event_starttimem));
1275 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1276 $timed_hours = $output->FormSelectMultiple('event_starttimeh', $stimes['h'], 0, 1, "", "", false, /* $double_book*/ '');
1277 $timed_minutes = $output->FormSelectMultiple('event_starttimem', $stimes['m'], 0, 1, "", "", false, /* $double_book*/ '');
1278 if (!_SETTING_TIME_24HOUR) {
1279 $ampm = array();
1280 $ampm[0]['id'] = pnVarPrepForStore(_AM_VAL);
1281 $ampm[0]['name'] = pnVarPrepForDisplay(_PC_AM);
1282 $ampm[1]['id'] = pnVarPrepForStore(_PM_VAL);
1283 $ampm[1]['name'] = pnVarPrepForDisplay(_PC_PM);
1284 if ($event_startampm == "AM" || $event_startampm == _AM_VAL) {
1285 $ampm[0]['selected'] = 1;
1286 } else {
1287 $ampm[1]['selected'] = 1;
1290 $timed_ampm = $output->FormSelectMultiple('event_startampm', $ampm, 0, 1, "", "", false, /* $double_book*/ '');
1291 } else {
1292 $timed_ampm = '';
1295 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1296 $tpl->assign('SelectTimedHours', $timed_hours);
1297 $tpl->assign('SelectTimedMinutes', $timed_minutes);
1298 $tpl->assign('SelectTimedAMPM', $timed_ampm);
1299 $tpl->assign('event_startday', $event_startday);
1300 $tpl->assign('event_startmonth', $event_startmonth);
1301 $tpl->assign('event_startyear', $event_startyear);
1302 $tpl->assign('event_starttimeh', $event_starttimeh);
1303 $tpl->assign('event_starttimem', $event_starttimem);
1304 $tpl->assign('event_startampm', $event_startampm);
1305 $tpl->assign('event_dur_hours', $event_dur_hours);
1306 $tpl->assign('event_dur_minutes', $event_dur_minutes);
1308 //=================================================================
1309 // PARSE SELECT_DURATION
1310 //=================================================================
1311 $event_dur_hours = (int) $event_dur_hours;
1313 for ($i=0; $i<=24; $i+=1) {
1314 $TimedDurationHours[$i] = array('value'=>$i,
1315 'selected'=>($event_dur_hours==$i ? 'selected':''),
1316 'name'=>sprintf('%02d', $i));
1319 $tpl->assign('TimedDurationHours', $TimedDurationHours);
1320 $tpl->assign('InputTimedDurationHours', 'event_dur_hours');
1321 $found_time = false;
1322 for ($i=0; $i<60; $i+=_SETTING_TIME_INCREMENT) {
1323 $TimedDurationMinutes[$i] = array('value'=>$i,
1324 'selected'=>($event_dur_minutes==$i ? 'selected':''),
1325 'name'=>sprintf('%02d', $i));
1326 if ($TimedDurationMinutes[$i]['selected'] == 'selected') {
1327 $found_time = true;
1331 if (!$found_time) {
1332 $TimedDurationMinutes[$i] = array('value'=>$event_dur_minutes,
1333 'selected'=>'selected',
1334 'name'=>sprintf('%02d', $event_dur_minutes));
1337 $tpl->assign('TimedDurationMinutes', $TimedDurationMinutes);
1338 $tpl->assign('hidden_event_dur_minutes', $event_dur_minutes);
1339 $tpl->assign('InputTimedDurationMinutes', 'event_dur_minutes');
1340 //=================================================================
1341 // PARSE INPUT_EVENT_DESC
1342 //=================================================================
1343 $tpl->assign('InputEventDesc', 'event_desc');
1344 if (empty($pc_html_or_text)) {
1345 $display_type = substr($event_desc, 0, 6);
1346 if ($display_type == ':text:') {
1347 $pc_html_or_text = 'text';
1348 $event_desc = substr($event_desc, 6);
1349 } elseif ($display_type == ':html:') {
1350 $pc_html_or_text = 'html';
1351 $event_desc = substr($event_desc, 6);
1352 } else {
1353 $pc_html_or_text = 'text';
1356 unset($display_type);
1359 $tpl->assign('ValueEventDesc', pnVarPrepForDisplay($event_desc));
1360 $eventHTMLorText = "<select name=\"pc_html_or_text\">";
1361 if ($pc_html_or_text == 'text') {
1362 $eventHTMLorText .= "<option value=\"text\" selected=\"selected\">"._PC_SUBMIT_TEXT."</option>";
1363 } else {
1364 $eventHTMLorText .= "<option value=\"text\">"._PC_SUBMIT_TEXT."</option>";
1367 if ($pc_html_or_text == 'html') {
1368 $eventHTMLorText .= "<option value=\"html\" selected=\"selected\">"._PC_SUBMIT_HTML."</option>";
1369 } else {
1370 $eventHTMLorText .= "<option value=\"html\">"._PC_SUBMIT_HTML."</option>";
1373 $eventHTMLorText .= "</select>";
1374 $tpl->assign('EventHTMLorText', $eventHTMLorText);
1375 //=================================================================
1376 // PARSE select_event_topic_block
1377 //=================================================================
1378 $tpl->assign('displayTopics', _SETTING_DISPLAY_TOPICS);
1379 if ((bool)_SETTING_DISPLAY_TOPICS) {
1380 $a_topics =& postcalendar_userapi_getTopics();
1381 $topics = array();
1382 foreach ($a_topics as $topic) {
1383 array_push($topics, array('value'=>$topic['id'],
1384 'selected'=>($topic['id']==$event_topic ? 'selected':''),
1385 'name'=>$topic['text']));
1388 unset($a_topics);
1389 // only show this if we have topics to show
1390 if (count($topics) > 0) {
1391 $tpl->assign('topics', $topics);
1392 $tpl->assign('EventTopicTitle', _PC_EVENT_TOPIC);
1393 $tpl->assign('InputEventTopic', 'event_topic');
1397 //=================================================================
1398 // PARSE select_event_type_block
1399 //=================================================================
1400 $categories = array();
1401 foreach ($all_categories as $category) {
1402 array_push($categories, array('value'=>$category['id'],
1403 'selected'=>($category['id']==$event_category ? 'selected' : ''),
1404 'name'=>$category['name'],
1405 'color'=>$category['color'],
1406 'desc'=>$category['desc']));
1409 // only show this if we have categories to show
1410 // you should ALWAYS have at least one valid category
1411 if (count($categories) > 0) {
1412 $tpl->assign('categories', $categories);
1413 $tpl->assign('EventCategoriesTitle', _PC_EVENT_CATEGORY);
1414 $tpl->assign('InputEventCategory', 'event_category');
1415 $tpl->assign('hidden_event_category', $event_category);
1418 //=================================================================
1419 // PARSE event_sharing_block
1420 //=================================================================
1421 $data = array();
1422 if (_SETTING_ALLOW_USER_CAL) {
1423 array_push($data, array(SHARING_PRIVATE,_PC_SHARE_PRIVATE));
1424 array_push($data, array(SHARING_PUBLIC,_PC_SHARE_PUBLIC));
1425 array_push($data, array(SHARING_BUSY,_PC_SHARE_SHOWBUSY));
1428 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN) || _SETTING_ALLOW_GLOBAL || !_SETTING_ALLOW_USER_CAL) {
1429 array_push($data, array(SHARING_GLOBAL,_PC_SHARE_GLOBAL));
1432 $sharing = array();
1433 foreach ($data as $cell) {
1434 array_push($sharing, array('value'=>$cell[0],
1435 'selected'=>((int) $event_sharing == $cell[0] ? 'selected' : ''),
1436 'name'=>$cell[1]));
1439 //pennfirm get list of providers from openemr code in calendar.inc
1440 $tpl->assign("user", getCalendarProviderInfo());
1443 $tpl->assign('sharing', $sharing);
1444 $tpl->assign('EventSharingTitle', _PC_SHARING);
1445 $tpl->assign('InputEventSharing', 'event_sharing');
1446 //=================================================================
1447 // location information
1448 //=================================================================
1449 $tpl->assign('EventLocationTitle', _PC_EVENT_LOCATION);
1450 $tpl->assign('InputLocation', 'event_location');
1451 $tpl->assign('ValueLocation', pnVarPrepForDisplay($event_location));
1452 $tpl->assign('EventStreetTitle', _PC_EVENT_STREET);
1453 $tpl->assign('InputStreet1', 'event_street1');
1454 $tpl->assign('ValueStreet1', pnVarPrepForDisplay($event_street1));
1455 $tpl->assign('InputStreet2', 'event_street2');
1456 $tpl->assign('ValueStreet2', pnVarPrepForDisplay($event_street2));
1457 $tpl->assign('EventCityTitle', _PC_EVENT_CITY);
1458 $tpl->assign('InputCity', 'event_city');
1459 $tpl->assign('ValueCity', pnVarPrepForDisplay($event_city));
1460 $tpl->assign('EventStateTitle', _PC_EVENT_STATE);
1461 $tpl->assign('InputState', 'event_state');
1462 $tpl->assign('ValueState', pnVarPrepForDisplay($event_state));
1463 $tpl->assign('EventPostalTitle', _PC_EVENT_POSTAL);
1464 $tpl->assign('InputPostal', 'event_postal');
1465 $tpl->assign('ValuePostal', pnVarPrepForDisplay($event_postal));
1466 //=================================================================
1467 // contact information
1468 //=================================================================
1469 $tpl->assign('EventContactTitle', _PC_EVENT_CONTACT);
1470 $tpl->assign('InputContact', 'event_contname');
1471 $tpl->assign('ValueContact', pnVarPrepForDisplay($event_contname));
1472 $tpl->assign('EventPhoneTitle', _PC_EVENT_PHONE);
1473 $tpl->assign('InputPhone', 'event_conttel');
1474 $tpl->assign('ValuePhone', pnVarPrepForDisplay($event_conttel));
1475 $tpl->assign('EventEmailTitle', _PC_EVENT_EMAIL);
1476 $tpl->assign('InputEmail', 'event_contemail');
1477 $tpl->assign('ValueEmail', pnVarPrepForDisplay($event_contemail));
1478 $tpl->assign('EventWebsiteTitle', _PC_EVENT_WEBSITE);
1479 $tpl->assign('InputWebsite', 'event_website');
1480 $tpl->assign('ValueWebsite', pnVarPrepForDisplay($event_website));
1481 $tpl->assign('EventFeeTitle', _PC_EVENT_FEE);
1482 $tpl->assign('InputFee', 'event_fee');
1483 $tpl->assign('ValueFee', pnVarPrepForDisplay($event_fee));
1484 //=================================================================
1485 // Repeating Information
1486 //=================================================================
1487 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
1488 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
1489 $tpl->assign('RepeatTitle', _PC_REPEAT);
1490 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
1491 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
1492 $tpl->assign('EndDateTitle', _PC_END_DATE);
1493 $tpl->assign('NoEndDateTitle', _PC_NO_END);
1494 $tpl->assign('InputNoRepeat', 'event_repeat');
1495 $tpl->assign('ValueNoRepeat', '0');
1496 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
1497 $tpl->assign('InputRepeat', 'event_repeat');
1498 $tpl->assign('ValueRepeat', '1');
1499 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
1501 unset($in);
1502 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
1503 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
1504 $repeat_freq = array();
1505 foreach ($in as $k => $v) {
1506 array_push($repeat_freq, array('value'=>$keys[$k],
1507 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
1508 'name'=>$v));
1511 $tpl->assign('InputRepeatFreq', 'event_repeat_freq');
1512 if (empty($event_repeat_freq) || $event_repeat_freq < 1) {
1513 $event_repeat_freq = 1;
1516 $tpl->assign('InputRepeatFreqVal', $event_repeat_freq);
1517 $tpl->assign('repeat_freq', $repeat_freq);
1518 unset($in);
1519 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
1520 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
1521 $repeat_freq_type = array();
1522 foreach ($in as $k => $v) {
1523 array_push($repeat_freq_type, array('value'=>$keys[$k],
1524 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
1525 'name'=>$v));
1528 $tpl->assign('InputRepeatFreqType', 'event_repeat_freq_type');
1529 $tpl->assign('repeat_freq_type', $repeat_freq_type);
1531 $tpl->assign('InputRepeatOn', 'event_repeat');
1532 $tpl->assign('ValueRepeatOn', '2');
1533 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
1535 unset($in);
1536 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
1537 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
1538 $repeat_on_num = array();
1539 foreach ($in as $k => $v) {
1540 array_push($repeat_on_num, array('value'=>$keys[$k],
1541 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
1542 'name'=>$v));
1545 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1546 $tpl->assign('repeat_on_num', $repeat_on_num);
1548 unset($in);
1549 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
1550 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
1551 $repeat_on_day = array();
1552 foreach ($in as $k => $v) {
1553 array_push($repeat_on_day, array('value'=>$keys[$k],
1554 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
1555 'name'=>$v));
1558 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1559 $tpl->assign('repeat_on_day', $repeat_on_day);
1561 unset($in);
1562 $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);
1563 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
1564 $repeat_on_freq = array();
1565 foreach ($in as $k => $v) {
1566 array_push($repeat_on_freq, array('value'=>$keys[$k],
1567 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
1568 'name'=>$v));
1571 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1572 if (empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) {
1573 $event_repeat_on_freq = 1;
1576 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1577 $tpl->assign('repeat_on_freq', $repeat_on_freq);
1578 $tpl->assign('MonthsTitle', _PC_MONTHS);
1580 //=================================================================
1581 // PARSE INPUT_END_DATE
1582 //=================================================================
1583 $tpl->assign('InputEndOn', 'event_endtype');
1584 $tpl->assign('ValueEndOn', '1');
1585 $tpl->assign('SelectedEndOn', (int) $event_endtype==1 ? 'checked':'');
1586 //=================================================================
1587 // PARSE INPUT_NO_END
1588 //=================================================================
1589 $tpl->assign('InputNoEnd', 'event_endtype');
1590 $tpl->assign('ValueNoEnd', '0');
1591 $tpl->assign('SelectedNoEnd', (int) $event_endtype==0 ? 'checked':'');
1592 $qstring = preg_replace("/provider_id=[0-9]*[&]{0,1}/", "", $_SERVER['QUERY_STRING']);
1593 $tpl->assign('qstring', $qstring);
1595 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1596 $authkey = $output->FormHidden('authid', pnSecGenAuthKey());
1597 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1599 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1600 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1601 $form_hidden .= "<input type=\"hidden\" name=\"category\" value=\"$cat\" />";
1602 if (isset($data_loaded)) {
1603 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1604 $tpl->assign('FormHidden', $form_hidden);
1607 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1608 '.$authkey.'<input type="submit" name="submit" value="go">' ;
1609 $tpl->assign('FormSubmit', $form_submit);
1611 // do not cache this page
1612 if ($admin) {
1613 $output->Text($tpl->fetch($template_name.'/admin/submit.html'));
1616 //check flag no_nav, if true use much smaller submit form for find_patient.php, etc
1617 //elseif (pnVarCleanFromInput("no_nav") == 1) {
1618 // $output->Text($tpl->fetch($template_name.'/user/submit_no_nav.html'));
1619 //} else {
1620 // $output->Text($tpl->fetch($template_name.'/user/submit.html'));
1622 $output->Text(postcalendar_footer());
1623 return $output->GetOutput();
1626 function &postcalendar_userapi_pcGetEventDetails($eid)
1629 if (!isset($eid)) {
1630 return false;
1633 list($dbconn) = pnDBGetConn();
1634 $pntable = pnDBGetTables();
1636 // link to the events tables
1637 $table = $pntable['postcalendar_events'];
1638 $cattable = $pntable['postcalendar_categories'];
1640 $sql = "SELECT DISTINCT e.pc_eid,
1641 e.pc_informant,
1642 e.pc_catid,
1643 e.pc_title,
1644 e.pc_time,
1645 e.pc_hometext,
1646 e.pc_eventDate,
1647 e.pc_duration,
1648 e.pc_endDate,
1649 e.pc_startTime,
1650 e.pc_recurrtype,
1651 e.pc_recurrfreq,
1652 e.pc_recurrspec,
1653 e.pc_topic,
1654 e.pc_alldayevent,
1655 e.pc_location,
1656 e.pc_conttel,
1657 e.pc_contname,
1658 e.pc_contemail,
1659 e.pc_website,
1660 e.pc_fee,
1661 e.pc_sharing,
1662 c.pc_catcolor,
1663 c.pc_catname,
1664 c.pc_catdesc,
1665 e.pc_pid,
1666 e.pc_aid,
1667 pd.pubpid
1668 FROM ($table e, $cattable c)
1669 LEFT JOIN patient_data as pd ON (pd.pid = e.pc_pid)
1670 WHERE (e.pc_eid = '$eid' AND c.pc_catid = e.pc_catid)";
1672 $result = $dbconn->Execute($sql);
1673 if ($dbconn->ErrorNo() != 0) {
1674 die($dbconn->ErrorMsg());
1677 $event = array();
1678 if (!isset($result)) {
1679 return $event;
1682 list($event['eid'], $event['uname'], $event['catid'],
1683 $event['title'], $event['time'], $event['hometext'],
1684 $event['eventDate'], $event['duration'], $event['endDate'],
1685 $event['startTime'], $event['recurrtype'], $event['recurrfreq'],
1686 $event['recurrspec'], $event['topic'], $event['alldayevent'],
1687 $event['location'], $event['conttel'], $event['contname'],
1688 $event['contemail'], $event['website'], $event['fee'], $event['sharing'],
1689 $event['catcolor'], $event['catname'], $event['catdesc'], $event['pid'], $event['aid'],$event['pubpid']) = $result->fields;
1690 // there has to be a more intelligent way to do this
1691 @list($event['duration_hours'],$dmin) = @explode('.', ($event['duration']/60/60));
1692 $event['duration_minutes'] = substr(sprintf('%.2f', '.' . 60*($dmin/100)), 2, 2);
1693 //''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1694 $result->Close();
1695 //pennfirm fix to reflect openemr user/informant
1696 $userid = pnUserGetVar('uid');
1698 // get the user id of event's author
1699 $users = pnUserGetAll();
1700 foreach ($users as $user) {
1701 if ($user['uname'] == $event['uname']) {
1702 $cuserid = $user['uid'];
1703 break;
1707 unset($users);
1709 // is this a public event to be shown as busy?
1710 if ($event['sharing'] == SHARING_PRIVATE && $cuserid != $userid) {
1711 // they are not supposed to see this
1712 return false;
1713 } elseif ($event['sharing'] == SHARING_BUSY && $cuserid != $userid) {
1714 // make it not display any information
1715 $event['title'] = _USER_BUSY_TITLE;
1716 $event['hometext'] = _USER_BUSY_MESSAGE;
1717 $event['location'] = '';
1718 $event['conttel'] = '';
1719 $event['contname'] = '';
1720 $event['contemail'] = '';
1721 $event['website'] = '';
1722 $event['fee'] = '';
1723 } else {
1724 $event['title'] = $event['title'];
1725 $event['hometext'] = $event['hometext'];
1726 $event['location'] = $event['location'];
1727 $event['conttel'] = $event['conttel'];
1728 $event['contname'] = $event['contname'];
1729 $event['contemail'] = $event['contemail'];
1730 $event['website'] = $event['website'];
1731 $event['fee'] = $event['fee'];
1734 $event['desc'] = $event['hometext'];
1735 $event['website'] = $event['website'];
1736 if (!empty($event['pid'])) {
1737 $event['patient_name'] = getPatientName($event['pid']);
1740 if (empty($event['aid'])) {
1741 $event['aid']= -1;
1744 return $event;
1748 * postcalendar_userapi_eventDetail
1749 * Creates the detailed event display and outputs html.
1750 * Accepts an array of key/value pairs
1751 * @param int $eid the id of the event to display
1752 * @return string html output
1753 * @access public
1755 function postcalendar_adminapi_eventDetail($args)
1757 return postcalendar_userapi_eventDetail($args, true);
1759 function postcalendar_userapi_eventDetail($args, $admin = false)
1761 if (!(bool)PC_ACCESS_READ) {
1762 return _POSTCALENDARNOAUTH;
1765 // get the theme globals :: is there a better way to do this?
1766 pnThemeLoad(pnUserGetTheme());
1767 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
1768 global $textcolor1, $textcolor2;
1769 $popup = pnVarCleanFromInput('popup');
1770 extract($args);
1771 unset($args);
1772 if (!isset($cacheid)) {
1773 $cacheid = null;
1776 if (!isset($eid)) {
1777 return false;
1780 if (!isset($nopop)) {
1781 $nopop = false;
1784 $uid = pnUserGetVar('uid');
1785 //=================================================================
1786 // Find out what Template we're using
1787 //=================================================================
1788 $template_name = _SETTING_TEMPLATE;
1789 if (!isset($template_name)) {
1790 $template_name = 'default';
1793 //=================================================================
1794 // Setup Smarty Template Engine
1795 //=================================================================
1796 $tpl = new pcSmarty();
1798 if ($admin) {
1799 $template = $template_name.'/admin/details.html';
1800 $args['cacheid'] = '';
1801 $print=0;
1802 $Date =& postcalendar_getDate();
1803 $tpl->caching = false;
1804 } else {
1805 $template = $template_name.'/user/details.html';
1808 if (!$tpl->is_cached($template, $cacheid)) {
1809 // let's get the DB information
1810 list($dbconn) = pnDBGetConn();
1811 $pntable = pnDBGetTables();
1812 // get the event's information
1813 $event =& postcalendar_userapi_pcGetEventDetails($eid);
1814 // if the above is false, it's a private event for another user
1815 // we should not diplay this - so we just exit gracefully
1816 if ($event === false) {
1817 return false;
1820 //=================================================================
1821 // get event's topic information
1822 //=================================================================
1823 $topics_table = $pntable['topics'];
1824 $topics_column = $pntable['topics_column'];
1825 $topicsql = "SELECT $topics_column[topictext],$topics_column[topicimage]
1826 FROM $topics_table
1827 WHERE $topics_column[topicid] = $event[topic]
1828 LIMIT 1";
1829 $topic_result = $dbconn->Execute($topicsql);
1830 list($event['topictext'],$event['topicimg']) = $topic_result->fields;
1831 $location = unserialize($event['location']);
1832 $event['location'] = $location['event_location'];
1833 $event['street1'] = $location['event_street1'];
1834 $event['street2'] = $location['event_street2'];
1835 $event['city'] = $location['event_city'];
1836 $event['state'] = $location['event_state'];
1837 $event['postal'] = $location['event_postal'];
1838 $event['date'] = str_replace('-', '', $Date);
1839 //=================================================================
1840 // populate the template
1841 //=================================================================
1842 if (!empty($event['location']) || !empty($event['street1']) ||
1843 !empty($event['street2']) || !empty($event['city']) ||
1844 !empty($event['state']) || !empty($event['postal'])) {
1845 $tpl->assign('LOCATION_INFO', true);
1846 } else {
1847 $tpl->assign('LOCATION_INFO', false);
1850 if (!empty($event['contname']) || !empty($event['contemail']) ||
1851 !empty($event['conttel']) || !empty($event['website'])) {
1852 $tpl->assign('CONTACT_INFO', true);
1853 } else {
1854 $tpl->assign('CONTACT_INFO', false);
1857 $display_type = substr($event['hometext'], 0, 6);
1858 if ($display_type == ':text:') {
1859 $prepFunction = 'pcVarPrepForDisplay';
1860 $event['hometext'] = substr($event['hometext'], 6);
1861 } elseif ($display_type == ':html:') {
1862 $prepFunction = 'pcVarPrepHTMLDisplay';
1863 $event['hometext'] = substr($event['hometext'], 6);
1864 } else {
1865 $prepFunction = 'pcVarPrepHTMLDisplay';
1868 unset($display_type);
1869 // prep the vars for output
1870 $event['title'] =& $prepFunction($event['title']);
1871 $event['hometext'] =& $prepFunction($event['hometext']);
1872 $event['desc'] =& $event['hometext'];
1873 $event['conttel'] =& $prepFunction($event['conttel']);
1874 $event['contname'] =& $prepFunction($event['contname']);
1875 $event['contemail'] =& $prepFunction($event['contemail']);
1876 $event['website'] =& $prepFunction(postcalendar_makeValidURL($event['website']));
1877 $event['fee'] =& $prepFunction($event['fee']);
1878 $event['location'] =& $prepFunction($event['location']);
1879 $event['street1'] =& $prepFunction($event['street1']);
1880 $event['street2'] =& $prepFunction($event['street2']);
1881 $event['city'] =& $prepFunction($event['city']);
1882 $event['state'] =& $prepFunction($event['state']);
1883 $event['postal'] =& $prepFunction($event['postal']);
1885 $tpl->assign_by_ref('A_EVENT', $event);
1886 //=================================================================
1887 // populate the template $ADMIN_OPTIONS
1888 //=================================================================
1889 $target='';
1890 if (_SETTING_OPEN_NEW_WINDOW) {
1891 $target = 'target="csCalendar"';
1894 $admin_edit_url = $admin_delete_url = '';
1895 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADMIN)) {
1896 $admin_edit_url = pnModURL(__POSTCALENDAR__, 'admin', 'submit', array('pc_event_id'=>$eid));
1897 $admin_delete_url = pnModURL(__POSTCALENDAR__, 'admin', 'adminevents', array('action'=>_ACTION_DELETE,'pc_event_id'=>$eid));
1900 $user_edit_url = $user_delete_url = '';
1901 if (pnUserLoggedIn()) {
1902 $logged_in_uname = $_SESSION['authUser'];
1903 } else {
1904 $logged_in_uname = '';
1908 $can_edit = false;
1909 if (pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_ADD) && validateGroupStatus($logged_in_uname, getUsername($event['uname']))) {
1910 $user_edit_url = pnModURL(__POSTCALENDAR__, 'user', 'submit', array('pc_event_id'=>$eid));
1911 $user_delete_url = pnModURL(__POSTCALENDAR__, 'user', 'delete', array('pc_event_id'=>$eid));
1912 $can_edit = true;
1915 $tpl->assign('STYLE', $GLOBALS['style']);
1916 $tpl->assign_by_ref('ADMIN_TARGET', $target);
1917 $tpl->assign_by_ref('ADMIN_EDIT', $admin_edit_url);
1918 $tpl->assign_by_ref('ADMIN_DELETE', $admin_delete_url);
1919 $tpl->assign_by_ref('USER_TARGET', $target);
1920 $tpl->assign_by_ref('USER_EDIT', $user_edit_url);
1921 $tpl->assign_by_ref('USER_DELETE', $user_delete_url);
1922 $tpl->assign_by_ref('USER_CAN_EDIT', $can_edit);
1925 //=================================================================
1926 // Parse the template
1927 //=================================================================
1928 if ($popup != 1 && $print != 1) {
1929 $output = "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1930 $output .= $tpl->fetch($template, $cacheid);
1931 $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
1932 } else {
1933 $theme = pnUserGetTheme();
1934 echo "<html><head>";
1935 echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
1936 echo "<style type=\"text/css\">\n";
1937 echo "@import url(\"themes/$theme/style/style.css\"); ";
1938 echo "</style>\n";
1939 echo "</head><body>\n";
1940 $tpl->display($template, $cacheid);
1941 echo postcalendar_footer();
1942 echo "\n</body></html>";
1943 session_write_close();
1944 exit;
1947 return $output;
1950 function postcalendar_footer()
1952 // lets get the module's information
1953 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1954 //$footer = "<p align=\"right\"><a href=\"http://www.postcalendar.tv\">PostCalendar v$modinfo[version]</a></p>";
1955 $footer = "";
1956 return $footer;
1959 function postcalendar_smarty_pc_sort_day($params, &$smarty)
1961 extract($params);
1963 if (empty($var)) {
1964 $smarty->trigger_error("sort_array: missing 'var' parameter");
1965 return;
1968 if (!in_array('value', array_keys($params))) {
1969 $smarty->trigger_error("sort_array: missing 'value' parameter");
1970 return;
1973 if (!in_array('order', array_keys($params))) {
1974 $order = 'asc';
1977 if (!in_array('inc', array_keys($params))) {
1978 $inc = '15';
1981 if (!in_array('start', array_keys($params))) {
1982 $sh = '08';
1983 $sm = '00';
1984 } else {
1985 list($sh,$sm) = explode(':', $start);
1988 if (!in_array('end', array_keys($params))) {
1989 $eh = '21';
1990 $em = '00';
1991 } else {
1992 list($eh,$em) = explode(':', $end);
1995 if (strtolower($order) == 'asc') {
1996 $function = 'sort_byTimeA';
1999 if (strtolower($order) == 'desc') {
2000 $function = 'sort_byTimeD';
2003 foreach ($value as $events) {
2004 usort($events, $function);
2005 $newArray = $events;
2008 // here we want to create an intelligent array of
2009 // columns and rows to build a nice day view
2010 $ch = $sh;
2011 $cm = $sm;
2012 while ("$ch:$cm" <= "$eh:$em") {
2013 $hours["$ch:$cm"] = array();
2014 $cm += $inc;
2015 if ($cm >= 60) {
2016 $cm = '00';
2017 $ch = sprintf('%02d', $ch+1);
2021 $alldayevents = array();
2022 foreach ($newArray as $event) {
2023 list($sh,$sm,$ss) = explode(':', $event['startTime']);
2024 $eh = sprintf('%02d', $sh + $event['duration_hours']);
2025 $em = sprintf('%02d', $sm + $event['duration_minutes']);
2027 if ($event['alldayevent']) {
2028 // we need an entire column . save till later
2029 $alldayevents[] = $event;
2030 } else {
2031 //find open time slots - avoid overlapping
2032 $needed = array();
2033 $ch = $sh;
2034 $cm = $sm;
2035 //what times do we need?
2036 while ("$ch:$cm" < "$eh:$em") {
2037 $needed[] = "$ch:$cm";
2038 $cm += $inc;
2039 if ($cm >= 60) {
2040 $cm = '00';
2041 $ch = sprintf('%02d', $ch+1);
2045 $i = 0;
2046 foreach ($needed as $time) {
2047 if ($i==0) {
2048 $hours[$time][] = $event;
2049 $key = count($hours[$time])-1;
2050 } else {
2051 $hours[$time][$key] = 'continued';
2054 $i++;
2059 //pcDebugVar($hours);
2060 $smarty->assign_by_ref($var, $hours);
2063 function sort_byCategoryA($a, $b)
2065 if ($a['catname'] < $b['catname']) {
2066 return -1;
2067 } elseif ($a['catname'] > $b['catname']) {
2068 return 1;
2071 function sort_byCategoryD($a, $b)
2073 if ($a['catname'] < $b['catname']) {
2074 return 1;
2075 } elseif ($a['catname'] > $b['catname']) {
2076 return -1;
2079 function sort_byTitleA($a, $b)
2081 if ($a['title'] < $b['title']) {
2082 return -1;
2083 } elseif ($a['title'] > $b['title']) {
2084 return 1;
2087 function sort_byTitleD($a, $b)
2089 if ($a['title'] < $b['title']) {
2090 return 1;
2091 } elseif ($a['title'] > $b['title']) {
2092 return -1;
2095 function sort_byTimeA($a, $b)
2097 if ($a['startTime'] < $b['startTime']) {
2098 return -1;
2099 } elseif ($a['startTime'] > $b['startTime']) {
2100 return 1;
2103 function sort_byTimeD($a, $b)
2105 if ($a['startTime'] < $b['startTime']) {
2106 return 1;
2107 } elseif ($a['startTime'] > $b['startTime']) {
2108 return -1;
2112 * pc_clean
2113 * @param s string text to clean
2114 * @return string cleaned up text
2116 function pc_clean($s)
2118 $display_type = substr($s, 0, 6);
2119 if ($display_type == ':text:') {
2120 $s = substr($s, 6);
2121 } elseif ($display_type == ':html:') {
2122 $s = substr($s, 6);
2125 unset($display_type);
2126 $s = preg_replace('/[\r|\n]/i', '', $s);
2127 $s = str_replace("'", "\'", $s);
2128 $s = str_replace('"', '&quot;', $s);
2129 // ok, now we need to break really long lines
2130 // we only want to break at spaces to allow for
2131 // correct interpretation of special characters
2132 $tmp = explode(' ', $s);
2133 return join("'+' ", $tmp);
2136 function &postcalendar_adminapi_getCategoryLimits()
2138 return postcalendar_userapi_getCategoryLimits();
2140 function &postcalendar_userapi_getCategoryLimits()
2142 list($dbconn) = pnDBGetConn();
2143 $pntable = pnDBGetTables();
2144 $cat_table = $pntable['postcalendar_limits'];
2145 $sql = "SELECT pc_limitid,pc_catid,pc_starttime,pc_endtime,
2146 pc_limit FROM $cat_table
2147 ORDER BY pc_limitid";
2148 $result = $dbconn->Execute($sql);
2150 if ($dbconn->ErrorNo() != 0) {
2151 return array();
2154 if (!isset($result)) {
2155 return array();
2158 $limits = array();
2159 for ($i=0; !$result->EOF; $result->MoveNext()) {
2160 list($limitid,$catid,$startTime,$endTime,$limit) = $result->fields;
2161 // check the category's permissions
2162 if (!pnSecAuthAction(0, 'PostCalendar::Category', "$catname::$catid", ACCESS_OVERVIEW)) {
2163 continue;
2166 $limits[$i]['limitid'] = $limitid;
2167 $limits[$i]['catid'] = $catid;
2168 $limits[$i]['startTime']= $startTime;
2169 $limits[$i]['endTime'] = $endTime;
2170 $limits[$i++]['limit'] = $limit;
2173 $result->Close();
2174 return $limits;