Passed
Push — master ( d3e687...4990f6 )
by Michael
02:43
created

NewbbXoopsGroupPermForm   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
C render() 0 45 7
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 54 and the first side effect is on line 35.

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
//                       <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;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
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...
Bug introduced by
The type XoopsGroupPermForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    /*
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...
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'] = [];
0 ignored issues
show
Bug Best Practice introduced by
The property _itemTree does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
92
            $this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']);
93
        }
94
        /** @var \XoopsGroupPermHandler $gpermHandler */
95
        $gpermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
        $gpermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
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('');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
108
        $tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
109
        $tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset'));
0 ignored issues
show
Bug introduced by
The constant _CANCEL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
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...
Bug introduced by
The type XoopsGroupFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
139
{
140
    /**
141
     * @param      $caption
142
     * @param      $name
143
     * @param      $groupId
144
     * @param null $values
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $values is correct as it would always require null to be passed?
Loading history...
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']);
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...
198
                    $parentIds[] = $option['id'];
199
                }
200
                $this->_renderOptionTree($tree, $this->_optionTree[$child], $prefix . '&nbsp;-', $parentIds);
201
            }
202
        }
203
    }
204
}
205
206
//$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...
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();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

215
        /** @scrutinizer ignore-call */ 
216
        xoops_cp_header();
Loading history...
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');
0 ignored issues
show
Bug introduced by
The type XoopsSimpleForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
219
        $op_select = new \XoopsFormSelect('', 'action');
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
220
        $op_select->setExtra('onchange="document.forms.actionform.submit()"');
221
        $op_select->addOptionArray([
222
                                       'no'       => _SELECT,
0 ignored issues
show
Bug introduced by
The constant _SELECT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

230
        $memberHandler = /** @scrutinizer ignore-call */ xoops_getHandler('member');
Loading history...
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 . ']\')" />';
0 ignored issues
show
Bug introduced by
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
259
        $tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
260
        $tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset'));
0 ignored issues
show
Bug introduced by
The constant _CANCEL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
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...
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);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

276
            /** @scrutinizer ignore-call */ 
277
            redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_CREATED);
Loading history...
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));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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);
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $cacheHelper is correct as XoopsModules\Newbb\Utility::cleanCache() targeting XoopsModules\Newbb\Utility::cleanCache() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
344
        //$cacheHelper->delete('permission');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
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']);
0 ignored issues
show
Unused Code introduced by
The call to NewbbXoopsGroupPermForm::__construct() has too many arguments starting with $fm_options[$op]['anonymous']. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

418
        $form = /** @scrutinizer ignore-call */ new NewbbXoopsGroupPermForm($fm_options[$op]['title'], $module_id, $fm_options[$op]['item'], $fm_options[$op]['desc'], 'admin/admin_permissions.php', $fm_options[$op]['anonymous']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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>&nbsp;' . _MI_NEWBB_ADMENU_PERMISSION . '&nbsp;</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();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $cacheHelper is correct as XoopsModules\Newbb\Utility::cleanCache() targeting XoopsModules\Newbb\Utility::cleanCache() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
454
        //$cacheHelper->delete('permission');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
455
        include_once __DIR__ . '/admin_footer.php';
456
        break;
457
}
458