Completed
Branch master (4e8684)
by Michael
05:31 queued 02:57
created

NewbbXoopsGroupFormCheckBox::_renderOptionTree()   C

Complexity

Conditions 9
Paths 12

Size

Total Lines 47
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 36
nc 12
nop 4
dl 0
loc 47
rs 5.2941
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 53 and the first side effect is on line 34.

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.

Loading history...
2
//
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <http://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: http://xoops.org/                                                //
29
// Project: XOOPS Project                                                    //
30
// ------------------------------------------------------------------------- //
31
32
use Xmf\Request;
33
34
include_once __DIR__ . '/admin_header.php';
35
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
36
if (!class_exists('XoopsGroupPermForm')) {
37
    include_once $GLOBALS['xoops']->path('class/xoopsform/grouppermform.php');
38
}
39
40
/**
41
 * TODO: synchronize cascade permissions for multi-level
42
 */
43
44
/**
45
 * Add category navigation to forum casscade structure
46
 * <ol>Special points:
47
 *    <li> Use negative values for category IDs to avoid conflict between category and forum
48
 *    <li> Disabled checkbox for categories to avoid unnecessary permission items for categories in forum permission table
49
 * </ol>
50
 *
51
 * 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
52
 */
53
class NewbbXoopsGroupPermForm extends XoopsGroupPermForm
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
54
{
55
    /**
56
     * @param        $title
57
     * @param        $modid
58
     * @param        $permname
59
     * @param        $permdesc
60
     * @param string $url
61
     */
62
63
    public function __construct($title, $modid, $permname, $permdesc, $url = '')
64
    {
65
        parent::__construct($title, $modid, $permname, $permdesc, $url);
66
    }
67
68
    /**
69
     * @param        $title
70
     * @param        $modid
71
     * @param        $permname
72
     * @param        $permdesc
73
     * @param string $url
74
     */
75
76
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
    public function newbb_XoopsGroupPermForm($title, $modid, $permname, $permdesc, $url = "")
78
    {
79
//        $this->XoopsGroupPermForm($title, $modid, $permname, $permdesc, $url);
80
        self::__construct($title, $modid, $permname, $permdesc, $url);
81
    }
82
*/
83
    /**
84
     * @return string
85
     */
86
    public function render()
87
    {
88
        // load all child ids for javascript codes
89
        foreach (array_keys($this->_itemTree) as $item_id) {
90
            $this->_itemTree[$item_id]['allchild'] = [];
91
            $this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']);
92
        }
93
        /** @var \XoopsGroupPermHandler $gpermHandler */
94
        $gpermHandler = xoops_getHandler('groupperm');
95
        /** @var \XoopsMemberHandler $memberHandler */
96
        $memberHandler = xoops_getHandler('member');
97
        $glist         = $memberHandler->getGroupList();
98
        foreach (array_keys($glist) as $i) {
99
            // get selected item id(s) for each group
100
            $selected = $gpermHandler->getItemIds($this->_permName, $i, $this->_modid);
101
            $ele      = new NewbbXoopsGroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected);
102
            $ele->setOptionTree($this->_itemTree);
103
            $this->addElement($ele);
104
            unset($ele);
105
        }
106
        $tray = new XoopsFormElementTray('');
107
        $tray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
108
        $tray->addElement(new XoopsFormButton('', 'reset', _CANCEL, 'reset'));
109
        $this->addElement($tray);
110
        $ret      = '<h4>' . $this->getTitle() . '</h4>' . $this->_permDesc . '<br>';
111
        $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";
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
112
        $elements = $this->getElements();
113
        $hidden   = '';
114
        foreach (array_keys($elements) as $i) {
115
            if (!is_object($elements[$i])) {
116
                $ret .= $elements[$i];
117
            } elseif (!$elements[$i]->isHidden()) {
118
                $ret .= "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption();
119
                if ($elements[$i]->getDescription() !== '') {
120
                    $ret .= '<br><br><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>';
121
                }
122
                $ret .= "</td>\n<td class='even'>\n" . $elements[$i]->render() . "\n</td></tr>\n";
123
            } else {
124
                $hidden .= $elements[$i]->render();
125
            }
126
        }
127
        $ret .= "</table>$hidden</form>";
128
        $ret .= $this->renderValidationJS(true);
129
130
        return $ret;
131
    }
132
}
133
134
/**
135
 * Class NewbbXoopsGroupFormCheckBox
136
 */
137
class NewbbXoopsGroupFormCheckBox extends XoopsGroupFormCheckBox
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
138
{
139
    /**
140
     * @param      $caption
141
     * @param      $name
142
     * @param      $groupId
143
     * @param null $values
144
     */
145
    public function __construct($caption, $name, $groupId, $values = null)
146
    {
147
        parent::__construct($caption, $name, $groupId, $values);
148
    }
149
150
    /**
151
     * @param string $tree
152
     * @param array  $option
153
     * @param string $prefix
154
     * @param array  $parentIds
155
     */
156
    public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = [])
