Passed
Push — master ( 2744eb...81ba93 )
by Michael
02:46
created

displayCategory()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 43
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 43
rs 8.439
c 1
b 0
f 0
cc 6
eloc 34
nc 12
nop 2
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 36 and the first side effect is on line 11.

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
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use XoopsModules\Smartfaq;
10
11
require_once __DIR__ . '/admin_header.php';
12
13
/** @var Smartfaq\Helper $helper */
14
$helper = Smartfaq\Helper::getInstance();
15
16
// Creating the category handler object
17
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
18
$categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category');
19
20
$op = '';
21
22
if (isset($_GET['op'])) {
23
    $op = $_GET['op'];
24
}
25
if (isset($_POST['op'])) {
26
    $op = $_POST['op'];
27
}
28
29
// Where do we start?
30
$startcategory = \Xmf\Request::getInt('startcategory', 0, 'GET');
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...
31
32
/**
33
 * @param XoopsObject $categoryObj
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
34
 * @param int         $level
35
 */
36
function displayCategory($categoryObj, $level = 0)
37
{
38
    global $xoopsModule, $categoryHandler, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
39
    $description = $categoryObj->description();
40
    if (!XOOPS_USE_MULTIBYTES) {
0 ignored issues
show
Bug introduced by
The constant XOOPS_USE_MULTIBYTES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
        if (strlen($description) >= 100) {
42
            $description = substr($description, 0, 100 - 1) . '...';
43
        }
44
    }
45
    $modify = "<a href='category.php?op=mod&categoryid=" . $categoryObj->categoryid() . "'><img src='" . $pathIcon16 . '/edit.png' . "' title='" . _AM_SF_EDITCOL . "' alt='" . _AM_SF_EDITCOL . "'></a>";
46
    $delete = "<a href='category.php?op=del&categoryid=" . $categoryObj->categoryid() . "'><img src='" . $pathIcon16 . '/delete.png' . "' title='" . _AM_SF_DELETECOL . "' alt='" . _AM_SF_DELETECOL . "'></a>";
47
48
    $spaces = '';
49
    for ($j = 0; $j < $level; ++$j) {
50
        $spaces .= '&nbsp;&nbsp;&nbsp;';
51
    }
52
53
    echo '<tr>';
54
    echo "<td class='even' align='lefet'>"
55
         . $spaces
56
         . "<a href='"
57
         . XOOPS_URL
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
         . '/modules/'
59
         . $xoopsModule->dirname()
60
         . '/category.php?categoryid='
61
         . $categoryObj->categoryid()
62
         . "'><img src='"
63
         . XOOPS_URL
64
         . "/modules/smartfaq/assets/images/icon/subcat.gif' alt=''>&nbsp;"
65
         . $categoryObj->name()
66
         . '</a></td>';
67
    echo "<td class='even' align='left'>" . $description . '</td>';
68
    echo "<td class='even' align='center'>" . $categoryObj->weight() . '</td>';
69
    echo "<td class='even' align='center'> $modify $delete </td>";
70
    echo '</tr>';
71
    $subCategoriesObj =& $categoryHandler->getCategories(0, 0, $categoryObj->categoryid());
72
    if (count($subCategoriesObj) > 0) {
73
        ++$level;
74
        foreach ($subCategoriesObj as $key => $thiscat) {
75
            displayCategory($thiscat, $level);
76
        }
77
    }
78
    unset($categoryObj);
79
}
80
81
/**
82
 * @param bool $showmenu
83
 * @param int  $categoryid
84
 */
