-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnadmin.php
441 lines (376 loc) · 17.5 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
<?php
/**
* Zikula Application Framework
*
* @copyright (c) 2002, Zikula Development Team
* @link http://www.zikula.org
* @version $Id$
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_System_Modules
* @subpackage Admin_Messages
* @license http://www.gnu.org/copyleft/gpl.html
*/
/**
* the main administration function
* This function is the default function, and is called whenever the
* module is initiated without defining arguments. As such it can
* be used for a number of things, but most commonly it either just
* shows the module menu and returns or calls whatever the module
* designer feels should be the default function (often this is the
* view() function)
* @author Mark West
* @return string HTML output string
*/
function Admin_Messages_admin_main()
{
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError ();
}
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_main.htm');
}
/**
* add a new admin message
* This is a standard function that is called whenever an administrator
* wishes to create a new module item
* @author Mark West
* @return string HTML output string
*/
function Admin_Messages_admin_new()
{
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError ();
}
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// Assign the default language
$view->assign('language', ZLanguage::getLanguageCode());
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_new.htm');
}
/**
* This is a standard function that is called with the results of the
* form supplied by Admin_Messages_admin_new() to create a new item
* @author Mark West
* @see Admin_Messages_admin_new()
* @param string $args['title'] the title of the admin message
* @param string $args['content'] the text of the admin message
* @param string $args['language'] the language of the admin message
* @param int $args['active'] active status of the admin message
* @param int $args['expire'] the expiry date of the message
* @param int $args['view'] who can view the message
* @return bool true if creation successful, false otherwiise
*/
function Admin_Messages_admin_create($args)
{
$message = FormUtil::getPassedValue('message', isset($args['message']) ? $args['message'] : null, 'POST');
// Confirm authorisation code.
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError();
}
// Notable by its absence there is no security check here.
// Create the admin message
$mid = ModUtil::apiFunc('Admin_Messages', 'admin', 'create',
array('title' => $message['title'],
'content' => $message['content'],
'language' => isset($message['language']) ? $message['language'] : '',
'active' => $message['active'],
'expire' => $message['expire'],
'view' => $message['view']));
// The return value of the function is checked
if ($mid != false) {
// Success
LogUtil::registerStatus(__('Done! Created administrator message.'));
}
// 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
return System::redirect(ModUtil::url('Admin_Messages', 'admin', 'view'));
}
/**
* modify an Admin Message
* This is a standard function that is called whenever an administrator
* wishes to modify a current module item
* @author Mark West
* @param int $args['mid'] the id of the admin message to modify
* @param int $args['objectid'] generic object id maps to mid if present
* @return string HTML output string
*/
function Admin_Messages_admin_modify($args)
{
$mid = FormUtil::getPassedValue('mid', isset($args['mid']) ? $args['mid'] : null, 'GET');
$objectid = FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'GET');
if (!empty($objectid)) {
$mid = $objectid;
}
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// Get the admin message
$item = ModUtil::apiFunc('Admin_Messages', 'user', 'get', array('mid' => $mid));
if ($item == false) {
return LogUtil::registerError(__('Sorry! No such administrator message found.'), 404);
}
// Security check.
if (!SecurityUtil::checkPermission('Admin_Messages::item', "$item[title]::$mid", ACCESS_EDIT)) {
return LogUtil::registerPermissionError ();
}
// Assign the item
$view->assign($item);
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_modify.htm');
}
/**
* This is a standard function that is called with the results of the
* form supplied by Admin_Messages_admin_modify() to update a current item
* @author Mark West
* @see Admin_Messages_admin_modify()
* @param int $args['mid'] the id of the admin message to update
* @param int $args['objectid'] generic object id maps to mid if present
* @param string $args['title'] the title of the admin message
* @param string $args['content'] the text of the admin message
* @param string $args['language'] the language of the admin message
* @param int $args['active'] active status of the admin message
* @param int $args['expire'] the expiry date of the message
* @param int $args['view'] who can view the message
* @return bool true if successful, false otherwise
*/
function Admin_Messages_admin_update($args)
{
$message = FormUtil::getPassedValue('message', isset($args['message']) ? $args['message'] : null, 'POST');
if (!empty($message['objectid'])) {
$message['mid'] = $message['objectid'];
}
// Confirm authorisation code.
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError();
}
// Notable by its absence there is no security check here.
// Update the admin message
if (ModUtil::apiFunc('Admin_Messages', 'admin', 'update',
array('mid' => $message['mid'],
'title' => $message['title'],
'content' => $message['content'],
'language' => isset($message['language']) ? $message['language'] : '',
'active' => $message['active'],
'expire' => $message['expire'],
'oldtime' => $message['oldtime'],
'changestartday' => $message['changestartday'],
'view' => $message['view']))) {
// Success
LogUtil::registerStatus(__('Done! Saved administrator message.'));
}
// 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
return System::redirect(ModUtil::url('Admin_Messages', 'admin', 'view'));
}
/**
* delete item
* This is a standard function that is called whenever an administrator
* wishes to delete a current module item. Note that this function is
* the equivalent of both of the modify() and update() functions above as
* it both creates a form and processes its output. This is fine for
* simpler functions, but for more complex operations such as creation and
* modification it is generally easier to separate them into separate
* functions. There is no requirement in the Zikula MDG to do one or the
* other, so either or both can be used as seen appropriate by the module
* developer
* @author Mark West
* @param int $args['mid'] the id of the admin message to delete
* @param int $args['objectid'] generic object id maps to mid if present
* @param bool $args['confirmation'] confirmation of the deletion
* @return mixed HTML output string if no confirmation, true if succesful, false otherwise
*/
function Admin_Messages_admin_delete($args)
{
$mid = FormUtil::getPassedValue('mid', isset($args['mid']) ? $args['mid'] : null, 'REQUEST');
$objectid = FormUtil::getPassedValue('objectid', isset($args['objectid']) ? $args['objectid'] : null, 'REQUEST');
$confirmation = FormUtil::getPassedValue('confirmation', null, 'POST');
if (!empty($objectid)) {
$mid = $objectid;
}
// Get the existing admin message
$item = ModUtil::apiFunc('Admin_Messages', 'user', 'get', array('mid' => $mid));
if ($item == false) {
return LogUtil::registerError(__('Sorry! No such administrator message found.'), 404);
}
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$mid", ACCESS_DELETE)) {
return LogUtil::registerPermissionError ();
}
// Check for confirmation.
if (empty($confirmation)) {
// No confirmation yet
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// Add the message id
$view->assign('mid', $mid);
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_delete.htm');
}
// If we get here it means that the user has confirmed the action
// Confirm authorisation code.
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError(ModUtil::url('Admin_Messages', 'admin', 'view'));
}
// Delete the admin message
// The return value of the function is checked
if (ModUtil::apiFunc('Admin_Messages', 'admin', 'delete',
array('mid' => $mid))) {
// Success
LogUtil::registerStatus(__('Done! Deleted administrator message.'));
}
// 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
return System::redirect(ModUtil::url('Admin_Messages', 'admin', 'view'));
}
/**
* view items
* @author Mark West
* @param int $startnum the start item id for the pager
* @return string HTML output string
*/
function Admin_Messages_admin_view()
{
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_EDIT)) {
return LogUtil::registerPermissionError ();
}
$startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GET');
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// The user 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 = ModUtil::apiFunc('Admin_Messages', 'user', 'getall',
array('startnum' => $startnum,
'numitems' => ModUtil::getVar('Admin_Messages', 'itemsperpage')));
if (!$items)
$items = array();
$rows = array();
foreach ($items as $item) {
if (SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$item[mid]", ACCESS_READ)) {
$fullitem = ModUtil::apiFunc('Admin_Messages', 'user', 'get',
array('mid' => $item['mid']));
if ($fullitem['language'] == '') {
$fullitem['language'] = __('All');
}
$row[] = $fullitem['language'];
if (!isset($fullitem['view'])) $fullitem['view'] = __('All visitors');
switch ($fullitem['view']) {
case '1':
$fullitem['view'] = __('All visitors');
break;
case '2':
$fullitem['view'] = __('Registered users only');
break;
case '3':
$fullitem['view'] = __('Anonymous guests only');
break;
case '4':
$fullitem['view'] = __('Administrators only');
break;
}
$row[] = $fullitem['view'];
if ($fullitem['active'] == 1) {
$active = __('Yes');
} else {
$active = __('No');
}
if ($fullitem['expire'] == 0) {
$expire = __('Never');
} else if ($fullitem['expire']/86400 == 1) {
$expire = $fullitem['expire']/86400 . ' ' . __('day');
} else {
$expire = $fullitem['expire']/86400 . ' ' . __('days');
}
if ($fullitem['expire'] == 0) {
$expiredate = __('No expiration date');
} else {
$expiredate = ml_ftime(__('%b %d, %Y - %I:%M %p'), $fullitem['date'] + $fullitem['expire']);
}
// Options for the item. Note that each item has the appropriate
// levels of authentication checked to ensure that it is suitable
// for display
$options = array();
if (SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$item[mid]", ACCESS_EDIT)) {
$options[] = array('url' => ModUtil::url('Admin_Messages', 'admin', 'modify', array('mid' => $item['mid'])),
'image' => 'xedit.gif',
'title' => __('Edit'));
if (SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$item[mid]", ACCESS_DELETE)) {
$options[] = array('url' => ModUtil::url('Admin_Messages', 'admin', 'delete', array('mid' => $item['mid'])),
'image' => '14_layer_deletelayer.gif',
'title' => __('Delete'));
}
}
$rows[] = array( 'mid' => $item['mid'],
'title' => $item['title'],
'language' => $fullitem['language'],
'view' => $fullitem['view'],
'active' => $active,
'expire' => $expire,
'expiredate' => $expiredate,
'options' => $options);
}
}
$view->assign('items', $rows);
// Assign the information required to create the pager
$view->assign('pager', array('numitems' => ModUtil::apiFunc('Admin_Messages', 'user', 'countitems'),
'itemsperpage' => ModUtil::getVar('Admin_Messages', 'itemsperpage')));
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_view.htm');
}
/**
* This is a standard function to modify the configuration parameters of the
* module
* @author Mark West
* @return string HTML output string
*/
function Admin_Messages_admin_modifyconfig()
{
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADMIN)) {
return LogUtil::registerPermissionError ();
}
// Create output object
$view = Zikula_View::getInstance('Admin_Messages', false);
// Number of items to display per page
$view->assign(ModUtil::getVar('Admin_Messages'));
// Return the output that has been generated by this function
return $view->fetch('admin_messages_admin_modifyconfig.htm');
}
/**
* This is a standard function to update the configuration parameters of the
* module given the information passed back by the modification form
* @author Mark West
* @see Admin_Messages_admin_modifyconfig()
* @param int $itemsperpage the number messages per page in the admin panel
* @return bool true if successful, false otherwise
*/
function Admin_Messages_admin_updateconfig()
{
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADMIN)) {
return LogUtil::registerPermissionError ();
}
// Confirm authorisation code.
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError(ModUtil::url('Admin_Messages', 'admin', 'view'));
}
// Update module variables.
$itemsperpage = (int)FormUtil::getPassedValue('itemsperpage', 25, 'POST');
if ($itemsperpage < 1) $itemsperpage = 25;
ModUtil::setVar('Admin_Messages', 'itemsperpage', $itemsperpage);
$allowsearchinactive = (bool)FormUtil::getPassedValue('allowsearchinactive', false, 'POST');
ModUtil::setVar('Admin_Messages', 'allowsearchinactive', $allowsearchinactive);
// Let any other modules know that the modules configuration has been updated
ModUtil::callHooks('module','updateconfig','Admin_Messages', array('module' => 'Admin_Messages'));
// the module configuration has been updated successfuly
LogUtil::registerStatus(__('Done! Saved module configuration.'));
// 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
return System::redirect(ModUtil::url('Admin_Messages', 'admin', 'view'));
}