157
    {
158
        if ($option['id'] > 0) {
159
            $tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
160
            foreach ($parentIds as $pid) {
161
                if ($pid <= 0) {
162
                    continue;
163
                }
164
                $parent_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $pid . ']';
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
165
                $tree       .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if (ele.checked !== true) {ele.checked = this.checked;}";
166
            }
167
            foreach ($option['allchild'] as $cid) {
168
                $child_ele = $this->getName() . '[groups][' . $this->_groupId . '][' . $cid . ']';
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
169
                $tree      .= "var ele = xoopsGetElementById('" . $child_ele . "'); if (this.checked !== true) {ele.checked = false;}";
170
            }
171
            $tree .= '" value="1"';
172
            if (in_array($option['id'], $this->_value)) {
173
                $tree .= ' checked';
174
            }
175
            $tree .= ' />'
176
                     . $option['name']
177
                     . '<input type="hidden" name="'
178
                     . $this->getName()
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
179
                     . '[parents]['
180
                     . $option['id']
181
                     . ']" value="'
182
                     . implode(':', $parentIds)
183
                     . '" /><input type="hidden" name="'
184
                     . $this->getName()
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
185
                     . '[itemname]['
186
                     . $option['id']
187
                     . ']" value="'
188
                     . htmlspecialchars($option['name'])
189
                     . "\" /><br>\n";
190
        } else {
191
            $tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\" /><br>\n";
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
192
        }
193
        if (isset($option['children'])) {
194
            foreach ($option['children'] as $child) {
195
                if ($option['id'] > 0) {
196
                    //                  array_push($parentIds, $option['id']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
197
                    $parentIds[] = $option['id'];
198
                }
199
                $this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . '&nbsp;-', $parentIds);
200
            }
201
        }
202
    }
203
}
204
205
//$action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : "";
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
206
$action    = strtolower(Request::getCmd('action', ''));
207
$module_id = $xoopsModule->getVar('mid');
208
/** @var \NewbbPermissionHandler $newbbpermHandler */
209
$newbbpermHandler = xoops_getModuleHandler('permission', 'newbb');
210
$perms            = $newbbpermHandler->getValidForumPerms();
211
212
switch ($action) {
213
    case 'template':
214
        xoops_cp_header();
215
        $adminObject->displayNavigation(basename(__FILE__));
216
        echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>';
217
        $opform    = new XoopsSimpleForm(_AM_NEWBB_PERM_ACTION, 'actionform', 'admin_permissions.php', 'get');
218
        $op_select = new XoopsFormSelect('', 'action');
219
        $op_select->setExtra('onchange="document.forms.actionform.submit()"');
220
        $op_select->addOptionArray([
221
                                       'no'       => _SELECT,
222
                                       'template' => _AM_NEWBB_PERM_TEMPLATE,
223
                                       'apply'    => _AM_NEWBB_PERM_TEMPLATEAPP,
224
                                       'default'  => _AM_NEWBB_PERM_SETBYGROUP
225
                                   ]);
226
        $opform->addElement($op_select);
227
        $opform->display();
228
229
        $memberHandler = xoops_getHandler('member');
230
        $glist         = $memberHandler->getGroupList();
231
        $elements      = [];
232
        $perm_template = $newbbpermHandler->getTemplate();
233
        foreach (array_keys($glist) as $i) {
234
            $selected   = !empty($perm_template[$i]) ? array_keys($perm_template[$i]) : [];
235
            $ret_ele    = '<tr align="left" valign="top"><td class="head">' . $glist[$i] . '</td>';
236
            $ret_ele    .= '<td class="even">';
237
            $ret_ele    .= '<table class="outer"><tr><td class="odd"><table><tr>';
238
            $ii         = 0;
239
            $option_ids = [];
240
            foreach ($perms as $perm) {
241
                ++$ii;
242
                if ($ii % 5 == 0) {
243
                    $ret_ele .= '</tr><tr>';
244
                }
245
                $checked      = in_array('forum_' . $perm, $selected) ? ' checked' : '';
246
                $option_id    = $perm . '_' . $i;
247
                $option_ids[] = $option_id;
248
                $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>';
249
            }
250
            $ret_ele    .= '</tr></table></td><td class="even">';
251
            $ret_ele    .= _ALL . ' <input id="checkall[' . $i . ']" type="checkbox" value="" onclick="var optionids = new Array(' . implode(', ', $option_ids) . '); xoopsCheckAllElements(optionids, \'checkall[' . $i . ']\')" />';
252
            $ret_ele    .= '</td></tr></table>';
253
            $ret_ele    .= '</td></tr>';
254
            $elements[] = $ret_ele;
255
        }
256
        $tray = new XoopsFormElementTray('');
257
        $tray->addElement(new XoopsFormHidden('action', 'template_save'));
258
        $tray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
259
        $tray->addElement(new XoopsFormButton('', 'reset', _CANCEL, 'reset'));
260
        $ret = '<h4>' . _AM_NEWBB_PERM_TEMPLATE . '</h4>' . _AM_NEWBB_PERM_TEMPLATE_DESC . '<br><br><br>';
261
        $ret .= "<form name='template' id='template' method='post'>\n<table width='100%' class='outer' cellspacing='1'>\n";
262
        $ret .= implode("\n", $elements);
263
        $ret .= '<tr align="left" valign="top"><td class="head"></td><td class="even">';
264
        $ret .= $tray->render();
265
        $ret .= '</td></tr>';
266
        $ret .= '</table></form>';
267
        echo $ret;
268
        include_once __DIR__ . '/admin_footer.php';
269
        break;
270
271
    case 'template_save':
272
        //        $res = $newbbpermHandler->setTemplate($_POST['perms'], $groupid = 0);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
273
        $res = $newbbpermHandler->setTemplate(Request::getArray('perms', '', 'POST'), $groupid = 0);
274
        if ($res) {
275
            redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_CREATED);
276
        } else {
277
            redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE_ERROR);
