PHP warning fixes
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnadmin.php
blobe814adea94a9be0ba41f5f7e97e4219a61624a8a
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
9 *
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) { return _POSTCALENDAR_NOAUTH; }
45 return postcalendar_admin_modifyconfig();
47 function postcalendar_admin_listapproved() { return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN); }
48 function postcalendar_admin_listhidden() { return postcalendar_admin_showlist('',_EVENT_HIDDEN,'listhidden',_PC_HIDDEN_ADMIN); }
49 function postcalendar_admin_listqueued() { return postcalendar_admin_showlist('',_EVENT_QUEUED,'listqueued',_PC_QUEUED_ADMIN); }
50 function postcalendar_admin_showlist($e='',$type,$function,$title,$msg='')
52 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
53 $header = <<<EOF
54 <html>
55 <head></head>
56 <body bgcolor=
57 EOF;
58 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
59 $output .= $header;
60 $output .= postcalendar_adminmenu();
62 if(!empty($e)) {
63 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
64 $output .= '<center><b>'.$e.'</b></center>';
65 $output .= '</div><br />';
68 if(!empty($msg)) {
69 $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
70 $output .= '<center><b>'.$msg.'</b></center>';
71 $output .= '</div><br />';
74 $offset_increment = _SETTING_HOW_MANY_EVENTS;
75 if(empty($offset_increment)) $offset_increment = 15;
77 pnThemeLoad(pnUserGetTheme());
78 // get the theme globals :: is there a better way to do this?
79 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
80 global $textcolor1, $textcolor2;
82 $offset = pnVarCleanFromInput('offset');
83 $sort = pnVarCleanFromInput('sort');
84 $sdir = pnVarCleanFromInput('sdir');
85 if(!isset($sort)) $sort = 'time';
86 if(!isset($sdir)) $sdir = 1;
87 if(!isset($offset)) $offset = 0;
89 $result = pnModAPIFunc(__POSTCALENDAR__,'admin','getAdminListEvents',
90 array('type'=>$type,
91 'sdir'=>$sdir,
92 'sort'=>$sort,
93 'offset'=>$offset,
94 'offset_increment'=>$offset_increment));
96 $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','buildAdminList',
97 array('type'=>$type,
98 'title'=>$title,
99 'sdir'=>$sdir,
100 'sort'=>$sort,
101 'offset'=>$offset,
102 'offset_increment'=>$offset_increment,
103 'function'=>$function,
104 'result'=>$result));
106 $output .= "</body></html>";
107 return $output;
110 function postcalendar_admin_adminevents()
112 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
114 $output = '';
115 list($action,$pc_event_id,$thelist) = pnVarCleanFromInput('action','pc_event_id','thelist');
117 if(!isset($pc_event_id)) {
118 $e = _PC_NO_EVENT_SELECTED;
120 switch($thelist) {
121 case 'listqueued' :
122 $output .= postcalendar_admin_showlist($e,_EVENT_QUEUED,'showlist');
123 break;
125 case 'listhidden' :
126 $output .= postcalendar_admin_showlist($e,_EVENT_HIDDEN,'showlist');
127 break;
129 case 'listapproved' :
130 $output .= postcalendar_admin_showlist($e,_EVENT_APPROVED,'showlist');
131 break;
133 return $output;
136 // main menu
137 $output = postcalendar_adminmenu();
138 $function = '';
139 switch ($action) {
140 case _ADMIN_ACTION_APPROVE :
141 $function = 'approveevents';
142 $are_you_sure_text = _PC_APPROVE_ARE_YOU_SURE;
143 break;
145 case _ADMIN_ACTION_HIDE :
146 $function = 'hideevents';
147 $are_you_sure_text = _PC_HIDE_ARE_YOU_SURE;
148 break;
150 case _ADMIN_ACTION_DELETE :
151 $function = 'deleteevents';
152 $are_you_sure_text = _PC_DELETE_ARE_YOU_SURE;
153 break;
156 if(!empty($function)) {
157 $output .= '<form action="'.pnModUrl(__POSTCALENDAR__,'admin',$function).'" method="post">';
158 $output .= $are_you_sure_text.' ';
159 $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
160 $output .= '<br /><br />';
162 if(is_array($pc_event_id)) {
163 foreach($pc_event_id as $eid) {
164 $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','eventDetail',array('eid'=>$eid,'nopop'=>true));
165 $output .= '<br /><br />';
166 $output .= '<input type="hidden" name="pc_eid[]" value="'.$eid.'" />';
168 } else {
169 $output .= pnModAPIFunc(__POSTCALENDAR__,'admin','eventDetail',array('eid'=>$pc_event_id,'nopop'=>true));
170 $output .= '<br /><br />';
171 $output .= '<input type="hidden" name="pc_eid[]" value="'.$pc_event_id.'" />';
173 if(!empty($function)) {
174 $output .= $are_you_sure_text.' ';
175 $output .= '<input type="submit" name="submit" value="'._PC_ADMIN_YES.'" />';
176 $output .= '</form>';
179 return $output;
182 function postcalendar_admin_approveevents()
184 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
186 $pc_eid = pnVarCleanFromInput('pc_eid');
187 $approve_list = '';
188 foreach($pc_eid as $eid) {
189 if(!empty($approve_list)) { $approve_list .= ','; }
190 $approve_list .= $eid;
193 list($dbconn) = pnDBGetConn();
194 $pntable = pnDBGetTables();
195 $events_table = $pntable['postcalendar_events'];
196 $events_column = &$pntable['postcalendar_events_column'];
198 $sql = "UPDATE $events_table
199 SET $events_column[eventstatus] = "._EVENT_APPROVED."
200 WHERE $events_column[eid] IN ($approve_list)";
202 $dbconn->Execute($sql);
203 if ($dbconn->ErrorNo() != 0) {
204 $msg = _PC_ADMIN_EVENT_ERROR;
205 } else {
206 $msg = _PC_ADMIN_EVENTS_APPROVED;
209 // clear the template cache
210 $tpl = new pcSmarty();
211 $tpl->clear_all_cache();
212 return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
215 function postcalendar_admin_hideevents()
217 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
219 $pc_eid = pnVarCleanFromInput('pc_eid');
220 $output = postcalendar_adminmenu();
221 $event_list = '';
222 foreach($pc_eid as $eid) {
223 if(!empty($event_list)) { $event_list .= ','; }
224 $event_list .= $eid;
227 list($dbconn) = pnDBGetConn();
228 $pntable = pnDBGetTables();
229 $events_table = $pntable['postcalendar_events'];
230 $events_column = &$pntable['postcalendar_events_column'];
232 $sql = "UPDATE $events_table
233 SET $events_column[eventstatus] = "._EVENT_HIDDEN."
234 WHERE $events_column[eid] IN ($event_list)";
236 $dbconn->Execute($sql);
237 if ($dbconn->ErrorNo() != 0) {
238 $msg = _PC_ADMIN_EVENT_ERROR;
239 } else {
240 $msg = _PC_ADMIN_EVENTS_HIDDEN;
243 // clear the template cache
244 $tpl = new pcSmarty();
245 $tpl->clear_all_cache();
246 return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
249 function postcalendar_admin_deleteevents()
251 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
253 $pc_eid = pnVarCleanFromInput('pc_eid');
254 $output = postcalendar_adminmenu();
255 $event_list = '';
256 foreach($pc_eid as $eid) {
257 if(!empty($event_list)) { $event_list .= ','; }
258 $event_list .= $eid;
261 list($dbconn) = pnDBGetConn();
262 $pntable = pnDBGetTables();
263 $events_table = $pntable['postcalendar_events'];
264 $events_column = &$pntable['postcalendar_events_column'];
266 $sql = "DELETE FROM $events_table WHERE $events_column[eid] IN ($event_list)";
268 $dbconn->Execute($sql);
269 if ($dbconn->ErrorNo() != 0) {
270 $msg = _PC_ADMIN_EVENT_ERROR;
271 } else {
272 $msg = _PC_ADMIN_EVENTS_DELETED;
275 // clear the t
276 $tpl = new pcSmarty();
277 $tpl->clear_all_cache();
278 return postcalendar_admin_showlist('',_EVENT_APPROVED,'listapproved',_PC_APPROVED_ADMIN,$msg);
281 function postcalendar_admin_edit($args) { return postcalendar_admin_submit($args); }
282 function postcalendar_admin_submit($args)
284 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
286 pnModAPILoad(__POSTCALENDAR__,'user');
287 $output = postcalendar_adminmenu();
289 // get the theme globals :: is there a better way to do this?
290 pnThemeLoad(pnUserGetTheme());
291 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $textcolor1, $textcolor2;
293 extract($args);
295 $Date = postcalendar_getDate();
296 $year = substr($Date,0,4);
297 $month = substr($Date,4,2);
298 $day = substr($Date,6,2);
300 // basic event information
301 $event_subject = pnVarCleanFromInput('event_subject');
302 $event_desc = pnVarCleanFromInput('event_desc');
303 $event_sharing = pnVarCleanFromInput('event_sharing');
304 $event_category = pnVarCleanFromInput('event_category');
305 $event_topic = pnVarCleanFromInput('event_topic');
307 // event start information
308 $event_startmonth = pnVarCleanFromInput('event_startmonth');
309 $event_startday = pnVarCleanFromInput('event_startday');
310 $event_startyear = pnVarCleanFromInput('event_startyear');
311 $event_starttimeh = pnVarCleanFromInput('event_starttimeh');
312 $event_starttimem = pnVarCleanFromInput('event_starttimem');
313 $event_startampm = pnVarCleanFromInput('event_startampm');
315 // event end information
316 $event_endmonth = pnVarCleanFromInput('event_endmonth');
317 $event_endday = pnVarCleanFromInput('event_endday');
318 $event_endyear = pnVarCleanFromInput('event_endyear');
319 $event_endtype = pnVarCleanFromInput('event_endtype');
320 $event_dur_hours = pnVarCleanFromInput('event_dur_hours');
321 $event_dur_minutes = pnVarCleanFromInput('event_dur_minutes');
322 $event_duration = (60*60*$event_dur_hours) + (60*$event_dur_minutes);
323 $event_allday = pnVarCleanFromInput('event_allday');
325 // location data
326 $event_location = pnVarCleanFromInput('event_location');
327 $event_street1 = pnVarCleanFromInput('event_street1');
328 $event_street2 = pnVarCleanFromInput('event_street2');
329 $event_city = pnVarCleanFromInput('event_city');
330 $event_state = pnVarCleanFromInput('event_state');
331 $event_postal = pnVarCleanFromInput('event_postal');
332 $event_location_info = serialize(compact('event_location', 'event_street1', 'event_street2',
333 'event_city', 'event_state', 'event_postal'));
334 // contact data
335 $event_contname = pnVarCleanFromInput('event_contname');
336 $event_conttel = pnVarCleanFromInput('event_conttel');
337 $event_contemail = pnVarCleanFromInput('event_contemail');
338 $event_website = pnVarCleanFromInput('event_website');
339 $event_fee = pnVarCleanFromInput('event_fee');
341 // event repeating data
342 $event_repeat = pnVarCleanFromInput('event_repeat');
343 $event_repeat_freq = pnVarCleanFromInput('event_repeat_freq');
344 $event_repeat_freq_type = pnVarCleanFromInput('event_repeat_freq_type');
345 $event_repeat_on_num = pnVarCleanFromInput('event_repeat_on_num');
346 $event_repeat_on_day = pnVarCleanFromInput('event_repeat_on_day');
347 $event_repeat_on_freq = pnVarCleanFromInput('event_repeat_on_freq');
348 $event_recurrspec = serialize(compact('event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num',
349 'event_repeat_on_day', 'event_repeat_on_freq'));
351 $pc_html_or_text = pnVarCleanFromInput('pc_html_or_text');
352 $form_action = pnVarCleanFromInput('form_action');
353 $pc_event_id = pnVarCleanFromInput('pc_event_id');
354 $data_loaded = pnVarCleanFromInput('data_loaded');
355 $is_update = pnVarCleanFromInput('is_update');
356 $authid = pnVarCleanFromInput('authid');
358 if(pnUserLoggedIn()) { $uname = pnUserGetVar('uname'); }
359 else { $uname = pnConfigGetVar('anonymous'); }
360 if(!isset($event_repeat)) { $event_repeat = 0; }
362 // lets wrap all the data into array for passing to submit and preview functions
363 if(!isset($pc_event_id) || empty($pc_event_id) || $data_loaded) {
364 $eventdata = compact('event_subject','event_desc','event_sharing','event_category','event_topic',
365 'event_startmonth','event_startday','event_startyear','event_starttimeh','event_starttimem','event_startampm',
366 'event_endmonth','event_endday','event_endyear','event_endtype','event_dur_hours','event_dur_minutes',
367 'event_duration','event_allday','event_location','event_street1','event_street2','event_city','event_state',
368 'event_postal','event_location_info','event_contname','event_conttel','event_contemail',
369 'event_website','event_fee','event_repeat','event_repeat_freq','event_repeat_freq_type',
370 'event_repeat_on_num','event_repeat_on_day','event_repeat_on_freq','event_recurrspec','uname',
371 'Date','year','month','day','pc_html_or_text');
372 $eventdata['is_update'] = $is_update;
373 $eventdata['pc_event_id'] = $pc_event_id;
374 $eventdata['data_loaded'] = true;
375 } else {
376 $event = postcalendar_userapi_pcGetEventDetails($pc_event_id);
377 $eventdata['event_subject'] = $event['title'];
378 $eventdata['event_desc'] = $event['hometext'];
379 $eventdata['event_sharing'] = $event['sharing'];
380 $eventdata['event_category'] = $event['catid'];
381 $eventdata['event_topic'] = $event['topic'];
382 $eventdata['event_startmonth'] = substr($event['eventDate'],5,2);
383 $eventdata['event_startday'] = substr($event['eventDate'],8,2);
384 $eventdata['event_startyear'] = substr($event['eventDate'],0,4);
385 $eventdata['event_starttimeh'] = substr($event['startTime'],0,2);
386 $eventdata['event_starttimem'] = substr($event['startTime'],3,2);
387 $eventdata['event_startampm'] = $eventdata['event_starttimeh'] < 12 ? _PC_AM : _PC_PM ;
388 $eventdata['event_endmonth'] = substr($event['endDate'],5,2);
389 $eventdata['event_endday'] = substr($event['endDate'],8,2);
390 $eventdata['event_endyear'] = substr($event['endDate'],0,4);
391 $eventdata['event_endtype'] = $event['endDate'] == '0000-00-00' ? '0' : '1' ;
392 $eventdata['event_dur_hours'] = $event['duration_hours'];
393 $eventdata['event_dur_minutes'] = $event['duration_minutes'];
394 $eventdata['event_duration'] = $event['duration'];
395 $eventdata['event_allday'] = $event['alldayevent'];
396 $loc_data = unserialize($event['location']);
397 $eventdata['event_location'] = $loc_data['event_location'];
398 $eventdata['event_street1'] = $loc_data['event_street1'];
399 $eventdata['event_street2'] = $loc_data['event_street2'];
400 $eventdata['event_city'] = $loc_data['event_city'];
401 $eventdata['event_state'] = $loc_data['event_state'];
402 $eventdata['event_postal'] = $loc_data['event_postal'];
403 $eventdata['event_location_info'] = $loc_data;
404 $eventdata['event_contname'] = $event['contname'];
405 $eventdata['event_conttel'] = $event['conttel'];
406 $eventdata['event_contemail'] = $event['contemail'];
407 $eventdata['event_website'] = $event['website'];
408 $eventdata['event_fee'] = $event['fee'];
409 $eventdata['event_repeat'] = $event['recurrtype'];
410 $eventdata['event_pid'] = $event['pid'];
411 $eventdata['event_aid'] = $event['aid'];
412 $rspecs = unserialize($event['recurrspec']);
413 $eventdata['event_repeat_freq'] = $rspecs['event_repeat_freq'];
414 $eventdata['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
415 $eventdata['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
416 $eventdata['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
417 $eventdata['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
418 $eventdata['event_recurrspec'] = $rspecs;
419 $eventdata['uname'] = $uname;
420 $eventdata['Date'] = $Date;
421 $eventdata['year'] = $year;
422 $eventdata['month'] = $month;
423 $eventdata['day'] = $day;
424 $eventdata['is_update'] = true;
425 $eventdata['pc_event_id'] = $pc_event_id;
426 $eventdata['data_loaded'] = true;
427 $eventdata['pc_html_or_text'] = $pc_html_or_text;
430 // lets get the module's information
431 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
432 $categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
434 //================================================================
435 // ERROR CHECKING
436 //================================================================
437 $required_vars = array('event_subject','event_desc');
438 $required_name = array(_PC_EVENT_TITLE,_PC_EVENT_DESC);
439 $error_msg = '';
440 $reqCount = count($required_vars);
441 for ($r=0; $r<$reqCount; $r++) {
442 if(empty($$required_vars[$r]) || !preg_match('/\S/i',$$required_vars[$r])) {
443 $error_msg .= '<b>' . $required_name[$r] . '</b> ' . _PC_SUBMIT_ERROR4 . '<br />';
446 unset($reqCount);
447 // check repeating frequencies
448 if($event_repeat == REPEAT) {
449 if(!isset($event_repeat_freq) || $event_repeat_freq < 1 || empty($event_repeat_freq)) {
450 $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
451 } elseif(!is_numeric($event_repeat_freq)) {
452 $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
454 } elseif($event_repeat == REPEAT_ON) {
455 if(!isset($event_repeat_on_freq) || $event_repeat_on_freq < 1 || empty($event_repeat_on_freq)) {
456 $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
457 } elseif(!is_numeric($event_repeat_on_freq)) {
458 $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
461 // check date validity
462 if(_SETTING_TIME_24HOUR) {
463 $startTime = $event_starttimeh.':'.$event_starttimem;
464 $endTime = $event_endtimeh.':'.$event_endtimem;
465 } else {
466 if($event_startampm == _AM_VAL) {
467 $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
468 } else {
469 $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh+=12 : $event_starttimeh;
471 $startTime = $event_starttimeh.':'.$event_starttimem;
473 $sdate = strtotime($event_startyear.'-'.$event_startmonth.'-'.$event_startday);
474 $edate = strtotime($event_endyear.'-'.$event_endmonth.'-'.$event_endday);
475 $tdate = strtotime(date('Y-m-d'));
476 if($edate < $sdate && $event_endtype == 1) {
477 $error_msg .= _PC_SUBMIT_ERROR1 . '<br />';
479 if(!checkdate($event_startmonth,$event_startday,$event_startyear)) {
480 $error_msg .= _PC_SUBMIT_ERROR2 . '<br />';
482 if(!checkdate($event_endmonth,$event_endday,$event_endyear)) {
483 $error_msg .= _PC_SUBMIT_ERROR3 . '<br />';
486 //================================================================
487 // Preview the event
488 //================================================================
489 if($form_action == 'preview') {
490 if(!empty($error_msg)) {
491 $preview = false;
492 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
493 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
494 $output .= '<center><b>' . _PC_SUBMIT_ERROR . '</b></center>';
495 $output .= '<br />';
496 $output .= $error_msg;
497 $output .= '</td></td></table>';
498 $output .= '</td></td></table>';
499 $output .= '<br /><br />';
500 } else {
501 $output .= pnModAPIFunc(__POSTCALENDAR__,'user','eventPreview',$eventdata);
502 $output .= '<br />';
506 //================================================================
507 // Enter the event into the DB
508 //================================================================
509 if($form_action == 'commit') {
510 //if (!pnSecConfirmAuthKey()) { return(_NO_DIRECT_ACCESS); }
511 if(!empty($error_msg)) {
512 $preview = false;
513 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
514 $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
515 $output .= '<center><b>'._PC_SUBMIT_ERROR.'</b></center>';
516 $output .= '<br />';
517 $output .= $error_msg;
518 $output .= '</td></td></table>';
519 $output .= '</td></td></table>';
520 $output .= '<br /><br />';
521 } else {
522 if (!pnModAPIFunc(__POSTCALENDAR__,'admin','submitEvent',$eventdata)) {
523 $output .= '<center><div style="padding:5px; border:1px solid red; background-color: pink;">';
524 $output .= "<b>"._PC_EVENT_SUBMISSION_FAILED."</b>";
525 $output .= '</div></center><br />';
526 $output .= '<br />';
527 } else {
528 // clear the Smarty cache
529 $tpl = new pcSmarty();
530 $tpl->clear_all_cache();
531 $output .= '<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
532 if($is_update) {
533 $output .= "<b>"._PC_EVENT_EDIT_SUCCESS."</b>";
534 } else {
535 $output .= "<b>"._PC_EVENT_SUBMISSION_SUCCESS."</b>";
537 $output .= '</div></center><br />';
538 $output .= '<br />';
539 // clear the form vars
540 $event_subject=$event_desc=$event_sharing=$event_category=$event_topic=
541 $event_startmonth=$event_startday=$event_startyear=$event_starttimeh=$event_starttimem=$event_startampm=
542 $event_endmonth=$event_endday=$event_endyear=$event_endtype=$event_dur_hours=$event_dur_minutes=
543 $event_duration=$event_allday=$event_location=$event_street1=$event_street2=$event_city=$event_state=
544 $event_postal=$event_location_info=$event_contname=$event_conttel=$event_contemail=
545 $event_website=$event_fee=$event_repeat=$event_repeat_freq=$event_repeat_freq_type=
546 $event_repeat_on_num=$event_repeat_on_day=$event_repeat_on_freq=$event_recurrspec=$uname=
547 $Date=$year=$month=$day=$pc_html_or_text=null;
548 $is_update = false;
549 $pc_event_id = 0;
550 // lets wrap all the data into array for passing to submit and preview functions
551 $eventdata = compact('event_subject','event_desc','event_sharing','event_category','event_topic',
552 'event_startmonth','event_startday','event_startyear','event_starttimeh','event_starttimem','event_startampm',
553 'event_endmonth','event_endday','event_endyear','event_endtype','event_dur_hours','event_dur_minutes',
554 'event_duration','event_allday','event_location','event_street1','event_street2','event_city','event_state',
555 'event_postal','event_location_info','event_contname','event_conttel','event_contemail',
556 'event_website','event_fee','event_repeat','event_repeat_freq','event_repeat_freq_type',
557 'event_repeat_on_num','event_repeat_on_day','event_repeat_on_freq','event_recurrspec','uname',
558 'Date','year','month','day','pc_html_or_text','is_update','pc_event_id');
563 $output .= pnModAPIFunc('PostCalendar','admin','buildSubmitForm',$eventdata);
564 return $output;
567 function postcalendar_admin_modifyconfig($msg='',$showMenu=true)
569 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
571 $output = new pnHTML();
572 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
573 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
575 $defaultsURL = pnModURL(__POSTCALENDAR__,'admin','resetDefaults');
576 $defaultsText = _EDIT_PC_CONFIG_DEFAULT;
578 $jsColorPicker = <<<EOF
579 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
580 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
581 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
582 <script LANGUAGE="JavaScript">
583 var cp = new ColorPicker('window');
584 // Runs when a color is clicked
585 function pickColor(color) {
586 field.value = color;
589 var field;
590 function pick(anchorname) {
591 field = document.forms.pcConfig.pcDayHighlightColor;
592 cp.show(anchorname);
594 </SCRIPT>
595 EOF;
597 $output->SetInputMode(_PNH_VERBATIMINPUT);
598 $header = <<<EOF
599 <html>
600 <head></head>
601 <body bgcolor=
602 EOF;
603 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
604 $output->Text($header);
605 $output->Text($jsColorPicker);
606 if($showMenu) {
607 $output->Text(postcalendar_adminmenu());
610 if(!empty($msg)) {
611 $output->Text('<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
612 $output->Text("<b>$msg</b>");
613 $output->Text('</div></center><br />');
617 $formURL = pnModUrl(__POSTCALENDAR__,'admin','updateconfig');
618 /*$output->Text("<form action=\"$formURL\" method=\"post\" enctype=\"application/x-www-form-urlencoded\" name=\"pcConfig\" id=\"pcConfig\">");
619 $output->Text('<table border="1" cellpadding="5" cellspacing="1">');
620 $output->Text('<tr><td align="left">'._PC_ADMIN_GLOBAL_SETTINGS,'</td>');
621 $output->Text("<td nowrap><a href=\"$defaultsURL\">$defaultsText</a></td></tr>");
623 $settings = array();
624 $output->SetOutputMode(_PNH_RETURNOUTPUT);
625 $i=0;
627 // global PostCalendar config options
628 $settings[$i][] = $output->Text(_PC_NOTIFY_ADMIN);
629 $settings[$i++][] = $output->FormCheckBox('pcNotifyAdmin', pnModGetVar(__POSTCALENDAR__,'pcNotifyAdmin'));
630 $settings[$i][] = $output->Text(_PC_NOTIFY_EMAIL);
631 $settings[$i++][] = $output->FormText('pcNotifyEmail', pnModGetVar(__POSTCALENDAR__,'pcNotifyEmail'));
633 $settings[$i][] = $output->Text(_PC_ALLOW_DIRECT_SUBMIT);
634 $settings[$i++][] = $output->FormCheckBox('pcAllowDirectSubmit', pnModGetVar(__POSTCALENDAR__,'pcAllowDirectSubmit'));
635 $settings[$i][] = $output->Text(_PC_ALLOW_USER_CALENDAR);
636 $settings[$i++][] = $output->FormCheckBox('pcAllowUserCalendar', pnModGetVar(__POSTCALENDAR__,'pcAllowUserCalendar'));
637 $settings[$i][] = $output->Text(_PC_ALLOW_SITEWIDE_SUBMIT);
638 $settings[$i++][] = $output->FormCheckBox('pcAllowSiteWide', pnModGetVar(__POSTCALENDAR__,'pcAllowSiteWide'));
639 $settings[$i][] = $output->Text(_PC_LIST_HOW_MANY);
640 $settings[$i++][] = $output->FormText('pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__,'pcListHowManyEvents'),5);
641 $settings[$i][] = $output->Text(_PC_TIME24HOURS);
642 $settings[$i++][] = $output->FormCheckBox('pcTime24Hours', pnModGetVar(__POSTCALENDAR__,'pcTime24Hours'));
643 $settings[$i][] = $output->Text(_PC_TIME_INCREMENT);
644 $settings[$i++][] = $output->FormText('pcTimeIncrement', pnModGetVar(__POSTCALENDAR__,'pcTimeIncrement'),5);
645 $settings[$i][] = $output->Text(_PC_EVENTS_IN_NEW_WINDOW);
646 $settings[$i++][] = $output->FormCheckBox('pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__,'pcEventsOpenInNewWindow'));
647 $settings[$i][] = $output->Text(_PC_INTERNATIONAL_DATES);
648 $settings[$i++][] = $output->FormCheckBox('pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__,'pcUseInternationalDates'));
649 $settings[$i][] = $output->Text(_PC_EVENT_DATE_FORMAT);
650 $settings[$i++][] = $output->FormText('pcEventDateFormat', pnModGetVar(__POSTCALENDAR__,'pcEventDateFormat'));
651 $settings[$i][] = $output->Text(_PC_DISPLAY_TOPICS);
652 //$settings[$i++][] = $output->FormCheckBox('pcDisplayTopics', pnModGetVar(__POSTCALENDAR__,'pcDisplayTopics'));
653 $settings[$i][] = $output->Text(_PC_FIRST_DAY_OF_WEEK);
654 $options = array();
655 $selected = pnModGetVar(__POSTCALENDAR__,'pcFirstDayOfWeek');
656 $options[0]['id'] = '0';
657 $options[0]['selected'] = ($selected == 0);
658 $options[0]['name'] = _PC_SUNDAY;
659 $options[1]['id'] = '1';
660 $options[1]['selected'] = ($selected == 1);
661 $options[1]['name'] = _PC_MONDAY;
662 $options[2]['id'] = '6';
663 $options[2]['selected'] = ($selected == 6);
664 $options[2]['name'] = _PC_SATURDAY;
665 $settings[$i++][] = $output->FormSelectMultiple('pcFirstDayOfWeek', $options);
666 $settings[$i][] = $output->Text(_PC_DEFAULT_VIEW);
667 $options = array();
668 $selected = pnModGetVar(__POSTCALENDAR__,'pcDefaultView');
669 $options[0]['id'] = 'day';
670 $options[0]['selected'] = ($selected == 'day');
671 $options[0]['name'] = _CAL_DAYVIEW;
672 $options[1]['id'] = 'week';
673 $options[1]['selected'] = ($selected == 'week');
674 $options[1]['name'] = _CAL_WEEKVIEW;
675 $options[2]['id'] = 'month';
676 $options[2]['selected'] = ($selected == 'month');
677 $options[2]['name'] = _CAL_MONTHVIEW;
678 $options[3]['id'] = 'year';
679 $options[3]['selected'] = ($selected == 'year');
680 $options[3]['name'] = _CAL_YEARVIEW;
681 $settings[$i++][] = $output->FormSelectMultiple('pcDefaultView', $options);
682 $settings[$i][] = $output->Text(_PC_DAY_HIGHLIGHT_COLOR . ' [<a HREF="#" onClick="pick(\'pick\');return false;" NAME="pick" ID="pick">pick</a>]');
683 $settings[$i++][] = $output->FormText('pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__,'pcDayHighlightColor'));
684 $settings[$i][] = $output->Text(_PC_USE_JS_POPUPS);
685 $settings[$i++][] = $output->FormCheckBox('pcUsePopups', pnModGetVar(__POSTCALENDAR__,'pcUsePopups'));
686 $settings[$i][] = $output->Text(_PC_USE_CACHE);
687 $settings[$i++][] = $output->FormCheckBox('pcUseCache', pnModGetVar(__POSTCALENDAR__,'pcUseCache'));
688 $settings[$i][] = $output->Text(_PC_CACHE_LIFETIME);
689 $settings[$i++][] = $output->FormText('pcCacheLifetime', pnModGetVar(__POSTCALENDAR__,'pcCacheLifetime'));
691 $templatelist = array();
692 $handle = opendir('modules/'.$pcDir.'/pntemplates');
693 $hide_list = array('.','..','CVS','compiled','cache');
694 while($f=readdir($handle))
695 { if(!in_array($f,$hide_list) && !ereg("[.]",$f)) {
696 $templatelist[] = $f;
699 closedir($handle); unset($hide_list);
700 sort($templatelist);
701 $tcount = count($templatelist);
702 $settings[$i][] = $output->Text(_PC_DEFAULT_TEMPLATE);
703 $options = array();
704 $selected = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
705 for($t=0;$t<$tcount;$t++) {
706 $options[$t]['id'] = $templatelist[$t];
707 $options[$t]['selected'] = ($selected == $templatelist[$t]);
708 $options[$t]['name'] = $templatelist[$t];
710 $settings[$i++][] = $output->FormSelectMultiple('pcTemplate', $options);
713 $output->SetOutputMode(_PNH_KEEPOUTPUT);
715 // Add row
716 for($i = 0 ; $i < count($settings) ; $i++) {
717 $output->TableAddRow($settings[$i], 'left');
720 $output->Text('</table>');
721 $output->FormSubmit(_PC_ADMIN_SUBMIT);
722 $output->FormEnd();*/
723 $output->Text("</body></html>");
725 return $output->GetOutput();
728 function postcalendar_admin_resetDefaults()
730 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
732 // remove all the PostCalendar variables from the DB
733 pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
734 pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
735 pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
736 pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
737 pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
738 pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
739 pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
740 pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
741 pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
742 pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
743 pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
744 pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
745 pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
746 pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
747 pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
748 pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
749 pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
750 pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
751 pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
753 // PostCalendar Default Settings
754 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', '0');
755 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', '0');
756 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', '0');
757 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', '0');
758 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', '#EEEEEE');
759 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', '1');
760 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', '0');
761 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
762 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', '15');
763 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
764 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
765 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
766 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
767 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
768 pnModSetVar(__POSTCALENDAR__, 'pcUseCache', '1');
769 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', '3600');
770 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', 'month');
771 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0');
772 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail'));
774 $tpl = new pcSmarty();
775 $tpl->clear_all_cache();
777 return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED_DEFAULTS.'</center>');
780 function postcalendar_admin_updateconfig()
782 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
784 list($pcTime24Hours, $pcEventsOpenInNewWindow, $pcUseInternationalDates,
785 $pcFirstDayOfWeek, $pcDayHighlightColor, $pcUsePopups,
786 $pcAllowDirectSubmit, $pcListHowManyEvents, $pcDisplayTopics,
787 $pcEventDateFormat, $pcTemplate, $pcAllowSiteWide,
788 $pcAllowUserCalendar, $pcTimeIncrement,$pcUseCache, $pcCacheLifetime,
789 $pcDefaultView, $pcNotifyAdmin, $pcNotifyEmail) = pnVarCleanFromInput('pcTime24Hours',
790 'pcEventsOpenInNewWindow', 'pcUseInternationalDates', 'pcFirstDayOfWeek',
791 'pcDayHighlightColor', 'pcUsePopups', 'pcAllowDirectSubmit',
792 'pcListHowManyEvents', 'pcDisplayTopics', 'pcEventDateFormat',
793 'pcTemplate', 'pcAllowSiteWide', 'pcAllowUserCalendar', 'pcTimeIncrement',
794 'pcUseCache', 'pcCacheLifetime', 'pcDefaultView', 'pcNotifyAdmin', 'pcNotifyEmail');
796 // make sure we enter something into the DB
797 if(!isset($pcTime24Hours)) { $pcTime24Hours = '0'; }
798 if(!isset($pcEventsOpenInNewWindow)) { $pcEventsOpenInNewWindow='0'; }
799 if(!isset($pcUseInternationalDates)) { $pcUseInternationalDates='0'; }
800 if(!isset($pcFirstDayOfWeek)) { $pcFirstDayOfWeek='0'; }
801 if(!isset($pcUsePopups)) { $pcUsePopups='0'; }
802 if(!isset($pcAllowDirectSubmit)) { $pcAllowDirectSubmit='0'; }
803 if(!isset($pcDisplayTopics)) { $pcDisplayTopics='0'; }
804 if(!isset($pcTemplate)) { $pcTemplate='default'; }
805 if(!isset($pcAllowSiteWide)) { $pcAllowSiteWide='0'; }
806 if(!isset($pcAllowUserCalendar)) { $pcAllowUserCalendar='0'; }
807 if(!isset($pcUseCache)) { $pcUseCache='0'; }
808 if(!isset($pcDefaultView)) { $pcDefaultView='month'; }
809 if(empty($pcCacheLifetime)) { $pcCacheLifetime='3600'; }
810 if(empty($pcDayHighlightColor)) { $pcDayHighlightColor='#EEEEEE'; }
811 if(empty($pcListHowManyEvents)) { $pcListHowManyEvents='15'; }
812 if(empty($pcEventDateFormat)) { $pcEventDateFormat='%Y-%m-%d'; }
813 if(empty($pcTimeIncrement)) { $pcTimeIncrement='15'; }
814 if(empty($pcNotifyAdmin)) { $pcNotifyAdmin='0'; }
815 if(empty($pcNotifyEmail)) { $pcNotifyEmail=pnConfigGetVar('adminmail'); }
817 // delete the old vars - we're doing this because PostNuke variable
818 // handling sometimes has old values in the $GLOBALS we need to clear
819 pnModDelVar(__POSTCALENDAR__, 'pcTime24Hours');
820 pnModDelVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow');
821 pnModDelVar(__POSTCALENDAR__, 'pcUseInternationalDates');
822 pnModDelVar(__POSTCALENDAR__, 'pcFirstDayOfWeek');
823 pnModDelVar(__POSTCALENDAR__, 'pcDayHighlightColor');
824 pnModDelVar(__POSTCALENDAR__, 'pcUsePopups');
825 pnModDelVar(__POSTCALENDAR__, 'pcAllowDirectSubmit');
826 pnModDelVar(__POSTCALENDAR__, 'pcListHowManyEvents');
827 pnModDelVar(__POSTCALENDAR__, 'pcDisplayTopics');
828 pnModDelVar(__POSTCALENDAR__, 'pcEventDateFormat');
829 pnModDelVar(__POSTCALENDAR__, 'pcTemplate');
830 pnModDelVar(__POSTCALENDAR__, 'pcAllowSiteWide');
831 pnModDelVar(__POSTCALENDAR__, 'pcAllowUserCalendar');
832 pnModDelVar(__POSTCALENDAR__, 'pcTimeIncrement');
833 pnModDelVar(__POSTCALENDAR__, 'pcDefaultView');
834 pnModDelVar(__POSTCALENDAR__, 'pcUseCache');
835 pnModDelVar(__POSTCALENDAR__, 'pcCacheLifetime');
836 pnModDelVar(__POSTCALENDAR__, 'pcNotifyAdmin');
837 pnModDelVar(__POSTCALENDAR__, 'pcNotifyEmail');
839 // set the new variables
840 pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', $pcTime24Hours);
841 pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', $pcEventsOpenInNewWindow);
842 pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', $pcUseInternationalDates);
843 pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', $pcFirstDayOfWeek);
844 pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', $pcDayHighlightColor);
845 pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', $pcUsePopups);
846 pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', $pcAllowDirectSubmit);
847 pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', $pcListHowManyEvents);
848 pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', $pcDisplayTopics);
849 pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', $pcEventDateFormat);
850 pnModSetVar(__POSTCALENDAR__, 'pcTemplate', $pcTemplate);
851 pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', $pcAllowSiteWide);
852 pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', $pcAllowUserCalendar);
853 pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', $pcTimeIncrement);
854 pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', $pcDefaultView);
855 pnModSetVar(__POSTCALENDAR__, 'pcUseCache', $pcUseCache);
856 pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', $pcCacheLifetime);
857 pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', $pcNotifyAdmin);
858 pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', $pcNotifyEmail);
860 $tpl = new pcSmarty();
861 $tpl->clear_all_cache();
863 return postcalendar_admin_modifyconfig('<center>'._PC_UPDATED.'</center>');
866 function postcalendar_admin_categoriesOld($msg='',$e='')
868 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
870 $output = new pnHTML();
871 $output->SetInputMode(_PNH_VERBATIMINPUT);
873 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
874 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
875 $jsColorPicker = <<<EOF
876 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/AnchorPosition.js"></SCRIPT>
877 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/PopupWindow.js"></SCRIPT>
878 <script LANGUAGE="Javascript" SRC="modules/$pcDir/pnincludes/ColorPicker2.js"></SCRIPT>
879 <script LANGUAGE="JavaScript">
880 var cp = new ColorPicker('window');
881 // Runs when a color is clicked
882 function pickColor(color) {
883 field.value = color;
886 var field;
887 function pick(anchorname,target) {
888 field = this.document.forms.cats.elements[target];
889 cp.show(anchorname);
891 </SCRIPT>
892 EOF;
893 $header = <<<EOF
894 <html>
895 <head></head>
896 <body bgcolor=
897 EOF;
898 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
899 $output->Text($header);
900 $output->Text($jsColorPicker);
901 $output->Text(postcalendar_adminmenu());
903 if(!empty($e)) {
904 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
905 $output->Text('<center><b>'.$e.'</b></center>');
906 $output->Text('</div><br />');
909 if(!empty($msg)) {
910 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
911 $output->Text('<center><b>'.$msg.'</b></center>');
912 $output->Text('</div><br />');
915 $cats = pnModAPIFunc(__POSTCALENDAR__,'admin','getCategories');
916 if(!is_array($cats)) {
917 $output->Text($cats);
918 return $output->GetOutput();
921 $output->Text('<form name="cats" method="post" action="'.pnModURL(__POSTCALENDAR__,'admin','categoriesConfirm').'">');
922 $output->Text('<table border="1" cellpadding="5" cellspacing="0">');
923 $output->Text('<tr><th>'._PC_CAT_DELETE.'</th><th>'._PC_CAT_NAME.'</th><th>'._PC_CAT_DESC.'</th><th>'._PC_CAT_COLOR.'</th></tr>');
924 $i = 0;
925 foreach($cats as $cat) {
926 $output->Text('<tr>');
927 $output->Text('<td valign="top" align="left">');
928 $output->FormHidden('id[]',$cat['id']);
929 $output->FormCheckbox('del[]',false,$cat['id']);
930 $output->Text('</td>');
931 $output->Text('<td valign="top" align="left">');
932 $output->FormText('name[]',$cat['name'],20);
933 $output->Text('</td>');
934 $output->Text('<td valign="top" align="left">');
935 $output->FormTextarea('desc[]',$cat['desc'],3,20);
936 $output->Text('</td>');
937 $output->Text('<td valign="top" align="left">');
938 $output->FormText('color[]',$cat['color'],10);
939 $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\''.($i+4).'\'); return false;" NAME="pick" ID="pick">pick</a>]');
940 $output->Text('</td>');
941 $output->Text('</tr>');
942 $i+=5;
944 $output->Text('<tr>');
945 $output->Text('<td><a href="'.pnModURL(__POSTCALENDAR__,'admin','categoriesNew').'">'._PC_CAT_NEW.'</a></td>');
947 $output->Text('<td valign="top" align="left">');
948 $output->Text(_PC_CAT_NEW);
949 $output->Text('</td>');
950 $output->Text('<td valign="top" align="left">');
951 $output->FormText('newname','',20);
952 $output->Text('</td>');
953 $output->Text('<td valign="top" align="left">');
954 $output->FormTextarea('newdesc','',3,20);
955 $output->Text('</td>');
956 $output->Text('<td valign="top" align="left">');
957 $output->FormText('newcolor','',10);
958 $output->Text('[<a href="javascript:void(0);" onClick="pick(\'pick\',\'newcolor\');return false;" NAME="pick" ID="pick">pick</a>]');
959 $output->Text('</td>');
961 $output->Text('</tr>');
962 $output->Text('</table>');
963 $output->FormSubmit(_PC_ADMIN_SUBMIT);
964 $output->FormEnd();
965 $output->Text("</body></html>");
966 return $output->GetOutput();
968 function postcalendar_admin_categoriesConfirm()
970 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
972 $output = new pnHTML();
973 $output->SetInputMode(_PNH_VERBATIMINPUT);
974 $header = <<<EOF
975 <html>
976 <head></head>
977 <body bgcolor=
978 EOF;
979 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
980 $output->Text($header);
981 $output->Text(postcalendar_adminmenu());
983 list($id,$del,$name,$value_cat_type,$desc,$color,
984 $event_repeat,$event_repeat_freq,
985 $event_repeat_freq_type,$event_repeat_on_num,
986 $event_repeat_on_day,$event_repeat_on_freq,$durationh,$durationm,
987 $end_date_flag,$end_date_type,$end_date_freq,$end_all_day,
988 $newname,$newdesc,$newcolor,$new_event_repeat,$new_event_repeat_freq,
989 $new_event_repeat_freq_type,$new_event_repeat_on_num,$new_event_repeat_on_day,
990 $new_event_repeat_on_freq,$new_durationh,$new_durationm,$new_limitid,$new_end_date_flag,
991 $new_end_date_type,$new_end_date_freq,$new_end_all_day,$new_value_cat_type
992 ) = pnVarCleanFromInput('id','del','name','value_cat_type','desc','color',
993 'event_repeat','event_repeat_freq','event_repeat_freq_type',
994 'event_repeat_on_num','event_repeat_on_day',
995 'event_repeat_on_freq','durationh','durationm',
996 'end_date_flag','end_date_type','end_date_freq',
997 'end_all_day','newname','newdesc','newcolor',
998 'newevent_repeat','newevent_repeat_freq',
999 'newevent_repeat_freq_type','newevent_repeat_on_num',
1000 'newevent_repeat_on_day','newevent_repeat_on_freq',
1001 'newdurationh','newdurationm','newlimitid','newend_date_flag',
1002 'newend_date_type','newend_date_freq','newend_all_day','newvalue_cat_type'
1004 //data validation
1005 foreach($name as $i=>$item)
1007 if(empty($item))
1009 $output->Text(postcalendar_admin_categories($msg,"Category Names must contain a value!"));
1010 return $output->GetOutput();
1012 $tmp = $color[$i];
1013 if(strlen($tmp) != 7 || $tmp[0] != "#")
1015 $e = $tmp." size ".strlen($tmp)." at 0 ".$tmp[0];
1016 $output->Text(postcalendar_admin_categories($msg,"You entered an invalid color(USE Pick) $e!"));
1017 return $output->GetOutput();
1020 foreach($durationh as $i=>$val)
1022 if(!is_numeric($durationh[$i]) || !is_numeric($durationm[$i]) ||
1023 !is_numeric($event_repeat_freq[$i]) ||
1024 !is_numeric($event_repeat_on_freq[$i]) || !is_numeric($end_date_freq[$i]))
1026 $output->Text(postcalendar_admin_categories($msg," Hours, Minutes and recurrence values must be numeric!"));
1027 return $output->GetOutput();
1031 if(!empty($newnam))
1033 if(!is_numeric($new_durationh) || !is_numeric($new_durationm) ||
1034 !is_numeric($new_event_repeat_freq) || !is_numeric($new_event_repeat_on_freq)
1035 || !is_numeric($new_end_date_freq) )
1037 $output->Text(postcalendar_admin_categories($msg,"Hours, Minutes and recurrence values must be numeric!"));
1038 return $output->GetOutput();
1041 $new_duration = ($new_durationh * (60 * 60)) + ($new_durationm * 60);
1042 $event_recurrspec = serialize(compact('event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num',
1043 'event_repeat_on_day', 'event_repeat_on_freq'));
1045 $new_event_recurrspec = serialize(compact('new_event_repeat_freq', 'new_event_repeat_freq_type', 'new_event_repeat_on_num',
1046 'new_event_repeat_on_day', 'new_event_repeat_on_freq'));
1047 if(is_array($del)) {
1048 $dels = implode(',',$del);
1049 $delText = _PC_DELETE_CATS . $dels .'.';
1051 $output->FormStart(pnModURL(__POSTCALENDAR__,'admin','categoriesUpdate'));
1052 $output->Text(_PC_ARE_YOU_SURE);
1053 $output->Linebreak(2);
1054 // deletions
1055 if(isset($delText)) {
1056 $output->FormHidden('dels',$dels);
1057 $output->Text($delText);
1058 $output->Linebreak();
1060 if(!empty($newname)) {
1061 $output->FormHidden('newname',$newname);
1062 $output->FormHidden('newdesc',$newdesc);
1063 $output->FormHidden('newvalue_cat_type',$new_value_cat_type);
1064 $output->FormHidden('newcolor',$newcolor);
1065 $output->FormHidden('newevent_repeat',$new_event_repeat);
1066 $output->FormHidden('newevent_recurrfreq',$new_event_repeat_freq);
1067 $output->FormHidden('newevent_recurrspec',$new_event_recurrspec);
1068 $output->FormHidden('newduration',$new_duration);
1069 $output->FormHidden('newlimitid',$new_limitid);
1070 $output->FormHidden('newend_date_flag',$new_end_date_flag);
1071 $output->FormHidden('newend_date_type',$new_end_date_type);
1072 $output->FormHidden('newend_date_freq',$new_end_date_freq);
1073 $output->FormHidden('newend_all_day', $new_end_all_day);
1075 $output->Text(_PC_ADD_CAT . $newname .'.');
1076 $output->Linebreak();
1078 $output->Text(_PC_MODIFY_CATS);
1079 $output->FormHidden('id',serialize($id));
1080 $output->FormHidden('del',serialize($del));
1081 $output->FormHidden('name',serialize($name));
1082 $output->FormHidden('desc',serialize($desc));
1083 $output->FormHidden('value_cat_type',serialize($value_cat_type));
1084 $output->FormHidden('color',serialize($color));
1085 $output->FormHidden('event_repeat',serialize($event_repeat));
1086 $output->FormHidden('event_recurrspec',$event_recurrspec);
1087 $output->FormHidden('durationh',serialize($durationh));
1088 $output->FormHidden('durationm',serialize($durationm));
1089 $output->FormHidden('end_date_flag',serialize($end_date_flag));
1090 $output->FormHidden('end_date_type',serialize($end_date_type));
1091 $output->FormHidden('end_date_freq',serialize($end_date_freq));
1092 $output->FormHidden('end_all_day',serialize($end_all_day));
1093 $output->Linebreak();
1094 $output->FormSubmit(_PC_CATS_CONFIRM);
1095 $output->FormEnd();
1097 return $output->GetOutput();
1100 function postcalendar_admin_categoriesUpdate()
1102 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1104 $output = new pnHTML();
1105 $output->SetInputMode(_PNH_VERBATIMINPUT);
1107 list($dbconn) = pnDBGetConn();
1108 $pntable = pnDBGetTables();
1110 list($id,$del,$name,$value_cat_type,$desc,$color,
1111 $event_repeat_array,$event_recurrspec_array,$dels,$durationh,$durationm,
1112 $end_date_flag,$end_date_type,$end_date_freq,$end_all_day,$newname,$newdesc,$newcolor,
1113 $new_event_repeat,$new_event_recurrspec,$new_event_recurrfreq,
1114 $new_duration,$new_dailylimitid,$new_end_date_flag,$new_end_date_type,
1115 $new_end_date_freq,$new_end_all_day,$new_value_cat_type
1116 ) = pnVarCleanFromInput('id','del','name','value_cat_type','desc','color','event_repeat',
1117 'event_recurrspec','dels','durationh','durationm',
1118 'end_date_flag','end_date_type','end_date_freq','end_all_day',
1119 'newname','newdesc','newcolor',
1120 'newevent_repeat','newevent_recurrspec',
1121 'newevent_recurrfreq','newduration','newlimitid',
1122 'newend_date_flag','newend_date_type',
1123 'newend_date_freq','newend_all_day','newvalue_cat_type'
1126 $id = unserialize($id);
1127 $del = unserialize($del);
1128 $name = unserialize($name);
1129 $value_cat_type = unserialize($value_cat_type);
1130 $desc = unserialize($desc);
1131 $color = unserialize($color);
1132 $event_repeat_array = unserialize($event_repeat_array);
1133 $event_recurrspec_array = unserialize($event_recurrspec_array);
1134 $durationh = unserialize($durationh);
1135 $durationm = unserialize($durationm);
1136 $end_date_flag = unserialize($end_date_flag);
1137 $end_date_type = unserialize($end_date_type);
1138 $end_date_freq = unserialize($end_date_freq);
1139 $end_all_day = unserialize($end_all_day);
1140 $updates = array();
1142 if(isset($id)) {
1143 foreach($id as $k=>$i) {
1144 $found = false;
1145 if(count($del)) {
1146 foreach($del as $d) {
1147 if($i == $d) {
1148 $found = true;
1149 break;
1153 if(!$found) {
1154 $event_repeat_freq = $event_recurrspec_array['event_repeat_freq'][$i];
1155 $event_repeat_freq_type = $event_recurrspec_array['event_repeat_freq_type'][$i];
1156 $event_repeat_on_num = $event_recurrspec_array['event_repeat_on_num'][$i];
1157 $event_repeat_on_day = $event_recurrspec_array['event_repeat_on_day'][$i];
1158 $event_repeat_on_freq = $event_recurrspec_array['event_repeat_on_freq'][$i];
1160 $recurrspec = serialize(compact('event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num',
1161 'event_repeat_on_day', 'event_repeat_on_freq'));
1163 $dur = ( ($durationh[$i]*(60 * 60)) + ($durationm[$i] * 60));
1165 $update_sql = "UPDATE $pntable[postcalendar_categories]
1166 SET pc_catname='".pnVarPrepForStore($name[$k])."',
1167 pc_catdesc='".trim(pnVarPrepForStore($desc[$k]))."',
1168 pc_cattype='".trim(pnVarPrepForStore($value_cat_type[$k]))."',
1169 pc_catcolor='".pnVarPrepForStore($color[$k])."',
1170 pc_recurrtype='".pnVarPrepForStore($event_repeat_array[$i])."',
1171 pc_recurrspec='".pnVarPrepForStore($recurrspec)."',
1172 pc_duration='".pnVarPrepForStore($dur)."',
1173 pc_end_date_flag='".pnVarPrepForStore($end_date_flag[$i])."',
1174 pc_end_date_type='".pnVarPrepForStore($end_date_type[$i])."',
1175 pc_end_date_freq='".pnVarPrepForStore($end_date_freq[$i])."',
1176 pc_end_all_day='".pnVarPrepForStore($end_all_day[$i])."'
1177 WHERE pc_catid=$i";
1178 array_push($updates, $update_sql);
1179 unset($recurrspec);
1180 unset($dur);
1186 $delete = "DELETE FROM $pntable[postcalendar_categories] WHERE pc_catid IN ($dels)";
1187 $e = $msg = '';
1188 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','updateCategories',array('updates'=>$updates))) {
1189 $e .= 'UPDATE FAILED';
1191 if(isset($dels)) {
1192 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','deleteCategories',array('delete'=>$delete))) {
1193 $e .= 'DELETE FAILED';
1196 if(isset($newname)) {
1197 $unpacked = unserialize($new_event_recurrspec);
1198 unset($new_event_recurrspec);
1199 $new_event_recurrspec['event_repeat_freq'] = $unpacked['new_event_repeat_freq'];
1200 $new_event_recurrspec['event_repeat_freq_type'] = $unpacked['new_event_repeat_freq_type'];
1201 $new_event_recurrspec['event_repeat_on_num'] = $unpacked['new_event_repeat_on_num'];
1202 $new_event_recurrspec['event_repeat_on_day'] = $unpacked['new_event_repeat_on_day'];
1203 $new_event_recurrspec['event_repeat_on_freq'] = $unpacked['new_event_repeat_on_freq'];
1204 $new_event_recurrspec = serialize($new_event_recurrspec);
1206 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','addCategories',
1207 array('name'=>$newname,'desc'=>$newdesc,'value_cat_type'=>$new_value_cat_type,'color'=>$newcolor,
1208 'repeat'=>$new_event_repeat,'spec'=>$new_event_recurrspec,
1209 'recurrfreq'=>$new_recurrfreq,'duration'=>$new_duration,'limitid'=>$new_dailylimitid,
1210 'end_date_flag'=>$new_end_date_flag,'end_date_type'=>$new_end_date_flag,
1211 'end_date_freq'=>$new_end_date_freq,'end_all_day'=>$new_end_all_day))) {
1212 $e .= 'INSERT FAILED';
1216 if(empty($e)) { $msg = 'DONE'; }
1217 $output->Text(postcalendar_admin_categories($msg,$e));
1218 return $output->GetOutput();
1222 * Creates a new category
1224 function postcalendar_admin_categories($msg='',$e='',$args)
1226 if(!PC_ACCESS_ADD) { return _POSTCALENDARNOAUTH; }
1227 extract($args); unset($args);
1229 $output = new pnHTML();
1230 $output->SetInputMode(_PNH_VERBATIMINPUT);
1231 // set up Smarty
1232 $tpl = new pcSmarty();
1233 $tpl->caching = false;
1235 $template_name = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
1237 if(!isset($template_name)) {
1238 $template_name ='default';
1241 if(!empty($e)) {
1242 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
1243 $output->Text('<center><b>'.$e.'</b></center>');
1244 $output->Text('</div><br />');
1247 if(!empty($msg)) {
1248 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
1249 $output->Text('<center><b>'.$msg.'</b></center>');
1250 $output->Text('</div><br />');
1253 //=================================================================
1254 // Setup the correct config file path for the templates
1255 //=================================================================
1256 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1257 $modir = pnVarPrepForOS($modinfo['directory']);
1258 $modname = $modinfo['displayname'];
1259 $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
1260 //print_r($all_categories);
1261 unset($modinfo);
1262 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
1263 //=================================================================
1264 // PARSE MAIN
1265 //=================================================================
1267 // create translations if applicable
1268 if (($GLOBALS['translate_appt_categories']) && ($_SESSION['language_choice'] > 1)) {
1269 $sizeAllCat = count($all_categories);
1270 for ($m = 0; $m < $sizeAllCat; $m++) {
1271 $tempCategory = $all_categories[$m]["name"];
1272 $tempDescription = $all_categories[$m]["desc"];
1273 $all_categories[$m]["nameTranslate"] = xl($tempCategory);
1274 $all_categories[$m]["descTranslate"] = xl($tempDescription);
1277 $tpl->assign('globals', $GLOBALS);
1279 $tpl->assign_by_ref('TPL_NAME',$template_name);
1280 $tpl->assign('FUNCTION',pnVarCleanFromInput('func'));
1281 $tpl->assign_by_ref('ModuleName', $modname);
1282 $tpl->assign_by_ref('ModuleDirectory', $modir);
1283 $tpl->assign_by_ref('all_categories', $all_categories);
1285 $tpl->assign('pcDir', $modir);
1286 $tpl->assign('action', pnModURL(__POSTCALENDAR__,'admin','categoriesConfirm'));
1287 $tpl->assign('adminmenu', postcalendar_adminmenu());
1288 $tpl->assign('BGCOLOR2', $GLOBALS['style']['BGCOLOR2']);
1289 $tpl->assign('_PC_REP_CAT_TITLE_S',_PC_REP_CAT_TITLE_S);
1290 $tpl->assign('_PC_NEW_CAT_TITLE_S',_PC_NEW_CAT_TITLE_S);
1291 $tpl->assign('_PC_CAT_NAME',_PC_CAT_NAME);
1292 $tpl->assign('_PC_CAT_TYPE',_PC_CAT_TYPE);
1293 $tpl->assign('_PC_CAT_NAME_XL',_PC_CAT_NAME_XL);
1294 $tpl->assign('_PC_CAT_DESC',_PC_CAT_DESC);
1295 $tpl->assign('_PC_CAT_DESC_XL',_PC_CAT_DESC_XL);
1296 $tpl->assign('_PC_CAT_COLOR',_PC_CAT_COLOR);
1297 $tpl->assign('_PC_CAT_DELETE',_PC_CAT_DELETE);
1298 $tpl->assign('_PC_CAT_DUR',_PC_CAT_DUR);
1299 $tpl->assign('_PC_COLOR_PICK_TITLE',_PC_COLOR_PICK_TITLE);
1301 //=================================================================
1302 // Repeating Information
1303 //=================================================================
1304 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
1305 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
1306 $tpl->assign('RepeatTitle', _PC_REPEAT);
1307 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
1308 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
1309 $tpl->assign('EndDateTitle', _PC_END_DATE);
1310 $tpl->assign('NoEndDateTitle', _PC_NO_END);
1311 $tpl->assign('REP_CAT_TITLE', _PC_REP_CAT_TITLE);
1312 $tpl->assign('NEW_CAT_TITLE', _PC_NEW_CAT_TITLE);
1313 $tpl->assign('InputNoRepeat', 'event_repeat');
1314 $tpl->assign('ValueNoRepeat', '0');
1315 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
1316 $tpl->assign('InputRepeat', 'event_repeat');
1317 $tpl->assign('ValueRepeat', '1');
1318 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
1321 unset($in);
1322 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
1323 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
1324 $repeat_freq = array();
1325 foreach($in as $k=>$v) {
1326 array_push($repeat_freq,array('value'=>$keys[$k],
1327 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
1328 'name'=>$v));
1330 $tpl->assign('InputRepeatFreq','event_repeat_freq');
1331 if(empty($event_repeat_freq) || $event_repeat_freq < 1) $event_repeat_freq = 1;
1332 $tpl->assign('InputRepeatFreqVal',$event_repeat_freq);
1333 $tpl->assign('repeat_freq',$event_repeat_freq);
1334 unset($in);
1336 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
1337 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
1338 $repeat_freq_type = array();
1339 foreach($in as $k=>$v) {
1340 array_push($repeat_freq_type,array('value'=>$keys[$k],
1341 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
1342 'name'=>$v));
1344 $tpl->assign('InputRepeatFreqType','event_repeat_freq_type');
1345 $tpl->assign('InuptRepeatFreq', '' .'event_repeat_freq');
1346 $tpl->assign('repeat_freq_type',$repeat_freq_type);
1348 $tpl->assign('InputRepeatOn', 'event_repeat');
1349 $tpl->assign('ValueRepeatOn', '2');
1350 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
1352 // All Day START
1353 $tpl->assign('InputAllDay', 'end_all_day');
1354 $tpl->assign('ValueAllDay', '1');
1355 $tpl->assign('ValueAllDayNo', '0');
1356 $tpl->assign('ALL_DAY_CAT_TITLE', _PC_ALL_DAY_CAT_TITLE);
1357 $tpl->assign('ALL_DAY_CAT_YES', _PC_ALL_DAY_CAT_YES);
1358 $tpl->assign('ALL_DAY_CAT_NO', _PC_ALL_DAY_CAT_NO);
1360 //ALL Day End
1361 // End date gather date start
1363 $tpl->assign('InputEndDateFreq','end_date_freq');
1364 $tpl->assign('InputEndOn', 'end_date_flag');
1365 $tpl->assign('InputEndDateFreqType', 'end_date_type');
1366 $tpl->assign('ValueNoEnd', '0');
1367 $tpl->assign('ValueEnd', '1');
1370 foreach($in as $k=>$v) {
1371 array_push($end_date_type,array('value'=>$keys[$k],
1372 'selected'=>($keys[$k]==$end_date_type?'selected':''),
1373 'name'=>$v));
1375 unset($in);
1378 // End date gather date end
1381 unset($in);
1382 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
1383 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
1384 $repeat_on_num = array();
1385 foreach($in as $k=>$v) {
1386 array_push($repeat_on_num,array('value'=>$keys[$k],
1387 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
1388 'name'=>$v));
1390 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1391 $tpl->assign('repeat_on_num',$repeat_on_num);
1393 unset($in);
1394 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
1395 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
1396 $repeat_on_day = array();
1397 foreach($in as $k=>$v) {
1398 array_push($repeat_on_day,array('value'=>$keys[$k],
1399 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
1400 'name'=>$v));
1402 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1403 $tpl->assign('repeat_on_day',$repeat_on_day);
1405 unset($in);
1406 $in = array(_PC_CAT_PATIENT,_PC_CAT_PROVIDER);
1407 $keys = array(TYPE_ON_PATIENT,TYPE_ON_PROVIDER);
1408 $cat_type = array();
1409 foreach($in as $k=>$v) {
1410 array_push($cat_type,array('value'=>$keys[$k],
1411 'selected'=>($keys[$k]==$value_cat_type ? 'selected' : ''),
1412 'name'=>$v));
1414 $tpl->assign('InputCatType', 'value_cat_type');
1415 $tpl->assign('cat_type',$cat_type);
1417 unset($in);
1418 $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);
1419 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
1420 $repeat_on_freq = array();
1421 foreach($in as $k=>$v) {
1422 array_push($repeat_on_freq,array('value'=>$keys[$k],
1423 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
1424 'name'=>$v));
1426 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1427 if(empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) $event_repeat_on_freq = 1;
1428 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1429 $tpl->assign('repeat_on_freq',$repeat_on_freq);
1430 $tpl->assign('MonthsTitle',_PC_MONTHS);
1431 $tpl->assign('DurationHourTitle', _PC_DURATION_HOUR);
1432 $tpl->assign('DurationMinTitle', _PC_DURATION_MIN);
1433 $tpl->assign('InputDurationHour', "durationh");
1434 $tpl->assign('InputDurationMin', "durationm");
1436 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1437 $authkey = $output->FormHidden('authid',pnSecGenAuthKey());
1438 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1440 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1441 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1442 if(isset($data_loaded)) {
1443 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1444 $tpl->assign('FormHidden',$form_hidden);
1446 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1447 '.$authkey.'<input type="submit" name="submit" value="' . xl('go') . '">';
1448 $tpl->assign('FormSubmit',$form_submit);
1450 $output->Text($tpl->fetch($template_name.'/admin/submit_category.html'));
1451 $output->Text(postcalendar_footer());
1452 return $output->GetOutput();
1456 * Main administration menu
1458 function postcalendar_adminmenu($upgraded=false)
1460 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1462 pnThemeLoad(pnUserGetTheme());
1463 // get the theme globals :: is there a better way to do this?
1464 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6;
1465 global $textcolor1, $textcolor2;
1467 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1468 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1470 @define('_AM_VAL', 1);
1471 @define('_PM_VAL', 2);
1473 @define('_EVENT_APPROVED', 1);
1474 @define('_EVENT_QUEUED', 0);
1475 @define('_EVENT_HIDDEN', -1);
1477 $adminURL = pnModURL(__POSTCALENDAR__,'admin','');
1478 $settingsURL = pnModURL(__POSTCALENDAR__,'admin','modifyconfig');
1479 $categoryURL = pnModURL(__POSTCALENDAR__,'admin','categories');
1480 $submitURL = pnModURL(__POSTCALENDAR__,'admin','submit');
1481 $approvedURL = pnModURL(__POSTCALENDAR__,'admin','listapproved');
1482 $hiddenURL = pnModURL(__POSTCALENDAR__,'admin','listhidden');
1483 $queuedURL = pnModURL(__POSTCALENDAR__,'admin','listqueued');
1484 $cacheURL = pnModURL(__POSTCALENDAR__,'admin','clearCache');
1485 $systemURL = pnModURL(__POSTCALENDAR__,'admin','testSystem');
1486 $limitsURL = pnModURL(__POSTCALENDAR__,'admin','categoryLimits');
1488 $adminText = _POSTCALENDAR;
1489 $settingsText = _EDIT_PC_CONFIG_GLOBAL;
1490 $categoryText = _EDIT_PC_CONFIG_CATEGORIES;
1491 $submitText = _PC_CREATE_EVENT;
1492 $approvedText = "Event List";
1493 $hiddenText = _PC_VIEW_HIDDEN;
1494 $queuedText = "Marked for Deletion";
1495 $cacheText = _PC_CLEAR_CACHE;
1496 $cacheText = _PC_CLEAR_CACHE;
1497 $systemText = _PC_TEST_SYSTEM;
1498 $limitsText = _PC_CAT_LIMITS;
1500 // check for upgrade
1501 $upgrade = '';
1502 if($upgraded === false) {
1503 $upgrade = pc_isNewVersion();
1507 $output = <<<EOF
1508 <table border="0" cellpadding="1" cellspacing="0" width="100%" bgcolor="$bgcolor2"><tr><td>
1509 <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1510 <tr>
1511 <td align="left" valign="middle"><a href="$adminURL"><img
1512 border="0" src="modules/$pcDir/pnimages/admin.gif"></a></td>
1513 <td width="100%" align="left" valign="middle">
1514 <table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="$bgcolor2">
1515 <table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="$bgcolor1">
1516 <tr>
1517 <td nowrap>
1518 <!--<a href="$settingsURL">$settingsText</a> |-->
1519 <!--<a href="$submitURL">$submitText</a> |-->
1520 <a href="$cacheURL">$cacheText</a> |
1521 <a href="$systemURL">$systemText</a> |
1522 <a href="$categoryURL">$categoryText</a> |
1523 <a href="$limitsURL">$limitsText</a><!-- |
1524 <a href="$queuedURL">$queuedText</a> |
1525 <a href="$approvedURL">$approvedText</a> |
1526 <a href="$hiddenURL">$hiddenText</a>-->
1527 $upgrade
1528 </tr>
1529 </table>
1530 </td></tr></table>
1531 </td>
1532 </tr>
1533 </table>
1534 </td></tr></table>
1535 <br />
1536 EOF;
1537 // Return the output that has been generated by this function
1538 return $output;
1541 function postcalendar_admin_clearCache()
1543 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1545 $tpl = new pcSmarty();
1546 //fmg: check that both subdirs to be cleared first exist and are writeable
1547 $spec_err = '';
1548 if (!file_exists($tpl->compile_dir))
1549 $spec_err .= "Error: folder '$tpl->compile_dir' doesn't exist!<br>";
1550 else if (!is_writeable($tpl->compile_dir))
1551 $spec_err .= "Error: folder '$tpl->compile_dir' not writeable!<br>";
1552 if (!file_exists($tpl->cache_dir))
1553 $spec_err .= "Error: folder '$tpl->cache_dir' doesn't exist!<br>";
1554 else if (!is_writeable($tpl->cache_dir))
1555 $spec_err .= "Error: folder '$tpl->cache_dir' not writeable!<br>";
1556 //note: we don't abort on error... like before.
1557 $tpl->clear_all_cache();
1558 $tpl->clear_compiled_tpl();
1560 return postcalendar_admin_modifyconfig('<center>'.$spec_err._PC_CACHE_CLEARED.'</center>');
1563 function pc_isNewVersion()
1565 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1566 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1567 @include("modules/$pcDir/pnversion.php");
1569 if($pcModInfo['version'] <> $modversion['version']) {
1570 $upgradeURL = pnModURL(__POSTCALENDAR__,'admin','upgrade');
1571 $upgradeText = "Upgrade PostCalendar $pcModInfo[version] to $modversion[version]";
1572 $upgrade = "<br /><br />[ <a href=\"$upgradeURL\">$upgradeText</a> ]";
1573 } else {
1574 $upgrade = '';
1577 return $upgrade;
1580 // UPGRADE WORKAROUND SCRIPT - POSTNUKE BUG
1581 function postcalendar_admin_upgrade()
1583 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1585 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1586 $pcDir = pnVarPrepForOS($pcModInfo['directory']);
1587 @include("modules/$pcDir/pnversion.php");
1588 @include("modules/$pcDir/pninit.php");
1590 $result = postcalendar_upgrade($pcModInfo['version']);
1592 if($result === false) {
1593 $output = postcalendar_adminmenu(false);
1594 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1595 $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b></center>';
1596 $output .= '</div><br />';
1597 return $output;
1600 // if we've gotten this far, then it's time to increment the version in the db
1601 list($dbconn) = pnDBGetConn();
1602 $pntable = pnDBGetTables();
1603 $modulestable = $pntable['modules'];
1604 $modulescolumn = &$pntable['modules_column'];
1606 // Get module ID
1607 $modulestable = $pntable['modules'];
1608 $modulescolumn = &$pntable['modules_column'];
1609 $query = "SELECT $modulescolumn[id]
1610 FROM $modulestable
1611 WHERE $modulescolumn[name] = '". pnVarPrepForStore(__POSTCALENDAR__)."'";
1612 $result = $dbconn->Execute($query);
1614 if ($result->EOF) { die("Failed to get module ID"); }
1616 list($mid) = $result->fields;
1617 $result->Close();
1619 $sql = "UPDATE $modulestable
1620 SET $modulescolumn[version] = '".pnVarPrepForStore($modversion['version'])."',
1621 $modulescolumn[state] = '".pnVarPrepForStore(_PNMODULE_STATE_ACTIVE)."'
1622 WHERE $modulescolumn[id] = '".pnVarPrepForStore($mid)."'";
1624 // upgrade did not succeed
1625 if($dbconn->Execute($sql) === false) {
1626 $output = postcalendar_adminmenu(false);
1627 $output .= '<div style="padding:5px; border:1px solid red; background-color: pink;">';
1628 $output .= '<center><b>SORRY :: MODULE UPGRADE FAILED</b><br />';
1629 $output .= $dbconn->ErrorMsg();
1630 $output .= '</center>';
1631 $output .= '</div><br />';
1633 $output = postcalendar_adminmenu(true);
1634 $output .= '<div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
1635 $output .= '<center><b>CONGRATULATIONS :: MODULE UPGRADE SUCCEEDED</b></center>';
1636 $output .= '</div><br />';
1637 return $output;
1640 function postcalendar_admin_testSystem()
1642 global $bgcolor1,$bgcolor2;
1644 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
1646 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1647 $pcDir = pnVarPrepForOS($modinfo['directory']);
1648 $version = $modinfo['version'];
1649 unset($modinfo);
1651 $tpl = new pcSmarty();
1652 $infos = array();
1654 if(phpversion() >= '4.1.0') {
1655 $__SERVER =& $_SERVER;
1656 $__ENV =& $_ENV;
1657 } else {
1658 $__SERVER =& $HTTP_SERVER_VARS;
1659 $__ENV =& $HTTP_ENV_VARS;
1662 if(defined('_PN_VERSION_NUM')) {
1663 $pnVersion = _PN_VERSION_NUM;
1664 } else {
1665 $pnVersion = pnConfigGetVar('Version_Num');
1668 array_push($infos, array('CMS Version', $pnVersion));
1669 array_push($infos, array('Sitename', pnConfigGetVar('sitename')));
1670 array_push($infos, array('url', pnGetBaseURL()));
1671 array_push($infos, array('PHP Version', phpversion()));
1672 if ((bool) ini_get('safe_mode')) {
1673 $safe_mode = "On";
1674 } else {
1675 $safe_mode = "Off";
1677 array_push($infos, array('PHP safe_mode', $safe_mode));
1678 if ((bool) ini_get('safe_mode_gid')) {
1679 $safe_mode_gid = "On";
1680 } else {
1681 $safe_mode_gid = "Off";
1683 array_push($infos, array('PHP safe_mode_gid', $safe_mode_gid));
1684 $base_dir = ini_get('open_basedir');
1685 if(!empty($base_dir)) {
1686 $open_basedir = "$base_dir";
1687 } else {
1688 $open_basedir = "NULL";
1690 array_push($infos, array('PHP open_basedir', $open_basedir));
1691 array_push($infos, array('SAPI', php_sapi_name()));
1692 array_push($infos, array('OS', php_uname()));
1693 array_push($infos, array('WebServer', $__SERVER['SERVER_SOFTWARE']));
1694 array_push($infos, array('Module dir', "modules/$pcDir"));
1696 $modversion = array();
1697 include "modules/$pcDir/pnversion.php";
1699 $error = '';
1700 if ($modversion['version'] != $version) {
1701 $error = '<br /><div style=\"color: red;\">';
1702 $error .= "new version $modversion[version] installed but not updated!";
1703 $error .= '</div>';
1705 array_push($infos, array('Module version', $version . " $error"));
1706 array_push($infos, array('smarty version', $tpl->_version));
1707 array_push($infos, array('smarty location', SMARTY_DIR));
1708 array_push($infos, array('smarty template dir', $tpl->template_dir));
1710 $info = $tpl->compile_dir;
1711 $error = '';
1712 if (!file_exists($tpl->compile_dir)) {
1713 $error .= " compile dir doesn't exist! [$tpl->compile_dir]<br />";
1714 } else {
1715 // dir exists -> check if it's writeable
1716 if (!is_writeable($tpl->compile_dir)) {
1717 $error .= " compile dir not writeable! [$tpl->compile_dir]<br />";
1720 if (strlen($error) > 0) {
1721 $info .= "<br /><div style=\"color: red;\">$error</div>";
1723 array_push($infos, array('smarty compile dir', $info));
1725 $info = $tpl->cache_dir;
1726 $error = "";
1727 if (!file_exists($tpl->cache_dir)) {
1728 $error .= " cache dir doesn't exist! [$tpl->cache_dir]<br />";
1729 } else {
1730 // dir exists -> check if it's writeable
1731 if (!is_writeable($tpl->cache_dir)) {
1732 $error .= " cache dir not writeable! [$tpl->cache_dir]<br />";
1735 if (strlen($error) > 0) {
1736 $info .= "<br /><div style=\"color: red;\">$error</div>";
1738 array_push($infos, array('smarty cache dir', $info));
1740 $header = <<<EOF
1741 <html>
1742 <head></head>
1743 <body bgcolor=
1744 EOF;
1745 $header .= '"' . $GLOBALS['style']['BGCOLOR2'] . '">';
1746 $output .= $header;
1747 $output = postcalendar_adminmenu();
1748 $output .= '<table border="1" cellpadding="3" cellspacing="1">';
1749 $output .= ' <tr><th align="left">Name</th><th align="left">Value</th>';
1750 $output .= '</tr>';
1751 foreach ($infos as $info) {
1752 $output.= '<tr><td ><b>' . pnVarPrepHTMLDisplay($info[0]) . '</b></td>';
1753 $output.= '<td>' . pnVarPrepHTMLDisplay($info[1]) . '</td></tr>';
1755 $output .= '</table>';
1756 $output .= '<br /><br />';
1757 $output .= postcalendar_admin_modifyconfig('',false);
1758 $output .= "</body></html>";
1759 return $output;
1762 function postcalendar_admin_categoryDetail($args)
1764 if(!PC_ACCESS_ADD) { return _POSTCALENDARNOAUTH; }
1765 extract($args); unset($args);
1767 $output = new pnHTML();
1768 $output->SetInputMode(_PNH_VERBATIMINPUT);
1769 // set up Smarty
1770 $tpl = new pcSmarty();
1771 $tpl->caching = false;
1773 $template_name = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
1775 if(!isset($template_name)) {
1776 $template_name ='default';
1779 //=================================================================
1780 // Setup the correct config file path for the templates
1781 //=================================================================
1782 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1783 $modir = pnVarPrepForOS($modinfo['directory']);
1784 $modname = $modinfo['displayname'];
1785 $all_categories = & pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
1786 $all_details =& pnModAPIFunc(__POSTCALENDAR__,'user','getCatDetails');
1787 unset($modinfo);
1788 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
1789 //=================================================================
1790 // PARSE MAIN
1791 //=================================================================
1794 $tpl->assign_by_ref('TPL_NAME',$template_name);
1795 $tpl->assign('FUNCTION',pnVarCleanFromInput('func'));
1796 $tpl->assign_by_ref('ModuleName', $modname);
1797 $tpl->assign_by_ref('ModuleDirectory', $modir);
1798 $tpl->assign('Category', "Category");
1799 $tpl->assign_by_ref('categories', $all_categories);
1801 //=================================================================
1802 // Repeating Information
1803 //=================================================================
1804 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
1805 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
1806 $tpl->assign('RepeatTitle', _PC_REPEAT);
1807 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
1808 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
1809 $tpl->assign('EndDateTitle', _PC_END_DATE);
1810 $tpl->assign('NoEndDateTitle', _PC_NO_END);
1811 $tpl->assign('InputNoRepeat', 'event_repeat');
1812 $tpl->assign('ValueNoRepeat', '0');
1813 $tpl->assign('SelectedNoRepeat', (int) $event_repeat==0 ? 'checked':'');
1814 $tpl->assign('InputRepeat', 'event_repeat');
1815 $tpl->assign('ValueRepeat', '1');
1816 $tpl->assign('SelectedRepeat', (int) $event_repeat==1 ? 'checked':'');
1818 unset($in);
1819 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
1820 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
1821 $repeat_freq = array();
1822 foreach($in as $k=>$v) {
1823 array_push($repeat_freq,array('value'=>$keys[$k],
1824 'selected'=>($keys[$k]==$event_repeat_freq?'selected':''),
1825 'name'=>$v));
1827 $tpl->assign('InputRepeatFreq','event_repeat_freq');
1828 if(empty($event_repeat_freq) || $event_repeat_freq < 1) $event_repeat_freq = 1;
1829 $tpl->assign('InputRepeatFreqVal',$event_repeat_freq);
1830 $tpl->assign('repeat_freq',$repeat_freq);
1831 unset($in);
1832 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
1833 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
1834 $repeat_freq_type = array();
1835 foreach($in as $k=>$v) {
1836 array_push($repeat_freq_type,array('value'=>$keys[$k],
1837 'selected'=>($keys[$k]==$event_repeat_freq_type?'selected':''),
1838 'name'=>$v));
1840 $tpl->assign('InputRepeatFreqType','event_repeat_freq_type');
1841 $tpl->assign('repeat_freq_type',$repeat_freq_type);
1843 $tpl->assign('InputRepeatOn', 'event_repeat');
1844 $tpl->assign('ValueRepeatOn', '2');
1845 $tpl->assign('SelectedRepeatOn', (int) $event_repeat==2 ? 'checked':'');
1847 unset($in);
1848 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
1849 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
1850 $repeat_on_num = array();
1851 foreach($in as $k=>$v) {
1852 array_push($repeat_on_num,array('value'=>$keys[$k],
1853 'selected'=>($keys[$k]==$event_repeat_on_num?'selected':''),
1854 'name'=>$v));
1856 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
1857 $tpl->assign('repeat_on_num',$repeat_on_num);
1859 unset($in);
1860 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
1861 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
1862 $repeat_on_day = array();
1863 foreach($in as $k=>$v) {
1864 array_push($repeat_on_day,array('value'=>$keys[$k],
1865 'selected'=>($keys[$k]==$event_repeat_on_day ? 'selected' : ''),
1866 'name'=>$v));
1868 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
1869 $tpl->assign('repeat_on_day',$repeat_on_day);
1871 unset($in);
1872 $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);
1873 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
1874 $repeat_on_freq = array();
1875 foreach($in as $k=>$v) {
1876 array_push($repeat_on_freq,array('value'=>$keys[$k],
1877 'selected'=>($keys[$k] == $event_repeat_on_freq ? 'selected' : ''),
1878 'name'=>$v));
1880 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
1881 if(empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) $event_repeat_on_freq = 1;
1882 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
1883 $tpl->assign('repeat_on_freq',$repeat_on_freq);
1884 $tpl->assign('MonthsTitle',_PC_MONTHS);
1886 $output->SetOutputMode(_PNH_RETURNOUTPUT);
1887 $authkey = $output->FormHidden('authid',pnSecGenAuthKey());
1888 $output->SetOutputMode(_PNH_KEEPOUTPUT);
1890 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"$is_update\" />";
1891 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"$pc_event_id\" />";
1892 if(isset($data_loaded)) {
1893 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"$data_loaded\" />";
1894 $tpl->assign('FormHidden',$form_hidden);
1896 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1897 '.$authkey.'<input type="submit" name="submit" value="go">' ;
1898 $tpl->assign('FormSubmit',$form_submit);
1900 $output->Text($tpl->fetch($template_name.'/admin/submit_detail.html'));
1902 $output->Text(postcalendar_footer());
1903 return $output->GetOutput();
1906 function postcalendar_admin_categoryLimits($msg='',$e='',$args)
1908 if(!PC_ACCESS_ADD) { return _POSTCALENDARNOAUTH; }
1909 extract($args); unset($args);
1911 $output = new pnHTML();
1912 $output->SetInputMode(_PNH_VERBATIMINPUT);
1913 // set up Smarty
1914 $tpl = new pcSmarty();
1915 $tpl->caching = false;
1917 $template_name = pnModGetVar(__POSTCALENDAR__,'pcTemplate');
1919 if(!isset($template_name)) {
1920 $template_name ='default';
1923 if(!empty($e)) {
1924 $output->Text('<div style="padding:5px; border:1px solid red; background-color: pink;">');
1925 $output->Text('<center><b>'.$e.'</b></center>');
1926 $output->Text('</div><br />');
1929 if(!empty($msg)) {
1930 $output->Text('<div style="padding:5px; border:1px solid green; background-color: lightgreen;">');
1931 $output->Text('<center><b>'.$msg.'</b></center>');
1932 $output->Text('</div><br />');
1935 //=================================================================
1936 // Setup the correct config file path for the templates
1937 //=================================================================
1938 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
1939 $modir = pnVarPrepForOS($modinfo['directory']);
1940 $modname = $modinfo['displayname'];
1942 //print_r($all_categories);
1943 unset($modinfo);
1944 $tpl->assign('action', pnModURL(__POSTCALENDAR__,'admin','categoryLimitsUpdate'));
1945 //===============================================================
1946 // Setup titles for smarty
1947 //===============================================================
1949 $tpl->assign('_PC_LIMIT_TITLE', _PC_LIMIT_TITLE);
1950 $tpl->assign('StartTimeTitle', _PC_LIMIT_START_TIME);
1951 $tpl->assign('EndTimeTile', _PC_LIMIT_END_TIME);
1952 $tpl->assign('LimitHoursTitle',_PC_TIMED_DURATION_HOURS);
1953 $tpl->assign('LimitMinutesTitle',_PC_TIMED_DURATION_MINUTES);
1955 //=============================================================
1956 // Setup Vars for smarty
1957 //============================================================
1958 $tpl->assign('mer_title', 'mer');
1959 $mer = array('am','pm');
1960 $tpl->assign_by_ref('mer', $mer);
1961 $tpl->assign('starttimeh', 'starttimeh');
1962 $tpl->assign('starttimem', 'starttimem');
1963 $tpl->assign('endtimeh', 'endtimeh');
1964 $tpl->assign('endtimem', 'endtimem');
1965 $tpl->assign('InputLimit', 'limit');
1966 $tpl->assign('LimitTitle', _PC_LIMIT_TITLE);
1967 $tpl->assign('_PC_NEW_LIMIT_TITLE', _PC_NEW_LIMIT_TITLE);
1968 $tpl->assign('_PC_CAT_DELETE', _PC_CAT_DELETE);
1969 $tpl->assign('EndTimeTitle', _PC_LIMIT_END_TIME);
1971 $hour_array =array('00','01','02','03','04','05','06','07','08','09','10','11','12',
1972 '13','14','15','16','17','18','19','21','21','22','23');
1973 $min_array = array('00','05','10','15','20','25','30','35','40','45','50','55');
1974 $tpl->assign_by_ref('hour_array', $hour_array);
1975 $tpl->assign_by_ref('min_array', $min_array);
1977 $categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
1978 // create translations of category names if applicable
1979 $sizeAllCat = count($categories);
1980 for ($m = 0; $m < $sizeAllCat; $m++) {
1981 $tempCategory = $categories[$m]["name"];
1982 $categories[$m]["name"] = xl_appt_category($tempCategory);
1984 $tpl->assign_by_ref('categories', $categories);
1985 $limits = pnModAPIFunc(__POSTCALENDAR__,'user','getCategoryLimits');
1986 $tpl->assign_by_ref('limits', $limits);
1987 $tpl->assign('BGCOLOR2',$GLOBALS['style']['BGCOLOR2']);
1988 $tpl->assign("catTitle",_PC_REP_CAT_TITLE_S);
1989 $tpl->assign("catid", "catid");
1990 $form_submit = '<input type=hidden name="form_action" value="commit"/>
1991 '.$authkey.'<input type="submit" name="submit" value="' . xl('go') . '">';
1992 $tpl->assign('FormSubmit',$form_submit);
1995 $output->Text($tpl->fetch($template_name.'/admin/submit_category_limit.html'));
1996 $output->Text(postcalendar_footer());
1997 return $output->GetOutput();
2001 function postcalendar_admin_categoryLimitsUpdate()
2003 if(!PC_ACCESS_ADMIN) { return _POSTCALENDAR_NOAUTH; }
2005 $output = new pnHTML();
2006 $output->SetInputMode(_PNH_VERBATIMINPUT);
2008 list($dbconn) = pnDBGetConn();
2009 $pntable = pnDBGetTables();
2011 list($id,$del,$catId,$startTimeH,$startTimeM,$endTimeH,$endTimeM,$limit,
2012 $newCatId,$newStartTimeH,$newStartTimeM,$newEndTimeH,
2013 $newEndTimeM,$newLimit,
2014 ) = pnVarCleanFromInput('id','del','catid','starttimeh','starttimem',
2015 'endtimeh','endtimem','limit',
2016 'newcatid','newstarttimeh','newstarttimem','newendtimeh',
2017 'newendtimem','newlimit');
2018 $updates = array();
2019 if(isset($id)) {
2020 foreach($id as $k=>$i) {
2021 $found = false;
2022 if(count($del)) {
2023 foreach($del as $d) {
2024 if($i == $d) {
2025 $found = true;
2026 break;
2030 if(!$found) {
2032 $start = date("H:i:s", mktime($startTimeH[$k],$startTimeM[$k],0));
2033 $end = date("H:i:s", mktime($endTimeH[$k],$endTimeM[$k],0));
2034 $update_sql = "UPDATE $pntable[postcalendar_limits]
2035 SET pc_catid='".pnVarPrepForStore($catId[$k])."',
2036 pc_starttime='".pnVarPrepForStore($start)."',
2037 pc_endtime='".pnVarPrepForStore($end)."',
2038 pc_limit='".pnVarPrepForStore($limit[$k])."'
2039 WHERE pc_limitid=$i";
2040 array_push($updates, $update_sql);
2045 $dels = implode(",", $del);
2046 $delete = "DELETE FROM $pntable[postcalendar_limits] WHERE pc_limitid IN ($dels)";
2047 $e = $msg = '';
2048 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','updateCategoryLimit',array('updates'=>$updates))) {
2049 $e .= 'UPDATE FAILED';
2051 if(isset($dels)) {
2052 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','deleteCategoryLimit',array('delete'=>$delete))) {
2053 $e .= 'DELETE FAILED';
2056 if(isset($newLimit) && $newLimit > 0) {
2057 $start = date("H:i:s", mktime($newStartTimeH,$newStartTimeM,0));
2058 $end = date("H:i:s", mktime($newEndTimeH,$newEndTimeM,0));
2060 if(!pnModAPIFunc(__POSTCALENDAR__,'admin','addCategoryLimit',
2061 array('catid'=>$newCatId,'starttime'=>$start,'endtime'=>$end,
2062 'limit'=>$newLimit))) {
2063 $e .= 'INSERT FAILED';
2067 if(empty($e)) { $msg = 'DONE'; }
2068 $output->Text(postcalendar_admin_categoryLimits($msg,$e));
2069 return $output->GetOutput();