-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnadminapi.php
418 lines (355 loc) · 13.1 KB
/
pnadminapi.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
<?php
/**
* FEproc - Mail template backend module for FormExpress for
* Zikula Content Management System
*
* @copyrightt (C) 2002 by Jason Judge, 2011 Chris Candreva
* @Version $Id: tables.php 84 2011-05-27 18:19:28Z ccandreva $
* @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 <[email protected]>
* ----------------------------------------------------------------------
*
*/
/*******************
* SETS
*******************/
/**
* create a new set item TODO
* @param $args['name'] name of the template
* @param $args['description'] description of the template
* @returns int
* @return set item ID on success, false on failure
*/
function feproc_adminapi_createset($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError();
}
// Get arguments from argument array.
extract($args);
// Argument check.
if (!isset($name) || !isset($description)) {
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
$obj = array ('name' => $name, 'description' => $description, 'type' => 'set');
DBUtil::insertObject($obj, 'feproc_workflow');
$setid = $obj['id'];
// We don't have the object ID until after it is created,
// so we need to update the setid with the object id.
$obj['setid'] = $setid;
DBUtil::updateObject($obj, 'feproc_workflow');
// Let any hooks know that we have created a new set.
pnModCallHooks('item', 'createset', $setid, 'setid');
return $setid;
}
/**
* update a set item
* @param $args['hid'] the ID of the item
* @param $args['name'] the new name of the item
* @param $args['description'] the new description of the item
* @param $args['...'] the actual template
* TODO: complete parameter list
*/
function feproc_adminapi_updateset($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
// Get arguments from argument array.
extract($args);
// Argument check.
// TODO: success and failure stage IDs
if (!isset($setid) || !isset($name) || !isset($description)) {
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
/*
// The API function is called.
$item = pnModAPIFunc('feproc', 'user', 'getset',
array('setid' => $setid)
);
if ($item == false) {
pnSessionSetVar('errormsg', 'No such set'); // TODO: what next?
return false;
}
*/
$wftable = $pntable['feproc_workflow'];
$wfcolumn = &$pntable['feproc_workflow_column'];
// Update the item
$obj = array('id' => $setid, 'name' => $name, 'description' => $description,
'successid' => $startstageid);
DBUtil::updateObject($obj, 'feproc_workflow');
/*
// Now make sure the start stages are set if appropriate.
if ($startstageid > 0)
{
// Set the start stage.
$sql = "UPDATE $wftable
SET $wfcolumn[startstage] = 2
WHERE $wfcolumn[setid] = " . pnVarPrepForStore($setid) . "
AND $wfcolumn[id] = " . pnVarPrepForStore($startstageid) . "
AND $wfcolumn[startstage] <> 2";
$result = DBUtil::executeSQL($sql);
// Reset the non-default start stages.
$sql = "UPDATE $wftable
SET $wfcolumn[startstage] = 1
WHERE $wfcolumn[setid] = " . pnVarPrepForStore($setid) . "
AND $wfcolumn[id] <> " . pnVarPrepForStore($setid) . "
AND $wfcolumn[id] <> " . pnVarPrepForStore($startstageid) . "
AND $wfcolumn[startstage] = 2";
$result = DBUtil::executeSQL($sql);
}
*/
// Let the calling process know that we have finished successfully
return true;
}
/**
* delete a feproc handler item
* @param $args['hid'] ID of the item
* @returns bool
* @return true on success, false on failure
* TODO: don't allow a delete if the handler is being used by any workflow set stages.
*/
function feproc_adminapi_deleteset($args)
{
// Get arguments from argument array.
extract($args);
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_DELETE)) {
return LogUtil::registerPermissionError();
}
// Argument check.
if (!isset($setid)) {
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
// Check if there are any stages that have not been deleted yet.
$stages = pnModAPIFunc('feproc', 'user', 'getallstages',
array('setid' => $setid));
if (is_array($stages))
{
pnSessionSetVar('errormsg', __("You must delete all stages before the set can be deleted.") );
pnRedirect(pnModURL('feproc', 'admin', 'viewsets', array('setid' => $setid)));
return true;
}
// Get datbase setup.
DBUtil::deleteObjectByID('feproc_workflow', $setid);
// Let any hooks know that we have deleted an item.
// TODO: distinguish between different types of item.
pnModCallHooks('item', 'deleteset', $setid, 'setid');
// Let the calling process know that we have finished successfully
return true;
}
/*******************
* STAGES
*******************/
/**
* create a new stage item
* @param $args['name'] name of the template
* @param $args['description'] description of the template
* TODO...
* @returns int
* @return stage item ID on success, false on failure
*/
function feproc_adminapi_createstage($args)
{
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError();
}
// Get arguments from argument array.
extract($args);
// Argument check.
if (!isset($name) ||
!isset($description) ||
!isset($handlertype) ||
!isset($setid) ||
!isset($hid))
{
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
if (!isset($secure))
{
$secure = 0;
}
if (!isset($startstage))
{
$startstage = 0;
}
if (!is_numeric($startstage) || $startstage < 0 || $startstage > 2)
{
$startstage = 0;
}
// TODO: create default attributes for the stage.
// The attributes come from the handler details.
// Get the handler.
$sattributes = false;
if ($handlertype <> 'formexpress' && $handlertype <> 'form')
{
if ($handler = pnModAPIFunc(
'feproc', 'handleruser', 'gethandler',
array('hid' => $hid)))
{
if (is_array($handler['attributes']))
{
$sattributes = array();
foreach ($handler['attributes'] as $key => $attribute)
{
$sattributes[$key] = $attribute['default'];
}
}
}
}
$sattributes = serialize($sattributes);
// Add item.
$obj = array(
'name' => $name,
'description' => $description,
'type' => $handlertype,
'setid' => $setid,
'handlerid' => $hid,
'secure' => $secure,
'startstage' => $startstage,
'attributes' => $sattributes,
);
$result = DBUtil::insertObject($obj, 'feproc_workflow');
// Check for an error with the database code, and if so set an
// appropriate error message and return
if (!$result) {
pnSessionSetVar('errormsg', _FXCREATEFAILED . ' ' . $sql);
return false;
}
// Get the ID of the item that we inserted.
$stageid = $obj['id'];
// Let any hooks know that we have created a new item.
// TODO: this is not a standard item
pnModCallHooks('item', 'createstage', $stageid, 'stageid');
// Return the id of the newly created item to the calling process
return $stageid;
}
/**
* update a template item
* @param $args['hid'] the ID of the item
* @param $args['name'] the new name of the item
* @param $args['description'] the new description of the item
* @param $args['...'] the actual template
* TODO: complete parameter list
*/
function feproc_adminapi_updatestage($args)
{
// For now we'll use a pointer, use the object as passed in.
$obj = &$args;
// Argument check.
if (!isset($obj['id']) ||
!isset($obj['name']) ||
!isset($obj['description']) )
{
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
$startstage = &$obj['startstage'];
$stageid = &$obj['id'];
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', "$stageid::", ACCESS_EDIT)) {
return LogUtil::registerPermissionError();
}
if (!is_numeric($startstage) || $startstage < 0 || $startstage > 2)
{
$startstage = 0;
}
// The API function is called.
$item = pnModAPIFunc('feproc', 'user', 'getstage', array('stageid' => $stageid) );
if ($item == false)
{
pnSessionSetVar('errormsg', __('No such stage'));
return false;
}
// The attributes will be an array.
if ( isset($obj['attributes']) && is_array($obj['attributes']))
{
$sattributes = serialize($obj['attributes']);
} else {
$sattributes = serialize(false);
}
$obj['attributes'] = $sattributes;
$result = DBUtil::updateObject($obj, 'feproc_workflow');
// Let the calling process know that we have finished successfully
return $result;
}
/**
* delete a feproc handler item
* @param $args['hid'] ID of the item
* @returns bool
* @return true on success, false on failure
* TODO: don't allow a delete if the handler is being used by any workflow set stages.
*/
function feproc_adminapi_deletestage($args)
{
// Get arguments from argument array.
extract($args);
// Argument check.
if (!isset($stageid) || !isset($setid)) {
pnSessionSetVar('errormsg', _FXMODARGSERROR);
return false;
}
// Early security check.
if (!SecurityUtil::checkPermission ('FEproc::', "$stageid::", ACCESS_DELETE)) {
return LogUtil::registerPermissionError();
}
$item = pnModAPIFunc('feproc', 'user', 'getstage',
array('stageid' => $stageid));
if ($item == false) {
pnSessionSetVar('errormsg', "Stage $stageid does not exist");
return false;
}
DBUtil::deleteObjectById('feproc_workflow', $stageid);
$table = pnDBGetTables();
$wfcolumn = $table['feproc_workflow_column'];
// Update any other stages that point to the deleted item (so there are no
// dead-ends).
DBUtil::UpdateObject( array('successid' => 0),'feproc_workflow',
$wfcolumn[successid] . ' = ' . $stageid);
DBUtil::UpdateObject( array('failureid' => 0),'feproc_workflow',
$wfcolumn[failureid] . ' = ' . $stageid);
// Let any hooks know that we have deleted an item.
// TODO: distinguish between different types of item.
pnModCallHooks('item', 'deletestage', $stageid, 'stageid');
// Let the calling process know that we have finished successfully
return true;
}
function feproc_adminapi_getlinks()
{
$dom = ZLanguage::getModuleDomain('feproc');
return array(
array('url' => pnModURL('FEproc', 'admin', 'viewsets'), 'text' => __('Show Sets', $dom), 'id' => 'show_sets'),
array('url' => pnModURL('FEproc', 'admin', 'newset'), 'text' => __('New Set', $dom), 'id' => 'new_set'),
array('url' => pnModURL('FEproc', 'handleradmin', 'view'), 'text' => __('Show handlers', $dom), 'id' => 'show_handlers'),
array('url' => pnModURL('FEproc', 'handleradmin', 'new'), 'text' => __('Import handlers', $dom), 'id' => 'import_handlers'),
array('url' => pnModURL('FEproc', 'admin', 'modifyconfig'), 'text' => __('Configuration', $dom), 'id' => 'configuration'),
array('url' => 'modules/feproc/docs/help.html', 'text' => __('Help', $dom), 'id' => 'help'),
);
}
?>