-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpnhandleradmin.php
More file actions
685 lines (578 loc) · 23.4 KB
/
pnhandleradmin.php
File metadata and controls
685 lines (578 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<?php
// ----------------------------------------------------------------------
// FEproc - Mail template backend module for FormExpress for
// POST-NUKE Content Management System
// Copyright (C) 2002 by Jason Judge
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WIthOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Jason Judge.
// Based on template by Jim MacDonald.
// Current Maintainer of file: Klavs Klavsen <kl-feproc@vsen.dk>
// ----------------------------------------------------------------------
/**
* view items
*/
function feproc_handleradmin_view()
{
// Get parameters from whatever input we need.
$startnum = pnVarCleanFromInput('startnum');
// Create output object - this object will store all of our output so that
// we can return it easily when required.
$output = new pnHTML();
if (!pnSecAuthAction(0, 'FEproc::Handler', '::', ACCESS_EDIT)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
// Load the admin module so we have the menu.
// TODO: rename menu function so proper call can be made.
if (!pnModLoad('feproc', 'admin')) {
$output->Text(_FXMODLOADFAILED);
return $output->GetOutput();
}
// Add menu to output - it helps if all of the module pages have a standard
// menu at their head to aid in navigation
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Load API. If the API fails to load an appropriate
// error message is posted and the function returns
if (!pnModAPILoad('feproc', 'handleruser')) {
$output->Text(_FXMODLOADFAILED);
return $output->GetOutput();
}
// The API function is called. This takes the number of items
// required and the first number in the list of all items, which we
// obtained from the input and gets us the information on the appropriate
// items.
$items = pnModAPIFunc('feproc', 'handleruser', 'getallhandlers',
array('startnum' => $startnum,
'numitems' => 10/* FIXME pnModGetVar('FEproc',
'itemsperpage')*/));
// Start output table
$output->TableStart(_FXFETAXHANDLERS,
array(_FXID,
_FXNAME,
_FXDESCRIPTION,
_FXTYPE,
_FXSOURCE,
_FXOPTIONS), 1);
foreach ($items as $item)
{
$row = array();
// Output whatever we found
$row[] = "$item[hid]";
$row[] = "$item[name]";
$row[] = $item['description'];
$row[] = $item['type'];
$row[] = $item['source'];
// Options for the item
$options = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$options[] = $output->URL(pnModURL('feproc',
'handleradmin',
'helphandler',
array('hid' => $item['hid'])),
_FXHELP );
$options[] = $output->URL(pnModURL('feproc',
'handleradmin',
'delete',
array('hid' => $item['hid'])),
_FXDELETE);
$options = join(' | ', $options);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$row[] = $output->Text($options);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->TableAddRow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
$row = array(null, null, null, null, _FXSOURCEKEY, null);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddRow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
$output->TableEnd();
// Call the pnHTML helper function to produce a pager in case of there
// being many items to display.
//
// Note that this function includes another user API function. The
// function returns a simple count of the total number of items in the item
// table so that the pager function can do its job properly
$output->Pager($startnum,
pnModAPIFunc('feproc', 'handleruser', 'counthandlers'),
pnModURL('feproc',
'handleradmin',
'view',
array('startnum' => '%%')),
10 /* FIXME pnModGetVar('FEproc', 'itemsperpage')*/);
$modinfo = pnModGetInfo(pnModGetIDFromName('feproc'));
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* delete item
* @param 'hid' the id of the item to be deleted
* @param 'confirmation' confirmation that this item can be deleted
*/
function feproc_handleradmin_delete($args)
{
// Get parameters from whatever input we need.
list($hid,
$objectid,
$confirmation) = pnVarCleanFromInput('hid',
'objectid',
'confirmation');
// User functions of this type can be called by other modules.
// pnVarCleanFromInput().
extract($args);
// Check to see if we have been passed $objectid.
if (!empty($objectid))
{
$hid = $objectid;
}
$output = new pnHTML();
// Early security check.
if (!pnSecAuthAction(0, 'FEproc::Handler', "::$hid", ACCESS_DELETE)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
// Load API. If the API fails to load an appropriate
// error message is posted and the function returns
if (!pnModAPILoad('feproc', 'handleradmin')) {
$output->Text(_FXMODLOADFAILED);
return $output->GetOutput();
}
if (!pnModAPILoad('feproc', 'handleruser')) {
$output->Text(_FXMODLOADFAILED);
return $output->GetOutput();
}
// Load main admin module so we can call up the menu.
if (!pnModLoad('feproc', 'admin')) {
$output->Text(_FXMODLOADFAILED);
return $output->GetOutput();
}
// The user API function is called.
$item = pnModAPIFunc('feproc',
'handleruser',
'gethandler',
array('hid' => $hid));
if ($item == false) {
$output->Text(_FXNOSUCHHANDLER);
return $output->GetOutput();
}
// Check for confirmation.
if (empty($confirmation))
{
// No confirmation yet - display a suitable form to obtain confirmation
// of this action from the user
// Create output object - this object will store all of our output so
// that we can return it easily when required
$output = new pnHTML();
// Add menu to output - it helps if all of the module pages have a
// standard menu at their head to aid in navigation
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Title - putting a title at the head of each page reminds the user
// what they are doing
$output->Title(_FXDELETEHANDLER);
// Add confirmation to output.
$output->ConfirmAction(_FXCONFIRMHANDLERDELETE . " '$item[name]'",
pnModURL('feproc',
'handleradmin',
'delete'),
_FXCANCELHANDLERDELETE,
pnModURL('feproc',
'handleradmin',
'view'),
array('hid' => $hid));
// Return the output that has been generated by this function
return $output->GetOutput();
}
// If we get here it means that the user has confirmed the action
// Confirm authorisation code.
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', _FXBADAUTHKEY);
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// The API function is called.
if (pnModAPIFunc('feproc',
'handleradmin',
'delete',
array('hid' => $hid))) {
// Success
pnSessionSetVar('statusmsg', _FXHANDLERDELETED);
}
// This function generated no output, and so now it is complete we redirect
// the user to an appropriate page for them to carry on their work
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
// Return
return true;
}
/**
* add new item
* This is a standard function that is called whenever an administrator
* wishes to create a new module item
*/
function feproc_handleradmin_new()
{
// For the menu.
if (!pnModLoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
if (!pnModAPILoad('feproc', 'handleradmin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Create output object.
$output = new pnHTML();
// Early security check.
if (!pnSecAuthAction(0, 'FEproc::Handler', '::', ACCESS_ADD)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Title - putting a title ad the head of each page reminds the user what
// they are doing
$output->Title(_FXADDHANDLER);
// Start form.
$output->FormStart(pnModURL('feproc', 'handleradmin', 'scanmodule'));
// Add an authorisation ID.
$output->FormHidden('authid', pnSecGenAuthKey());
// Start the table that holds the information to be input.
$output->TableStart();
// Get a list of modules on the system
$modules = pnModGetUserMods();
$feprocid = '';
foreach ($modules as $module)
{
$data[] = Array(
'id' => $module['name'],
'name' => $module['displayname'] . ': ' . $module['description']
);
}
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXCHOOSEMODULE));
$row[] = $output->FormSelectMultiple('modulename', $data, 0, 1, 'feproc');
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
$output->TableEnd();
// End form
$output->Linebreak(2);
$output->FormSubmit(_FXSCANMODULE);
$output->FormEnd();
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* add new item
* Having chosen a module, scan that module for feproc APIs.
*/
function feproc_handleradmin_scanmodule()
{
// For the menu.
if (!pnModLoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' admin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Handler admin functions.
if (!pnModAPILoad('feproc', 'handleradmin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' handleradmin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Create output object.
$output = new pnHTML();
// Early security check.
if (!pnSecAuthAction(0, 'FEproc::Handler', '::', ACCESS_ADD)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
$modulename = pnVarCleanFromInput('modulename');
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Title - putting a title ad the head of each page reminds the user what
// they are doing
$output->Title(_FXADDHANDLER);
// Start form.
$output->FormStart(pnModURL('feproc', 'handleradmin', 'addhandlers'));
// Add an authorisation ID.
$output->FormHidden('authid', pnSecGenAuthKey());
// Start the table that holds the information to be input.
$output->TableStart(_FXCHOOSEHANDLERS,
array(_FXNAME,
_FXDESCRIPTION,
_FXTYPE,
_FXSOURCE,
_FXOPTIONS), 1);
// Scan the module and get the handlers (if any).
$handlers = pnModAPIFunc('feproc',
'handleradmin',
'modulehandlers',
array('modulename' => $modulename));
// Other hidden values to identify the module.
$output->FormHidden('modulename', $modulename);
// Loop for each handler found.
if (is_array($handlers))
{
$output->SetInputMode(_PNH_VERBATIMINPUT);
foreach($handlers as $handler)
{
$row = Array();
$row[] = $handler['name'];
$row[] = $handler['description'];
$row[] = $handler['type'];
$row[] = $handler['source'];
// TODO: this should be a checkbox.
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->FormCheckbox('sources[]', false, $handler['source'], 'checkbox') .' '. _FXIMPORTFLAG;
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->TableAddRow($row, 'left');
}
$row = Array('', '', '', _FXSOURCEKEY);
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->FormCheckbox('allsources', true, '1', 'checkbox') .' '. _FXIMPORTALLFLAG;
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->TableAddRow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
$output->TableEnd();
if (!is_array($handlers))
{
// TODO: ml message.
$output->Text(_FXNOHANDLERSINMODULE . $modulename . '"');
}
// End form
$output->Linebreak(2);
$output->FormSubmit(_FXIMPORTHANDLERS);
$output->FormEnd();
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* add new item
* Having chosen a module, scanned that module and selected the APIs for importing,
* now do the import.
*/
function feproc_handleradmin_addhandlers()
{
$output = new pnHTML();
// For the menu.
if (!pnModLoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' admin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Handler admin functions.
if (!pnModAPILoad('feproc', 'handleradmin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' handleradmin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Handler user functions.
if (!pnModAPILoad('feproc', 'handleruser')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' handleradmin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
list($modulename, $sources, $allsources) =
pnVarCleanFromInput('modulename', 'sources', 'allsources');
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Get the handlers for the module.
$handlers = pnModAPIFunc('feproc',
'handleradmin',
'modulehandlers',
array('modulename' => $modulename));
// $sources will not be set if user did not select any handlers for import.
if (!is_array($sources))
{
$sources = Array();
}
// Loop for the handlers and import the required ones.
if (is_array($handlers))
{
foreach ($handlers as $handler)
{
// If this is one for importing, then do so.
if ($allsources || in_array($handler['source'], $sources))
{
// Yes - import this one.
//$output->Text("$handler[source] ");
$output->Linebreak();
// Get the existing handler, if it exists.
if ($item = pnModAPIFunc('feproc', 'handleruser', 'gethandler',
array('source' => $handler['source'])
))
{
// Already exists: update the handler.
$result = pnModAPIFunc('feproc', 'handleradmin', 'update',
array(
'hid' => $item['hid'],
'name' => $handler['name'],
'description' => $handler['description'],
'type' => $handler['type'],
'version' => $handler['version'],
'modulename' => $handler['module'],
'apiname' => $handler['apiname'],
'apifunc' => $handler['apifunc'],
'attributes' => $handler['attributes']
)
);
if ($result)
{
// TODO: ml strings.
$output->Text("Updated handler: " . $handler['source']);
} else {
$output->Text("Error updating handler: " . $handler['source']);
}
$output->Linebreak();
} else {
$result = pnModAPIFunc('feproc', 'handleradmin', 'create',
array(
'name' => $handler['name'],
'description' => $handler['description'],
'type' => $handler['type'],
'version' => $handler['version'],
'modulename' => $handler['module'],
'apiname' => $handler['apiname'],
'apifunc' => $handler['apifunc'],
'attributes' => $handler['attributes']
)
);
if ($result)
{
// TODO: ml strings.
$output->Text("Inserted handler: " . $handler['source']);
} else {
$output->Text("Error inserting handler: " . $handler['source']);
}
$output->Linebreak();
}
}
}
} else {
// TODO: ml message.
// Module should have been stopped before getting here.
$output->Text(_FXNOHANDLERSINMODULE . $modulename . '"');
}
return $output->GetOutput();
}
/**
* help page for a handler
* Display the help page for a handler.
*/
function feproc_handleradmin_helphandler()
{
$output = new pnHTML();
// Handler user functions.
if (!pnModAPILoad('feproc', 'handleruser')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' handleradmin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
$hid = pnVarCleanFromInput('hid');
if (!isset($hid) || !is_numeric($hid))
{
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
}
// Get the item
$item = pnModAPIFunc(
'feproc', 'handleruser', 'gethandler',
array('hid' => $hid)
);
if (! $item)
{
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
// Now load the API for the item and call the help function.
if (!pnModAPILoad($item['modulename'], $item['apiname'])) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED . ' handleradmin');
pnRedirect(pnModURL('feproc', 'handleradmin', 'view'));
return true;
}
$help = pnModAPIFunc(
$item['modulename'], $item['apiname'], $item['apifunc'],
array('action' => 'help')
);
$info = pnModAPIFunc(
$item['modulename'], $item['apiname'], $item['apifunc'],
array('action' => 'info')
);
if ($help)
{
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Title('Handler Help');
$output->Text("<strong>Overview:</strong><br/>");
$output->Text("Handler Type: $item[type]<br/>");
$output->Text("Source Module: $item[modulename]<br/>");
$output->Text("API Name In Module: $item[apiname]<br/>");
$output->Text("Function Name In API: $item[apifunc]<br/>");
if (is_array($info['attributes']))
{
$output->Text("<br/>");
$output->Text("<strong>Function Attributes:</strong>");
$output->Text('<ul>');
foreach ($info['attributes'] as $key => $item)
{
$output->Text('<li>'.pnVarPrepHTMLdisplay("$key ($item[description]) type=$item[type]"));
if ($item['type'] == 'list')
{
$output->Text('<ol>');
foreach($item['list'] as $listitem)
{
if ($listitem == '')
{
$listitem = '<NULL>';
}
$output->Text(pnVarPrepHTMLdisplay("<li>$listitem</li>"));
}
$output->Text('</ol>');
}
$output->Text('</li>');
}
$output->Text('</ul>');
}
$output->Text("<br/>");
$output->Text("<strong>Description:</strong><br/>");
// The help function will format its own HTML, so send output verbatim.
$output->Text($help);
$output->SetInputMode(_PNH_PARSEINPUT);
} else {
// TODO: ml string
$output->Text(_FXHANDLERNOHELP);
}
return $output->GetOutput();
}
?>