1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000-2016 XOOPS.org // |
6
|
|
|
// <https://xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
// Author: XOOPS Foundation // |
28
|
|
|
// URL: https://xoops.org/ // |
29
|
|
|
// Project: XOOPS Project // |
30
|
|
|
// ------------------------------------------------------------------------- // |
31
|
|
|
|
32
|
|
|
use Xmf\Request; |
|
|
|
|
33
|
|
|
use XoopsModules\Newbb; |
34
|
|
|
|
35
|
|
|
include_once __DIR__ . '/admin_header.php'; |
36
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
37
|
|
|
if (!class_exists('XoopsGroupPermForm')) { |
38
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopsform/grouppermform.php'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* TODO: synchronize cascade permissions for multi-level |
43
|
|
|
*/ |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add category navigation to forum casscade structure |
47
|
|
|
* <ol>Special points: |
48
|
|
|
* <li> Use negative values for category IDs to avoid conflict between category and forum |
49
|
|
|
* <li> Disabled checkbox for categories to avoid unnecessary permission items for categories in forum permission table |
50
|
|
|
* </ol> |
51
|
|
|
* |
52
|
|
|
* Note: this is a __patchy__ solution. We should have a more extensible and flexible group permission management: not only for data architecture but also for management interface |
53
|
|
|
*/ |
54
|
|
|
class NewbbXoopsGroupPermForm extends XoopsGroupPermForm |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* @param $title |
58
|
|
|
* @param $modid |
59
|
|
|
* @param $permname |
60
|
|
|
* @param $permdesc |
61
|
|
|
* @param string $url |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
public function __construct($title, $modid, $permname, $permdesc, $url = '') |
65
|
|
|
{ |
66
|
|
|
parent::__construct($title, $modid, $permname, $permdesc, $url); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $title |
71
|
|
|
* @param $modid |
72
|
|
|
* @param $permname |
73
|
|
|
* @param $permdesc |
74
|
|
|
* @param string $url |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
/* |
|
|
|
|
78
|
|
|
public function newbb_XoopsGroupPermForm($title, $modid, $permname, $permdesc, $url = "") |
79
|
|
|
{ |
80
|
|
|
// $this->XoopsGroupPermForm($title, $modid, $permname, $permdesc, $url); |
81
|
|
|
self::__construct($title, $modid, $permname, $permdesc, $url); |
82
|
|
|
} |
83
|
|
|
*/ |
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function render() |
88
|
|
|
{ |
89
|
|
|
// load all child ids for javascript codes |
90
|
|
|
foreach (array_keys($this->_itemTree) as $item_id) { |
91
|
|
|
$this->_itemTree[$item_id]['allchild'] = []; |
|
|
|
|
92
|
|
|
$this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']); |
93
|
|
|
} |
94
|
|
|
/** @var \XoopsGroupPermHandler $gpermHandler */ |
95
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
96
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
97
|
|
|
$memberHandler = xoops_getHandler('member'); |
98
|
|
|
$glist = $memberHandler->getGroupList(); |
99
|
|
|
foreach (array_keys($glist) as $i) { |
100
|
|
|
// get selected item id(s) for each group |
101
|
|
|
$selected = $gpermHandler->getItemIds($this->_permName, $i, $this->_modid); |
102
|
|
|
$ele = new NewbbXoopsGroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected); |
103
|
|
|
$ele->setOptionTree($this->_itemTree); |
104
|
|
|
$this->addElement($ele); |
105
|
|
|
unset($ele); |
106
|
|
|
} |
107
|
|
|
$tray = new \XoopsFormElementTray(''); |
|
|
|
|
108
|
|
|
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
|
|
|
109
|
|
|
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); |
|
|
|
|
110
|
|
|
$this->addElement($tray); |
111
|
|
|
$ret = '<br><strong>' . $this->getTitle() . '</strong><br>' . $this->_permDesc . '<br>'; |
112
|
|
|
$ret .= "<form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "'" . $this->getExtra() . ">\n<table width='100%' class='outer' cellspacing='1' valign='top'>\n"; |
113
|
|
|
$elements = $this->getElements(); |
114
|
|
|
$hidden = ''; |
115
|
|
|
foreach (array_keys($elements) as $i) { |
116
|
|
|
if (!is_object($elements[$i])) { |
117
|
|
|
$ret .= $elements[$i]; |
118
|
|
|
} elseif (!$elements[$i]->isHidden()) { |
119
|
|
|
$ret .= "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption(); |
120
|
|
|
if ('' !== $elements[$i]->getDescription()) { |
121
|
|
|
$ret .= '<br><br><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>'; |
122
|
|
|
} |
123
|
|
|
$ret .= "</td>\n<td class='even' style='text-align:center;'>\n" . $elements[$i]->render() . "\n</td></tr>\n"; |
124
|
|
|
} else { |
125
|
|
|
$hidden .= $elements[$i]->render(); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
$ret .= "</table>$hidden</form>"; |
129
|
|
|
$ret .= $this->renderValidationJS(true); |
130
|
|
|
|
131
|
|
|
return $ret; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Class NewbbXoopsGroupFormCheckBox |
137
|
|
|
*/ |
138
|
|
|
class NewbbXoopsGroupFormCheckBox extends XoopsGroupFormCheckBox |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
/** |
141
|
|
|
* @param $caption |
142
|
|
|
* @param $name |
143
|
|
|
* @param $groupId |
144
|
|
|
* @param null $values |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
public function __construct($caption, $name, $groupId, $values = null) |
147
|
|
|
{ |
148
|
|
|
parent::__construct($caption, $name, $groupId, $values); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $tree |
153
|
|
|
* @param array $option |
154
|
|
|
* @param string $prefix |
155
|
|
|
* @param array $parentIds |
156
|
|
|
*/ |
157
|
|
|
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []) |
158
|
|
|
{ |
159
|
|
|
if ($option['id'] > 0) { |
160
|
|
|
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="'; |
161
|
|
|
foreach ($parentIds as $pid) { |
162
|
|
|
if ($pid <= 0) { |
163
|
|
|
continue; |
164
|
|
|
} |
165
|
|
|
$parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']'; |
166
|
|
|
$tree .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if (ele.checked !== true) {ele.checked = this.checked;}"; |
167
|
|
|
} |
168
|
|
|
foreach ($option['allchild'] as $cid) { |
169
|
|
|
$child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']'; |
170
|
|
|
$tree .= "var ele = xoopsGetElementById('" . $child_ele . "'); if (this.checked !== true) {ele.checked = false;}"; |
171
|
|
|
} |
172
|
|
|
$tree .= '" value="1"'; |
173
|
|
|
if (in_array($option['id'], $this->_value)) { |
174
|
|
|
$tree .= ' checked'; |
175
|
|
|
} |
176
|
|
|
$tree .= ' />' |
177
|
|
|
. $option['name'] |
178
|
|
|
. '<input type="hidden" name="' |
179
|
|
|
. $this->getName() |
180
|
|
|
. '[parents][' |
181
|
|
|
. $option['id'] |
182
|
|
|
. ']" value="' |
183
|
|
|
. implode(':', $parentIds) |
184
|
|
|
. '" /><input type="hidden" name="' |
185
|
|
|
. $this->getName() |
186
|
|
|
. '[itemname][' |
187
|
|
|
. $option['id'] |
188
|
|
|
. ']" value="' |
189
|
|
|
. htmlspecialchars($option['name']) |
190
|
|
|
. "\" /><br>\n"; |
191
|
|
|
} else { |
192
|
|
|
$tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\" /><br>\n"; |
193
|
|
|
} |
194
|
|
|
if (isset($option['children'])) { |
195
|
|
|
foreach ($option['children'] as $child) { |
196
|
|
|
if ($option['id'] > 0) { |
197
|
|
|
// array_push($parentIds, $option['id']); |
|
|
|
|
198
|
|
|
$parentIds[] = $option['id']; |
199
|
|
|
} |
200
|
|
|
$this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . ' -', $parentIds); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
//$action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : ""; |
|
|
|
|
207
|
|
|
$action = strtolower(Request::getCmd('action', '')); |
208
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
209
|
|
|
/** var Newbb\PermissionHandler $newbbpermHandler */ |
210
|
|
|
$newbbpermHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
211
|
|
|
$perms = $newbbpermHandler->getValidForumPerms(); |
212
|
|
|
|
213
|
|
|
switch ($action) { |
214
|
|
|
case 'template': |
215
|
|
|
xoops_cp_header(); |
|
|
|
|
216
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
217
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
218
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP_TEMPLAT, 'actionform', 'admin_permissions.php', 'get'); |
|
|
|
|
219
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
|
|
|
|
220
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
221
|
|
|
$op_select->addOptionArray([ |
222
|
|
|
'no' => _SELECT, |
|
|
|
|
223
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
224
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP, |
225
|
|
|
'default' => _AM_NEWBB_PERM_SETBYGROUP |
226
|
|
|
]); |
227
|
|
|
$opform->addElement($op_select); |
228
|
|
|
$opform->display(); |
229
|
|
|
|
230
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
|
|
|
231
|
|
|
$glist = $memberHandler->getGroupList(); |
232
|
|
|
$elements = []; |
233
|
|
|
$perm_template = $newbbpermHandler->getTemplate(); |
234
|
|
|
foreach (array_keys($glist) as $i) { |
235
|
|
|
$selected = !empty($perm_template[$i]) ? array_keys($perm_template[$i]) : []; |
236
|
|
|
$ret_ele = '<tr align="left" valign="top"><td class="head">' . $glist[$i] . '</td>'; |
237
|
|
|
$ret_ele .= '<td class="even">'; |
238
|
|
|
$ret_ele .= '<table class="outer"><tr><td class="odd"><table><tr>'; |
239
|
|
|
$ii = 0; |
240
|
|
|
$option_ids = []; |
241
|
|
|
foreach ($perms as $perm) { |
242
|
|
|
++$ii; |
243
|
|
|
if (0 == $ii % 5) { |
244
|
|
|
$ret_ele .= '</tr><tr>'; |
245
|
|
|
} |
246
|
|
|
$checked = in_array('forum_' . $perm, $selected) ? ' checked' : ''; |
247
|
|
|
$option_id = $perm . '_' . $i; |
248
|
|
|
$option_ids[] = $option_id; |
249
|
|
|
$ret_ele .= '<td><input name="perms[' . $i . '][' . 'forum_' . $perm . ']" id="' . $option_id . '" onclick="" value="1" type="checkbox"' . $checked . '>' . constant('_AM_NEWBB_CAN_' . strtoupper($perm)) . '<br></td>'; |
250
|
|
|
} |
251
|
|
|
$ret_ele .= '</tr></table></td><td class="even">'; |
252
|
|
|
$ret_ele .= _ALL . ' <input id="checkall[' . $i . ']" type="checkbox" value="" onclick="var optionids = new Array(' . implode(', ', $option_ids) . '); xoopsCheckAllElements(optionids, \'checkall[' . $i . ']\')" />'; |
|
|
|
|
253
|
|
|
$ret_ele .= '</td></tr></table>'; |
254
|
|
|
$ret_ele .= '</td></tr>'; |
255
|
|
|
$elements[] = $ret_ele; |
256
|
|
|
} |
257
|
|
|
$tray = new \XoopsFormElementTray(''); |
258
|
|
|
$tray->addElement(new \XoopsFormHidden('action', 'template_save')); |
|
|
|
|
259
|
|
|
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
|
|
|
260
|
|
|
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); |
|
|
|
|
261
|
|
|
$ret = '<br><strong>' . _AM_NEWBB_PERM_TEMPLATE . '</strong><br>' . _AM_NEWBB_PERM_TEMPLATE_DESC . '<br>'; |
262
|
|
|
$ret .= "<form name='template' id='template' method='post'>\n<table width='100%' class='outer' cellspacing='1'>\n"; |
263
|
|
|
$ret .= implode("\n", $elements); |
264
|
|
|
$ret .= '<tr align="left" valign="top"><td class="head"></td><td class="even" style="text-align:center;">'; |
265
|
|
|
$ret .= $tray->render(); |
266
|
|
|
$ret .= '</td></tr>'; |
267
|
|
|
$ret .= '</table></form>'; |
268
|
|
|
echo $ret; |
269
|
|
|
include_once __DIR__ . '/admin_footer.php'; |
270
|
|
|
break; |
271
|
|
|
|
272
|
|
|
case 'template_save': |
273
|
|
|
// $res = $newbbpermHandler->setTemplate($_POST['perms'], $groupid = 0); |
|
|
|
|
274
|
|
|
$res = $newbbpermHandler->setTemplate(Request::getArray('perms', '', 'POST'), $groupid = 0); |
275
|
|
|
if ($res) { |
276
|
|
|
redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_CREATED); |
|
|
|
|
277
|
|
|
} else { |
278
|
|
|
redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE_ERROR); |
279
|
|
|
} |
280
|
|
|
break; |
281
|
|
|
// exit(); |
282
|
|
|
|
283
|
|
|
case 'apply': |
284
|
|
|
$perm_template = $newbbpermHandler->getTemplate(); |
285
|
|
|
if (null === $perm_template) { |
286
|
|
|
redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE); |
287
|
|
|
} |
288
|
|
|
xoops_cp_header(); |
289
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
290
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
291
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP_APPLY, 'actionform', 'admin_permissions.php', 'get'); |
292
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
293
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
294
|
|
|
$op_select->addOptionArray([ |
295
|
|
|
'no' => _SELECT, |
296
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
297
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP |
298
|
|
|
]); |
299
|
|
|
$opform->addElement($op_select); |
300
|
|
|
$opform->display(); |
301
|
|
|
|
302
|
|
|
/** @var Newbb\CategoryHandler $categoryHandler */ |
303
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
304
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
|
|
|
|
305
|
|
|
$criteriaCategory->setSort('cat_order'); |
306
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
307
|
|
|
|
308
|
|
|
/** @var Newbb\ForumHandler $forumHandler */ |
309
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
310
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
311
|
|
|
foreach (array_keys($forums) as $c) { |
312
|
|
|
$fm_options[-1 * $c - 1000] = ' '; |
313
|
|
|
$fm_options[-1 * $c] = '[' . $categories[$c] . ']'; |
314
|
|
|
foreach (array_keys($forums[$c]) as $f) { |
315
|
|
|
$fm_options[$f] = $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name']; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
unset($forums, $categories); |
319
|
|
|
|
320
|
|
|
$fmform = new \XoopsThemeForm(_AM_NEWBB_PERM_TEMPLATEAPP, 'fmform', 'admin_permissions.php', 'post', true); |
|
|
|
|
321
|
|
|
$fm_select = new \XoopsFormSelect(_AM_NEWBB_PERM_FORUMS, 'forums', null, 10, true); |
322
|
|
|
$fm_select->addOptionArray($fm_options); |
323
|
|
|
$fmform->addElement($fm_select); |
324
|
|
|
$tray = new \XoopsFormElementTray(''); |
325
|
|
|
$tray->addElement(new \XoopsFormHidden('action', 'apply_save')); |
326
|
|
|
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
327
|
|
|
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); |
328
|
|
|
$fmform->addElement($tray); |
329
|
|
|
$fmform->display(); |
330
|
|
|
include_once __DIR__ . '/admin_footer.php'; |
331
|
|
|
break; |
332
|
|
|
|
333
|
|
|
case 'apply_save': |
334
|
|
|
if (!Request::getArray('forums', '', 'POST')) { |
335
|
|
|
break; |
336
|
|
|
} |
337
|
|
|
foreach (Request::getArray('forums', '', 'POST') as $forum) { |
338
|
|
|
if ($forum < 1) { |
339
|
|
|
continue; |
340
|
|
|
} |
341
|
|
|
$newbbpermHandler->applyTemplate($forum, $module_id); |
342
|
|
|
} |
343
|
|
|
$cacheHelper = Newbb\Utility::cleanCache(); |
|
|
|
|
344
|
|
|
//$cacheHelper->delete('permission'); |
|
|
|
|
345
|
|
|
redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_APPLIED); |
346
|
|
|
break; |
347
|
|
|
|
348
|
|
|
default: |
349
|
|
|
xoops_cp_header(); |
350
|
|
|
|
351
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
352
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
353
|
|
|
$criteriaCategory->setSort('cat_order'); |
354
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
355
|
|
|
|
356
|
|
|
if (0 === count($categories)) { |
357
|
|
|
redirect_header('admin_cat_manager.php', 2, _AM_NEWBB_CREATENEWCATEGORY); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
361
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
362
|
|
|
|
363
|
|
|
if (0 === count($forums)) { |
364
|
|
|
redirect_header('admin_forum_manager.php', 2, _AM_NEWBB_CREATENEWFORUM); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
368
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
369
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP, 'actionform', 'admin_permissions.php', 'get'); |
370
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
371
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
372
|
|
|
$op_select->addOptionArray([ |
373
|
|
|
'no' => _SELECT, |
374
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
375
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP, |
376
|
|
|
'default' => _AM_NEWBB_PERM_SETBYGROUP |
377
|
|
|
]); |
378
|
|
|
$opform->addElement($op_select); |
379
|
|
|
$opform->display(); |
380
|
|
|
|
381
|
|
|
$op_options = ['category' => _AM_NEWBB_CAT_ACCESS]; |
382
|
|
|
$fm_options = [ |
383
|
|
|
'category' => [ |
384
|
|
|
'title' => _AM_NEWBB_CAT_ACCESS, |
385
|
|
|
'item' => 'category_access', |
386
|
|
|
'desc' => '', |
387
|
|
|
'anonymous' => true |
388
|
|
|
] |
389
|
|
|
]; |
390
|
|
|
foreach ($perms as $perm) { |
391
|
|
|
$op_options[$perm] = constant('_AM_NEWBB_CAN_' . strtoupper($perm)); |
392
|
|
|
$fm_options[$perm] = [ |
393
|
|
|
'title' => constant('_AM_NEWBB_CAN_' . strtoupper($perm)), |
394
|
|
|
'item' => 'forum_' . $perm, |
395
|
|
|
'desc' => '', |
396
|
|
|
'anonymous' => true |
397
|
|
|
]; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
$op_keys = array_keys($op_options); |
401
|
|
|
$op = strtolower(Request::getCmd('op', Request::getCmd('op', '', 'COOKIE'), 'GET')); |
402
|
|
|
if (empty($op)) { |
403
|
|
|
$op = $op_keys[0]; |
404
|
|
|
setcookie('op', isset($op_keys[1]) ? $op_keys[1] : ''); |
405
|
|
|
} elseif (false !== ($key = array_search($op, $op_keys))) { |
406
|
|
|
setcookie('op', isset($op_keys[$key + 1]) ? $op_keys[$key + 1] : ''); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
$opform = new \XoopsSimpleForm('', 'opform', 'admin_permissions.php', 'get'); |
410
|
|
|
$op_select = new \XoopsFormSelect('', 'op', $op); |
411
|
|
|
$op_select->setExtra('onchange="document.forms.opform.submit()"'); |
412
|
|
|
$op_select->addOptionArray($op_options); |
413
|
|
|
$opform->addElement($op_select); |
414
|
|
|
$opform->display(); |
415
|
|
|
|
416
|
|
|
$perm_desc = ''; |
417
|
|
|
|
418
|
|
|
$form = new NewbbXoopsGroupPermForm($fm_options[$op]['title'], $module_id, $fm_options[$op]['item'], $fm_options[$op]['desc'], 'admin/admin_permissions.php', $fm_options[$op]['anonymous']); |
|
|
|
|
419
|
|
|
|
420
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
421
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
422
|
|
|
$criteriaCategory->setSort('cat_order'); |
423
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
424
|
|
|
if ('category' === $op) { |
425
|
|
|
foreach (array_keys($categories) as $key) { |
426
|
|
|
$form->addItem($key, $categories[$key]); |
427
|
|
|
} |
428
|
|
|
unset($categories); |
429
|
|
|
} else { |
430
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
431
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
432
|
|
|
if (count($forums) > 0) { |
433
|
|
|
foreach (array_keys($forums) as $c) { |
434
|
|
|
$key_c = -1 * $c; |
435
|
|
|
$form->addItem($key_c, '<strong>[' . $categories[$c] . ']</strong>'); |
436
|
|
|
foreach (array_keys($forums[$c]) as $f) { |
437
|
|
|
$pid = $forums[$c][$f]['parent_forum'] ?: $key_c; |
438
|
|
|
$form->addItem($f, $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name'], $pid); |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
unset($forums, $categories); |
443
|
|
|
} |
444
|
|
|
$form->display(); |
445
|
|
|
echo '<fieldset>'; |
446
|
|
|
echo '<legend> ' . _MI_NEWBB_ADMENU_PERMISSION . ' </legend>'; |
447
|
|
|
echo _AM_NEWBB_HELP_PERMISSION_TAB; |
448
|
|
|
echo '</fieldset>'; |
449
|
|
|
// Since we can not control the permission update, a trick is used here |
450
|
|
|
/** var Newbb\PermissionHandler $permissionHandler */ |
451
|
|
|
$permissionHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
452
|
|
|
$permissionHandler->createPermData(); |
453
|
|
|
$cacheHelper = Newbb\Utility::cleanCache(); |
|
|
|
|
454
|
|
|
//$cacheHelper->delete('permission'); |
|
|
|
|
455
|
|
|
include_once __DIR__ . '/admin_footer.php'; |
456
|
|
|
break; |
457
|
|
|
} |
458
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.