85
function editcat($showmenu = false, $categoryid = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $showmenu is not used and could be removed. ( Ignorable by Annotation )

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

85
function editcat(/** @scrutinizer ignore-unused */ $showmenu = false, $categoryid = 0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
{
87
    //$moderators = array(); // just to define the variable
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
88
    //$allmods = array();
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...
89
    $startfaq = \Xmf\Request::getInt('startfaq', 0, 'GET');
0 ignored issues
show
Unused Code introduced by
The assignment to $startfaq is dead and can be removed.
Loading history...
90
    global $categoryHandler, $xoopsUser, $xoopsUser, $myts, $xoopsConfig, $xoopsDB, $modify,  $xoopsModule, $_GET;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
91
    /** @var Smartfaq\Helper $helper */
92
    $helper = Smartfaq\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
93
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
94
95
    // Creating the faq handler object
96
    /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
97
    $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
0 ignored issues
show
Unused Code introduced by
The assignment to $faqHandler is dead and can be removed.
Loading history...
98
99
    echo '<script type="text/javascript" src="funcs.js"></script>';
100
    echo '<style>';
101
    echo '<!-- ';
102
    echo 'select { width: 130px; }';
103
    echo '-->';
104
    echo '</style>';
105
    // If there is a parameter, and the id exists, retrieve data: we're editing a category
106
    if (0 != $categoryid) {
107
108
        // Creating the category object for the selected category
109
        $categoryObj = new  \XoopsModules\Smartfaq\Category($categoryid);
110
111
        echo "<br>\n";
112
        if ($categoryObj->notLoaded()) {
113
            redirect_header('category.php', 1, _AM_SF_NOCOLTOEDIT);
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

113
            /** @scrutinizer ignore-call */ 
114
            redirect_header('category.php', 1, _AM_SF_NOCOLTOEDIT);
Loading history...
114
        }
115
        Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon');
116
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . _AM_SF_EDITCOL . '</h3>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
        echo "<div id='bottomtable'>";
118
    } else {
119
        $categoryObj = $categoryHandler->create();
120
        echo "<br>\n";
121
        Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon');
122
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . _AM_SF_CATEGORY_CREATE . '</h3>';
123
        echo "<div id='bottomtable'>";
124
    }
125
    // Start category form
126
    $sform = new \XoopsThemeForm(_AM_SF_CATEGORY, 'op', xoops_getenv('PHP_SELF'), '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...
Bug introduced by
The function xoops_getenv 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

126
    $sform = new \XoopsThemeForm(_AM_SF_CATEGORY, 'op', /** @scrutinizer ignore-call */ xoops_getenv('PHP_SELF'), 'post', true);
Loading history...
127
    $sform->setExtra('enctype="multipart/form-data"');
128
129
    // Name
130
    $sform->addElement(new \XoopsFormText(_AM_SF_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormText 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...
131
132
    // Parent Category
133
    $mytree = new Smartfaq\Tree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid');
134
    ob_start();
135
    $mytree->makeMySelBox('name', 'weight', $categoryObj->parentid(), 1, 'parentid');
136
137
    //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="")
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
138
    $sform->addElement(new \XoopsFormLabel(_AM_SF_PARENT_CATEGORY_EXP, ob_get_contents()));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel 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
    ob_end_clean();
140
141
    /*  $mytree = new Smartfaq\Tree($xoopsDB->prefix("smartfaq_categories"), "categoryid" , "parentid");
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
142
        ob_start();
143
        $sform->addElement(new \XoopsFormHidden('categoryid', $categoryObj->categoryid()));
144
        $mytree->makeMySelBox("name", "weight", $categoryObj->categoryid());
145
        $sform->addElement(new \XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents()));
146
        ob_end_clean();
147
        */
148
149
    // Decsription
150
    $sform->addElement(new \XoopsFormTextArea(_AM_SF_COLDESCRIPT, 'description', $categoryObj->description('e'), 7, 60));
0 ignored issues
show
Bug introduced by
The type XoopsFormTextArea 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...
151
152
    // Weight
153
    $sform->addElement(new \XoopsFormText(_AM_SF_COLPOSIT, 'weight', 4, 4, $categoryObj->weight()));
154
155
    // READ PERMISSIONS
156
    $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

156
    $memberHandler = /** @scrutinizer ignore-call */ xoops_getHandler('member');
Loading history...
157
    $group_list    = $memberHandler->getGroupList();
158
159
    $groups_read_checkbox = new \XoopsFormCheckBox(_AM_SF_PERMISSIONS_CAT_READ, 'groups_read[]', $categoryObj->getGroups_read());
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox 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...
160
    foreach ($group_list as $group_id => $group_name) {
161
        if (XOOPS_GROUP_ADMIN != $group_id) {
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
162
            $groups_read_checkbox->addOption($group_id, $group_name);
163
        }
164
    }
165
    $sform->addElement($groups_read_checkbox);
166
    // Apply permissions on all faqs
167
    $addapplyall_radio = new \XoopsFormRadioYN(_AM_SF_PERMISSIONS_APPLY_ON_FAQS, 'applyall', 0, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
0 ignored issues
show
Bug introduced by
The type XoopsFormRadioYN 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...
168
    $sform->addElement($addapplyall_radio);
169
    // MODERATORS
170
    //$moderators_tray = new \XoopsFormElementTray(_AM_SF_MODERATORS_DEF, '');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
171
172
    $module_id = $xoopsModule->getVar('mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $module_id is dead and can be removed.
Loading history...
173
174
    /*$gpermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
175
    $mod_perms = $gpermHandler->getGroupIds('category_moderation', $categoryid, $module_id);
176
177
    $moderators_select = new \XoopsFormSelect('', 'moderators', $moderators, 5, true);
178
    $moderators_tray->addElement($moderators_select);
179
180
    $butt_mngmods = new \XoopsFormButton('', '', 'Manage mods', 'button');
181
    $butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"');
182
    $moderators_tray->addElement($butt_mngmods);
183
184
    $butt_delmod = new \XoopsFormButton('', '', 'Delete mod', 'button');
185
    $butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"');
186
    $moderators_tray->addElement($butt_delmod);
187
188
    $sform->addElement($moderators_tray);
189
    */
190
    $sform->addElement(new \XoopsFormHidden('categoryid', $categoryid));
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...
191
192
    // Action buttons tray
193
    $button_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...
194
195
    /*for ($i = 0, $iMax = count($moderators); $i < $iMax; ++$i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
196
    $allmods[] = $moderators[$i];
197
    }
198
199
    $hiddenmods = new \XoopsFormHidden('allmods', $allmods);
200
    $button_tray->addElement($hiddenmods);
201
    */
202
    $hidden = new \XoopsFormHidden('op', 'addcategory');
203
    $button_tray->addElement($hidden);
204
    // No ID for category -- then it's new category, button says 'Create'
205
    if (!$categoryid) {
206
        $butt_create = new \XoopsFormButton('', '', _AM_SF_CREATE, 'submit');
0 ignored issues
show
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...
207
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
208
        $button_tray->addElement($butt_create);
209
210
        $butt_clear = new \XoopsFormButton('', '', _AM_SF_CLEAR, 'reset');
211
        $button_tray->addElement($butt_clear);
212
213
        $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
214
        $butt_cancel->setExtra('onclick="history.go(-1)"');
215
        $button_tray->addElement($butt_cancel);
216
    } else {
217
        // button says 'Update'
218
        $butt_create = new \XoopsFormButton('', '', _AM_SF_MODIFY, 'submit');
219
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
220
        $button_tray->addElement($butt_create);
221
222
        $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
223
        $butt_cancel->setExtra('onclick="history.go(-1)"');
224
        $button_tray->addElement($butt_cancel);
225
    }
226
227
    $sform->addElement($button_tray);
228
    $sform->display();
229
    echo '</div>';
230
231
    if ($categoryid) {
232
        require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php';
233
    }
234
235
    unset($hidden);
236
}
237
238
switch ($op) {
239
    case 'mod':
240
        $categoryid  = \Xmf\Request::getInt('categoryid', 0, 'GET');
241
        $destList    = \Xmf\Request::getString('destList', '', 'POST');
242
        $adminObject = \Xmf\Module\Admin::getInstance();
0 ignored issues
show
Bug introduced by
The type Xmf\Module\Admin 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...
243
        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

243
        /** @scrutinizer ignore-call */ 
244
        xoops_cp_header();
Loading history...
244
245
        $adminObject->displayNavigation(basename(__FILE__));
246
        editcat(true, $categoryid);
247
        break;
248
249
    case 'addcategory':
250
        global $_POST, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule,  $modify, $myts, $categoryid;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
251
252
        $categoryid = \Xmf\Request::getInt('categoryid', 0, 'POST');
253
254
        if (0 != $categoryid) {
255
            $categoryObj = new Smartfaq\Category($categoryid);
256
        } else {
257
            $categoryObj = $categoryHandler->create();
258
        }
259
260
        //if (isset($_POST['allmods'])) $allmods = $_POST['allmods'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
261
        //if (isset($_POST['moderators'])) $moderators = $_POST['moderators'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
262
263
        $categoryObj->setVar('parentid', isset($_POST['parentid']) ? (int)$_POST['parentid'] : 0);
264
        $applyall = \Xmf\Request::getInt('applyall', 0, 'POST');
265
        $categoryObj->setVar('weight', isset($_POST['weight']) ? (int)$_POST['weight'] : 1);
266
267
        // Groups and permissions
268
        if (isset($_POST['groups_read'])) {
269
            $categoryObj->setGroups_read($_POST['groups_read']);
270
        } else {
271
            $categoryObj->setGroups_read();
272
        }
273
        //  $groups_admin = isset($_POST['groups_admin'])? $_POST['groups_admin'] : array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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
        //  $mod_perms = isset($_POST['mod_perms'])? $_POST['mod_perms'] : array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
275
276
        $categoryObj->setVar('name', $_POST['name']);
277
278
        $categoryObj->setVar('description', $_POST['description']);
279
        if ($categoryObj->isNew()) {
280
            $redirect_msg = _AM_SF_CATCREATED;
281
            $redirect_to  = 'category.php?op=mod';
282
        } else {
283
            $redirect_msg = _AM_SF_COLMODIFIED;
284
            $redirect_to  = 'category.php';
285
        }
286
287
        if (!$categoryObj->store()) {
288
            redirect_header('javascript:history.go(-1)', 3, _AM_SF_CATEGORY_SAVE_ERROR . Smartfaq\Utility::formatErrors($categoryObj->getErrors()));
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

288
            /** @scrutinizer ignore-call */ 
289
            redirect_header('javascript:history.go(-1)', 3, _AM_SF_CATEGORY_SAVE_ERROR . Smartfaq\Utility::formatErrors($categoryObj->getErrors()));
Loading history...
289
        }
290
        // TODO : put this function in the category class
291
        Smartfaq\Utility::saveCategoryPermissions($categoryObj->getGroups_read(), $categoryObj->categoryid(), 'category_read');
292
        //Smartfaq\Utility::saveCategoryPermissions($groups_admin, $categoriesObj->categoryid(), 'category_admin');
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
293
294
        if ($applyall) {
295
            // TODO : put this function in the category class
296
            Smartfaq\Utility::overrideFaqsPermissions($categoryObj->getGroups_read(), $categoryObj->categoryid());
297
        }
298
299
        redirect_header($redirect_to, 2, $redirect_msg);
300
        break;
301
302
    case 'del':
303
        global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
304
305
        $module_id    = $xoopsModule->getVar('mid');
306
        $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

306
        $gpermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
307
308
        $categoryid = \Xmf\Request::getInt('categoryid', 0, 'POST');
309
        $categoryid = \Xmf\Request::getInt('categoryid', $categoryid, 'GET');
310
311
        $categoryObj = new Smartfaq\Category($categoryid);
312
313
        $confirm = \Xmf\Request::getInt('confirm', 0, POST);
0 ignored issues
show
Bug introduced by
The constant POST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
314
        $name    = \Xmf\Request::getString('name', '', 'POST');
315
316
        if ($confirm) {
317
            if (!$categoryHandler->delete($categoryObj)) {
318
                redirect_header('category.php', 1, _AM_SF_DELETE_CAT_ERROR);
319
            }
320
            redirect_header('category.php', 1, sprintf(_AM_SF_COLISDELETED, $name));
321
        } else {
322
            // no confirm: show deletion condition
323
            $categoryid = \Xmf\Request::getInt('categoryid', 0, 'GET');
324
            xoops_cp_header();
325
            xoops_confirm([
0 ignored issues
show
Bug introduced by
The function xoops_confirm 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

325
            /** @scrutinizer ignore-call */ 
326
            xoops_confirm([
Loading history...
326
                              'op'         => 'del',
327
                              'categoryid' => $categoryObj->categoryid(),
328
                              'confirm'    => 1,
329
                              'name'       => $categoryObj->name()
330
                          ], 'category.php', _AM_SF_DELETECOL . " '" . $categoryObj->name() . "'. <br> <br>" . _AM_SF_DELETE_CAT_CONFIRM, _AM_SF_DELETE);
331
            xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer 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

331
            /** @scrutinizer ignore-call */ 
332
            xoops_cp_footer();
Loading history...
332
        }
333
        exit();
334
        break;
335
336
    case 'cancel':
337
        redirect_header('category.php', 1, sprintf(_AM_SF_BACK2IDX, ''));
338
        break;
339
    case 'default':
340
    default:
341
        $adminObject = \Xmf\Module\Admin::getInstance();
342
        xoops_cp_header();
343
344
        $adminObject->displayNavigation(basename(__FILE__));
345
        echo "<br>\n";
346
347
        // Creating the objects for top categories
348
        $categoriesObj =& $categoryHandler->getCategories($helper->getConfig('perpage'), $startcategory, 0);
349
350
        Smartfaq\Utility::collapsableBar('toptable', 'toptableicon');
351
        echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . _AM_SF_CATEGORIES_TITLE . '</h3>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
352
        echo "<div id='toptable'>";
353
        echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_CATEGORIES_DSC . '</span>';
354
355
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
356
        echo '<tr>';
357
        echo "<th width='35%' class='bg3' align='left'><b>" . _AM_SF_ARTCOLNAME . '</b></td>';
358
        echo "<th class='bg3' align='left'><b>" . _AM_SF_DESCRIP . '</b></td>';
359
        echo "<th class='bg3' width='65' align='center'><b>" . _AM_SF_WEIGHT . '</b></td>';
360
        echo "<th width='60' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>';
361
        echo '</tr>';
362
        $totalCategories = $categoryHandler->getCategoriesCount(0);
363
        if (count($categoriesObj) > 0) {
364
            foreach ($categoriesObj as $key => $thiscat) {
365
                displayCategory($thiscat);
366
            }
367
        } else {
368
            echo '<tr>';
369
            echo "<td class='head' align='center' colspan= '7'>" . _AM_SF_NOCAT . '</td>';
370
            echo '</tr>';
371
            $categoryid = '0';
372
        }
373
        echo "</table>\n";
374
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
375
        $pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('perpage'), $startcategory, 'startcategory');
0 ignored issues
show
Bug introduced by
The type XoopsPageNav 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...
376
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
377
        echo '</div>';
378
379
        editcat(false);
380
381
        break;
382
}
383
384
require_once __DIR__ . '/admin_footer.php';
385