Completed
Branch master (c92e39)
by Michael
02:32
created

category.php ➔ editcat()   C

Complexity

Conditions 8
Paths 72

Size

Total Lines 149
Code Lines 71

Duplication

Lines 21
Ratio 14.09 %

Importance

Changes 0
Metric Value
cc 8
eloc 71
nc 72
nop 2
dl 21
loc 149
rs 5.2676
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 30 and the first side effect is on line 9.

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
require_once __DIR__ . '/admin_header.php';
10
11
// Creating the category handler object
12
$categoryHandler = sf_gethandler('category');
13
14
$op = '';
15
16
if (isset($_GET['op'])) {
17
    $op = $_GET['op'];
18
}
19
if (isset($_POST['op'])) {
20
    $op = $_POST['op'];
21
}
22
23
// Where do we start?
24
$startcategory = isset($_GET['startcategory']) ? (int)$_GET['startcategory'] : 0;
25
26
/**
27
 * @param     $categoryObj
28
 * @param int $level
29
 */
30
function displayCategory($categoryObj, $level = 0)
31
{
32
    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...
33
    $description = $categoryObj->description();
34 View Code Duplication
    if (!XOOPS_USE_MULTIBYTES) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        if (strlen($description) >= 100) {
36
            $description = substr($description, 0, 100 - 1) . '...';
37
        }
38
    }
39
    $modify = "<a href='category.php?op=mod&categoryid="
40
              . $categoryObj->categoryid()
41
              . "'><img src='"
42
              . $pathIcon16
43
              . '/edit.png'
44
              . "' title='"
45
              . _AM_SF_EDITCOL
46
              . "' alt='"
47
              . _AM_SF_EDITCOL
48
              . "' /></a>";
49
    $delete = "<a href='category.php?op=del&categoryid="
50
              . $categoryObj->categoryid()
51
              . "'><img src='"
52
              . $pathIcon16
53
              . '/delete.png'
54
              . "' title='"
55
              . _AM_SF_DELETECOL
56
              . "' alt='"
57
              . _AM_SF_DELETECOL
58
              . "' /></a>";
59
60
    $spaces = '';
61
    for ($j = 0; $j < $level; ++$j) {
62
        $spaces .= '&nbsp;&nbsp;&nbsp;';
63
    }
64
65
    echo '<tr>';
66
    echo "<td class='even' align='lefet'>"
67
         . $spaces
68
         . "<a href='"
69
         . XOOPS_URL
70
         . '/modules/'
71
         . $xoopsModule->dirname()
72
         . '/category.php?categoryid='
73
         . $categoryObj->categoryid()
74
         . "'><img src='"
75
         . XOOPS_URL
76
         . "/modules/smartfaq/assets/images/icon/subcat.gif' alt='' />&nbsp;"
77
         . $categoryObj->name()
78
         . '</a></td>';
79
    echo "<td class='even' align='left'>" . $description . '</td>';
80
    echo "<td class='even' align='center'>" . $categoryObj->weight() . '</td>';
81
    echo "<td class='even' align='center'> $modify $delete </td>";
82
    echo '</tr>';
83
    $subCategoriesObj = $categoryHandler->getCategories(0, 0, $categoryObj->categoryid());
84
    if (count($subCategoriesObj) > 0) {
85
        ++$level;
86
        foreach ($subCategoriesObj as $key => $thiscat) {
87
            displayCategory($thiscat, $level);
88
        }
89
    }
90
    unset($categoryObj);
91
}
92
93
/**
94
 * @param bool $showmenu
95
 * @param int  $categoryid
96
 */
