fix issue #1176
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnadmin.php
blobf7a45efb133ea6db08520433b2a8caab20958463
1 <?php
2 @define('__POSTCALENDAR__', 'PostCalendar');
3 /**
4 * $Id$
6 * PostCalendar::PostNuke Events Calendar Module
7 * Copyright (C) 2002 The PostCalendar Team
8 * http://postcalendar.tv
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * To read the license please read the docs/license.txt or visit
25 * http://www.gnu.org/copyleft/gpl.html
28 //=========================================================================
29 // Load the API Functions
30 //=========================================================================
31 pnModAPILoad(__POSTCALENDAR__, 'admin');
33 /**
34 * the main administration function
35 * This function is the default function, and is called whenever the
36 * module is initiated without defining arguments. As such it can
37 * be used for a number of things, but most commonly it either just
38 * shows the module menu and returns or calls whatever the module
39 * designer feels should be the default function (often this is the
40 * view() function)
42 function postcalendar_admin_main()
44 if (!PC_ACCESS_ADMIN) {
45 return _POSTCALENDAR_NOAUTH; }
46 return postcalendar_admin_modifyconfig();
48 function postcalendar_admin_listapproved()
50 return postcalendar_admin_showlist('', _EVENT_APPROVED, 'listapproved', _PC_APPROVED_ADMIN); }
51 function postcalendar_admin_listhidden()
53 return postcalendar_admin_showlist('', _EVENT_HIDDEN, 'listhidden', _PC_HIDDEN_ADMIN); }
54 function postcalendar_admin_listqueued()
56 return postcalendar_admin_showlist('', _EVENT_QUEUED, 'listqueued', _PC_QUEUED_ADMIN); }
57 function postcalendar_admin_showlist($e = '', $type, $function, $title, $msg = '')
59 if (!PC_ACCESS_ADMIN) {
60 return _POSTCALENDAR_NOAUTH; }
61 $header = <<<EOF
62 <html>
63 <head></head>
64 <body bgcolor=
65 EOF;
66 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
67 $output .= $header;
68 $output .= postcalendar_adminmenu();
70 if (!empty($e)) {
71 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
72 $output .= '<center><b>'.$e.'</b></center>';
73 $output .= '</div><br />';
76 if (!empty($msg)) {
77 $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
78 $output .= '<center><b>'.$msg.'</b></center>';
79 $output .= '</div><br />';
82 $offset_increment = _SETTING_HOW_MANY_EVENTS;
83 if (empty($offset_increment)) {
84 $offset_increment = 15;
87 pnThemeLoad(pnUserGetTheme());
88 // get the theme globals :: is there a better way to do this?
89 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
90 global $textcolor1, $textcolor2;
92 $offset = pnVarCleanFromInput('offset');
93 $sort = pnVarCleanFromInput('sort');
94 $sdir = pnVarCleanFromInput('sdir');
95 if (!isset($sort)) {
96 $sort = 'time';
98 if (!isset($sdir)) {
99 $sdir = 1;
101 if (!isset($offset)) {
102 $offset = 0;
105 $result = pnModAPIFunc(
106 __POSTCALENDAR__,
107 'admin',
108 'getAdminListEvents',
109 array('type'=>$type,
110 'sdir'=>$sdir,
111 'sort'=>$sort,
112 'offset'=>$offset,
113 'offset_increment'=>$offset_increment)
116 $output .= pnModAPIFunc(
117 __POSTCALENDAR__,
118 'admin',
119 'buildAdminList',
120 array('type'=>$type,
121 'title'=>$title,
122 'sdir'=>$sdir,
123 'sort'=>$sort,
124 'offset'=>$offset,
125 'offset_increment'=>$offset_increment,
126 'function'=>$function,
127 'result'=>$result)
130 $output .= "</body></html>";
131 return $output;
134 function postcalendar_admin_adminevents()
136 if (!PC_ACCESS_ADMIN) {
137 return _POSTCALENDAR_NOAUTH; }
139 $output = '';
140 list($action,$pc_event_id,$thelist) = pnVarCleanFromInput('action', 'pc_event_id', 'thelist');
142 if (!isset($pc_event_id)) {
143 $e = _PC_NO_EVENT_SELECTED;
145 switch ($thelist) {
146 case 'listqueued':
147 $output .= postcalendar_admin_showlist($e, _EVENT_QUEUED, 'showlist');
148 break;
150 case 'listhidden':
151 $output .= postcalendar_admin_showlist($e, _EVENT_HIDDEN, 'showlist');
152 break;
154 case 'listapproved':
155 $output .= postcalendar_admin_showlist($e, _EVENT_APPROVED, 'showlist');
156 break;
158 return $output;
161 // main menu
162 $output = postcalendar_adminmenu();
163 $function = '';
164 switch ($action) {
165 case _ADMIN_ACTION_APPROVE:
166 $function = 'approveevents';
167 $are_you_sure_text = _PC_APPROVE_ARE_YOU_SURE;
168 break;
170 case _ADMIN_ACTION_HIDE:
171 $function = 'hideevents';
172 $are_you_sure_text = _PC_HIDE_ARE_YOU_SURE;
173 break;
175 case _ADMIN_ACTION_DELETE:
176 $function = 'deleteevents';
177 $are_you_sure_text = _PC_DELETE_ARE_YOU_SURE;
178 break;
181 if (!empty($function)) {
182 $output .= '<form action="'.pnModUrl(__POSTCALENDAR__, 'admin', $function).'" method="post">';
183 $output .= $are_you_sure_text.' ';
184 $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
185 $output .= '<br /><br />';
187 if (is_array($pc_event_id)) {
188 foreach ($pc_event_id as $eid) {
189 $output .= pnModAPIFunc(__POSTCALENDAR__, 'admin', 'eventDetail', array('eid'=>$eid,'nopop'=>true));
190 $output .= '<br /><br />';
191 $output .= '<input type="hidden" name="pc_eid[]" value="'.$eid.'" />';
193 } else {
194 $output .= pnModAPIFunc(__POSTCALENDAR__, 'admin', 'eventDetail', array('eid'=>$pc_event_id,'nopop'=>true));
195 $output .= '<br /><br />';
196 $output .= '<input type="hidden" name="pc_eid[]" value="'.$pc_event_id.'" />';
198 if (!empty($function)) {
199 $output .= $are_you_sure_text.' ';
200 $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
201 $output .= '</form>';
204 return $output;
207 function postcalendar_admin_approveevents()
209 if (!PC_ACCESS_ADMIN) {
210 return _POSTCALENDAR_NOAUTH; }
212 $pc_eid = pnVarCleanFromInput('pc_eid');
213 $approve_list = '';
214 foreach ($pc_eid as $eid) {
215 if (!empty($approve_list)) {
216 $approve_list .= ','; }
217 $approve_list .= $eid;
220 list($dbconn) = pnDBGetConn();
221 $pntable = pnDBGetTables();
222 $events_table = $pntable['postcalendar_events'];
223 $events_column = &$pntable['postcalendar_events_column'];
225 $sql = "UPDATE $events_table
226 SET $events_column[eventstatus] = "._EVENT_APPROVED."
227 WHERE $events_column[eid] IN ($approve_list)";
229 $dbconn->Execute($sql);
230 if ($dbconn->ErrorNo() != 0) {
231 $msg = _PC_ADMIN_EVENT_ERROR;
232 } else {
233 $msg = _PC_ADMIN_EVENTS_APPROVED;
236 // clear the template cache
237 $tpl = new pcSmarty();
238 $tpl->clear_all_cache();
239 return postcalendar_admin_showlist('', _EVENT_APPROVED, 'listapproved', _PC_APPROVED_ADMIN, $msg);
242 function postcalendar_admin_hideevents()
244 if (!PC_ACCESS_ADMIN) {
245 return _POSTCALENDAR_NOAUTH; }
247 $pc_eid = pnVarCleanFromInput('pc_eid');
248 $output = postcalendar_adminmenu();
249 $event_list = '';
250 foreach ($pc_eid as $eid) {
251 if (!empty($event_list)) {
252 $event_list .= ','; }
253 $event_list .= $eid;
256 list($dbconn) = pnDBGetConn();
257 $pntable = pnDBGetTables();
258 $events_table = $pntable['postcalendar_events'];
259 $events_column = &$pntable['postcalendar_events_column'];
261 $sql = "UPDATE $events_table
262 SET $events_column[eventstatus] = "._EVENT_HIDDEN."
263 WHERE $events_column[eid] IN ($event_list)";
265 $dbconn->Execute($sql);
266 if ($dbconn->ErrorNo() != 0) {
267 $msg = _PC_ADMIN_EVENT_ERROR;
268 } else {
269 $msg = _PC_ADMIN_EVENTS_HIDDEN;
272 // clear the template cache
273 $tpl = new pcSmarty();
274 $tpl->clear_all_cache();
275 return postcalendar_admin_showlist('', _EVENT_APPROVED, 'listapproved', _PC_APPROVED_ADMIN, $msg);
278 function postcalendar_admin_deleteevents()
280 if (!PC_ACCESS_ADMIN) {
281 return _POSTCALENDAR_NOAUTH; }
283 $pc_eid = pnVarCleanFromInput('pc_eid');
284 $output = postcalendar_adminmenu();
285 $event_list = '';
286 foreach ($pc_eid as $eid) {
287 if (!empty($event_list)) {
288 $event_list .= ','; }
289 $event_list .= $eid;
292 list($dbconn) = pnDBGetConn();
293 $pntable = pnDBGetTables();
294 $events_table = $pntable['postcalendar_events'];
295 $events_column = &$pntable['postcalendar_events_column'];
297 $sql = "DELETE FROM $events_table WHERE $events_column[eid] IN ($event_list)";
299 $dbconn->Execute($sql);
300 if ($dbconn->ErrorNo() != 0) {
301 $msg = _PC_ADMIN_EVENT_ERROR;
302 } else {
303 $msg = _PC_ADMIN_EVENTS_DELETED;
306 // clear the t
307 $tpl = new pcSmarty();
308 $tpl->clear_all_cache();
309 return postcalendar_admin_showlist('', _EVENT_APPROVED, 'listapproved', _PC_APPROVED_ADMIN, $msg);
312 function postcalendar_admin_edit($args)
314 return postcalendar_admin_submit($args); }
315 function postcalendar_admin_submit($args)
317 if (!PC_ACCESS_ADMIN) {
318 return _POSTCALENDAR_NOAUTH; }
320 pnModAPILoad(__POSTCALENDAR__, 'user');
321 $output = postcalendar_adminmenu();
323 // get the theme globals :: is there a better way to do this?
324 pnThemeLoad(pnUserGetTheme());
325 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $textcolor1, $textcolor2;
327 extract($args);
329 $Date = postcalendar_getDate();
330 $year = substr($Date, 0, 4);
331 $month = substr($Date, 4, 2);
332 $day = substr($Date, 6, 2);
334 // basic event information
335 $event_subject = pnVarCleanFromInput('event_subject');
336 $event_desc = pnVarCleanFromInput('event_desc');
337 $event_sharing = pnVarCleanFromInput('event_sharing');
338 $event_category = pnVarCleanFromInput('event_category');
339 $event_topic = pnVarCleanFromInput('event_topic');
341 // event start information
342 $event_startmonth = pnVarCleanFromInput('event_startmonth');
343 $event_startday = pnVarCleanFromInput('event_startday');
344 $event_startyear = pnVarCleanFromInput('event_startyear');
345 $event_starttimeh = pnVarCleanFromInput('event_starttimeh');
346 $event_starttimem = pnVarCleanFromInput('event_starttimem');
347 $event_startampm = pnVarCleanFromInput('event_startampm');
349 // event end information
350 $event_endmonth = pnVarCleanFromInput('event_endmonth');
351 $event_endday = pnVarCleanFromInput('event_endday');
352 $event_endyear = pnVarCleanFromInput('event_endyear');
353 $event_endtype = pnVarCleanFromInput('event_endtype');
354 $event_dur_hours = pnVarCleanFromInput('event_dur_hours');
355 $event_dur_minutes = pnVarCleanFromInput('event_dur_minutes');
356 $event_duration = (60*60*$event_dur_hours) + (60*$event_dur_minutes);
357 $event_allday = pnVarCleanFromInput('event_allday');
359 // location data
360 $event_location = pnVarCleanFromInput('event_location');
361 $event_street1 = pnVarCleanFromInput('event_street1');
362 $event_street2 = pnVarCleanFromInput('event_street2');
363 $event_city = pnVarCleanFromInput('event_city');
364 $event_state = pnVarCleanFromInput('event_state');
365 $event_postal = pnVarCleanFromInput('event_postal');
366 $event_location_info = serialize(compact(
367 'event_location',
368 'event_street1',
369 'event_street2',
370 'event_city',
371 'event_state',
372 'event_postal'
374 // contact data
375 $event_contname = pnVarCleanFromInput('event_contname');
376 $event_conttel = pnVarCleanFromInput('event_conttel');
377 $event_contemail = pnVarCleanFromInput('event_contemail');
378 $event_website = pnVarCleanFromInput('event_website');
379 $event_fee = pnVarCleanFromInput('event_fee');
381 // event repeating data
382 $event_repeat = pnVarCleanFromInput('event_repeat');
383 $event_repeat_freq = pnVarCleanFromInput('event_repeat_freq');
384 $event_repeat_freq_type = pnVarCleanFromInput('event_repeat_freq_type');
385 $event_repeat_on_num = pnVarCleanFromInput('event_repeat_on_num');
386 $event_repeat_on_day = pnVarCleanFromInput('event_repeat_on_day');
387 $event_repeat_on_freq = pnVarCleanFromInput('event_repeat_on_freq');
388 $event_recurrspec = serialize(compact(
389 'event_repeat_freq',
390 'event_repeat_freq_type',
391 'event_repeat_on_num',
392 'event_repeat_on_day',
393 'event_repeat_on_freq'
396 $pc_html_or_text = pnVarCleanFromInput('pc_html_or_text');
397 $form_action = pnVarCleanFromInput('form_action');
398 $pc_event_id = pnVarCleanFromInput('pc_event_id');
399 $data_loaded = pnVarCleanFromInput('data_loaded');
400 $is_update = pnVarCleanFromInput('is_update');
401 $authid = pnVarCleanFromInput('authid');
403 if (pnUserLoggedIn()) {
404 $uname = pnUserGetVar('uname'); } else {
405 $uname = pnConfigGetVar('anonymous'); }
406 if (!isset($event_repeat)) {
407 $event_repeat = 0; }
409 // lets wrap all the data into array for passing to submit and preview functions
410 if (!isset($pc_event_id) || empty($pc_event_id) || $data_loaded) {
411 $eventdata = compact(
412 'event_subject',
413 'event_desc',
414 'event_sharing',
415 'event_category',
416 'event_topic',
417 'event_startmonth',
418 'event_startday',
419 'event_startyear',
420 'event_starttimeh',
421 'event_starttimem',
422 'event_startampm',
423 'event_endmonth',
424 'event_endday',
425 'event_endyear',
426 'event_endtype',
427 'event_dur_hours',
428 'event_dur_minutes',
429 'event_duration',
430 'event_allday',
431 'event_location',
432 'event_street1',
433 'event_street2',
434 'event_city',
435 'event_state',
436 'event_postal',
437 'event_location_info',
438 'event_contname',
439 'event_conttel',
440 'event_contemail',
441 'event_website',
442 'event_fee',
443 'event_repeat',
444 'event_repeat_freq',
445 'event_repeat_freq_type',
446 'event_repeat_on_num',
447 'event_repeat_on_day',
448 'event_repeat_on_freq',
449 'event_recurrspec',
450 'uname',
451 'Date',
452 'year',
453 'month',
454 'day',
455 'pc_html_or_text'
457 $eventdata['is_update'] = $is_update;
458 $eventdata['pc_event_id'] = $pc_event_id;
459 $eventdata['data_loaded'] = true;
460 } else {
461 $event = postcalendar_userapi_pcGetEventDetails($pc_event_id);
462 $eventdata['event_subject'] = $event['title'];
463 $eventdata['event_desc'] = $event['hometext'];
464 $eventdata['event_sharing'] = $event['sharing'];
465 $eventdata['event_category'] = $event['catid'];
466 $eventdata['event_topic'] = $event['topic'];
467 $eventdata['event_startmonth'] = substr($event['eventDate'], 5, 2);
468 $eventdata['event_startday'] = substr($event['eventDate'], 8, 2);
469 $eventdata['event_startyear'] = substr($event['eventDate'], 0, 4);
470 $eventdata['event_starttimeh'] = substr($event['startTime'], 0, 2);
471 $eventdata['event_starttimem'] = substr($event['startTime'], 3, 2);
472 $eventdata['event_startampm'] = $eventdata['event_starttimeh'] < 12 ? _PC_AM : _PC_PM ;
473 $eventdata['event_endmonth'] = substr($event['endDate'], 5, 2);
474 $eventdata['event_endday'] = substr($event['endDate'], 8, 2);
475 $eventdata['event_endyear'] = substr($event['endDate'], 0, 4);
476 $eventdata['event_endtype'] = $event['endDate'] == '0000-00-00' ? '0' : '1' ;
477 $eventdata['event_dur_hours'] = $event['duration_hours'];
478 $eventdata['event_dur_minutes'] = $event['duration_minutes'];
479 $eventdata['event_duration'] = $event['duration'];
480 $eventdata['event_allday'] = $event['alldayevent'];
481 $loc_data = unserialize($event['location']);
482 $eventdata['event_location'] = $loc_data['event_location'];
483 $eventdata['event_street1'] = $loc_data['event_street1'];
484 $eventdata['event_street2'] = $loc_data['event_street2'];
485 $eventdata['event_city'] = $loc_data['event_city'];
486 $eventdata['event_state'] = $loc_data['event_state'];
487 $eventdata['event_postal'] = $loc_data['event_postal'];
488 $eventdata['event_location_info'] = $loc_data;
489 $eventdata['event_contname'] = $event['contname'];
490 $eventdata['event_conttel'] = $event['conttel'];
491 $eventdata['event_contemail'] = $event['contemail'];
492 $eventdata['event_website'] = $event['website'];
493 $eventdata['event_fee'] = $event['fee'];
494 $eventdata['event_repeat'] = $event['recurrtype'];
495 $eventdata['event_pid'] = $event['pid'];
496 $eventdata['event_aid'] = $event['aid'];
497 $rspecs = unserialize($event['recurrspec']);
498 $eventdata['event_repeat_freq'] = $rspecs['event_repeat_freq'];
499 $eventdata['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
500 $eventdata['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
501 $eventdata['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
502 $eventdata['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
503 $eventdata['event_recurrspec'] = $rspecs;
504 $eventdata['uname'] = $uname;
505 $eventdata['Date'] = $Date;
506 $eventdata['year'] = $year;
507 $eventdata['month'] = $month;
508 $eventdata['day'] = $day;
509 $eventdata['is_update'] = true;
510 $eventdata['pc_event_id'] = $pc_event_id;
511 $eventdata['data_loaded'] = true;
512 $eventdata['pc_html_or_text'] = $pc_html_or_text;
515 // lets get the module's information
516 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
517 $categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
519 //================================================================
520 // ERROR CHECKING
521 //================================================================
522 $required_vars = array('event_subject','event_desc');
523 $required_name = array(_PC_EVENT_TITLE,_PC_EVENT_DESC);
524 $error_msg = '';
525 $reqCount = count($required_vars);
526 for ($r=0; $r<$reqCount; $r++) {
527 if (empty($$required_vars[$r]) || !preg_match('/\S/i', $$required_vars[$r])) {
528 $error_msg .= '<b>' . $required_name[$r] . '</b> ' . _PC_SUBMIT_ERROR4 . '<br />';
531 unset($reqCount);
532 // check repeating frequencies
533 if ($event_repeat == REPEAT) {
534 if (!isset($event_repeat_freq) || $event_repeat_freq < 1 || empty($event_repeat_freq)) {
535 $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
536 } elseif (!is_numeric($event_repeat_freq)) {
537 $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
539 } elseif ($event_repeat == REPEAT_ON) {
540 if (!isset($event_repeat_on_freq) || $event_repeat_on_freq < 1 || empty($event_repeat_on_freq)) {
541 $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
542 } elseif (!is_numeric($event_repeat_on_freq)) {
543 $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
546 // check date validity
547 if (_SETTING_TIME_24HOUR) {
548 $startTime = $event_starttimeh.':'.$event_starttimem;
549 $endTime = $event_endtimeh.':'.$event_endtimem;
550 } else {
551 if ($event_startampm == _AM_VAL) {
552 $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
553 } else {
554 $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
556 $startTime = $event_starttimeh.':'.$event_starttimem;
558 $sdate = strtotime($event_startyear.'-'.$event_startmonth.'-'.$event_startday);
559 $edate = strtotime($event_endyear.'-'.$event_endmonth.'-'.$event_endday);
560 $tdate = strtotime(date('Y-m-d'));
561 if ($edate < $sdate && $event_endtype == 1) {
562 $error_msg .= _PC_SUBMIT_ERROR1 . '<br />';
564 if (!checkdate($event_startmonth, $event_startday, $event_startyear)) {
565 $error_msg .= _PC_SUBMIT_ERROR2 . '<br />';
567 if (!checkdate($event_endmonth, $event_endday, $event_endyear)) {
568 $error_msg .= _PC_SUBMIT_ERROR3 . '<br />';
571 //================================================================
572 // Preview the event
573 //================================================================
574 if ($form_action == 'preview') {
575 if (!empty($error_msg)) {
576 $preview = false;
577 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
578 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
579 $output .= '<center><b>' . _PC_SUBMIT_ERROR . '</b></center>';
580 $output .= '<br />';
581 $output .= $error_msg;
582 $output .= '</td></td></table>';
583 $output .= '</td></td></table>';
584 $output .= '<br /><br />';
585 } else {
586 $output .= pnModAPIFunc(__POSTCALENDAR__, 'user', 'eventPreview', $eventdata);
587 $output .= '<br />';
591 //================================================================
592 // Enter the event into the DB
593 //================================================================
594 if ($form_action == 'commit') {
595 //if (!pnSecConfirmAuthKey()) { return(_NO_DIRECT_ACCESS); }
596 if (!empty($error_msg)) {
597 $preview = false;
598 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
599 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
600 $output .= '<center><b>'._PC_SUBMIT_ERROR.'</b></center>';
601 $output .= '<br />';
602 $output .= $error_msg;
603 $output .= '</td></td></table>';
604 $output .= '</td></td></table>';
605 $output .= '<br /><br />';
606 } else {
607 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'submitEvent', $eventdata)) {
608 $output .= '<center><div style="padding:5px; border:1px solid red; background-color: pink;">';
609 $output .= "<b>"._PC_EVENT_SUBMISSION_FAILED."</b>";
610 $output .= '</div></center><br />';
611 $output .= '<br />';
612 } else {
613 // clear the Smarty cache
614 $tpl = new pcSmarty();
615 $tpl->clear_all_cache();
616 $output .= '<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
617 if ($is_update) {
618 $output .= "<b>"._PC_EVENT_EDIT_SUCCESS."</b>";
619 } else {
620 $output .= "<b>"._PC_EVENT_SUBMISSION_SUCCESS."</b>";
622 $output .= '</div></center><br />';
623 $output .= '<br />';
624 // clear the form vars
625 $event_subject=$event_desc=$event_sharing=$event_category=$event_topic=
626 $event_startmonth=$event_startday=$event_startyear=$event_starttimeh=$event_starttimem=$event_startampm=
627 $event_endmonth=$event_endday=$event_endyear=$event_endtype=$event_dur_hours=$event_dur_minutes=
628 $event_duration=$event_allday=$event_location=$event_street1=$event_street2=$event_city=$event_state=
629 $event_postal=$event_location_info=$event_contname=$event_conttel=$event_contemail=
630 $event_website=$event_fee=$event_repeat=$event_repeat_freq=$event_repeat_freq_type=
631 $event_repeat_on_num=$event_repeat_on_day=$event_repeat_on_freq=$event_recurrspec=$uname=
632 $Date=$year=$month=$day=$pc_html_or_text=null;
633 $is_update = false;
634 $pc_event_id = 0;
635 // lets wrap all the data into array for passing to submit and preview functions
636 $eventdata = compact(
637 'event_subject',
638 'event_desc',
639 'event_sharing',
640 'event_category',
641 'event_topic',
642 'event_startmonth',
643 'event_startday',
644 'event_startyear',
645 'event_starttimeh',
646 'event_starttimem',
647 'event_startampm',
648 'event_endmonth',
649 'event_endday',
650 'event_endyear',
651 'event_endtype',
652 'event_dur_hours',
653 'event_dur_minutes',
654 'event_duration',
655 'event_allday',
656 'event_location',
657 'event_street1',
658 'event_street2',
659 'event_city',
660 'event_state',
661 'event_postal',
662 'event_location_info',
663 'event_contname',
664 'event_conttel',
665 'event_contemail',
666 'event_website',
667 'event_fee',
668 'event_repeat',
669 'event_repeat_freq',
670 'event_repeat_freq_type',
671 'event_repeat_on_num',
672 'event_repeat_on_day',
673 'event_repeat_on_freq',
674 'event_recurrspec',
675 'uname',
676 'Date',
677 'year',
678 'month',
679 'day',
680 'pc_html_or_text',
681 'is_update',
682 'pc_event_id'
688 $output .= pnModAPIFunc('PostCalendar', 'admin', 'buildSubmitForm', $eventdata);
689 return $output;
692 function postcalendar_admin_modifyconfig($msg = '', $showMenu = true)
694 if (!PC_ACCESS_ADMIN) {
695 return _POSTCALENDAR_NOAUTH; }
697 $output = new pnHTML();
698 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
699 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
701 $defaultsURL = pnModURL(__POSTCALENDAR__, 'admin', 'resetDefaults');
702 $defaultsText = _EDIT_PC_CONFIG_DEFAULT;
704 $jsColorPicker = <<<EOF
705 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
706 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
707 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
708 <script LANGUAGE="JavaScript">
709 var cp = new ColorPicker('window');
710 // Runs when a color is clicked
711 function pickColor(color) {
712 field.value = color;
715 var field;
716 function pick(anchorname) {
717 field = document.forms.pcConfig.pcDayHighlightColor;
718 cp.show(anchorname);
720 </SCRIPT>
721 EOF;
723 $output->SetInputMode(_PNH_VERBATIMINPUT);
724 $header = <<<EOF
725 <html>
726 <head></head>
727 <body bgcolor=
728 EOF;
729 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
730 $output->Text($header);
731 $output->Text($jsColorPicker);
732 if ($showMenu) {
733 $output->Text(postcalendar_adminmenu());
736 if (!empty($msg)) {
737 $output->Text('<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
738 $output->Text("<b>$msg</b>");
739 $output->Text('</div></center><br />');
742 $formURL = pnModUrl(__POSTCALENDAR__, 'admin', 'updateconfig');
743 /*$output->Text("<form action=\"$formURL\" method=\"post\" enctype=\"application/x-www-form-urlencoded\" name=\"pcConfig\" id=\"pcConfig\">");
744 $output->Text('<table border="1" cellpadding="5" cellspacing="1">');
745 $output->Text('<tr><td align="left">'._PC_ADMIN_GLOBAL_SETTINGS,'</td>');
746 $output->Text("<td nowrap><a href=\"$defaultsURL\">$defaultsText</a></td></tr>");
748 $settings = array();
749 $output->SetOutputMode(_PNH_RETURNOUTPUT);
750 $i=0;
752 // global PostCalendar config options
753 $settings[$i][] = $output->Text(_PC_NOTIFY_ADMIN);
754 $settings[$i++][] = $output->FormCheckBox('pcNotifyAdmin', pnModGetVar(__POSTCALENDAR__,'pcNotifyAdmin'));
755 $settings[$i][] = $output->Text(_PC_NOTIFY_EMAIL);
756 $settings[$i++][] = $output->FormText('pcNotifyEmail', pnModGetVar(__POSTCALENDAR__,'pcNotifyEmail'));
758 $settings[$i][] = $output->Text(_PC_ALLOW_DIRECT_SUBMIT);
759 $settings[$i++][] = $output->FormCheckBox('pcAllowDirectSubmit', pnModGetVar(__POSTCALENDAR__,'pcAllowDirectSubmit'));
760 $settings[$i][] = $output->Text(_PC_ALLOW_USER_CALENDAR);
761 $settings[$i++][] = $output->FormCheckBox('pcAllowUserCalendar', pnModGetVar(__POSTCALENDAR__,'pcAllowUserCalendar'));
762 $settings[$i][] = $output->Text(_PC_ALLOW_SITEWIDE_SUBMIT);
763 $settings[$i++][] = $output->FormCheckBox('pcAllowSiteWide', pnModGetVar(__POSTCALENDAR__,'pcAllowSiteWide'));
764 $settings[$i][] = $output->Text(_PC_LIST_HOW_MANY);
765 $settings[$i++][] = $output->FormText('pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__,'pcListHowManyEvents'),5);
766 $settings[$i][] = $output->Text(_PC_TIME24HOURS);
767 $settings[$i++][] = $output->FormCheckBox('pcTime24Hours', pnModGetVar(__POSTCALENDAR__,'pcTime24Hours'));
768 $settings[$i][] = $output->Text(_PC_TIME_INCREMENT);
769 $settings[$i++][] = $output->FormText('pcTimeIncrement', pnModGetVar(__POSTCALENDAR__,'pcTimeIncrement'),5);
770 $settings[$i][] = $output->Text(_PC_EVENTS_IN_NEW_WINDOW);
771 $settings[$i++][] = $output->FormCheckBox('pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__,'pcEventsOpenInNewWindow'));
772 $settings[$i][] = $output->Text(_PC_INTERNATIONAL_DATES);
773 $settings[$i++][] = $output->FormCheckBox('pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__,'pcUseInternationalDates'));
774 $settings[$i][] = $output->Text(_PC_EVENT_DATE_FORMAT);
775 $settings[$i++][] = $output->FormText('pcEventDateFormat', pnModGetVar(__POSTCALENDAR__,'pcEventDateFormat'));
776 $settings[$i][] = $output->Text(_PC_DISPLAY_TOPICS);
777 //$settings[$i++][] = $output->FormCheckBox('pcDisplayTopics', pnModGetVar(__POSTCALENDAR__,'pcDisplayTopics'));
778 $settings[$i][] = $output->Text(_PC_FIRST_DAY_OF_WEEK);
779 $options = array();
780 $selected = pnModGetVar(__POSTCALENDAR__,'pcFirstDayOfWeek');
781 $options[0]['id'] = '0';
782 $options[0]['selected'] = ($selected == 0);
783 $options[0]['name'] = _PC_SUNDAY;
784 $options[1]['id'] = '1';
785 $options[1]['selected'] = ($selected == 1);
786 $options[1]['name'] = _PC_MONDAY;
787 $options[2]['id'] = '6';
788 $options[2]['selected'] = ($selected == 6);
789 $options[2]['name'] = _PC_SATURDAY;
790 $settings[$i++][] = $output->FormSelectMultiple('pcFirstDayOfWeek', $options);
791 $settings[$i][] = $output->Text(_PC_DEFAULT_VIEW);
792 $options = array();
793 $selected = pnModGetVar(__POSTCALENDAR__,'pcDefaultView');
794 $options[0]['id'] = 'day';
795 $options[0]['selected'] = ($selected == 'day');
796 $options[0]['name'] = _CAL_DAYVIEW;
797 $options[1]['id'] = 'week';
798 $options[1]['selected'] = ($selected == 'week');
799 $options[1]['name'] = _CAL_WEEKVIEW;
800 $options[2]['id'] = 'month';
801 $options[2]['selected'] = ($selected == 'month');
802 $options[2]['name'] = _CAL_MONTHVIEW;
803 $options[3]['id'] = 'year';
804 $options[3]['selected'] = ($selected == 'year');
805 $options[3]['name'] = _CAL_YEARVIEW;
806 $settings[$i++][] = $output->FormSelectMultiple('pcDefaultView', $options);
807 $settings[$i][] = $output->Text(_PC_DAY_HIGHLIGHT_COLOR . ' [<a HREF="#" onClick="pick(\'pick\');return false;" NAME="pick" ID="pick">pick</a>]');
808 $settings[$i++][] = $output->FormText('pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__,'pcDayHighlightColor'));
809 $settings[$i][] = $output->Text(_PC_USE_JS_POPUPS);
810 $settings[$i++][] = $output->FormCheckBox('pcUsePopups', pnModGetVar(__POSTCALENDAR__,'pcUsePopups'));
811 $settings[$i][] = $output->Text(_PC_USE_CACHE);
812 $settings[$i++][] = $output->FormCheckBox('pcUseCache', pnModGetVar(__POSTCALENDAR__,'pcUseCache'));
813 $settings[$i][] = $output->Text(_PC_CACHE_LIFETIME);
814 $settings[$i++][] = $output->FormText('pcCacheLifetime', pnModGetVar(__POSTCALENDAR__,'pcCacheLifetime'));
816 $templatelist = array();
817 $handle = opendir('modules/'.$pcDir.'/pntemplates');
818 $hide_list = array('.','..','CVS','compiled','cache');
819 while($f=readdir($handle))
820 { if(!in_array($f,$hide_list) && !ereg("[.]",$f)) {
821 $templatelist[] = $f;
824 closedir($handle); unset($hide_list);
825 sort($templatelist);
826 $tcount = count($templatelist);
827 $settings[$i][] = $output->Text(_PC_DEFAULT_TEMPLATE);
828 $options = array();
829 $selected = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
830 for($t=0;$t<$tcount;$t++) {
831 $options[$t]['id'] = $templatelist[$t];
832 $options[$t]['selected'] = ($selected == $templatelist[$t]);
833 $options[$t]['name'] = $templatelist[$t];
835 $settings[$i++][] = $output->FormSelectMultiple('pcTemplate', $options);
838 $output->SetOutputMode(_PNH_KEEPOUTPUT);
840 // Add row
841 for($i = 0 ; $i < count($settings) ; $i++) {
842 $output->TableAddRow($settings[$i], 'left');
845 $output->Text('</table>');
846 $output->FormSubmit(_PC_ADMIN_SUBMIT);
847 $output->FormEnd();*/
848 $output->Text("</body></html>");
850 return $output->GetOutput();
853 function postcalendar_admin_resetDefaults()
855 if (!PC_ACCESS_ADMIN) {
856 return _POSTCALENDAR_NOAUTH; }
858 // remove all the PostCalendar variables from the DB
859 pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
860 pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
861 pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
862 pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
863 pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
864 pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
865 pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
866 pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
867 pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
868 pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
869 pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
870 pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
871 pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
872 pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
873 pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
874 pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
875 pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
876 pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
877 pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
879 // PostCalendar Default Settings
880 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', '0');
881 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', '0');
882 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', '0');
883 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
884 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', '#EEEEEE');
885 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', '1');
886 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', '0');
887 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
888 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', '15');
889 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
890 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
891 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
892 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
893 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
894 pnModSetVar(__POSTCALENDAR__, 'pcUseCache', '1');
895 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', '3600');
896 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', 'month');
897 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0');
898 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail'));
900 $tpl = new pcSmarty();
901 $tpl->clear_all_cache();
903 return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED_DEFAULTS.'</center>');
906 function postcalendar_admin_updateconfig()
908 if (!PC_ACCESS_ADMIN) {
909 return _POSTCALENDAR_NOAUTH; }
911 list($pcTime24Hours, $pcEventsOpenInNewWindow, $pcUseInternationalDates,
912 $pcFirstDayOfWeek, $pcDayHighlightColor, $pcUsePopups,
913 $pcAllowDirectSubmit, $pcListHowManyEvents, $pcDisplayTopics,
914 $pcEventDateFormat, $pcTemplate, $pcAllowSiteWide,
915 $pcAllowUserCalendar, $pcTimeIncrement,$pcUseCache, $pcCacheLifetime,
916 $pcDefaultView, $pcNotifyAdmin, $pcNotifyEmail) = pnVarCleanFromInput(
917 'pcTime24Hours',
918 'pcEventsOpenInNewWindow',
919 'pcUseInternationalDates',
920 'pcFirstDayOfWeek',
921 'pcDayHighlightColor',
922 'pcUsePopups',
923 'pcAllowDirectSubmit',
924 'pcListHowManyEvents',
925 'pcDisplayTopics',
926 'pcEventDateFormat',
927 'pcTemplate',
928 'pcAllowSiteWide',
929 'pcAllowUserCalendar',
930 'pcTimeIncrement',
931 'pcUseCache',
932 'pcCacheLifetime',
933 'pcDefaultView',
934 'pcNotifyAdmin',
935 'pcNotifyEmail'
938 // make sure we enter something into the DB
939 if (!isset($pcTime24Hours)) {
940 $pcTime24Hours = '0'; }
941 if (!isset($pcEventsOpenInNewWindow)) {
942 $pcEventsOpenInNewWindow='0'; }
943 if (!isset($pcUseInternationalDates)) {
944 $pcUseInternationalDates='0'; }
945 if (!isset($pcFirstDayOfWeek)) {
946 $pcFirstDayOfWeek='0'; }
947 if (!isset($pcUsePopups)) {
948 $pcUsePopups='0'; }
949 if (!isset($pcAllowDirectSubmit)) {
950 $pcAllowDirectSubmit='0'; }
951 if (!isset($pcDisplayTopics)) {
952 $pcDisplayTopics='0'; }
953 if (!isset($pcTemplate)) {
954 $pcTemplate='default'; }
955 if (!isset($pcAllowSiteWide)) {
956 $pcAllowSiteWide='0'; }
957 if (!isset($pcAllowUserCalendar)) {
958 $pcAllowUserCalendar='0'; }
959 if (!isset($pcUseCache)) {
960 $pcUseCache='0'; }
961 if (!isset($pcDefaultView)) {
962 $pcDefaultView='month'; }
963 if (empty($pcCacheLifetime)) {
964 $pcCacheLifetime='3600'; }
965 if (empty($pcDayHighlightColor)) {
966 $pcDayHighlightColor='#EEEEEE'; }
967 if (empty($pcListHowManyEvents)) {
968 $pcListHowManyEvents='15'; }
969 if (empty($pcEventDateFormat)) {
970 $pcEventDateFormat='%Y-%m-%d'; }
971 if (empty($pcTimeIncrement)) {
972 $pcTimeIncrement='15'; }
973 if (empty($pcNotifyAdmin)) {
974 $pcNotifyAdmin='0'; }
975 if (empty($pcNotifyEmail)) {
976 $pcNotifyEmail=pnConfigGetVar('adminmail'); }
978 // delete the old vars - we're doing this because PostNuke variable
979 // handling sometimes has old values in the $GLOBALS we need to clear
980 pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
981 pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
982 pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
983 pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
984 pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
985 pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
986 pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
987 pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
988 pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
989 pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
990 pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
991 pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
992 pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
993 pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
994 pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
995 pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
996 pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
997 pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
998 pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
1000 // set the new variables
1001 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', $pcTime24Hours);
1002 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', $pcEventsOpenInNewWindow);
1003 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', $pcUseInternationalDates);
1004 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', $pcFirstDayOfWeek);
1005 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', $pcDayHighlightColor);
1006 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', $pcUsePopups);
1007 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', $pcAllowDirectSubmit);
1008 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', $pcListHowManyEvents);
1009 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', $pcDisplayTopics);
1010 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', $pcEventDateFormat);
1011 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', $pcTemplate);
1012 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', $pcAllowSiteWide);
1013 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', $pcAllowUserCalendar);
1014 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', $pcTimeIncrement);
1015 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', $pcDefaultView);
1016 pnModSetVar(__POSTCALENDAR__, 'pcUseCache', $pcUseCache);
1017 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', $pcCacheLifetime);
1018 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', $pcNotifyAdmin);
1019 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', $pcNotifyEmail);
1021 $tpl = new pcSmarty();
1022 $tpl->clear_all_cache();
1024 return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED.'</center>');
1027 function postcalendar_admin_categoriesOld($msg = '', $e = '')
1029 if (!PC_ACCESS_ADMIN) {
1030 return _POSTCALENDAR_NOAUTH; }
1032 $output = new pnHTML();
1033 $output->SetInputMode(_PNH_VERBATIMINPUT);
1035 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1036 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1037 $jsColorPicker = <<<EOF
1038 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
1039 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
1040 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
1041 <script LANGUAGE="JavaScript">
1042 var cp = new ColorPicker('window');
1043 // Runs when a color is clicked
1044 function pickColor(color) {
1045 field.value = color;
1048 var field;
1049 function pick(anchorname,target) {
1050 field = this.document.forms.cats.elements[target];
1051 cp.show(anchorname);
1053 </SCRIPT>
1054 EOF;
1055 $header = <<<EOF
1056 <html>
1057 <head></head>
1058 <body bgcolor=
1059 EOF;
1060 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
1061 $output->Text($header);
1062 $output->Text($jsColorPicker);
1063 $output->Text(postcalendar_adminmenu());
1065 if (!empty($e)) {
1066 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
1067 $output->Text('<center><b>'.$e.'</b></center>');
1068 $output->Text('</div><br />');
1071 if (!empty($msg)) {
1072 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
1073 $output->Text('<center><b>'.$msg.'</b></center>');
1074 $output->Text('</div><br />');
1077 $cats = pnModAPIFunc(__POSTCALENDAR__, 'admin', 'getCategories');
1078 if (!is_array($cats)) {
1079 $output->Text($cats);
1080 return $output->GetOutput();
1083 $output->Text('<form name="cats" method="post" action="'.pnModURL(__POSTCALENDAR__, 'admin', 'categoriesConfirm').'">');
1084 $output->Text('<table border="1" cellpadding="5" cellspacing="0">');
1085 $output->Text('<tr><th>'._PC_CAT_DELETE.'</th><th>'._PC_CAT_NAME.'</th><th>'._PC_CAT_DESC.'</th><th>'._PC_CAT_COLOR.'</th></tr>');
1086 $i = 0;
1087 foreach ($cats as $cat) {
1088 $output->Text('<tr>');
1089 $output->Text('<td valign="top" align="left">');
1090 $output->FormHidden('id[]', $cat['id']);
1091 $output->FormCheckbox('del[]', false, $cat['id']);
1092 $output->Text('</td>');
1093 $output->Text('<td valign="top" align="left">');
1094 $output->FormText('name[]', $cat['name'], 20);
1095 $output->Text('</td>');
1096 $output->Text('<td valign="top" align="left">');
1097 $output->FormTextarea('desc[]', $cat['desc'], 3, 20);
1098 $output->Text('</td>');
1099 $output->Text('<td valign="top" align="left">');
1100 $output->FormText('color[]', $cat['color'], 10);
1101 $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\''.($i+4).'\'); return false;" NAME="pick" ID="pick">pick</a>]');
1102 $output->Text('</td>');
1103 $output->Text('</tr>');
1104 $i+=5;
1106 $output->Text('<tr>');
1107 $output->Text('<td><a href="'.pnModURL(__POSTCALENDAR__, 'admin', 'categoriesNew').'">'._PC_CAT_NEW.'</a></td>');
1109 $output->Text('<td valign="top" align="left">');
1110 $output->Text(_PC_CAT_NEW);
1111 $output->Text('</td>');
1112 $output->Text('<td valign="top" align="left">');
1113 $output->FormText('newname','',20);
1114 $output->Text('</td>');
1115 $output->Text('<td valign="top" align="left">');
1116 $output->FormTextarea('newdesc','',3,20);
1117 $output->Text('</td>');
1118 $output->Text('<td valign="top" align="left">');
1119 $output->FormText('newcolor','',10);
1120 $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\'newcolor\');return false;" NAME="pick" ID="pick">pick</a>]');
1121 $output->Text('</td>');
1123 $output->Text('</tr>');
1124 $output->Text('</table>');
1125 $output->FormSubmit(_PC_ADMIN_SUBMIT);
1126 $output->FormEnd();
1127 $output->Text("</body></html>");
1128 return $output->GetOutput();
1130 function postcalendar_admin_categoriesConfirm()
1132 if (!PC_ACCESS_ADMIN) {
1133 return _POSTCALENDAR_NOAUTH; }
1135 $output = new pnHTML();
1136 $output->SetInputMode(_PNH_VERBATIMINPUT);
1137 $header = <<<EOF
1138 <html>
1139 <head></head>
1140 <body bgcolor=
1141 EOF;
1142 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
1143 $output->Text($header);
1144 $output->Text(postcalendar_adminmenu());
1146 list($id,$del,$name,$value_cat_type,$desc,$color,
1147 $event_repeat,$event_repeat_freq,
1148 $event_repeat_freq_type,$event_repeat_on_num,
1149 $event_repeat_on_day,$event_repeat_on_freq,$durationh,$durationm,
1150 $end_date_flag,$end_date_type,$end_date_freq,$end_all_day,$active,$sequence,$aco,
1151 $newname,$newdesc,$newcolor,$new_event_repeat,$new_event_repeat_freq,
1152 $new_event_repeat_freq_type,$new_event_repeat_on_num,$new_event_repeat_on_day,
1153 $new_event_repeat_on_freq,$new_durationh,$new_durationm,$new_limitid,$new_end_date_flag,
1154 $new_end_date_type,$new_end_date_freq,$new_end_all_day,$new_value_cat_type,$newactive,$newsequence,$newaco
1155 ) = pnVarCleanFromInput(
1156 'id',
1157 'del',
1158 'name',
1159 'value_cat_type',
1160 'desc',
1161 'color',
1162 'event_repeat',
1163 'event_repeat_freq',
1164 'event_repeat_freq_type',
1165 'event_repeat_on_num',
1166 'event_repeat_on_day',
1167 'event_repeat_on_freq',
1168 'durationh',
1169 'durationm',
1170 'end_date_flag',
1171 'end_date_type',
1172 'end_date_freq',
1173 'end_all_day',
1174 'active',
1175 'sequence',
1176 'aco',
1177 'newname',
1178 'newdesc',
1179 'newcolor',
1180 'newevent_repeat',
1181 'newevent_repeat_freq',
1182 'newevent_repeat_freq_type',
1183 'newevent_repeat_on_num',
1184 'newevent_repeat_on_day',
1185 'newevent_repeat_on_freq',
1186 'newdurationh',
1187 'newdurationm',
1188 'newlimitid',
1189 'newend_date_flag',
1190 'newend_date_type',
1191 'newend_date_freq',
1192 'newend_all_day',
1193 'newvalue_cat_type',
1194 'newactive',
1195 'newsequence',
1196 'newaco'
1198 //data validation
1199 foreach ($name as $i => $item) {
1200 if (empty($item)) {
1201 $output->Text(postcalendar_admin_categories($msg, "Category Names must contain a value!"));
1202 return $output->GetOutput();
1204 $tmp = $color[$i];
1205 if (strlen($tmp) != 7 || $tmp[0] != "#") {
1206 $e = $tmp." size ".strlen($tmp)." at 0 ".$tmp[0];
1207 $output->Text(postcalendar_admin_categories($msg, "You entered an invalid color(USE Pick) $e!"));
1208 return $output->GetOutput();
1211 foreach ($durationh as $i => $val) {
1212 if (!is_numeric($durationh[$i]) || !is_numeric($durationm[$i]) ||
1213 !is_numeric($event_repeat_freq[$i]) ||
1214 !is_numeric($event_repeat_on_freq[$i]) || !is_numeric($end_date_freq[$i])) {
1215 $output->Text(postcalendar_admin_categories($msg, " Hours, Minutes and recurrence values must be numeric!"));
1216 return $output->GetOutput();
1220 if (!empty($newnam)) {
1221 if (!is_numeric($new_durationh) || !is_numeric($new_durationm) ||
1222 !is_numeric($new_event_repeat_freq) || !is_numeric($new_event_repeat_on_freq)
1223 || !is_numeric($new_end_date_freq) ) {
1224 $output->Text(postcalendar_admin_categories($msg, "Hours, Minutes and recurrence values must be numeric!"));
1225 return $output->GetOutput();
1228 $new_duration = ($new_durationh * (60 * 60)) + ($new_durationm * 60);
1229 $event_recurrspec = serialize(compact(
1230 'event_repeat_freq',
1231 'event_repeat_freq_type',
1232 'event_repeat_on_num',
1233 'event_repeat_on_day',
1234 'event_repeat_on_freq'
1237 $new_event_recurrspec = serialize(compact(
1238 'new_event_repeat_freq',
1239 'new_event_repeat_freq_type',
1240 'new_event_repeat_on_num',
1241 'new_event_repeat_on_day',
1242 'new_event_repeat_on_freq'
1244 if (is_array($del)) {
1245 $dels = implode(',', $del);
1246 $delText = _PC_DELETE_CATS . $dels .'.';
1248 $output->FormStart(pnModURL(__POSTCALENDAR__, 'admin', 'categoriesUpdate'));
1249 $output->Text(_PC_ARE_YOU_SURE);
1250 $output->Linebreak(2);
1251 // deletions
1252 if (isset($delText)) {
1253 $output->FormHidden('dels', $dels);
1254 $output->Text($delText);
1255 $output->Linebreak();
1257 if (!empty($newname)) {
1258 $output->FormHidden('newname', $newname);
1259 $output->FormHidden('newdesc', $newdesc);
1260 $output->FormHidden('newvalue_cat_type', $new_value_cat_type);
1261 $output->FormHidden('newcolor', $newcolor);
1262 $output->FormHidden('newevent_repeat', $new_event_repeat);
1263 $output->FormHidden('newevent_recurrfreq', $new_event_repeat_freq);
1264 $output->FormHidden('newevent_recurrspec', $new_event_recurrspec);
1265 $output->FormHidden('newduration', $new_duration);
1266 $output->FormHidden('newlimitid', $new_limitid);
1267 $output->FormHidden('newend_date_flag', $new_end_date_flag);
1268 $output->FormHidden('newend_date_type', $new_end_date_type);
1269 $output->FormHidden('newend_date_freq', $new_end_date_freq);
1270 $output->FormHidden('newend_all_day', $new_end_all_day);
1271 $output->FormHidden("newactive", $newactive);
1272 $output->FormHidden("newsequence", $newsequence);
1273 $output->FormHidden("newaco", $newaco);
1275 $output->Text(_PC_ADD_CAT . $newname .'.');
1276 $output->Linebreak();
1278 $output->Text(_PC_MODIFY_CATS);
1279 $output->FormHidden('id', serialize($id));
1280 $output->FormHidden('del', serialize($del));
1281 $output->FormHidden('name', serialize($name));
1282 $output->FormHidden('desc', serialize($desc));
1283 $output->FormHidden('value_cat_type', serialize($value_cat_type));
1284 $output->FormHidden('color', serialize($color));
1285 $output->FormHidden('event_repeat', serialize($event_repeat));
1286 $output->FormHidden('event_recurrspec', $event_recurrspec);
1287 $output->FormHidden('durationh', serialize($durationh));
1288 $output->FormHidden('durationm', serialize($durationm));
1289 $output->FormHidden('end_date_flag', serialize($end_date_flag));
1290 $output->FormHidden('end_date_type', serialize($end_date_type));
1291 $output->FormHidden('end_date_freq', serialize($end_date_freq));
1292 $output->FormHidden('end_all_day', serialize($end_all_day));
1293 $output->FormHidden("active", serialize($active));
1294 $output->FormHidden("sequence", serialize($sequence));
1295 $output->FormHidden("aco", serialize($aco));
1296 $output->Linebreak();
1297 $output->FormSubmit(_PC_CATS_CONFIRM);
1298 $output->FormEnd();
1300 return $output->GetOutput();
1302 function postcalendar_admin_categoriesUpdate()
1304 if (!PC_ACCESS_ADMIN) {
1305 return _POSTCALENDAR_NOAUTH; }
1307 $output = new pnHTML();
1308 $output->SetInputMode(_PNH_VERBATIMINPUT);
1310 list($dbconn) = pnDBGetConn();
1311 $pntable = pnDBGetTables();
1313 list($id,$del,$name,$value_cat_type,$desc,$color,
1314 $event_repeat_array,$event_recurrspec_array,$dels,$durationh,$durationm,
1315 $end_date_flag,$end_date_type,$end_date_freq,$end_all_day,$active,$sequence,$aco,$newname,$newdesc,$newcolor,
1316 $new_event_repeat,$new_event_recurrspec,$new_event_recurrfreq,
1317 $new_duration,$new_dailylimitid,$new_end_date_flag,$new_end_date_type,
1318 $new_end_date_freq,$new_end_all_day,$new_value_cat_type,$newactive,$newsequence,$newaco
1319 ) = pnVarCleanFromInput(
1320 'id',
1321 'del',
1322 'name',
1323 'value_cat_type',
1324 'desc',
1325 'color',
1326 'event_repeat',
1327 'event_recurrspec',
1328 'dels',
1329 'durationh',
1330 'durationm',
1331 'end_date_flag',
1332 'end_date_type',
1333 'end_date_freq',
1334 'end_all_day',
1335 'active',
1336 'sequence',
1337 'aco',
1338 'newname',
1339 'newdesc',
1340 'newcolor',
1341 'newevent_repeat',
1342 'newevent_recurrspec',
1343 'newevent_recurrfreq',
1344 'newduration',
1345 'newlimitid',
1346 'newend_date_flag',
1347 'newend_date_type',
1348 'newend_date_freq',
1349 'newend_all_day',
1350 'newvalue_cat_type',
1351 'newactive',
1352 'newsequence',
1353 'newaco'
1356 $id = unserialize($id);
1357 $del = unserialize($del);
1358 $name = unserialize($name);
1359 $value_cat_type = unserialize($value_cat_type);
1360 $desc = unserialize($desc);
1361 $color = unserialize($color);
1362 $event_repeat_array = unserialize($event_repeat_array);
1363 $event_recurrspec_array = unserialize($event_recurrspec_array);
1364 $durationh = unserialize($durationh);
1365 $durationm = unserialize($durationm);
1366 $end_date_flag = unserialize($end_date_flag);
1367 $end_date_type = unserialize($end_date_type);
1368 $end_date_freq = unserialize($end_date_freq);
1369 $end_all_day = unserialize($end_all_day);
1370 $active = unserialize($active);
1371 $sequence = unserialize($sequence);
1372 $aco = unserialize($aco);
1373 $updates = array();
1375 if (isset($id)) {
1376 foreach ($id as $k => $i) {
1377 $found = false;
1378 if (count($del)) {
1379 foreach ($del as $d) {
1380 if ($i == $d) {
1381 $found = true;
1382 break;
1386 if (!$found) {
1387 $event_repeat_freq = $event_recurrspec_array['event_repeat_freq'][$i];
1388 $event_repeat_freq_type = $event_recurrspec_array['event_repeat_freq_type'][$i];
1389 $event_repeat_on_num = $event_recurrspec_array['event_repeat_on_num'][$i];
1390 $event_repeat_on_day = $event_recurrspec_array['event_repeat_on_day'][$i];
1391 $event_repeat_on_freq = $event_recurrspec_array['event_repeat_on_freq'][$i];
1393 $recurrspec = serialize(compact(
1394 'event_repeat_freq',
1395 'event_repeat_freq_type',
1396 'event_repeat_on_num',
1397 'event_repeat_on_day',
1398 'event_repeat_on_freq'
1401 $dur = ( ($durationh[$i]*(60 * 60)) + ($durationm[$i] * 60));
1403 $update_sql = "UPDATE $pntable[postcalendar_categories]
1404 SET pc_catname='".pnVarPrepForStore($name[$k])."',
1405 pc_catdesc='".trim(pnVarPrepForStore($desc[$k]))."',
1406 pc_cattype='".trim(pnVarPrepForStore($value_cat_type[$k]))."',
1407 pc_catcolor='".pnVarPrepForStore($color[$k])."',
1408 pc_recurrtype='".pnVarPrepForStore($event_repeat_array[$i])."',
1409 pc_recurrspec='".pnVarPrepForStore($recurrspec)."',
1410 pc_duration='".pnVarPrepForStore($dur)."',
1411 pc_end_date_flag='".pnVarPrepForStore($end_date_flag[$i])."',
1412 pc_end_date_type='".pnVarPrepForStore($end_date_type[$i])."',
1413 pc_end_date_freq='".pnVarPrepForStore($end_date_freq[$i])."',
1414 pc_end_all_day='".pnVarPrepForStore($end_all_day[$i])."',
1415 pc_active ='".pnVarPrepForStore($active[$i])."',
1416 pc_seq = '".pnVarPrepForStore($sequence[$k])."',
1417 aco_spec = '".pnVarPrepForStore($aco[$k])."'
1418 WHERE pc_catid=$i";
1420 array_push($updates, $update_sql);
1421 unset($recurrspec);
1422 unset($dur);
1428 $delete = "DELETE FROM $pntable[postcalendar_categories] WHERE pc_catid IN ($dels)";
1429 $e = $msg = '';
1430 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'updateCategories', array('updates'=>$updates))) {
1431 $e .= 'UPDATE FAILED';
1433 if (isset($dels)) {
1434 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'deleteCategories', array('delete'=>$delete))) {
1435 $e .= 'DELETE FAILED';
1438 if (isset($newname)) {
1439 $unpacked = unserialize($new_event_recurrspec);
1440 unset($new_event_recurrspec);
1441 $new_event_recurrspec['event_repeat_freq'] = $unpacked['new_event_repeat_freq'];
1442 $new_event_recurrspec['event_repeat_freq_type'] = $unpacked['new_event_repeat_freq_type'];
1443 $new_event_recurrspec['event_repeat_on_num'] = $unpacked['new_event_repeat_on_num'];
1444 $new_event_recurrspec['event_repeat_on_day'] = $unpacked['new_event_repeat_on_day'];
1445 $new_event_recurrspec['event_repeat_on_freq'] = $unpacked['new_event_repeat_on_freq'];
1446 $new_event_recurrspec = serialize($new_event_recurrspec);
1448 if (!pnModAPIFunc(
1449 __POSTCALENDAR__,
1450 'admin',
1451 'addCategories',
1452 array('name'=>$newname,'desc'=>$newdesc,'value_cat_type'=>$new_value_cat_type,'color'=>$newcolor,'active'=>$newactive,'sequence'=>$newsequence, 'aco'=>$newaco,
1453 'repeat'=>$new_event_repeat,'spec'=>$new_event_recurrspec,
1454 'recurrfreq'=>$new_recurrfreq,'duration'=>$new_duration,'limitid'=>$new_dailylimitid,
1455 'end_date_flag'=>$new_end_date_flag,'end_date_type'=>$new_end_date_flag,
1456 'end_date_freq'=>$new_end_date_freq,
1457 'end_all_day'=>$new_end_all_day)
1458 )) {
1459 $e .= 'INSERT FAILED';
1463 if (empty($e)) {
1464 $msg = 'DONE'; }
1465 $output->Text(postcalendar_admin_categories($msg, $e));
1466 return $output->GetOutput();
1470 * Creates a new category
1472 function postcalendar_admin_categories($msg = '', $e = '', $args = array())
1474 if (!PC_ACCESS_ADD) {
1475 return _POSTCALENDARNOAUTH; }
1476 extract($args);
1477 unset($args);
1479 $output = new pnHTML();
1480 $output->SetInputMode(_PNH_VERBATIMINPUT);
1481 // set up Smarty
1482 $tpl = new pcSmarty();
1483 $tpl->caching = false;
1485 $template_name = pnModGetVar(__POSTCALENDAR__, 'pcTemplate');
1487 if (!isset($template_name)) {
1488 $template_name ='default';
1491 if (!empty($e)) {
1492 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
1493 $output->Text('<center><b>'.$e.'</b></center>');
1494 $output->Text('</div><br />');
1497 if (!empty($msg)) {
1498 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
1499 $output->Text('<center><b>'.$msg.'</b></center>');
1500 $output->Text('</div><br />');
1503 //=================================================================
1504 // Setup the correct config file path for the templates
1505 //=================================================================
1506 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1507 $modir = pnVarPrepForOS($modinfo['directory']);
1508 $modname = $modinfo['displayname'];
1509 $all_categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
1510 //print_r($all_categories);
1511 unset($modinfo);
1512 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
1514 //=================================================================
1515 // PARSE MAIN
1516 //=================================================================
1518 // create translations if applicable
1519 if (($GLOBALS['translate_appt_categories']) && ($_SESSION['language_choice'] > 1)) {
1520 $sizeAllCat = count($all_categories);
1521 for ($m = 0; $m < $sizeAllCat; $m++) {
1522 $tempCategory = $all_categories[$m]["name"];
1523 $tempDescription = $all_categories[$m]["desc"];
1524 $all_categories[$m]["nameTranslate"] = xl($tempCategory);
1525 $all_categories[$m]["descTranslate"] = xl($tempDescription);
1528 $tpl->assign('globals', $GLOBALS);
1530 $tpl->assign_by_ref('TPL_NAME', $template_name);
1531 $tpl->assign('FUNCTION', pnVarCleanFromInput('func'));
1532 $tpl->assign_by_ref('ModuleName', $modname);
1533 $tpl->assign_by_ref('ModuleDirectory', $modir);
1534 $tpl->assign_by_ref('all_categories', $all_categories);
1536 $tpl->assign('pcDir', $modir);
1537 $tpl->assign('action', pnModURL(__POSTCALENDAR__, 'admin', 'categoriesConfirm'));
1538 $tpl->assign('adminmenu', postcalendar_adminmenu());
1539 $tpl->assign('BGCOLOR2', $GLOBALS['style']['BGCOLOR2']);
1540 $tpl->assign('css_header', $GLOBALS['css_header']);
1541 $tpl->assign('_PC_REP_CAT_TITLE_S', _PC_REP_CAT_TITLE_S);
1542 $tpl->assign('_PC_NEW_CAT_TITLE_S', _PC_NEW_CAT_TITLE_S);
1543 $tpl->assign('_PC_CAT_NAME', _PC_CAT_NAME);
1544 $tpl->assign('_PC_CAT_TYPE', _PC_CAT_TYPE);
1545 $tpl->assign('_PC_CAT_NAME_XL', _PC_CAT_NAME_XL);
1546 $tpl->assign('_PC_CAT_DESC', _PC_CAT_DESC);
1547 $tpl->assign('_PC_CAT_DESC_XL', _PC_CAT_DESC_XL);
1548 $tpl->assign('_PC_CAT_COLOR', _PC_CAT_COLOR);
1549 $tpl->assign('_PC_CAT_DELETE', _PC_CAT_DELETE);
1550 $tpl->assign('_PC_CAT_DUR', _PC_CAT_DUR);
1551 $tpl->assign('_PC_COLOR_PICK_TITLE', _PC_COLOR_PICK_TITLE);
1552 $tpl->assign('_EDIT_PC_CONFIG_CATDETAILS', _EDIT_PC_CONFIG_CATDETAILS);
1553 $tpl->assign("_PC_ACTIVE", _PC_ACTIVE);
1554 $tpl->assign("_PC_SEQ", _PC_SEQ);
1555 $tpl->assign("_ACO", _ACO);
1556 //=================================================================
1557 // Repeating Information
1558 //=================================================================
1559 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
1560 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
1561 $tpl->assign('RepeatTitle', _PC_REPEAT);
1562 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
1563 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
1564 $tpl->assign('EndDateTitle', _PC_END_DATE);
1565 $tpl->assign('NoEndDateTitle', _PC_NO_END);
1566 $tpl->assign('REP_CAT_TITLE', _PC_REP_CAT_TITLE);
1567 $tpl->assign('NEW_CAT_TITLE', _PC_NEW_CAT_TITLE);
1568 $tpl->assign('InputNoRepeat', 'event_repeat');
1569 $tpl->assign('ValueNoRepeat', '0');
1570 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
1571 $tpl->assign('InputRepeat', 'event_repeat');
1572 $tpl->assign('ValueRepeat', '1');
1573 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
1576 unset($in);
1577 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
1578 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
1579 $repeat_freq = array();
1580 foreach ($in as $k => $v) {
1581 array_push($repeat_freq, array('value'=>$keys[$k],
1582 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
1583 'name'=>$v));
1585 $tpl->assign('InputRepeatFreq', 'event_repeat_freq');
1586 if (empty($event_repeat_freq) || $event_repeat_freq < 1) {
1587 $event_repeat_freq = 1;
1589 $tpl->assign('InputRepeatFreqVal', $event_repeat_freq);
1590 $tpl->assign('repeat_freq', $event_repeat_freq);
1591 unset($in);
1593 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
1594 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
1595 $repeat_freq_type = array();
1596 foreach ($in as $k => $v) {
1597 array_push($repeat_freq_type, array('value'=>$keys[$k],
1598 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
1599 'name'=>$v));
1601 $tpl->assign('InputRepeatFreqType', 'event_repeat_freq_type');
1602 $tpl->assign('InuptRepeatFreq', '' .'event_repeat_freq');
1603 $tpl->assign('repeat_freq_type', $repeat_freq_type);
1605 $tpl->assign('InputRepeatOn', 'event_repeat');
1606 $tpl->assign('ValueRepeatOn', '2');
1607 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
1609 // All Day START
1610 $tpl->assign('InputAllDay', 'end_all_day');
1611 $tpl->assign('ValueAllDay', '1');
1612 $tpl->assign('ValueAllDayNo', '0');
1613 $tpl->assign('ALL_DAY_CAT_TITLE', _PC_ALL_DAY_CAT_TITLE);
1614 $tpl->assign('ALL_DAY_CAT_YES', _PC_ALL_DAY_CAT_YES);
1615 $tpl->assign('ALL_DAY_CAT_NO', _PC_ALL_DAY_CAT_NO);
1617 //ALL Day End
1618 // End date gather date start
1620 $tpl->assign('InputEndDateFreq', 'end_date_freq');
1621 $tpl->assign('InputEndOn', 'end_date_flag');
1622 $tpl->assign('InputEndDateFreqType', 'end_date_type');
1623 $tpl->assign('ValueNoEnd', '0');
1624 $tpl->assign('ValueEnd', '1');
1627 foreach ($in as $k => $v) {
1628 array_push($end_date_type, array('value'=>$keys[$k],
1629 'selected'=>($keys[$k]==$end_date_type?'selected':''),
1630 'name'=>$v));
1632 unset($in);
1635 // End date gather date end
1638 unset($in);
1639 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
1640 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
1641 $repeat_on_num = array();
1642 foreach ($in as $k => $v) {
1643 array_push($repeat_on_num, array('value'=>$keys[$k],
1644 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
1645 'name'=>$v));
1647 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1648 $tpl->assign('repeat_on_num', $repeat_on_num);
1650 unset($in);
1651 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
1652 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
1653 $repeat_on_day = array();
1654 foreach ($in as $k => $v) {
1655 array_push($repeat_on_day, array('value'=>$keys[$k],
1656 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
1657 'name'=>$v));
1659 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1660 $tpl->assign('repeat_on_day', $repeat_on_day);
1662 unset($in);
1663 $in = array(_PC_CAT_PATIENT,_PC_CAT_PROVIDER,_PC_CAT_CLINIC,_PC_CAT_THERAPY_GROUP);
1664 $keys = array(TYPE_ON_PATIENT,TYPE_ON_PROVIDER,TYPE_ON_CLINIC,TYPE_ON_THERAPY_GROUP);
1665 $cat_type = array();
1666 foreach ($in as $k => $v) {
1667 array_push($cat_type, array('value'=>$keys[$k],
1668 'selected'=>($keys[$k]==$value_cat_type ? 'selected' : ''),
1669 'name'=>$v));
1671 $tpl->assign('InputCatType', 'value_cat_type');
1672 $tpl->assign('cat_type', $cat_type);
1674 unset($in);
1675 $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);
1676 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
1677 $repeat_on_freq = array();
1678 foreach ($in as $k => $v) {
1679 array_push($repeat_on_freq, array('value'=>$keys[$k],
1680 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
1681 'name'=>$v));
1683 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1684 if (empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) {
1685 $event_repeat_on_freq = 1;
1687 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1688 $tpl->assign('repeat_on_freq', $repeat_on_freq);
1689 $tpl->assign('MonthsTitle', _PC_MONTHS);
1690 $tpl->assign('DurationHourTitle', _PC_DURATION_HOUR);
1691 $tpl->assign('DurationMinTitle', _PC_DURATION_MIN);
1692 $tpl->assign('InputDurationHour', "durationh");
1693 $tpl->assign('InputDurationMin', "durationm");
1694 $tpl->assign('ActiveTitleYes', xl('Yes'));
1695 $tpl->assign('ActiveTitleNo', xl('No'));
1697 // Added ACO for each category
1698 $tpl->assign('InputACO', 'aco');
1699 $acoList = gen_aco_array();
1700 $tpl->assign('ACO_List', $acoList);
1702 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1703 $authkey = $output->FormHidden('authid', pnSecGenAuthKey());
1704 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1706 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1707 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1708 if (isset($data_loaded)) {
1709 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1710 $tpl->assign('FormHidden', $form_hidden);
1712 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1713 '.$authkey.'<input type="submit" name="submit" value="' . xl('go') . '">';
1714 $tpl->assign('FormSubmit', $form_submit);
1716 $output->Text($tpl->fetch($template_name.'/admin/submit_category.html'));
1717 $output->Text(postcalendar_footer());
1718 return $output->GetOutput();
1722 * Main administration menu
1724 function postcalendar_adminmenu($upgraded = false)
1726 if (!PC_ACCESS_ADMIN) {
1727 return _POSTCALENDAR_NOAUTH; }
1729 pnThemeLoad(pnUserGetTheme());
1730 // get the theme globals :: is there a better way to do this?
1731 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6;
1732 global $textcolor1, $textcolor2;
1734 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1735 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1737 @define('_AM_VAL', 1);
1738 @define('_PM_VAL', 2);
1740 @define('_EVENT_APPROVED', 1);
1741 @define('_EVENT_QUEUED', 0);
1742 @define('_EVENT_HIDDEN', -1);
1744 $adminURL = pnModURL(__POSTCALENDAR__, 'admin', '');
1745 $settingsURL = pnModURL(__POSTCALENDAR__, 'admin', 'modifyconfig');
1746 $categoryURL = pnModURL(__POSTCALENDAR__, 'admin', 'categories');
1747 $submitURL = pnModURL(__POSTCALENDAR__, 'admin', 'submit');
1748 $approvedURL = pnModURL(__POSTCALENDAR__, 'admin', 'listapproved');
1749 $hiddenURL = pnModURL(__POSTCALENDAR__, 'admin', 'listhidden');
1750 $queuedURL = pnModURL(__POSTCALENDAR__, 'admin', 'listqueued');
1751 $cacheURL = pnModURL(__POSTCALENDAR__, 'admin', 'clearCache');
1752 $systemURL = pnModURL(__POSTCALENDAR__, 'admin', 'testSystem');
1753 $limitsURL = pnModURL(__POSTCALENDAR__, 'admin', 'categoryLimits');
1755 $adminText = _POSTCALENDAR;
1756 $settingsText = _EDIT_PC_CONFIG_GLOBAL;
1757 $categoryText = _EDIT_PC_CONFIG_CATEGORIES;
1758 $submitText = _PC_CREATE_EVENT;
1759 $approvedText = "Event List";
1760 $hiddenText = _PC_VIEW_HIDDEN;
1761 $queuedText = "Marked for Deletion";
1762 $cacheText = _PC_CLEAR_CACHE;
1763 $cacheText = _PC_CLEAR_CACHE;
1764 $systemText = _PC_TEST_SYSTEM;
1765 $limitsText = _PC_CAT_LIMITS;
1767 // check for upgrade
1768 $upgrade = '';
1769 if ($upgraded === false) {
1770 $upgrade = pc_isNewVersion();
1774 $output = <<<EOF
1775 <table border="0" cellpadding="1" cellspacing="0" width="100%" bgcolor="$bgcolor2"><tr><td>
1776 <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1777 <tr>
1778 <td align="left" valign="middle"><a href="$adminURL"><img
1779 border="0" src="modules/$pcDir/pnimages/admin.gif"></a></td>
1780 <td width="100%" align="left" valign="middle">
1781 <table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="$bgcolor2">
1782 <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1783 <tr>
1784 <td nowrap>
1785 <!--<a href="$settingsURL">$settingsText</a> |-->
1786 <!--<a href="$submitURL">$submitText</a> |-->
1787 <a href="$cacheURL">$cacheText</a> |
1788 <a href="$systemURL">$systemText</a> |
1789 <a href="$categoryURL">$categoryText</a> |
1790 <a href="$limitsURL">$limitsText</a><!-- |
1791 <a href="$queuedURL">$queuedText</a> |
1792 <a href="$approvedURL">$approvedText</a> |
1793 <a href="$hiddenURL">$hiddenText</a>-->
1794 $upgrade
1795 </tr>
1796 </table>
1797 </td></tr></table>
1798 </td>
1799 </tr>
1800 </table>
1801 </td></tr></table>
1802 <br />
1803 EOF;
1804 // Return the output that has been generated by this function
1805 return $output;
1808 function postcalendar_admin_clearCache()
1810 if (!PC_ACCESS_ADMIN) {
1811 return _POSTCALENDAR_NOAUTH; }
1813 $tpl = new pcSmarty();
1814 //fmg: check that both subdirs to be cleared first exist and are writeable
1815 $spec_err = '';
1816 if (!file_exists($tpl->compile_dir)) {
1817 $spec_err .= "Error: folder '$tpl->compile_dir' doesn't exist!<br>";
1818 } else if (!is_writeable($tpl->compile_dir)) {
1819 $spec_err .= "Error: folder '$tpl->compile_dir' not writeable!<br>";
1821 if (!file_exists($tpl->cache_dir)) {
1822 $spec_err .= "Error: folder '$tpl->cache_dir' doesn't exist!<br>";
1823 } else if (!is_writeable($tpl->cache_dir)) {
1824 $spec_err .= "Error: folder '$tpl->cache_dir' not writeable!<br>";
1826 //note: we don't abort on error... like before.
1827 $tpl->clear_all_cache();
1828 $tpl->clear_compiled_tpl();
1830 return postcalendar_admin_modifyconfig('<center>'.$spec_err._PC_CACHE_CLEARED.'</center>');
1833 function pc_isNewVersion()
1835 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1836 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1837 @include("modules/$pcDir/pnversion.php");
1839 if ($pcModInfo['version'] <> $modversion['version']) {
1840 $upgradeURL = pnModURL(__POSTCALENDAR__, 'admin', 'upgrade');
1841 $upgradeText = "Upgrade PostCalendar $pcModInfo[version] to $modversion[version]";
1842 $upgrade = "<br /><br />[ <a href=\"$upgradeURL\">$upgradeText</a> ]";
1843 } else {
1844 $upgrade = '';
1847 return $upgrade;
1850 // UPGRADE WORKAROUND SCRIPT - POSTNUKE BUG
1851 function postcalendar_admin_upgrade()
1853 if (!PC_ACCESS_ADMIN) {
1854 return _POSTCALENDAR_NOAUTH; }
1856 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1857 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1858 @include("modules/$pcDir/pnversion.php");
1859 @include("modules/$pcDir/pninit.php");
1861 $result = postcalendar_upgrade($pcModInfo['version']);
1863 if ($result === false) {
1864 $output = postcalendar_adminmenu(false);
1865 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1866 $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b></center>';
1867 $output .= '</div><br />';
1868 return $output;
1871 // if we've gotten this far, then it's time to increment the version in the db
1872 list($dbconn) = pnDBGetConn();
1873 $pntable = pnDBGetTables();
1874 $modulestable = $pntable['modules'];
1875 $modulescolumn = &$pntable['modules_column'];
1877 // Get module ID
1878 $modulestable = $pntable['modules'];
1879 $modulescolumn = &$pntable['modules_column'];
1880 $query = "SELECT $modulescolumn[id]
1881 FROM $modulestable
1882 WHERE $modulescolumn[name] = '". pnVarPrepForStore(__POSTCALENDAR__)."'";
1883 $result = $dbconn->Execute($query);
1885 if ($result->EOF) {
1886 die("Failed to get module ID"); }
1888 list($mid) = $result->fields;
1889 $result->Close();
1891 $sql = "UPDATE $modulestable
1892 SET $modulescolumn[version] = '".pnVarPrepForStore($modversion['version'])."',
1893 $modulescolumn[state] = '".pnVarPrepForStore(_PNMODULE_STATE_ACTIVE)."'
1894 WHERE $modulescolumn[id] = '".pnVarPrepForStore($mid)."'";
1896 // upgrade did not succeed
1897 if ($dbconn->Execute($sql) === false) {
1898 $output = postcalendar_adminmenu(false);
1899 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1900 $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b><br />';
1901 $output .= $dbconn->ErrorMsg();
1902 $output .= '</center>';
1903 $output .= '</div><br />';
1905 $output = postcalendar_adminmenu(true);
1906 $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
1907 $output .= '<center><b>CONGRATULATIONS :: MODULE UPGRADE SUCCEEDED</b></center>';
1908 $output .= '</div><br />';
1909 return $output;
1912 function postcalendar_admin_testSystem()
1914 global $bgcolor1,$bgcolor2;
1916 if (!PC_ACCESS_ADMIN) {
1917 return _POSTCALENDAR_NOAUTH; }
1919 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1920 $pcDir = pnVarPrepForOS($modinfo['directory']);
1921 $version = $modinfo['version'];
1922 unset($modinfo);
1924 $tpl = new pcSmarty();
1925 $infos = array();
1927 if (phpversion() >= '4.1.0') {
1928 $__SERVER =& $_SERVER;
1929 $__ENV =& $_ENV;
1930 } else {
1931 $__SERVER =& $HTTP_SERVER_VARS;
1932 $__ENV =& $HTTP_ENV_VARS;
1935 if (defined('_PN_VERSION_NUM')) {
1936 $pnVersion = _PN_VERSION_NUM;
1937 } else {
1938 $pnVersion = pnConfigGetVar('Version_Num');
1941 array_push($infos, array('CMS Version', $pnVersion));
1942 array_push($infos, array('Sitename', pnConfigGetVar('sitename')));
1943 array_push($infos, array('url', pnGetBaseURL()));
1944 array_push($infos, array('PHP Version', phpversion()));
1945 if ((bool) ini_get('safe_mode')) {
1946 $safe_mode = "On";
1947 } else {
1948 $safe_mode = "Off";
1950 array_push($infos, array('PHP safe_mode', $safe_mode));
1951 if ((bool) ini_get('safe_mode_gid')) {
1952 $safe_mode_gid = "On";
1953 } else {
1954 $safe_mode_gid = "Off";
1956 array_push($infos, array('PHP safe_mode_gid', $safe_mode_gid));
1957 $base_dir = ini_get('open_basedir');
1958 if (!empty($base_dir)) {
1959 $open_basedir = "$base_dir";
1960 } else {
1961 $open_basedir = "NULL";
1963 array_push($infos, array('PHP open_basedir', $open_basedir));
1964 array_push($infos, array('SAPI', php_sapi_name()));
1965 array_push($infos, array('OS', php_uname()));
1966 array_push($infos, array('WebServer', $__SERVER['SERVER_SOFTWARE']));
1967 array_push($infos, array('Module dir', "modules/$pcDir"));
1969 $modversion = array();
1970 include "modules/$pcDir/pnversion.php";
1972 $error = '';
1973 if ($modversion['version'] != $version) {
1974 $error = '<br /><div style=\"color: red;\">';
1975 $error .= "new version $modversion[version] installed but not updated!";
1976 $error .= '</div>';
1978 array_push($infos, array('Module version', $version . " $error"));
1979 array_push($infos, array('smarty version', $tpl->_version));
1980 array_push($infos, array('smarty location', SMARTY_DIR));
1981 array_push($infos, array('smarty template dir', $tpl->template_dir));
1983 $info = $tpl->compile_dir;
1984 $error = '';
1985 if (!file_exists($tpl->compile_dir)) {
1986 $error .= " compile dir doesn't exist! [$tpl->compile_dir]<br />";
1987 } else {
1988 // dir exists -> check if it's writeable
1989 if (!is_writeable($tpl->compile_dir)) {
1990 $error .= " compile dir not writeable! [$tpl->compile_dir]<br />";
1993 if (strlen($error) > 0) {
1994 $info .= "<br /><div style=\"color: red;\">$error</div>";
1996 array_push($infos, array('smarty compile dir', $info));
1998 $info = $tpl->cache_dir;
1999 $error = "";
2000 if (!file_exists($tpl->cache_dir)) {
2001 $error .= " cache dir doesn't exist! [$tpl->cache_dir]<br />";
2002 } else {
2003 // dir exists -> check if it's writeable
2004 if (!is_writeable($tpl->cache_dir)) {
2005 $error .= " cache dir not writeable! [$tpl->cache_dir]<br />";
2008 if (strlen($error) > 0) {
2009 $info .= "<br /><div style=\"color: red;\">$error</div>";
2011 array_push($infos, array('smarty cache dir', $info));
2013 $header = <<<EOF
2014 <html>
2015 <head></head>
2016 <body bgcolor=
2017 EOF;
2018 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
2019 $output .= $header;
2020 $output = postcalendar_adminmenu();
2021 $output .= '<table border="1" cellpadding="3" cellspacing="1">';
2022 $output .= ' <tr><th align="left">Name</th><th align="left">Value</th>';
2023 $output .= '</tr>';
2024 foreach ($infos as $info) {
2025 $output.= '<tr><td ><b>' . pnVarPrepHTMLDisplay($info[0]) . '</b></td>';
2026 $output.= '<td>' . pnVarPrepHTMLDisplay($info[1]) . '</td></tr>';
2028 $output .= '</table>';
2029 $output .= '<br /><br />';
2030 $output .= postcalendar_admin_modifyconfig('', false);
2031 $output .= "</body></html>";
2032 return $output;
2035 function postcalendar_admin_categoryDetail($args)
2037 if (!PC_ACCESS_ADD) {
2038 return _POSTCALENDARNOAUTH; }
2039 extract($args);
2040 unset($args);
2042 $output = new pnHTML();
2043 $output->SetInputMode(_PNH_VERBATIMINPUT);
2044 // set up Smarty
2045 $tpl = new pcSmarty();
2046 $tpl->caching = false;
2048 $template_name = pnModGetVar(__POSTCALENDAR__, 'pcTemplate');
2050 if (!isset($template_name)) {
2051 $template_name ='default';
2054 //=================================================================
2055 // Setup the correct config file path for the templates
2056 //=================================================================
2057 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
2058 $modir = pnVarPrepForOS($modinfo['directory']);
2059 $modname = $modinfo['displayname'];
2060 $all_categories = & pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
2061 $all_details =& pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCatDetails');
2062 unset($modinfo);
2063 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
2064 //=================================================================
2065 // PARSE MAIN
2066 //=================================================================
2069 $tpl->assign_by_ref('TPL_NAME', $template_name);
2070 $tpl->assign('FUNCTION', pnVarCleanFromInput('func'));
2071 $tpl->assign_by_ref('ModuleName', $modname);
2072 $tpl->assign_by_ref('ModuleDirectory', $modir);
2073 $tpl->assign('Category', "Category");
2074 $tpl->assign_by_ref('categories', $all_categories);
2076 //=================================================================
2077 // Repeating Information
2078 //=================================================================
2079 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
2080 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
2081 $tpl->assign('RepeatTitle', _PC_REPEAT);
2082 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
2083 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
2084 $tpl->assign('EndDateTitle', _PC_END_DATE);
2085 $tpl->assign('NoEndDateTitle', _PC_NO_END);
2086 $tpl->assign('InputNoRepeat', 'event_repeat');
2087 $tpl->assign('ValueNoRepeat', '0');
2088 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
2089 $tpl->assign('InputRepeat', 'event_repeat');
2090 $tpl->assign('ValueRepeat', '1');
2091 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
2093 unset($in);
2094 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
2095 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
2096 $repeat_freq = array();
2097 foreach ($in as $k => $v) {
2098 array_push($repeat_freq, array('value'=>$keys[$k],
2099 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
2100 'name'=>$v));
2102 $tpl->assign('InputRepeatFreq', 'event_repeat_freq');
2103 if (empty($event_repeat_freq) || $event_repeat_freq < 1) {
2104 $event_repeat_freq = 1;
2106 $tpl->assign('InputRepeatFreqVal', $event_repeat_freq);
2107 $tpl->assign('repeat_freq', $repeat_freq);
2108 unset($in);
2109 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
2110 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
2111 $repeat_freq_type = array();
2112 foreach ($in as $k => $v) {
2113 array_push($repeat_freq_type, array('value'=>$keys[$k],
2114 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
2115 'name'=>$v));
2117 $tpl->assign('InputRepeatFreqType', 'event_repeat_freq_type');
2118 $tpl->assign('repeat_freq_type', $repeat_freq_type);
2120 $tpl->assign('InputRepeatOn', 'event_repeat');
2121 $tpl->assign('ValueRepeatOn', '2');
2122 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
2124 unset($in);
2125 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
2126 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
2127 $repeat_on_num = array();
2128 foreach ($in as $k => $v) {
2129 array_push($repeat_on_num, array('value'=>$keys[$k],
2130 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
2131 'name'=>$v));
2133 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
2134 $tpl->assign('repeat_on_num', $repeat_on_num);
2136 unset($in);
2137 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
2138 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
2139 $repeat_on_day = array();
2140 foreach ($in as $k => $v) {
2141 array_push($repeat_on_day, array('value'=>$keys[$k],
2142 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
2143 'name'=>$v));
2145 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
2146 $tpl->assign('repeat_on_day', $repeat_on_day);
2148 unset($in);
2149 $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);
2150 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
2151 $repeat_on_freq = array();
2152 foreach ($in as $k => $v) {
2153 array_push($repeat_on_freq, array('value'=>$keys[$k],
2154 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
2155 'name'=>$v));
2157 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
2158 if (empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) {
2159 $event_repeat_on_freq = 1;
2161 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
2162 $tpl->assign('repeat_on_freq', $repeat_on_freq);
2163 $tpl->assign('MonthsTitle', _PC_MONTHS);
2165 $output->SetOutputMode(_PNH_RETURNOUTPUT);
2166 $authkey = $output->FormHidden('authid', pnSecGenAuthKey());
2167 $output->SetOutputMode(_PNH_KEEPOUTPUT);
2169 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
2170 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
2171 if (isset($data_loaded)) {
2172 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
2173 $tpl->assign('FormHidden', $form_hidden);
2175 $form_submit = '<input type=hidden name="form_action" value="commit"/>
2176 '.$authkey.'<input type="submit" name="submit" value="go">' ;
2177 $tpl->assign('FormSubmit', $form_submit);
2179 $output->Text($tpl->fetch($template_name.'/admin/submit_detail.html'));
2181 $output->Text(postcalendar_footer());
2182 return $output->GetOutput();
2185 function postcalendar_admin_categoryLimits($msg = '', $e = '', $args = array())
2187 if (!PC_ACCESS_ADD) {
2188 return _POSTCALENDARNOAUTH; }
2189 extract($args);
2190 unset($args);
2192 $output = new pnHTML();
2193 $output->SetInputMode(_PNH_VERBATIMINPUT);
2194 // set up Smarty
2195 $tpl = new pcSmarty();
2196 $tpl->caching = false;
2198 $template_name = pnModGetVar(__POSTCALENDAR__, 'pcTemplate');
2200 if (!isset($template_name)) {
2201 $template_name ='default';
2204 if (!empty($e)) {
2205 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
2206 $output->Text('<center><b>'.$e.'</b></center>');
2207 $output->Text('</div><br />');
2210 if (!empty($msg)) {
2211 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
2212 $output->Text('<center><b>'.$msg.'</b></center>');
2213 $output->Text('</div><br />');
2216 //=================================================================
2217 // Setup the correct config file path for the templates
2218 //=================================================================
2219 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
2220 $modir = pnVarPrepForOS($modinfo['directory']);
2221 $modname = $modinfo['displayname'];
2223 //print_r($all_categories);
2224 unset($modinfo);
2225 $tpl->assign('action', pnModURL(__POSTCALENDAR__, 'admin', 'categoryLimitsUpdate'));
2226 //===============================================================
2227 // Setup titles for smarty
2228 //===============================================================
2230 $tpl->assign('_PC_LIMIT_TITLE', _PC_LIMIT_TITLE);
2231 $tpl->assign('StartTimeTitle', _PC_LIMIT_START_TIME);
2232 $tpl->assign('EndTimeTile', _PC_LIMIT_END_TIME);
2233 $tpl->assign('LimitHoursTitle', _PC_TIMED_DURATION_HOURS);
2234 $tpl->assign('LimitMinutesTitle', _PC_TIMED_DURATION_MINUTES);
2236 //=============================================================
2237 // Setup Vars for smarty
2238 //============================================================
2239 $tpl->assign('mer_title', 'mer');
2240 $mer = array('am','pm');
2241 $tpl->assign_by_ref('mer', $mer);
2242 $tpl->assign('starttimeh', 'starttimeh');
2243 $tpl->assign('starttimem', 'starttimem');
2244 $tpl->assign('endtimeh', 'endtimeh');
2245 $tpl->assign('endtimem', 'endtimem');
2246 $tpl->assign('InputLimit', 'limit');
2247 $tpl->assign('LimitTitle', _PC_LIMIT_TITLE);
2248 $tpl->assign('_PC_NEW_LIMIT_TITLE', _PC_NEW_LIMIT_TITLE);
2249 $tpl->assign('_PC_CAT_DELETE', _PC_CAT_DELETE);
2250 $tpl->assign('EndTimeTitle', _PC_LIMIT_END_TIME);
2252 $hour_array =array('00','01','02','03','04','05','06','07','08','09','10','11','12',
2253 '13','14','15','16','17','18','19','21','21','22','23');
2254 $min_array = array('00','05','10','15','20','25','30','35','40','45','50','55');
2255 $tpl->assign_by_ref('hour_array', $hour_array);
2256 $tpl->assign_by_ref('min_array', $min_array);
2258 $categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
2259 // create translations of category names if applicable
2260 $sizeAllCat = count($categories);
2261 for ($m = 0; $m < $sizeAllCat; $m++) {
2262 $tempCategory = $categories[$m]["name"];
2263 $categories[$m]["name"] = xl_appt_category($tempCategory);
2265 $tpl->assign_by_ref('categories', $categories);
2266 $limits = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategoryLimits');
2267 $tpl->assign_by_ref('limits', $limits);
2268 $tpl->assign('BGCOLOR2', $GLOBALS['style']['BGCOLOR2']);
2269 $tpl->assign("catTitle", _PC_REP_CAT_TITLE_S);
2270 $tpl->assign("catid", "catid");
2271 $form_submit = '<input type=hidden name="form_action" value="commit"/>
2272 '.$authkey.'<input type="submit" name="submit" value="' . xl('go') . '">';
2273 $tpl->assign('FormSubmit', $form_submit);
2276 $output->Text($tpl->fetch($template_name.'/admin/submit_category_limit.html'));
2277 $output->Text(postcalendar_footer());
2278 return $output->GetOutput();
2281 function postcalendar_admin_categoryLimitsUpdate()
2283 if (!PC_ACCESS_ADMIN) {
2284 return _POSTCALENDAR_NOAUTH; }
2286 $output = new pnHTML();
2287 $output->SetInputMode(_PNH_VERBATIMINPUT);
2289 list($dbconn) = pnDBGetConn();
2290 $pntable = pnDBGetTables();
2292 list($id,$del,$catId,$startTimeH,$startTimeM,$endTimeH,$endTimeM,$limit,
2293 $newCatId,$newStartTimeH,$newStartTimeM,$newEndTimeH,
2294 $newEndTimeM,$newLimit,
2295 ) = pnVarCleanFromInput(
2296 'id',
2297 'del',
2298 'catid',
2299 'starttimeh',
2300 'starttimem',
2301 'endtimeh',
2302 'endtimem',
2303 'limit',
2304 'newcatid',
2305 'newstarttimeh',
2306 'newstarttimem',
2307 'newendtimeh',
2308 'newendtimem',
2309 'newlimit'
2311 $updates = array();
2312 if (isset($id)) {
2313 foreach ($id as $k => $i) {
2314 $found = false;
2315 if (count($del)) {
2316 foreach ($del as $d) {
2317 if ($i == $d) {
2318 $found = true;
2319 break;
2323 if (!$found) {
2324 $start = date("H:i:s", mktime($startTimeH[$k], $startTimeM[$k], 0));
2325 $end = date("H:i:s", mktime($endTimeH[$k], $endTimeM[$k], 0));
2326 $update_sql = "UPDATE $pntable[postcalendar_limits]
2327 SET pc_catid='".pnVarPrepForStore($catId[$k])."',
2328 pc_starttime='".pnVarPrepForStore($start)."',
2329 pc_endtime='".pnVarPrepForStore($end)."',
2330 pc_limit='".pnVarPrepForStore($limit[$k])."'
2331 WHERE pc_limitid=$i";
2332 array_push($updates, $update_sql);
2337 $dels = implode(",", $del);
2338 $delete = "DELETE FROM $pntable[postcalendar_limits] WHERE pc_limitid IN ($dels)";
2339 $e = $msg = '';
2340 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'updateCategoryLimit', array('updates'=>$updates))) {
2341 $e .= 'UPDATE FAILED';
2343 if (isset($dels)) {
2344 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'deleteCategoryLimit', array('delete'=>$delete))) {
2345 $e .= 'DELETE FAILED';
2348 if (isset($newLimit) && $newLimit > 0) {
2349 $start = date("H:i:s", mktime($newStartTimeH, $newStartTimeM, 0));
2350 $end = date("H:i:s", mktime($newEndTimeH, $newEndTimeM, 0));
2352 if (!pnModAPIFunc(
2353 __POSTCALENDAR__,
2354 'admin',
2355 'addCategoryLimit',
2356 array('catid'=>$newCatId,'starttime'=>$start,'endtime'=>$end,
2357 'limit'=>$newLimit)
2358 )) {
2359 $e .= 'INSERT FAILED';
2363 if (empty($e)) {
2364 $msg = 'DONE'; }
2365 $output->Text(postcalendar_admin_categoryLimits($msg, $e));
2366 return $output->GetOutput();