fix: add missing use statement in facility admin script (#7428)
[openemr.git] / interface / main / calendar / modules / PostCalendar / pnadmin.php
blob2597ea4e9ae38eec9490c49355ff770c76d3b375
1 <?php
3 @define('__POSTCALENDAR__', 'PostCalendar');
4 /**
5 * $Id$
7 * PostCalendar::PostNuke Events Calendar Module
8 * Copyright (C) 2002 The PostCalendar Team
9 * http://postcalendar.tv
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * To read the license please read the docs/license.txt or visit
26 * http://www.gnu.org/copyleft/gpl.html
30 use OpenEMR\Common\Acl\AclMain;
31 use OpenEMR\Common\Acl\AclExtended;
32 use OpenEMR\Core\Header;
33 use OpenEMR\Events\Core\ScriptFilterEvent;
34 use OpenEMR\Events\Core\StyleFilterEvent;
36 //=========================================================================
37 // Load the API Functions
38 //=========================================================================
39 pnModAPILoad(__POSTCALENDAR__, 'admin');
41 function postcalendar_admin_modifyconfig($msg = '', $showMenu = true)
43 $output = new pnHTML();
45 $output->SetInputMode(_PNH_VERBATIMINPUT);
47 $header = "<html><head><title>" . xlt("Calendar") . "</title>";
48 $header .= Header::setupHeader('', false) . '</head><body>';
50 $output->Text($header);
52 if (!empty($msg)) {
53 $output->Text(postcalendar_adminmenu("clearCache"));
54 $output -> Text('<div class="alert alert-success mx-1 text-center" role="alert">');
55 $output->Text("<b>$msg</b>");
56 $output -> Text('</div>');
57 } else {
58 if ($showMenu) {
59 $output->Text(postcalendar_adminmenu(""));
63 $output->Text("</body></html>");
65 return $output->GetOutput();
68 function postcalendar_admin_categoriesConfirm()
70 $output = new pnHTML();
71 $output->SetInputMode(_PNH_VERBATIMINPUT);
72 $header = <<<EOF
73 <html>
74 <head>
75 EOF;
76 $header .= Header::setupHeader('', false) . '</head><body><div class="container">';
77 $output->Text($header);
78 $output->Text(postcalendar_adminmenu("category"));
79 list($id, $del, $name, $constantid, $value_cat_type, $desc, $color,
80 $event_repeat, $event_repeat_freq,
81 $event_repeat_freq_type, $event_repeat_on_num,
82 $event_repeat_on_day, $event_repeat_on_freq, $durationh, $durationm,
83 $end_date_flag, $end_date_type, $end_date_freq, $end_all_day, $active, $sequence, $aco,
84 $newname, $newconstantid, $newdesc, $newcolor, $new_event_repeat, $new_event_repeat_freq,
85 $new_event_repeat_freq_type, $new_event_repeat_on_num, $new_event_repeat_on_day,
86 $new_event_repeat_on_freq, $new_durationh, $new_durationm, $new_limitid, $new_end_date_flag,
87 $new_end_date_type, $new_end_date_freq, $new_end_all_day, $new_value_cat_type, $newactive, $newsequence, $newaco
88 ) = pnVarCleanFromInput(
89 'id',
90 'del',
91 'name',
92 'constantid',
93 'value_cat_type',
94 'desc',
95 'color',
96 'event_repeat',
97 'event_repeat_freq',
98 'event_repeat_freq_type',
99 'event_repeat_on_num',
100 'event_repeat_on_day',
101 'event_repeat_on_freq',
102 'durationh',
103 'durationm',
104 'end_date_flag',
105 'end_date_type',
106 'end_date_freq',
107 'end_all_day',
108 'active',
109 'sequence',
110 'aco',
111 'newname',
112 'newconstantid',
113 'newdesc',
114 'newcolor',
115 'newevent_repeat',
116 'newevent_repeat_freq',
117 'newevent_repeat_freq_type',
118 'newevent_repeat_on_num',
119 'newevent_repeat_on_day',
120 'newevent_repeat_on_freq',
121 'newdurationh',
122 'newdurationm',
123 'newlimitid',
124 'newend_date_flag',
125 'newend_date_type',
126 'newend_date_freq',
127 'newend_all_day',
128 'newvalue_cat_type',
129 'newactive',
130 'newsequence',
131 'newaco'
133 //data validation
134 foreach ($name as $i => $item) {
135 if (empty($item)) {
136 $output->Text(postcalendar_admin_categories($msg, "Category Names must contain a value!"));
137 return $output->GetOutput();
139 if (empty($constantid[$i])) {
140 $output->Text(postcalendar_admin_categories($msg, "Category Identifiers must contain a value!"));
141 return $output->GetOutput();
143 $tmp = $constantid[$i];
144 if (strpos(trim($tmp), ' ')) {
145 $output->Text(postcalendar_admin_categories($msg, "Category Identifiers must be one word!"));
146 return $output->GetOutput();
148 $tmp = $color[$i];
149 if (strlen($tmp) != 7 || $tmp[0] != "#") {
150 $e = $tmp . " size " . strlen($tmp) . " at 0 " . $tmp[0];
151 $output->Text(postcalendar_admin_categories($msg, "You entered an invalid color(USE Pick) $e!"));
152 return $output->GetOutput();
155 foreach ($durationh as $i => $val) {
156 if (
157 !is_numeric($durationh[$i]) || !is_numeric($durationm[$i]) ||
158 !is_numeric($event_repeat_freq[$i]) ||
159 !is_numeric($event_repeat_on_freq[$i]) || !is_numeric($end_date_freq[$i])
161 $output->Text(postcalendar_admin_categories(
162 $msg,
163 " Hours, Minutes and recurrence values must be numeric!"
165 return $output->GetOutput();
168 if (!empty($newnam)) {
169 if (
170 !is_numeric($new_durationh) ||
171 !is_numeric($new_durationm) ||
172 !is_numeric($new_event_repeat_freq) ||
173 !is_numeric($new_event_repeat_on_freq) ||
174 !is_numeric($new_end_date_freq)
176 $output->Text(postcalendar_admin_categories($msg, "Hours, Minutes and recurrence values must be numeric!"));
177 return $output->GetOutput();
180 $new_duration = ($new_durationh * (60 * 60)) + ($new_durationm * 60);
181 $event_recurrspec = serialize(compact(
182 'event_repeat_freq',
183 'event_repeat_freq_type',
184 'event_repeat_on_num',
185 'event_repeat_on_day',
186 'event_repeat_on_freq'
188 $new_event_recurrspec = serialize(compact(
189 'new_event_repeat_freq',
190 'new_event_repeat_freq_type',
191 'new_event_repeat_on_num',
192 'new_event_repeat_on_day',
193 'new_event_repeat_on_freq'
195 if (is_array($del)) {
196 $dels = implode(',', $del);
197 $delText = _PC_DELETE_CATS . $dels . '.';
199 $output->FormStart(pnModURL(__POSTCALENDAR__, 'admin', 'categoriesUpdate'));
200 $output->Text(_PC_ARE_YOU_SURE);
201 $output->Linebreak(2);
202 // deletions
203 if (isset($delText)) {
204 $output->FormHidden('dels', $dels);
205 $output->Text($delText);
206 $output->Linebreak();
208 if (!empty($newname)) {
209 if (empty($newconstantid)) {
210 $output->Text(postcalendar_admin_categories($msg ?? '', "Category Identifiers must contain a value!"));
211 return $output->GetOutput();
213 if (strpos(trim($newconstantid), ' ')) {
214 $output->Text(postcalendar_admin_categories($msg, "Category Identifiers must be one word!"));
215 return $output->GetOutput();
217 $output->FormHidden('newname', $newname);
218 $output->FormHidden('newconstantid', $newconstantid);
219 $output->FormHidden('newdesc', $newdesc);
220 $output->FormHidden('newvalue_cat_type', $new_value_cat_type);
221 $output->FormHidden('newcolor', $newcolor);
222 $output->FormHidden('newevent_repeat', $new_event_repeat);
223 $output->FormHidden('newevent_recurrfreq', $new_event_repeat_freq);
224 $output->FormHidden('newevent_recurrspec', $new_event_recurrspec);
225 $output->FormHidden('newduration', $new_duration);
226 $output->FormHidden('newlimitid', $new_limitid);
227 $output->FormHidden('newend_date_flag', $new_end_date_flag);
228 $output->FormHidden('newend_date_type', $new_end_date_type);
229 $output->FormHidden('newend_date_freq', $new_end_date_freq);
230 $output->FormHidden('newend_all_day', $new_end_all_day);
231 $output->FormHidden("newactive", $newactive);
232 $output->FormHidden("newsequence", $newsequence);
233 $output->FormHidden("newaco", $newaco);
234 $output->Text(_PC_ADD_CAT . text($newname) . '.');
235 $output->Linebreak();
237 $output->Text(_PC_MODIFY_CATS);
238 $output->FormHidden('id', serialize($id));
239 $output->FormHidden('del', serialize($del));
240 $output->FormHidden('name', serialize($name));
241 $output->FormHidden('constantid', serialize($constantid));
242 $output->FormHidden('desc', serialize($desc));
243 $output->FormHidden('value_cat_type', serialize($value_cat_type));
244 $output->FormHidden('color', serialize($color));
245 $output->FormHidden('event_repeat', serialize($event_repeat));
246 $output->FormHidden('event_recurrspec', $event_recurrspec);
247 $output->FormHidden('durationh', serialize($durationh));
248 $output->FormHidden('durationm', serialize($durationm));
249 $output->FormHidden('end_date_flag', serialize($end_date_flag));
250 $output->FormHidden('end_date_type', serialize($end_date_type));
251 $output->FormHidden('end_date_freq', serialize($end_date_freq));
252 $output->FormHidden('end_all_day', serialize($end_all_day));
253 $output->FormHidden("active", serialize($active));
254 $output->FormHidden("sequence", serialize($sequence));
255 $output->FormHidden("aco", serialize($aco));
256 $output->Linebreak();
257 $output->FormSubmit(_PC_CATS_CONFIRM);
258 $output->FormEnd();
259 return $output->GetOutput();
262 function postcalendar_admin_categoriesUpdate()
264 $output = new pnHTML();
265 $output->SetInputMode(_PNH_VERBATIMINPUT);
267 list($dbconn) = pnDBGetConn();
268 $pntable = pnDBGetTables();
270 list($id,$del,$name,$constantid,$value_cat_type,$desc,$color,
271 $event_repeat_array,$event_recurrspec_array,$dels,$durationh,$durationm,
272 $end_date_flag,$end_date_type,$end_date_freq,$end_all_day,$active,$sequence,$aco,$newname,$newconstantid,$newdesc,$newcolor,
273 $new_event_repeat,$new_event_recurrspec,$new_event_recurrfreq,
274 $new_duration,$new_dailylimitid,$new_end_date_flag,$new_end_date_type,
275 $new_end_date_freq,$new_end_all_day,$new_value_cat_type,$newactive,$newsequence,$newaco
276 ) = pnVarCleanFromInput(
277 'id',
278 'del',
279 'name',
280 'constantid',
281 'value_cat_type',
282 'desc',
283 'color',
284 'event_repeat',
285 'event_recurrspec',
286 'dels',
287 'durationh',
288 'durationm',
289 'end_date_flag',
290 'end_date_type',
291 'end_date_freq',
292 'end_all_day',
293 'active',
294 'sequence',
295 'aco',
296 'newname',
297 'newconstantid',
298 'newdesc',
299 'newcolor',
300 'newevent_repeat',
301 'newevent_recurrspec',
302 'newevent_recurrfreq',
303 'newduration',
304 'newlimitid',
305 'newend_date_flag',
306 'newend_date_type',
307 'newend_date_freq',
308 'newend_all_day',
309 'newvalue_cat_type',
310 'newactive',
311 'newsequence',
312 'newaco'
315 $id = unserialize($id, ['allowed_classes' => false]);
316 $del = unserialize($del, ['allowed_classes' => false]);
317 $name = unserialize($name, ['allowed_classes' => false]);
318 $constantid = unserialize($constantid, ['allowed_classes' => false]);
319 $value_cat_type = unserialize($value_cat_type, ['allowed_classes' => false]);
320 $desc = unserialize($desc, ['allowed_classes' => false]);
321 $color = unserialize($color, ['allowed_classes' => false]);
322 $event_repeat_array = unserialize($event_repeat_array, ['allowed_classes' => false]);
323 $event_recurrspec_array = unserialize($event_recurrspec_array, ['allowed_classes' => false]);
324 $durationh = unserialize($durationh, ['allowed_classes' => false]);
325 $durationm = unserialize($durationm, ['allowed_classes' => false]);
326 $end_date_flag = unserialize($end_date_flag, ['allowed_classes' => false]);
327 $end_date_type = unserialize($end_date_type, ['allowed_classes' => false]);
328 $end_date_freq = unserialize($end_date_freq, ['allowed_classes' => false]);
329 $end_all_day = unserialize($end_all_day, ['allowed_classes' => false]);
330 $active = unserialize($active, ['allowed_classes' => false]);
331 $sequence = unserialize($sequence, ['allowed_classes' => false]);
332 $aco = unserialize($aco, ['allowed_classes' => false]);
333 $updates = array();
335 if (isset($id)) {
336 foreach ($id as $k => $i) {
337 $found = false;
338 if (!empty($del)) {
339 if (count($del)) {
340 foreach ($del as $d) {
341 if ($i == $d) {
342 $found = true;
343 break;
348 if (!$found) {
349 $event_repeat_freq = $event_recurrspec_array['event_repeat_freq'][$i];
350 $event_repeat_freq_type = $event_recurrspec_array['event_repeat_freq_type'][$i];
351 $event_repeat_on_num = $event_recurrspec_array['event_repeat_on_num'][$i];
352 $event_repeat_on_day = $event_recurrspec_array['event_repeat_on_day'][$i];
353 $event_repeat_on_freq = $event_recurrspec_array['event_repeat_on_freq'][$i];
355 $recurrspec = serialize(compact(
356 'event_repeat_freq',
357 'event_repeat_freq_type',
358 'event_repeat_on_num',
359 'event_repeat_on_day',
360 'event_repeat_on_freq'
363 $dur = ( ($durationh[$i] * (60 * 60)) + ($durationm[$i] * 60));
365 $update_sql = "UPDATE $pntable[postcalendar_categories]
366 SET pc_catname='" . pnVarPrepForStore($name[$k]) . "',
367 pc_constant_id='" . trim(pnVarPrepForStore($constantid[$k])) . "',
368 pc_catdesc='" . trim(pnVarPrepForStore($desc[$k])) . "',
369 pc_cattype='" . trim(pnVarPrepForStore($value_cat_type[$k])) . "',
370 pc_catcolor='" . pnVarPrepForStore($color[$k]) . "',
371 pc_recurrtype='" . pnVarPrepForStore($event_repeat_array[$i]) . "',
372 pc_recurrspec='" . pnVarPrepForStore($recurrspec) . "',
373 pc_duration='" . pnVarPrepForStore($dur) . "',
374 pc_end_date_flag='" . pnVarPrepForStore($end_date_flag[$i]) . "',
375 pc_end_date_type='" . pnVarPrepForStore($end_date_type[$i]) . "',
376 pc_end_date_freq='" . pnVarPrepForStore($end_date_freq[$i]) . "',
377 pc_end_all_day='" . pnVarPrepForStore($end_all_day[$i]) . "',
378 pc_active ='" . pnVarPrepForStore($active[$i]) . "',
379 pc_seq = '" . pnVarPrepForStore($sequence[$k]) . "',
380 aco_spec = '" . pnVarPrepForStore($aco[$k]) . "'
381 WHERE pc_catid = '" . pnVarPrepForStore($i) . "'";
383 array_push($updates, $update_sql);
384 unset($recurrspec);
385 unset($dur);
391 $delete = "DELETE FROM $pntable[postcalendar_categories] WHERE pc_catid IN ($dels)";
392 $e = $msg = '';
393 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'updateCategories', array('updates' => $updates))) {
394 $e .= 'UPDATE FAILED';
396 if (isset($dels)) {
397 if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'deleteCategories', array('delete' => $delete))) {
398 $e .= 'DELETE FAILED';
401 if (isset($newname)) {
402 $unpacked = unserialize($new_event_recurrspec, ['allowed_classes' => false]);
403 unset($new_event_recurrspec);
404 $new_event_recurrspec['event_repeat_freq'] = $unpacked['new_event_repeat_freq'];
405 $new_event_recurrspec['event_repeat_freq_type'] = $unpacked['new_event_repeat_freq_type'];
406 $new_event_recurrspec['event_repeat_on_num'] = $unpacked['new_event_repeat_on_num'];
407 $new_event_recurrspec['event_repeat_on_day'] = $unpacked['new_event_repeat_on_day'];
408 $new_event_recurrspec['event_repeat_on_freq'] = $unpacked['new_event_repeat_on_freq'];
409 $new_event_recurrspec = serialize($new_event_recurrspec);
411 if (
412 !pnModAPIFunc(
413 __POSTCALENDAR__,
414 'admin',
415 'addCategories',
416 array('name' => $newname,'constantid' => $newconstantid,'desc' => $newdesc,'value_cat_type' => $new_value_cat_type,'color' => $newcolor,'active' => $newactive,'sequence' => $newsequence, 'aco' => $newaco,
417 'repeat' => $new_event_repeat,'spec' => $new_event_recurrspec,
418 'recurrfreq' => $new_recurrfreq ?? '','duration' => $new_duration,'limitid' => $new_dailylimitid,
419 'end_date_flag' => $new_end_date_flag,'end_date_type' => $new_end_date_flag,
420 'end_date_freq' => $new_end_date_freq,
421 'end_all_day' => $new_end_all_day)
424 $e .= 'INSERT FAILED';
428 if (empty($e)) {
429 $msg = 'DONE';
431 $output->Text(postcalendar_admin_categories($msg, $e));
432 return $output->GetOutput();
436 * Creates a new category
438 function postcalendar_admin_categories($msg = '', $e = '', $args = array())
440 extract($args);
441 unset($args);
443 $output = new pnHTML();
444 $output->SetInputMode(_PNH_VERBATIMINPUT);
445 // set up Smarty
446 $tpl = new pcSmarty();
447 $tpl->caching = false;
449 $template_name = pnModGetVar(__POSTCALENDAR__, 'pcTemplate');
451 if (!isset($template_name)) {
452 $template_name = 'default';
455 $output->Text(postcalendar_adminmenu("category"));
457 if (!empty($e)) {
458 $output -> Text('<div class="alert alert-danger mx-1" role="alert">');
459 $output->Text('<span class="text-center font-weight-bold">' . text($e) . '</span>');
460 $output -> Text('</div><br />');
463 if (!empty($msg)) {
464 $output -> Text('<div class="alert alert-success mx-1" role="alert">');
465 $output->Text('<span class="text-center font-weight-bold">' . text($msg) . '</span>');
466 $output -> Text('</div><br />');
469 //=================================================================
470 // Setup the correct config file path for the templates
471 //=================================================================
472 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
473 $modir = pnVarPrepForOS($modinfo['directory']);
474 $modname = $modinfo['displayname'];
475 $all_categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
476 //print_r($all_categories);
477 unset($modinfo);
478 $tpl->config_dir = "modules/$modir/pntemplates/$template_name/config/";
480 //=================================================================
481 // PARSE MAIN
482 //=================================================================
484 // create translations if applicable
485 if (($GLOBALS['translate_appt_categories']) && ($_SESSION['language_choice'] > 1)) {
486 $sizeAllCat = count($all_categories);
487 for ($m = 0; $m < $sizeAllCat; $m++) {
488 $tempCategory = $all_categories[$m]["name"];
489 $tempDescription = $all_categories[$m]["desc"];
490 $all_categories[$m]["nameTranslate"] = xl($tempCategory);
491 $all_categories[$m]["descTranslate"] = xl($tempDescription);
494 $scriptFilterEvent = new ScriptFilterEvent('pnadmin.php');
495 $scriptFilterEvent->setContextArgument('viewtype', 'admin');
496 $calendarScripts = $GLOBALS['kernel']->getEventDispatcher()->dispatch($scriptFilterEvent, ScriptFilterEvent::EVENT_NAME);
498 $styleFilterEvent = new StyleFilterEvent('pnadmin.php');
499 $styleFilterEvent->setContextArgument('viewtype', 'admin');
500 $calendarStyles = $GLOBALS['kernel']->getEventDispatcher()->dispatch($styleFilterEvent, StyleFilterEvent::EVENT_NAME);
502 $tpl->assign('globals', $GLOBALS);
503 $tpl->assign('HEADER_SCRIPTS', $calendarScripts->getScripts());
504 $tpl->assign('HEADER_STYLES', $calendarStyles->getStyles());
505 $tpl->assign_by_ref('TPL_NAME', $template_name);
506 $tpl->assign('FUNCTION', pnVarCleanFromInput('func'));
507 $tpl->assign_by_ref('ModuleName', $modname);
508 $tpl->assign_by_ref('ModuleDirectory', $modir);
509 $tpl->assign_by_ref('all_categories', $all_categories);
511 $tpl->assign('pcDir', $modir);
512 $tpl->assign('action', pnModURL(__POSTCALENDAR__, 'admin', 'categoriesConfirm'));
513 $tpl->assign('adminmenu', postcalendar_adminmenu("category"));
514 $tpl->assign('BGCOLOR2', $GLOBALS['style']['BGCOLOR2']);
515 $tpl->assign('css_header', $GLOBALS['css_header']);
516 $tpl->assign('_PC_REP_CAT_TITLE_S', _PC_REP_CAT_TITLE_S);
517 $tpl->assign('_PC_NEW_CAT_TITLE_S', _PC_NEW_CAT_TITLE_S);
518 $tpl->assign('_PC_CAT_NAME', _PC_CAT_NAME);
519 $tpl->assign('_PC_CAT_CONSTANT_ID', _PC_CAT_CONSTANT_ID);
520 $tpl->assign('_PC_CAT_TYPE', _PC_CAT_TYPE);
521 $tpl->assign('_PC_CAT_NAME_XL', _PC_CAT_NAME_XL);
522 $tpl->assign('_PC_CAT_DESC', _PC_CAT_DESC);
523 $tpl->assign('_PC_CAT_DESC_XL', _PC_CAT_DESC_XL);
524 $tpl->assign('_PC_CAT_COLOR', _PC_CAT_COLOR);
525 $tpl->assign('_PC_CAT_DELETE', _PC_CAT_DELETE);
526 $tpl->assign('_PC_CAT_DUR', _PC_CAT_DUR);
527 $tpl->assign('_PC_COLOR_PICK_TITLE', _PC_COLOR_PICK_TITLE);
528 $tpl->assign('_EDIT_PC_CONFIG_CATDETAILS', _EDIT_PC_CONFIG_CATDETAILS);
529 $tpl->assign("_PC_ACTIVE", _PC_ACTIVE);
530 $tpl->assign("_PC_SEQ", _PC_SEQ);
531 $tpl->assign("_ACO", _ACO);
532 //=================================================================
533 // Repeating Information
534 //=================================================================
535 $tpl->assign('RepeatingHeader', _PC_REPEATING_HEADER);
536 $tpl->assign('NoRepeatTitle', _PC_NO_REPEAT);
537 $tpl->assign('RepeatTitle', _PC_REPEAT);
538 $tpl->assign('RepeatOnTitle', _PC_REPEAT_ON);
539 $tpl->assign('OfTheMonthTitle', _PC_OF_THE_MONTH);
540 $tpl->assign('EndDateTitle', _PC_END_DATE);
541 $tpl->assign('NoEndDateTitle', _PC_NO_END);
542 $tpl->assign('REP_CAT_TITLE', _PC_REP_CAT_TITLE);
543 $tpl->assign('NEW_CAT_TITLE', _PC_NEW_CAT_TITLE);
544 $tpl->assign('InputNoRepeat', 'event_repeat');
545 $tpl->assign('ValueNoRepeat', '0');
546 $tpl->assign('SelectedNoRepeat', (int) ($event_repeat ?? null) == 0 ? 'checked' : '');
547 $tpl->assign('InputRepeat', 'event_repeat');
548 $tpl->assign('ValueRepeat', '1');
549 $tpl->assign('SelectedRepeat', (int) ($event_repeat ?? null) == 1 ? 'checked' : '');
552 unset($in);
553 $in = array(_PC_EVERY,_PC_EVERY_OTHER,_PC_EVERY_THIRD,_PC_EVERY_FOURTH);
554 $keys = array(REPEAT_EVERY,REPEAT_EVERY_OTHER,REPEAT_EVERY_THIRD,REPEAT_EVERY_FOURTH);
555 $repeat_freq = array();
556 foreach ($in as $k => $v) {
557 array_push($repeat_freq, array('value' => $keys[$k],
558 'selected' => ($keys[$k] == ($event_repeat_freq ?? null) ? 'selected' : ''),
559 'name' => $v));
561 $tpl->assign('InputRepeatFreq', 'event_repeat_freq');
562 if (empty($event_repeat_freq) || $event_repeat_freq < 1) {
563 $event_repeat_freq = 1;
565 $tpl->assign('InputRepeatFreqVal', $event_repeat_freq);
566 $tpl->assign('repeat_freq', $event_repeat_freq);
567 unset($in);
569 $in = array(_PC_EVERY_DAY,_PC_EVERY_WORKDAY,_PC_EVERY_WEEK,_PC_EVERY_MONTH,_PC_EVERY_YEAR);
570 $keys = array(REPEAT_EVERY_DAY,REPEAT_EVERY_WORK_DAY,REPEAT_EVERY_WEEK,REPEAT_EVERY_MONTH,REPEAT_EVERY_YEAR);
571 $repeat_freq_type = array();
572 foreach ($in as $k => $v) {
573 array_push($repeat_freq_type, array('value' => $keys[$k],
574 'selected' => ($keys[$k] == ($event_repeat_freq_type ?? null) ? 'selected' : ''),
575 'name' => $v));
577 $tpl->assign('InputRepeatFreqType', 'event_repeat_freq_type');
578 $tpl->assign('InuptRepeatFreq', '' . 'event_repeat_freq');
579 $tpl->assign('repeat_freq_type', $repeat_freq_type);
581 $tpl->assign('InputRepeatOn', 'event_repeat');
582 $tpl->assign('ValueRepeatOn', '2');
583 $tpl->assign('SelectedRepeatOn', (int) ($event_repeat ?? null) == 2 ? 'checked' : '');
585 // All Day START
586 $tpl->assign('InputAllDay', 'end_all_day');
587 $tpl->assign('ValueAllDay', '1');
588 $tpl->assign('ValueAllDayNo', '0');
589 $tpl->assign('ALL_DAY_CAT_TITLE', _PC_ALL_DAY_CAT_TITLE);
590 $tpl->assign('ALL_DAY_CAT_YES', _PC_ALL_DAY_CAT_YES);
591 $tpl->assign('ALL_DAY_CAT_NO', _PC_ALL_DAY_CAT_NO);
593 //ALL Day End
594 // End date gather date start
596 $tpl->assign('InputEndDateFreq', 'end_date_freq');
597 $tpl->assign('InputEndOn', 'end_date_flag');
598 $tpl->assign('InputEndDateFreqType', 'end_date_type');
599 $tpl->assign('ValueNoEnd', '0');
600 $tpl->assign('ValueEnd', '1');
602 if (empty($end_date_type)) {
603 $end_date_type = array();
605 foreach ($in as $k => $v) {
606 array_push($end_date_type, array('value' => $keys[$k],
607 'selected' => ($keys[$k] == $end_date_type ? 'selected' : ''),
608 'name' => $v));
610 unset($in);
613 // End date gather date end
616 unset($in);
617 $in = array(_PC_EVERY_1ST,_PC_EVERY_2ND,_PC_EVERY_3RD,_PC_EVERY_4TH,_PC_EVERY_LAST);
618 $keys = array(REPEAT_ON_1ST,REPEAT_ON_2ND,REPEAT_ON_3RD,REPEAT_ON_4TH,REPEAT_ON_LAST);
619 $repeat_on_num = array();
620 foreach ($in as $k => $v) {
621 array_push($repeat_on_num, array('value' => $keys[$k],
622 'selected' => ($keys[$k] == ($event_repeat_on_num ?? null) ? 'selected' : ''),
623 'name' => $v));
625 $tpl->assign('InputRepeatOnNum', 'event_repeat_on_num');
626 $tpl->assign('repeat_on_num', $repeat_on_num);
628 unset($in);
629 $in = array(_PC_EVERY_SUN,_PC_EVERY_MON,_PC_EVERY_TUE,_PC_EVERY_WED,_PC_EVERY_THU,_PC_EVERY_FRI,_PC_EVERY_SAT);
630 $keys = array(REPEAT_ON_SUN,REPEAT_ON_MON,REPEAT_ON_TUE,REPEAT_ON_WED,REPEAT_ON_THU,REPEAT_ON_FRI,REPEAT_ON_SAT);
631 $repeat_on_day = array();
632 foreach ($in as $k => $v) {
633 array_push($repeat_on_day, array('value' => $keys[$k],
634 'selected' => ($keys[$k] == ($event_repeat_on_day ?? null) ? 'selected' : ''),
635 'name' => $v));
637 $tpl->assign('InputRepeatOnDay', 'event_repeat_on_day');
638 $tpl->assign('repeat_on_day', $repeat_on_day);
640 unset($in);
641 $in = array(_PC_CAT_PATIENT,_PC_CAT_PROVIDER,_PC_CAT_CLINIC,_PC_CAT_THERAPY_GROUP);
642 $keys = array(TYPE_ON_PATIENT,TYPE_ON_PROVIDER,TYPE_ON_CLINIC,TYPE_ON_THERAPY_GROUP);
643 $cat_type = array();
644 foreach ($in as $k => $v) {
645 array_push($cat_type, array('value' => $keys[$k],
646 'selected' => ($keys[$k] == ($value_cat_type ?? null) ? 'selected' : ''),
647 'name' => $v));
649 $tpl->assign('InputCatType', 'value_cat_type');
650 $tpl->assign('cat_type', $cat_type);
652 unset($in);
653 $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);
654 $keys = array(REPEAT_ON_MONTH,REPEAT_ON_2MONTH,REPEAT_ON_3MONTH,REPEAT_ON_4MONTH,REPEAT_ON_6MONTH,REPEAT_ON_YEAR);
655 $repeat_on_freq = array();
656 foreach ($in as $k => $v) {
657 array_push($repeat_on_freq, array('value' => $keys[$k],
658 'selected' => ($keys[$k] == ($event_repeat_on_freq ?? null) ? 'selected' : ''),
659 'name' => $v));
661 $tpl->assign('InputRepeatOnFreq', 'event_repeat_on_freq');
662 if (empty($event_repeat_on_freq) || $event_repeat_on_freq < 1) {
663 $event_repeat_on_freq = 1;
665 $tpl->assign('InputRepeatOnFreqVal', $event_repeat_on_freq);
666 $tpl->assign('repeat_on_freq', $repeat_on_freq);
667 $tpl->assign('MonthsTitle', _PC_MONTHS);
668 $tpl->assign('DurationHourTitle', _PC_DURATION_HOUR);
669 $tpl->assign('DurationMinTitle', _PC_DURATION_MIN);
670 $tpl->assign('InputDurationHour', "durationh");
671 $tpl->assign('InputDurationMin', "durationm");
672 $tpl->assign('ActiveTitleYes', xl('Yes'));
673 $tpl->assign('ActiveTitleNo', xl('No'));
675 // Added ACO for each category
676 $tpl->assign('InputACO', 'aco');
677 $acoList = AclExtended::genAcoArray();
678 $tpl->assign('ACO_List', $acoList);
680 $output->SetOutputMode(_PNH_RETURNOUTPUT);
681 $output->SetOutputMode(_PNH_KEEPOUTPUT);
683 if (isset($data_loaded)) {
684 $form_hidden = "<input type=\"hidden\" name=\"is_update\" value=\"" . attr($is_update ?? '') . "\" />";
685 $form_hidden .= "<input type=\"hidden\" name=\"pc_event_id\" value=\"" . attr($pc_event_id ?? '') . "\" />";
686 $form_hidden .= "<input type=\"hidden\" name=\"data_loaded\" value=\"" . attr($data_loaded) . "\" />";
687 $tpl->assign('FormHidden', $form_hidden);
690 $form_submit = '<input type=hidden name="form_action" value="commit"/>
691 ' . text($authkey ?? '') . '<input class="btn btn-primary" type="submit" name="submit" value="' . xla('Save') . '">';
692 $tpl->assign('FormSubmit', $form_submit);
694 $output->Text($tpl->fetch($template_name . '/admin/submit_category.html'));
695 $output->Text(postcalendar_footer());
696 return $output->GetOutput();
700 * Main administration menu
702 function postcalendar_adminmenu($menuItem)
704 global $bgcolor1, $bgcolor2;
706 if (!defined('_AM_VAL')) {
707 define('_AM_VAL', 1);
710 if (!defined('_PM_VAL')) {
711 define('_PM_VAL', 2);
714 if (!defined('_EVENT_APPROVED')) {
715 define('_EVENT_APPROVED', 1);
718 if (!defined('_EVENT_QUEUED')) {
719 define('_EVENT_QUEUED', 0);
722 if (!defined('_EVENT_HIDDEN')) {
723 define('_EVENT_HIDDEN', -1);
726 $categoryURL = pnModURL(__POSTCALENDAR__, 'admin', 'categories');
727 $cacheURL = pnModURL(__POSTCALENDAR__, 'admin', 'clearCache');
728 $systemURL = pnModURL(__POSTCALENDAR__, 'admin', 'testSystem');
730 $categoryText = text(_EDIT_PC_CONFIG_CATEGORIES);
731 $cacheText = text(_PC_CLEAR_CACHE);
732 $systemText = text(_PC_TEST_SYSTEM);
734 $output = " <div class='container mt-3 mb-3'><ul class='nav nav-pills'>";
736 if ($menuItem === "clearCache") {
737 $output .= <<<EOF
738 <li class="nav-item">
739 <a class="nav-link active" href="$cacheURL">$cacheText</a>
740 </li>
741 <li class="nav-item">
742 <a class="nav-link" href="$categoryURL">$categoryText</a>
743 </li>
744 EOF;
745 } elseif ($menuItem === "testSystem") {
746 $output .= <<<EOF
747 <li class="nav-item">
748 <a class="nav-link" href="$cacheURL">$cacheText</a>
749 </li>
750 <li class="nav-item">
751 <a class="nav-link" href="$categoryURL">$categoryText</a>
752 </li>
753 EOF;
754 } elseif ($menuItem === "category") {
755 $output .= <<<EOF
756 <li class="nav-item">
757 <a class="nav-link" href="$cacheURL">$cacheText</a>
758 </li>
759 <li class="nav-item">
760 <a class="nav-link active" href="$categoryURL">$categoryText</a>
761 </li>
762 EOF;
763 } else {
764 $output .= <<<EOF
765 <li class="nav-item">
766 <a class="nav-link" href="$cacheURL">$cacheText</a>
767 </li>
768 <li class="nav-item">
769 <a class="nav-link" href="$categoryURL">$categoryText</a>
770 </li>
771 EOF;
773 $output .= "</ul></div>";
774 // Return the output that has been generated by this function
775 return $output;
778 function postcalendar_admin_clearCache()
780 $tpl = new pcSmarty();
781 //fmg: check that both subdirs to be cleared first exist and are writeable
782 $spec_err = '';
784 if (!file_exists($tpl->compile_dir)) {
785 $spec_err .= "Error: folder '" . text($tpl->compile_dir) . "' doesn't exist!<br />";
786 } elseif (!is_writeable($tpl->compile_dir)) {
787 $spec_err .= "Error: folder '" . text($tpl->compile_dir) . "' not writeable!<br />";
790 //note: we don't abort on error... like before.
791 $tpl->clear_all_cache();
792 $tpl->clear_compiled_tpl();
794 return postcalendar_admin_modifyconfig('<div class="text-center">' . $spec_err . text(_PC_CACHE_CLEARED) . '</div>');
797 function postcalendar_admin_testSystem()
799 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
800 $pcDir = pnVarPrepForOS($modinfo['directory']);
801 $version = $modinfo['version'];
802 unset($modinfo);
804 $tpl = new pcSmarty();
805 $infos = array();
807 $__SERVER =& $_SERVER;
808 $__ENV =& $_ENV;
810 if (defined('_PN_VERSION_NUM')) {
811 $pnVersion = _PN_VERSION_NUM;
812 } else {
813 $pnVersion = pnConfigGetVar('Version_Num');
816 array_push($infos, array('CMS Version', $pnVersion));
817 array_push($infos, array('Sitename', pnConfigGetVar('sitename')));
818 array_push($infos, array('url', pnGetBaseURL()));
819 array_push($infos, array('PHP Version', phpversion()));
820 if ((bool) ini_get('safe_mode')) {
821 $safe_mode = "On";
822 } else {
823 $safe_mode = "Off";
825 array_push($infos, array('PHP safe_mode', $safe_mode));
826 if ((bool) ini_get('safe_mode_gid')) {
827 $safe_mode_gid = "On";
828 } else {
829 $safe_mode_gid = "Off";
831 array_push($infos, array('PHP safe_mode_gid', $safe_mode_gid));
832 $base_dir = ini_get('open_basedir');
833 if (!empty($base_dir)) {
834 $open_basedir = "$base_dir";
835 } else {
836 $open_basedir = "NULL";
838 array_push($infos, array('PHP open_basedir', $open_basedir));
839 array_push($infos, array('SAPI', php_sapi_name()));
840 array_push($infos, array('OS', php_uname()));
841 array_push($infos, array('WebServer', $__SERVER['SERVER_SOFTWARE']));
842 array_push($infos, array('Module dir', "modules/$pcDir"));
844 $modversion = array();
845 include "modules/$pcDir/pnversion.php";
847 $error = '';
848 if ($modversion['version'] != $version) {
849 $error = '<br /><div class="text-danger">';
850 $error .= "new version $modversion[version] installed but not updated!";
851 $error .= '</div>';
853 array_push($infos, array('Module version', $version . " $error"));
854 array_push($infos, array('smarty version', $tpl->_version));
855 array_push($infos, array('smarty location', SMARTY_DIR));
856 array_push($infos, array('smarty template dir', $tpl->template_dir));
858 $info = $tpl->compile_dir;
859 $error = '';
860 if (!file_exists($tpl->compile_dir)) {
861 $error .= " compile dir doesn't exist! [" . text($tpl->compile_dir) . "]<br />";
862 } else {
863 // dir exists -> check if it's writeable
864 if (!is_writeable($tpl->compile_dir)) {
865 $error .= " compile dir not writeable! [" . text($tpl->compile_dir) . "]<br />";
868 if (strlen($error) > 0) {
869 $info .= "<br /><div class='text-danger'>$error</div>";
871 array_push($infos, array('smarty compile dir', $info));
873 if (AclMain::aclCheckCore('admin', 'super')) {
874 $header = "<head><title>" . xlt("Diagnostics") . "</title></head><body>";
875 $output = $header;
876 $output .= '<div class="container mt-3"><div class="row"><div class="col-sm-12"><div class="clearfix">';
877 $output .= '<h2>' . xlt('Diagnostics') . '</h2>';
878 $output .= '</div></div></div>';
879 $output .= '<div class="table-responsive"><table class="table table-bordered table-striped"><thead>';
880 $output .= '<tr><th>' . xlt('Name') . '</th><th>' . xlt('Value') . '</th></tr></thead>';
881 foreach ($infos as $info) {
882 $output .= '<tr><td><b>' . pnVarPrepHTMLDisplay($info[0]) . '</b></td>';
883 $output .= '<td>' . pnVarPrepHTMLDisplay($info[1]) . '</td></tr>';
885 $output .= '</table></div></div>';
886 $output .= '<br /><br />';
887 $output .= postcalendar_admin_modifyconfig('', false);
888 $output .= "</body></html>";
889 return $output;
890 } else {
891 die(xlt("Not Authorized"));