278
        }
279
        break;
280
    //        exit();
281
282
    case 'apply':
283
        $perm_template = $newbbpermHandler->getTemplate();
284
        if ($perm_template === null) {
285
            redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE);
286
        }
287
        xoops_cp_header();
288
        $adminObject->displayNavigation(basename(__FILE__));
289
        echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>';
290
        $opform    = new XoopsSimpleForm(_AM_NEWBB_PERM_ACTION, 'actionform', 'admin_permissions.php', 'get');
291
        $op_select = new XoopsFormSelect('', 'action');
292
        $op_select->setExtra('onchange="document.forms.actionform.submit()"');
293
        $op_select->addOptionArray([
294
                                       'no'       => _SELECT,
295
                                       'template' => _AM_NEWBB_PERM_TEMPLATE,
296
                                       'apply'    => _AM_NEWBB_PERM_TEMPLATEAPP
297
                                   ]);
298
        $opform->addElement($op_select);
299
        $opform->display();
300
301
        /** @var \NewbbCategoryHandler $categoryHandler */
302
        $categoryHandler  = xoops_getModuleHandler('category', 'newbb');
303
        $criteriaCategory = new CriteriaCompo(new criteria('1', 1));
304
        $criteriaCategory->setSort('cat_order');
305
        $categories = $categoryHandler->getList($criteriaCategory);
306
307
        /** @var \NewbbForumHandler $forumHandler */
308
        $forumHandler = xoops_getModuleHandler('forum', 'newbb');
309
        $forums       = $forumHandler->getTree(array_keys($categories), 0, 'all');
310
        foreach (array_keys($forums) as $c) {
311
            $fm_options[-1 * $c - 1000] = ' ';
312
            $fm_options[-1 * $c]        = '[' . $categories[$c] . ']';
313
            foreach (array_keys($forums[$c]) as $f) {
314
                $fm_options[$f] = $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name'];
315
            }
316
        }
317
        unset($forums, $categories);
318
319
        $fmform    = new XoopsThemeForm(_AM_NEWBB_PERM_TEMPLATEAPP, 'fmform', 'admin_permissions.php', 'post');
320
        $fm_select = new XoopsFormSelect(_AM_NEWBB_PERM_FORUMS, 'forums', null, 10, true);
321
        $fm_select->addOptionArray($fm_options);
322
        $fmform->addElement($fm_select);
323
        $tray = new XoopsFormElementTray('');
324
        $tray->addElement(new XoopsFormHidden('action', 'apply_save'));
325
        $tray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
326
        $tray->addElement(new XoopsFormButton('', 'reset', _CANCEL, 'reset'));
327
        $fmform->addElement($tray);
328
        $fmform->display();
329
        include_once __DIR__ . '/admin_footer.php';
330
        break;
331
332
    case 'apply_save':
333
        if (!Request::getArray('forums', '', 'POST')) {
334
            break;
335
        }
336
        foreach (Request::getArray('forums', '', 'POST') as $forum) {
337
            if ($forum < 1) {
338
                continue;
339
            }
340
            $newbbpermHandler->applyTemplate($forum, $module_id);
341
        }
342
        $cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
343
        $cacheHelper->delete('permission');
344
        redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_APPLIED);
345
        break;
346
347
    default:
348
        xoops_cp_header();
349
350
        $categoryHandler  = xoops_getModuleHandler('category', 'newbb');
351
        $criteriaCategory = new CriteriaCompo(new criteria('1', 1));