97
function editcat($showmenu = false, $categoryid = 0)
0 ignored issues
show
Coding Style introduced by
editcat uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
98
{
99
    //$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...
100
    //$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...
101
    $startfaq = isset($_GET['startfaq']) ? (int)$_GET['startfaq'] : 0;
0 ignored issues
show
Unused Code introduced by
$startfaq is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
102
    global $categoryHandler, $xoopsUser, $xoopsUser, $myts, $xoopsConfig, $xoopsDB, $modify, $xoopsModuleConfig, $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...
103
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
104
105
    // Creating the faq handler object
106
    $faqHandler = sf_gethandler('faq');
0 ignored issues
show
Unused Code introduced by
$faqHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
107
108
    echo '<script type="text/javascript" src="funcs.js"></script>';
109
    echo '<style>';
110
    echo '<!-- ';
111
    echo 'select { width: 130px; }';
112
    echo '-->';
113
    echo '</style>';
114
    // If there is a parameter, and the id exists, retrieve data: we're editing a category
115
    if ($categoryid != 0) {
116
117
        // Creating the category object for the selected category
118
        $categoryObj = new sfCategory($categoryid);
119
120
        echo "<br>\n";
121
        if ($categoryObj->notLoaded()) {
122
            redirect_header('category.php', 1, _AM_SF_NOCOLTOEDIT);
123
        }
124
        sf_collapsableBar('bottomtable', 'bottomtableicon');
125
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a>&nbsp;" . _AM_SF_EDITCOL . '</h3>';
126
        echo "<div id='bottomtable'>";
127
    } else {
128
        $categoryObj = $categoryHandler->create();
129
        echo "<br>\n";
130
        sf_collapsableBar('bottomtable', 'bottomtableicon');
131
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a>&nbsp;" . _AM_SF_CATEGORY_CREATE . '</h3>';
132
        echo "<div id='bottomtable'>";
133
    }
134
    // Start category form
135
    $sform = new XoopsThemeForm(_AM_SF_CATEGORY, 'op', xoops_getenv('PHP_SELF'));
136
    $sform->setExtra('enctype="multipart/form-data"');
137
138
    // Name
139
    $sform->addElement(new XoopsFormText(_AM_SF_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true);
140
141
    // Parent Category
142
    $mytree = new XoopsTree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid');
143
    ob_start();
144
    $mytree->makeMySelBox('name', 'weight', $categoryObj->parentid(), 1, 'parentid');
145
146
    //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...
147
    $sform->addElement(new XoopsFormLabel(_AM_SF_PARENT_CATEGORY_EXP, ob_get_contents()));
148
    ob_end_clean();
149
150
    /*  $mytree = new XoopsTree($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...
151
        ob_start();
152
        $sform->addElement(new XoopsFormHidden('categoryid', $categoryObj->categoryid()));
153
        $mytree->makeMySelBox("name", "weight", $categoryObj->categoryid());
154
        $sform->addElement(new XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents()));
155
        ob_end_clean();
156
        */
157
158
    // Decsription
159
    $sform->addElement(new XoopsFormTextArea(_AM_SF_COLDESCRIPT, 'description', $categoryObj->description('e'), 7, 60));
160
161
    // Weight
162
    $sform->addElement(new XoopsFormText(_AM_SF_COLPOSIT, 'weight', 4, 4, $categoryObj->weight()));
163
164
    // READ PERMISSIONS
165
    $memberHandler = xoops_getHandler('member');
166
    $group_list    = $memberHandler->getGroupList();
167
168
    $groups_read_checkbox = new XoopsFormCheckBox(_AM_SF_PERMISSIONS_CAT_READ, 'groups_read[]', $categoryObj->getGroups_read());
169
    foreach ($group_list as $group_id => $group_name) {
170
        if ($group_id != XOOPS_GROUP_ADMIN) {
171
            $groups_read_checkbox->addOption($group_id, $group_name);
172
        }
173
    }
174
    $sform->addElement($groups_read_checkbox);
175
    // Apply permissions on all faqs
176
    $addapplyall_radio = new XoopsFormRadioYN(_AM_SF_PERMISSIONS_APPLY_ON_FAQS, 'applyall', 0, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
177
    $sform->addElement($addapplyall_radio);
178
    // MODERATORS
179
    //$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...
180
181
    $module_id = $xoopsModule->getVar('mid');
0 ignored issues
show
Unused Code introduced by
$module_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
182
183
    /*$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...
184
    $mod_perms = $gpermHandler->getGroupIds('category_moderation', $categoryid, $module_id);
185
186
    $moderators_select = new XoopsFormSelect('', 'moderators', $moderators, 5, true);
187
    $moderators_tray->addElement($moderators_select);
188
189
    $butt_mngmods = new XoopsFormButton('', '', 'Manage mods', 'button');
190
    $butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"');
191
    $moderators_tray->addElement($butt_mngmods);
192
193
    $butt_delmod = new XoopsFormButton('', '', 'Delete mod', 'button');
194
    $butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"');
195
    $moderators_tray->addElement($butt_delmod);
196
197
    $sform->addElement($moderators_tray);
198
    */
199
    $sform->addElement(new XoopsFormHidden('categoryid', $categoryid));
200
201
    // Action buttons tray
202
    $button_tray = new XoopsFormElementTray('', '');
203
204
    /*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...
205
    $allmods[] = $moderators[$i];
206
    }
207
208
    $hiddenmods = new XoopsFormHidden('allmods', $allmods);
209
    $button_tray->addElement($hiddenmods);
210
    */
211
    $hidden = new XoopsFormHidden('op', 'addcategory');
212
    $button_tray->addElement($hidden);
213
    // No ID for category -- then it's new category, button says 'Create'
214 View Code Duplication
    if (!$categoryid) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
215
        $butt_create = new XoopsFormButton('', '', _AM_SF_CREATE, 'submit');
216
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
217
        $button_tray->addElement($butt_create);
218
219
        $butt_clear = new XoopsFormButton('', '', _AM_SF_CLEAR, 'reset');
220
        $button_tray->addElement($butt_clear);
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
    } else {
226
        // button says 'Update'
227
        $butt_create = new XoopsFormButton('', '', _AM_SF_MODIFY, 'submit');
228
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
229
        $button_tray->addElement($butt_create);
230
231
        $butt_cancel = new XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
232
        $butt_cancel->setExtra('onclick="history.go(-1)"');
233
        $button_tray->addElement($butt_cancel);
234
    }
235
236
    $sform->addElement($button_tray);
237
    $sform->display();
238
    echo '</div>';
239
240
    if ($categoryid) {
241
        include_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php';
242
    }
243
244
    unset($hidden);
245
}
246
247
switch ($op) {
248
    case 'mod':
249
        $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0;
250
        $destList   = isset($_POST['destList']) ? $_POST['destList'] : '';
251
        $adminObject  = \Xmf\Module\Admin::getInstance();
252
        xoops_cp_header();
253
254
        $adminObject->displayNavigation(basename(__FILE__));
255
        editcat(true, $categoryid);
256
        break;
257
258
    case 'addcategory':
259
        global $_POST, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $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...
260
261
        $categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0;
262
263
        if ($categoryid != 0) {
264
            $categoryObj = new sfCategory($categoryid);
265
        } else {
266
            $categoryObj = $categoryHandler->create();
267
        }
268
269
        //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...
270
        //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...
271
272
        $categoryObj->setVar('parentid', isset($_POST['parentid']) ? (int)$_POST['parentid'] : 0);
273
        $applyall = isset($_POST['applyall']) ? (int)$_POST['applyall'] : 0;
274
        $categoryObj->setVar('weight', isset($_POST['weight']) ? (int)$_POST['weight'] : 1);
275
276
        // Groups and permissions
277
        if (isset($_POST['groups_read'])) {
278
            $categoryObj->setGroups_read($_POST['groups_read']);
279
        } else {
280
            $categoryObj->setGroups_read();
281
        }
282
        //  $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...
283
        //  $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...
284
285
        $categoryObj->setVar('name', $_POST['name']);
286
287
        $categoryObj->setVar('description', $_POST['description']);
288
        if ($categoryObj->isNew()) {
289
            $redirect_msg = _AM_SF_CATCREATED;
290
            $redirect_to  = 'category.php?op=mod';
291
        } else {
292
            $redirect_msg = _AM_SF_COLMODIFIED;
293
            $redirect_to  = 'category.php';
294
        }
295
296
        if (!$categoryObj->store()) {
297
            redirect_header('javascript:history.go(-1)', 3, _AM_SF_CATEGORY_SAVE_ERROR . sf_formatErrors($categoryObj->getErrors()));
298
        }
299
        // TODO : put this function in the category class
300
        sf_saveCategory_Permissions($categoryObj->getGroups_read(), $categoryObj->categoryid(), 'category_read');
301
        //sf_saveCategory_Permissions($groups_admin, $categoriesObj->categoryid(), 'category_admin');
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
302
303
        if ($applyall) {
304
            // TODO : put this function in the category class
305
            sf_overrideFaqsPermissions($categoryObj->getGroups_read(), $categoryObj->categoryid());
306
        }
307
308
        redirect_header($redirect_to, 2, $redirect_msg);
309
        break;
310
311 View Code Duplication
    case 'del':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
        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...
313
314
        $module_id    = $xoopsModule->getVar('mid');
315
        $gpermHandler = xoops_getHandler('groupperm');
316
317
        $categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0;
318
        $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : $categoryid;
319
320
        $categoryObj = new sfCategory($categoryid);
321
322
        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
323
        $name    = isset($_POST['name']) ? $_POST['name'] : '';
324
325
        if ($confirm) {
326
            if (!$categoryHandler->delete($categoryObj)) {
327
                redirect_header('category.php', 1, _AM_SF_DELETE_CAT_ERROR);
328
            }
329
            redirect_header('category.php', 1, sprintf(_AM_SF_COLISDELETED, $name));
330
        } else {
331
            // no confirm: show deletion condition
332
            $categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0;
333
            xoops_cp_header();
334
            xoops_confirm(array(
335
                              'op'         => 'del',
336
                              'categoryid' => $categoryObj->categoryid(),
337
                              'confirm'    => 1,
338
                              'name'       => $categoryObj->name()
339
                          ), 'category.php', _AM_SF_DELETECOL . " '" . $categoryObj->name() . "'. <br> <br>" . _AM_SF_DELETE_CAT_CONFIRM, _AM_SF_DELETE);
340
            xoops_cp_footer();
341
        }
342
        exit();
343
        break;
344
345
    case 'cancel':
346
        redirect_header('category.php', 1, sprintf(_AM_SF_BACK2IDX, ''));
347
        break;
348
    case 'default':
349
    default:
350
        $adminObject  = \Xmf\Module\Admin::getInstance();
351
        xoops_cp_header();
352
353
        $adminObject->displayNavigation(basename(__FILE__));
354
        echo "<br>\n";
355
356
        // Creating the objects for top categories
357
        $categoriesObj = $categoryHandler->getCategories($xoopsModuleConfig['perpage'], $startcategory, 0);
358
359
        sf_collapsableBar('toptable', 'toptableicon');
360
        echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a>&nbsp;" . _AM_SF_CATEGORIES_TITLE . '</h3>';
361
        echo "<div id='toptable'>";
362
        echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_CATEGORIES_DSC . '</span>';
363
364
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
365
        echo '<tr>';
366
        echo "<th width='35%' class='bg3' align='left'><b>" . _AM_SF_ARTCOLNAME . '</b></td>';
367
        echo "<th class='bg3' align='left'><b>" . _AM_SF_DESCRIP . '</b></td>';
368
        echo "<th class='bg3' width='65' align='center'><b>" . _AM_SF_WEIGHT . '</b></td>';
369
        echo "<th width='60' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>';
370
        echo '</tr>';
371
        $totalCategories = $categoryHandler->getCategoriesCount(0);
372
        if (count($categoriesObj) > 0) {
373
            foreach ($categoriesObj as $key => $thiscat) {
374
                displayCategory($thiscat);
375
            }
376
        } else {
377
            echo '<tr>';
378
            echo "<td class='head' align='center' colspan= '7'>" . _AM_SF_NOCAT . '</td>';
379
            echo '</tr>';
380
            $categoryid = '0';
381
        }
382
        echo "</table>\n";
383
        include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
384
        $pagenav = new XoopsPageNav($totalCategories, $xoopsModuleConfig['perpage'], $startcategory, 'startcategory');
385
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
386
        echo '</div>';
387
388
        editcat(false);
389
390
        break;
391
}
392
393
require_once __DIR__ . '/admin_footer.php';
394