-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnadmin.php
1295 lines (1085 loc) · 42.9 KB
/
pnadmin.php
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* FEproc - Mail template backend module for FormExpress for
* Zikula Content Management System
*
* @copyrightt (C) 2002 by Jason Judge, 2011 Chris Candreva
* @Version $Id: $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package FEproc
*
*
* 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: Chris Candreva <chris@westnet.com>
* ----------------------------------------------------------------------
*
*/
Loader::requireOnce('includes/pnForm.php');
require_once('pnclass/editsethandler.php');
require_once('pnclass/modifyconfighandler.php');
/**
* the main administration function
*/
function feproc_admin_main()
{
return pnModFunc('feproc', 'admin', 'viewsets');
}
function feproc_admin_view()
{
// Just call viewsets. This had a different permissions check
// previously so I have left it, but this should likely go away.
if (!SecurityUtil::checkPermission ('FEproc::Set', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
return pnModFunc('feproc', 'admin', 'viewsets');
}
/*******************
* SETS
*******************/
/**
* view set items
*/
function feproc_admin_viewsets()
{
// Get parameters from whatever input we need.
$startnum = pnVarCleanFromInput('startnum');
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// Load list of all sets
$items = pnModAPIFunc('feproc', 'user', 'getallsets',
array('startnum' => $startnum,
'numitems' => pnModGetVar('FEproc', 'itemsperpage')));
$render = pnRender::getInstance('feproc');
$render->assign('items',$items);
return $render->fetch('feproc_admin_viewsets.tpl');
}
/**
* add new set item
*/
function feproc_admin_newset()
{
if (!SecurityUtil::checkPermission ('FEproc::Set', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError();
}
$render = FormUtil::newpnForm('feproc');
$formobj = new feproc_admin_editsetHandler();
return $render->pnFormExecute('feproc_admin_editset.tpl', $formobj);
}
/**
* modify a set item
* This is a standard function that is called whenever an administrator
* wishes to modify a current module item
* @param 'stageid' the id of the item to be modified
* @param 'setid' the id of the set the item is in
*/
function feproc_admin_modifyset($args)
{
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// Get parameters from whatever input we need.
$setid = FormUtil::getPassedValue('setid');
// The API function is called.
$item = pnModAPIFunc('feproc', 'user', 'getset', array('setid' => $setid));
// TODO: better error
if (!$item)
{
pnSessionSetVar('errormsg', 'The set does not exist');
return pnRedirect(pnModURL('feproc', 'admin', 'view'));
}
$render = FormUtil::newpnForm('feproc');
$formobj = new feproc_admin_editsetHandler();
$formobj->setId($setid);
return $render->pnFormExecute('feproc_admin_editset.tpl', $formobj);
// Create output object.
$output = new pnHTML();
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Page title.
$output->Title("Modify Set"); //TODO
// Start form.
$output->FormStart(pnModURL('feproc', 'admin', 'updateset'));
// Add an authorisation ID.
$output->FormHidden('authid', pnSecGenAuthKey());
// Add a hidden variable for the item id.
$output->FormHidden('setid', pnVarPrepForDisplay($setid));
// Start the table that holds the information to be input.
$output->TableStart();
// Name
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXNAME));
$row[] = $output->FormText('name', $item['name'], 32, 64);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Description
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXDESCRIPTION));
$row[] = $output->FormText('description', $item['description'], 64, 200);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Get stages for drop-down lists.
$stages = pnModAPIFunc('feproc', 'user', 'getallstages',
array('setid' => $setid));
if (is_array($stages))
{
// TODO: make the default starting stage a simple attribute. The upgrade
// would need to do some conversion to do this.
// Create stages drop-down list.
$data = Array();
$data[] = Array('id' => '0', 'name' => '- None -');
foreach ($stages as $stage)
{
$data[] = Array('id' => $stage['stageid'], 'name' => "$stage[stageid]: $stage[name]");
}
// Default starting stage select.
$row = Array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Default starting stage: ')); //TODO: ml
$row[] = $output->FormSelectMultiple('startstageid', $data, 0, 1, $item['startstageid']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Default timeout stage select.
$row = Array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Stage on timeout: ')); //TODO: ml
$row[] = $output->FormSelectMultiple('attributes[timeoutstageid]', $data, 0, 1, $item['attributes']['timeoutstageid']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Stage on enexpected error.
$row = Array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Stage on error: ')); //TODO: ml
$row[] = $output->FormSelectMultiple('attributes[errorstageid]', $data, 0, 1, $item['attributes']['errorstageid']);
$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('Update Set'); //TODO
$output->FormEnd();
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* This is a standard function that is called with the results of the
* form supplied by template_admin_modify() to update a current item
* @param 'tid' the id of the template to be updated
* @param 'name' the name of the template to be updated
* @param 'description' the description of the template to be updated
* @param 'template' the actual template
*/
function feproc_admin_updateset($args)
{
// Get parameters from whatever input we need.
list($setid, $name, $description, $startstageid) = pnVarCleanFromInput(
'setid', 'name', 'description', 'startstageid'
);
// User functions of this type can be called by other modules.
extract($args);
// Confirm authorisation code.
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', _FXBADAUTHKEY);
pnRedirect(pnModURL('feproc', 'admin', 'view'));
return true;
}
// Load API.
if (!pnModAPILoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view'));
return true;
}
// TODO: validate parameters.
// The API function is called.
// TODO: success and failure stage IDs.
if(pnModAPIFunc('feproc', 'admin', 'updateset',
array('setid' => $setid,
'name' => $name,
'description' => $description,
'startstageid' => $startstageid)))
{
// Success
pnSessionSetVar('statusmsg', _FXTEMPLATEUPDATED);
}
pnRedirect(pnModURL('feproc', 'admin', 'viewsets'));
// Return
return true;
}
function feproc_admin_deleteset($args)
{
// Get parameters from whatever input we need.
list($setid, $objectid, $confirmation)
= pnVarCleanFromInput('setid', 'objectid', 'confirmation');
// User functions of this type can be called by other modules.
extract($args);
if (!empty($objectid))
{
$id = $objectid;
}
$output = new pnHTML();
// Security check.
if (!pnSecAuthAction(0, 'FEproc::Set', "::$setid", ACCESS_DELETE)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
// Load admin API.
if (!pnModAPILoad('feproc', 'admin'))
{
$output->Text(_FXMODLOADFAILED . ' feproc:admin');
return $output->GetOutput();
}
// Load workflow user API.
if (!pnModAPILoad('feproc', 'user'))
{
$output->Text(_FXMODLOADFAILED . ' feproc:user');
return $output->GetOutput();
}
// The user API function is called.
$item = pnModAPIFunc('feproc', 'user', 'getset', array('setid' => $setid));
if ($item == false) {
$output->Text('Set does not exist');
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.
$output = new pnHTML();
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Title.
$output->Title('Delete Set');
// Add confirmation to output.
$output->ConfirmAction('Delete set' . " '$item[name]'",
pnModURL('feproc', 'admin', 'deleteset'),
'Cancel set delete',
pnModURL('feproc', 'admin', 'viewsets'),
array('setid' => $setid)
);
// 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', 'admin', 'viewsets'));
return true;
}
// The API function is called.
if (pnModAPIFunc('feproc', 'admin', 'deleteset',
array('setid' => $setid))) {
// Success
pnSessionSetVar('statusmsg', 'Set deleted');
}
// 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', 'admin', 'viewsets'));
// Return
return true;
}
/*******************
* STAGES
*******************/
/**
* view set items
*/
function feproc_admin_viewstages()
{
// Get parameters from whatever input we need.
list($startnum, $setid) = pnVarCleanFromInput('startnum', 'setid');
// 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::', '::', ACCESS_EDIT)) {
$output->Text(_FXNOAUTH);
return $output->GetOutput();
}
// Add menu to output.
$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', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
// Load workflow API.
if (!pnModAPILoad('feproc', 'user')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
// 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', 'user', 'getallstages',
array('setid' => $setid,
'startnum' => $startnum,
'numitems' => pnModGetVar('FEproc',
'itemsperpage')));
// Start output table
$output->TableStart('Set Stages', //TODO
array(_FXNAMEID,
_FXDESCRIPTION,
'Type', //TODO
'ID: Success Stage', //TODO
'ID: Failure Stage', //TODO
_FXOPTIONS), 1);
// TODO: handle case of no stages.
if (is_array($items))
{
foreach ($items as $item)
{
$row = array();
// Output whatever we found
$row[] = "$item[stageid]: $item[name]";
$row[] = $item['description'];
$row[] = $item['type'];
if($item['successid'])
{
$row[] = $item['successid'] . ': ' . $item['successname'];
} else {
$row[] = null;
}
if($item['failureid'])
{
$row[] = $item['failureid'] . ': ' . $item['failurename'];
} else {
$row[] = null;
}
// Options for the item
$options = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$options[] = $output->URL(pnModURL('feproc', 'admin', 'modifystage',
array('stageid' => $item['stageid'], 'setid' => $item['setid'])), _FXEDIT);
$options[] = $output->URL(pnModURL('feproc', 'admin', 'deletestage',
array('stageid' => $item['stageid'], 'setid' => $item['setid'])), _FXDELETE);
if ($item['startstage'])
{
$options[] = $output->URL(
pnModAPIFunc('feproc', 'user', 'stageurl',
array('stageid' => $item['stageid'])
), 'Start'
);
$options[] = $output->URL(
pnModAPIFunc('feproc', 'user', 'stageurl',
array('stageid' => $item['stageid'], 'reset' => '1')
), 'Restart'
);
}
$options = join(' | ', $options);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$row[] = $output->Text($options);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->TableAddRow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
}
$output->TableEnd();
// If we are showing just one set, then provide options to create stages.
if ($setid)
{
$output->FormStart(pnModURL('feproc', 'admin', 'newstage', Array('setid' => $setid)));
// TODO: ml constants
$data = Array(
Array('id' => 'display', 'name' => 'display: Display a templated page'),
Array('id' => 'formexpress', 'name' => 'formexpress: FormExpress form'),
//Array('id' => 'form', 'name' => 'form: Custom form'),
Array('id' => 'validate', 'name' => 'validate: Validate form data'),
Array('id' => 'transform', 'name' => 'transform: Transform the data collected so far'),
Array('id' => 'transmit', 'name' => 'transmit: Send or store the data'),
Array('id' => 'redirect', 'name' => 'redirect: Jump to a URL')
);
$output->Text(pnVarPrepForDisplay('Stage type: ')); //TODO: ml
$output->FormSelectMultiple('handlertype', $data, 0, 1, $item['handlerid']);
$output->FormSubmit('New Stage'); //TODO: ml
$output->FormEnd();
}
// Call the pnHTML helper function to produce a pager in case of there
// being many items to display.
$output->Pager($startnum,
pnModAPIFunc('feproc', 'user', 'countstages', Array('setid' => $setid)),
pnModURL('feproc', 'admin', 'viewstages',
array('startnum' => '%%', 'setid' => $setid)),
pnModGetVar('FEproc', 'itemsperpage'));
$modinfo = pnModGetInfo(pnModGetIDFromName('feproc'));
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* add new stage item
* This is a standard function that is called whenever an administrator
* wishes to create a new module item
*/
function feproc_admin_newstage()
{
if (!pnModAPILoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
// Handlers user API
if (!pnModAPILoad('feproc', 'handleruser')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
list($setid, $type) = pnVarCleanFromInput('setid', 'handlertype');
// Create output object.
$output = new pnHTML();
// Security check.
if (!pnSecAuthAction(0, 'FEproc::Stage', '::', 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.
$output->Title(_FXADDTEMPLATE);
// Start form.
$output->FormStart(pnModURL('feproc', 'admin', 'createstage'));
// Add an authorisation ID.
$output->FormHidden('authid', pnSecGenAuthKey());
$output->FormHidden('handlertype', $type);
$output->FormHidden('setid', $setid);
// Start the table that holds the information to be input.
$output->TableStart();
// Handler type (display)
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Handler type')); //TODO
$row[] = $output->Text(pnVarPrepForDisplay($type));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Handler - FormExpress type.
// TODO: get list of forms from FormExpress module.
if ($type == 'formexpress' || $type == 'form')
{
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Form ID')); //TODO
$row[] = $output->FormText('hid', $item['handlerid'], 32, 32);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
} else {
// Handler - drop-down list based on handler type.
// Get the list of handlers.
$data = Array();
if ($handlerlist = pnModAPIFunc(
'feproc', 'handleruser', 'getallhandlers',
array('type' => $type)))
{
foreach ($handlerlist as $handler)
{
$data[] = Array(
'id' => $handler['hid'],
'name' => $handler['modulename'] . ': ' . $handler['name']
);
}
} else {
$data[] = Array('hid' => '0', 'name' => _FXHANDLERNONE);
}
// Handler
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Handler Name')); //TODO
$row[] = $output->FormSelectMultiple('hid', $data, 0, 1, $item['handlerid']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
// Name
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXNAME));
$row[] = $output->FormText('name', 'Stage name', 32, 64); //TODO
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Description
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXDESCRIPTION));
$row[] = $output->FormText('description', 'Stage Description', 64, 255);
$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('Add Stage'); //TODO
$output->FormEnd();
// Return the output that has been generated by this function
return $output->GetOutput();
}
/**
* This is a standard function that is called with the results of the
* form supplied by template_admin_new() to create a new item
* @param 'name' the name of the item to be created TODO
* @param 'number' the number of the item to be created TODO
*/
function feproc_admin_createstage($args)
{
// Get parameters.
list($setid, $handlertype, $hid, $name, $description) = pnVarCleanFromInput(
'setid', 'handlertype', 'hid', 'name', 'description'
);
extract($args);
// Confirm authorisation code.
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', _FXBADAUTHKEY);
pnRedirect(pnModURL('feproc', 'admin', 'view'));
return true;
}
// Load API.
if (!pnModAPILoad('feproc', 'admin')) {
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view'));
return true;
}
// TODO: validate parameters.
// ...
// The API function is called.
$stageid = pnModAPIFunc('feproc', 'admin', 'createstage',
array(
'setid' => $setid,
'name' => $name,
'description' => $description,
'handlertype' => $handlertype,
'hid' => $hid
)
);
// The return value of the function is checked here, and if the function
// suceeded then an appropriate message is posted. Note that if the
// function did not succeed then the API function should have already
// posted a failure message so no action is required.
if ($stageid != false) {
// Success
pnSessionSetVar('statusmsg', "Stage Created"); //TODO
pnRedirect(pnModURL('feproc', 'admin', 'modifystage', Array('setid' => $setid, 'stageid' => $stageid)));
return true;
} else {
pnSessionSetVar('statusmsg', "Could not create stage"); //TODO
pnRedirect(pnModURL('feproc', 'admin', 'modifyset', Array('setid' => $setid)));
}
// Return
return true;
}
/**
* modify a stage item
* This is a standard function that is called whenever an administrator
* wishes to modify a current module item
* @param 'stageid' the id of the item to be modified
* @param 'setid' the id of the set the item is in
*/
function feproc_admin_modifystage($args)
{
// Get parameters from whatever input we need.
list($stageid, $setid) = pnVarCleanFromInput('stageid', 'setid');
extract($args);
// Create output object.
$output = new pnHTML();
// Security check.
if (!pnSecAuthAction(0, 'FEproc::Stage', "::$stageid", ACCESS_EDIT))
{
pnSessionSetVar('errormsg', _FXNOAUTH);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
/*
// Load admin API.
if (!pnModAPILoad('feproc', 'admin'))
{
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
// Load workflow user API.
if (!pnModAPILoad('feproc', 'user'))
{
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
// Load handler user API.
if (!pnModAPILoad('feproc', 'handleruser'))
{
pnSessionSetVar('errormsg', _FXMODLOADFAILED);
pnRedirect(pnModURL('feproc', 'admin', 'view')); // TODO
return true;
}
*/
// The API function is called.
$item = pnModAPIFunc('feproc', 'user', 'getstage', array('stageid' => $stageid));
// TODO: better error
if (! $item)
{
$output->Text('Stage does not exist');
return $output->GetOutput();
}
// Add menu to output.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->Text(feproc_adminmenu());
$output->SetInputMode(_PNH_PARSEINPUT);
// Page title.
$output->Title("Modify Stage"); //TODO
// Start form.
$output->FormStart(pnModURL('feproc', 'admin', 'updatestage'));
// Add an authorisation ID.
$output->FormHidden('authid', pnSecGenAuthKey());
// Add a hidden variable for the item id.
$output->FormHidden('setid', pnVarPrepForDisplay($setid));
$output->FormHidden('stageid', pnVarPrepForDisplay($stageid));
// Start the table that holds the information to be input.
$output->TableStart();
// Handler type (display only - not a form item)
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay("Handler Type")); //TODO
$row[] = $output->Text(pnVarPrepForDisplay($item['type']));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Handler ID - Form or FormExpress type.
$handler = false;
if ($item['type'] == 'form' || $item['type'] == 'formexpress')
{
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Form ID')); //TODO
$row[] = $output->FormText('hid', $item['handlerid'], 32, 32);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
} else {
// Handler - just display the name (cannot change as the attributes may be
// different for a different handler).
if ($handler = pnModAPIFunc(
'feproc', 'handleruser', 'gethandler',
array('hid' => $item['handlerid'])))
{
// Handler
$handlerhelpurl = pnModURL('feproc', 'handleradmin', 'helphandler', array('hid' => $item['handlerid']));
$output->SetInputMode(_PNH_VERBATIMINPUT);
$row = array(
pnVarPrepForDisplay('Handler Name'), //TODO
'<a target="_new" href="'.$handlerhelpurl.'">'.pnVarPrepForDisplay($handler['name']).'</a>'
);
$output->SetInputMode(_PNH_PARSEINPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
$row = array(
pnVarPrepForDisplay('Handler Source'), //TODO
pnVarPrepForDisplay($handler['source'])
);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
}
// Name
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXNAME));
$row[] = $output->FormText('name', $item['name'], 32, 64);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Description
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay(_FXDESCRIPTION));
$row[] = $output->FormText('description', $item['description'], 64, 200);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Secure stage
if ($item['type'] == 'form' || $item['type'] == 'formexpress'
|| $item['type'] == 'redirect' || $item['type'] == 'display')
{
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Secure stage (https)')); //TODO: ml
$row[] = $output->FormCheckbox('secure', $item['secure']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
// Starting stage stage
// If this is the default starting stage, then don't allow option to be turned off.
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Starting stage')); //TODO: ml
if ($item['startstage'] == 2)
{
$row[] = $output->Text('Default set starting stage');
$row[] = $output->FormHidden('startstage', $item['startstage']);
} else {
$row[] = $output->FormCheckbox('startstage', $item['startstage']);
}
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
// Next stage on success.
$stages = pnModAPIFunc('feproc', 'user', 'getallstages',
array('setid' => $setid));
if (is_array($stages))
{
$data = Array();
$data[] = Array('id' => '', 'name' => '- None -');
$row = Array();
foreach ($stages as $stage)
{
if ($stage['stageid'] != $item['stageid'])
{
$data[] = Array('id' => $stage['stageid'], 'name' => "$stage[stageid]: $stage[name]");
}
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Stage on success: ')); //TODO: ml
$row[] = $output->FormSelectMultiple('successid', $data, 0, 1, $item['successid']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
// Next stage on failure.
if (is_array($stages))
{
$data = Array();
$data[] = Array('id' => '', 'name' => '- None -');
$row = Array();
foreach ($stages as $stage)
{
if ($stage['stageid'] != $item['stageid'])
{
$data[] = Array('id' => $stage['stageid'], 'name' => "$stage[stageid]: $stage[name]");
}
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay('Stage on failure: ')); //TODO: ml
$row[] = $output->FormSelectMultiple('failureid', $data, 0, 1, $item['failureid']);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow($row, 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
}
// TODO: the attributes.
//var_dump($handler);
if ($handler && is_array($handler['attributes']))
{
// Blank table row.
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->TableAddrow(array('<hr/>', NULL), 'left');
$output->SetInputMode(_PNH_PARSEINPUT);
foreach ($handler['attributes'] as $key => $attribute)
{
// TODO: don't treat everything as a text item! => $attribute['type']
// TODO: checkbox type (0/1).
$row = array();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$row[] = $output->Text(pnVarPrepForDisplay($attribute['description'] . ' {attribute:' .$key. '}'));
if ($attribute['type'] == 'text')
{
// Multi-line text item.
$row[] = $output->FormTextArea("attributes[$key]", $item['attributes'][$key],
pnModGetVar('FEproc', 'attrtextrows'), pnModGetVar('FEproc', 'attrtextcols'));
} elseif ($attribute['type'] == 'list')
{
// Selection list.
$list = array();
foreach($attribute['list'] as $listitem)
{
$list[] = Array('id' => $listitem, 'name' => $listitem);
}
$row[] = $output->FormSelectMultiple("attributes[$key]", $list, 0, 1, $item['attributes'][$key]);