352
        $criteriaCategory->setSort('cat_order');
353
        $categories = $categoryHandler->getList($criteriaCategory);
354
355
        if (0 === count($categories)) {
356
            redirect_header('admin_cat_manager.php', 2, _AM_NEWBB_CREATENEWCATEGORY);
357
        }
358
359
        $forumHandler = xoops_getModuleHandler('forum', 'newbb');
360
        $forums       = $forumHandler->getTree(array_keys($categories), 0, 'all');
361
362
        if (0 === count($forums)) {
363
            redirect_header('admin_forum_manager.php', 2, _AM_NEWBB_CREATENEWFORUM);
364
        }
365
366
        $adminObject->displayNavigation(basename(__FILE__));
367
        echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>';
368
        $opform    = new XoopsSimpleForm(_AM_NEWBB_PERM_ACTION, 'actionform', 'admin_permissions.php', 'get');
369
        $op_select = new XoopsFormSelect('', 'action');
370
        $op_select->setExtra('onchange="document.forms.actionform.submit()"');
371
        $op_select->addOptionArray([
372
                                       'no'       => _SELECT,
373
                                       'template' => _AM_NEWBB_PERM_TEMPLATE,
374
                                       'apply'    => _AM_NEWBB_PERM_TEMPLATEAPP,
375
                                       'default'  => _AM_NEWBB_PERM_SETBYGROUP
376
                                   ]);
377
        $opform->addElement($op_select);
378
        $opform->display();
379
380
        $op_options = ['category' => _AM_NEWBB_CAT_ACCESS];
381
        $fm_options = [
382
            'category' => [
383
                'title'     => _AM_NEWBB_CAT_ACCESS,
384
                'item'      => 'category_access',
385
                'desc'      => '',
386
                'anonymous' => true
387
            ]
388
        ];
389
        foreach ($perms as $perm) {
390
            $op_options[$perm] = constant('_AM_NEWBB_CAN_' . strtoupper($perm));
391
            $fm_options[$perm] = [
392
                'title'     => constant('_AM_NEWBB_CAN_' . strtoupper($perm)),
393
                'item'      => 'forum_' . $perm,
394
                'desc'      => '',
395
                'anonymous' => true
396
            ];
397
        }
398
399
        $op_keys = array_keys($op_options);
400
        $op      = strtolower(Request::getCmd('op', Request::getCmd('op', '', 'COOKIE'), 'GET'));
401
        if (empty($op)) {
402
            $op = $op_keys[0];
403
            setcookie('op', isset($op_keys[1]) ? $op_keys[1] : '');
404
        } elseif (false !== ($key = array_search($op, $op_keys))) {
405
            setcookie('op', isset($op_keys[$key + 1]) ? $op_keys[$key + 1] : '');
406
        }
407
408
        $opform    = new XoopsSimpleForm('', 'opform', 'admin_permissions.php', 'get');
409
        $op_select = new XoopsFormSelect('', 'op', $op);
410
        $op_select->setExtra('onchange="document.forms.opform.submit()"');
411
        $op_select->addOptionArray($op_options);
412
        $opform->addElement($op_select);
413
        $opform->display();
414
415
        $perm_desc = '';
416
417
        $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']);
418
419
        $categoryHandler  = xoops_getModuleHandler('category', 'newbb');
420
        $criteriaCategory = new CriteriaCompo(new criteria('1', 1));
421
        $criteriaCategory->setSort('cat_order');
422
        $categories = $categoryHandler->getList($criteriaCategory);
423
        if ($op === 'category') {
424
            foreach (array_keys($categories) as $key) {
425
                $form->addItem($key, $categories[$key]);
426
            }
427
            unset($categories);
428
        } else {
429
            $forumHandler = xoops_getModuleHandler('forum', 'newbb');
430
            $forums       = $forumHandler->getTree(array_keys($categories), 0, 'all');
431
            if (count($forums) > 0) {
432
                foreach (array_keys($forums) as $c) {
433
                    $key_c = -1 * $c;
434
                    $form->addItem($key_c, '<strong>[' . $categories[$c] . ']</strong>');
435
                    foreach (array_keys($forums[$c]) as $f) {
436
                        $pid = $forums[$c][$f]['parent_forum'] ?: $key_c;
437
                        $form->addItem($f, $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name'], $pid);
438
                    }
439
                }
440
            }
441
            unset($forums, $categories);
442
        }
443
        $form->display();
444
445
        // Since we can not control the permission update, a trick is used here
446
        /** @var \NewbbPermissionHandler $permissionHandler */
447
        $permissionHandler = xoops_getModuleHandler('permission', 'newbb');
448
        $permissionHandler->createPermData();
449
        $cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
450
        $cacheHelper->delete('permission');
451
        include_once __DIR__ . '/admin_footer.php';
452
        break;
453
}
454