Completed
Push — master ( 3024c9...954431 )
by Michael
04:21
created

category.php ➔ createCategory()   D

Complexity

Conditions 10
Paths 128

Size

Total Lines 197
Code Lines 151

Duplication

Lines 19
Ratio 9.64 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 10
eloc 151
c 3
b 0
f 0
nc 128
nop 1
dl 19
loc 197
rs 4.606

How to fix   Long Method    Complexity   

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

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
 * Module: XoopsTube
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @Module          XoopsTube
12
 * @Release         Date: 21 June 2005
13
 * @Developer       John N
14
 * @Team            XOOPS Development Team
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 */
17
18
include_once __DIR__ . '/admin_header.php';
19
include_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php';
20
21
$op = '';
22
23
if (isset($_POST)) {
24
    foreach ($_POST as $k => $v) {
25
        ${$k} = $v;
26
    }
27
}
28
29
if (isset($_GET)) {
30
    foreach ($_GET as $k => $v) {
31
        ${$k} = $v;
32
    }
33
}
34
35
/**
36
 * @param int $cid
37
 */
38
function createCategory($cid = 0)
0 ignored issues
show
Coding Style introduced by
createCategory uses the super-global variable $GLOBALS 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...
39
{
40
    include_once dirname(__DIR__) . '/class/xoopstube_lists.php';
41
    //    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
42
43
    global $xtubemyts, $totalcats, $xoopsModule;
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...
44
45
    $lid          = 0;
0 ignored issues
show
Unused Code introduced by
$lid 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...
46
    $title        = '';
47
    $imgurl       = '';
48
    $description  = '';
49
    $pid          = '';
0 ignored issues
show
Unused Code introduced by
$pid 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...
50
    $weight       = 0;
51
    $nohtml       = 0;
52
    $nosmiley     = 0;
53
    $noxcodes     = 0;
54
    $noimages     = 0;
55
    $nobreak      = 1;
56
    $spotlighttop = 0;
0 ignored issues
show
Unused Code introduced by
$spotlighttop 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...
57
    $spotlighthis = 0;
0 ignored issues
show
Unused Code introduced by
$spotlighthis 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...
58
    $client_id    = 0;
59
    $banner_id    = 0;
60
    $heading      = _AM_XOOPSTUBE_CCATEGORY_CREATENEW;
61
    $totalcats    = XoopstubeUtilities::xtubeGetTotalCategoryCount();
62
63
    if ($cid > 0) {
64
        $sql          = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . (int)$cid;
65
        $cat_arr      = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->query($sql));
66
        $title        = $xtubemyts->htmlSpecialChars($cat_arr['title']);
67
        $imgurl       = $xtubemyts->htmlSpecialChars($cat_arr['imgurl']);
68
        $description  = $xtubemyts->htmlSpecialChars($cat_arr['description']);
69
        $nohtml       = (int)$cat_arr['nohtml'];
70
        $nosmiley     = (int)$cat_arr['nosmiley'];
71
        $noxcodes     = (int)$cat_arr['noxcodes'];
72
        $noimages     = (int)$cat_arr['noimages'];
73
        $nobreak      = (int)$cat_arr['nobreak'];
74
        $spotlighthis = (int)$cat_arr['spotlighthis'];
0 ignored issues
show
Unused Code introduced by
$spotlighthis 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...
75
        $spotlighttop = (int)$cat_arr['spotlighttop'];
0 ignored issues
show
Unused Code introduced by
$spotlighttop 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...
76
        $weight       = $cat_arr['weight'];
77
        $client_id    = $cat_arr['client_id'];
78
        $banner_id    = $cat_arr['banner_id'];
79
        $heading      = _AM_XOOPSTUBE_CCATEGORY_MODIFY;
80
81
        $memberHandler = xoops_getHandler('member');
82
        $group_list    = $memberHandler->getGroupList();
0 ignored issues
show
Unused Code introduced by
$group_list 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...
83
84
        $gpermHandler = xoops_getHandler('groupperm');
85
        $groups       = $gpermHandler->getGroupIds('XTubeCatPerm', $cid, $xoopsModule->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
$groups 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...
86
        //        $groups        = $groups;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
87
    } else {
88
        $groups = true;
0 ignored issues
show
Unused Code introduced by
$groups 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...
89
    }
90
    echo '<br><br>';
91
    $sform = new XoopsThemeForm($heading, 'op', xoops_getenv('PHP_SELF'));
92
    $sform->setExtra('enctype="multipart/form-data"');
93
94
    $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_FCATEGORY_TITLE, 'title', 50, 80, $title), true);
95
    $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false);
96
97
    if ($totalcats > 0 && $cid) {
98
        $mytreechose = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
99
        ob_start();
100
        $mytreechose->makeMySelBox('title', 'title', $cat_arr['pid'], 1, 'pid');
0 ignored issues
show
Bug introduced by
The variable $cat_arr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
101
        $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_FCATEGORY_SUBCATEGORY, ob_get_contents()));
102
        ob_end_clean();
103
    } else {
104
        $mytreechose = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
105
        ob_start();
106
        $mytreechose->makeMySelBox('title', 'title', $cid, 1, 'pid');
107
        $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_FCATEGORY_SUBCATEGORY, ob_get_contents()));
108
        ob_end_clean();
109
    }
110
111
    $graph_array      =& XoopstubeLists::getListTypeAsArray(XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['catimage'], $type = 'images');
112
    $indexImageSelect = new XoopsFormSelect('', 'imgurl', $imgurl);
113
    $indexImageSelect->addOptionArray($graph_array);
114
    $indexImageSelect->setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $GLOBALS['xoopsModuleConfig']['catimage'] . "\", \"\", \"" . XOOPS_URL . "\")'");
115
    $indeximage_tray = new XoopsFormElementTray(_AM_XOOPSTUBE_FCATEGORY_CIMAGE, '&nbsp;');
116
    $indeximage_tray->addElement($indexImageSelect);
117
    if ('' !== $imgurl && 1 != $imgurl) {
118
        $indeximage_tray->addElement(new XoopsFormLabel('',
119
                                                        "<br><br><img src='" . XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['catimage'] . '/' . $imgurl . "' name='image' id='image' alt='' />"));
120
    } else {
121
        $indeximage_tray->addElement(new XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt='' />"));
122
    }
123
    $sform->addElement($indeximage_tray);
124
125
    //    $editor = xtube_getWysiwygForm(_AM_XOOPSTUBE_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, '');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
126
    //    $sform->addElement($editor, false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
127
128
    $optionsTrayNote = new XoopsFormElementTray(_AM_XOOPSTUBE_FCATEGORY_DESCRIPTION, '<br>');
129 View Code Duplication
    if (class_exists('XoopsFormEditor')) {
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...
130
        $options['name']   = 'description';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
131
        $options['value']  = $description;
132
        $options['rows']   = 5;
133
        $options['cols']   = '100%';
134
        $options['width']  = '100%';
135
        $options['height'] = '200px';
136
        $editor            = new XoopsFormEditor('', $GLOBALS['xoopsModuleConfig']['form_optionsuser'], $options, $nohtml = false, $onfailure = 'textarea');
137
        $optionsTrayNote->addElement($editor);
138
    } else {
139
        $editor = new XoopsFormDhtmlTextArea('', 'description', $item->getVar('description', 'e'), '100%', '100%');
0 ignored issues
show
Bug introduced by
The variable $item does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
140
        $optionsTrayNote->addElement($editor);
141
    }
142
143
    $sform->addElement($optionsTrayNote, false);
144
145
    // Select Client/Sponsor
146
    $client_select   = new XoopsFormSelect(_AM_XOOPSTUBE_CATSPONSOR, 'client_id', $client_id, false);
147
    $sql             = 'SELECT cid, name FROM ' . $GLOBALS['xoopsDB']->prefix('bannerclient') . ' ORDER BY name ASC';
148
    $result          = $GLOBALS['xoopsDB']->query($sql);
149
    $client_array    = array();
150
    $client_array[0] = '&nbsp;';
151 View Code Duplication
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
152
        $client_array[$myrow['cid']] = $myrow['name'];
153
    }
154
    $client_select->addOptionArray($client_array);
155
156
    $client_select->setDescription(_AM_XOOPSTUBE_CATSPONSORDSC);
157
    $sform->addElement($client_select);
158
159
    // Select Banner
160
    $banner_select   = new XoopsFormSelect(_AM_XOOPSTUBE_BANNERID, 'banner_id', $banner_id, false);
161
    $sql             = 'SELECT bid, cid FROM ' . $GLOBALS['xoopsDB']->prefix('banner') . ' ORDER BY bid ASC';
162
    $result          = $GLOBALS['xoopsDB']->query($sql);
163
    $banner_array    = array();
164
    $banner_array[0] = '&nbsp;';
165 View Code Duplication
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
166
        $banner_array[$myrow['bid']] = $myrow['bid'];
167
    }
168
    $banner_select->addOptionArray($banner_array);
169
    $banner_select->setDescription(_AM_XOOPSTUBE_BANNERIDDSC);
170
    $sform->addElement($banner_select);
171
172
    $options_tray = new XoopsFormElementTray(_AM_XOOPSTUBE_TEXTOPTIONS, '<br>');
173
174
    $html_checkbox = new XoopsFormCheckBox('', 'nohtml', $nohtml);
175
    $html_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEHTML);
176
    $options_tray->addElement($html_checkbox);
177
178
    $smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', $nosmiley);
179
    $smiley_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLESMILEY);
180
    $options_tray->addElement($smiley_checkbox);
181
182
    $xcodes_checkbox = new XoopsFormCheckBox('', 'noxcodes', $noxcodes);
183
    $xcodes_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEXCODE);
184
    $options_tray->addElement($xcodes_checkbox);
185
186
    $noimages_checkbox = new XoopsFormCheckBox('', 'noimages', $noimages);
187
    $noimages_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEIMAGES);
188
    $options_tray->addElement($noimages_checkbox);
189
190
    $breaks_checkbox = new XoopsFormCheckBox('', 'nobreak', $nobreak);
191
    $breaks_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEBREAK);
192
    $options_tray->addElement($breaks_checkbox);
193
    $sform->addElement($options_tray);
194
195
    //    $sform -> addElement(new XoopsFormSelectGroup(_AM_XOOPSTUBE_FCATEGORY_GROUPPROMPT, "groups", true, $groups, 5, true));
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...
196
197
    $sform->addElement(new XoopsFormHidden('cid', (int)$cid));
198
199
    $sform->addElement(new XoopsFormHidden('spotlighttop', (int)$cid));
200
201
    $button_tray = new XoopsFormElementTray('', '');
202
    $hidden      = new XoopsFormHidden('op', 'save');
203
    $button_tray->addElement($hidden);
204
205
    if (!$cid) {
206
        $butt_create = new XoopsFormButton('', '', _AM_XOOPSTUBE_BSAVE, 'submit');
207
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
208
        $button_tray->addElement($butt_create);
209
210
        $butt_clear = new XoopsFormButton('', '', _AM_XOOPSTUBE_BRESET, 'reset');
211
        $button_tray->addElement($butt_clear);
212
213
        $butt_cancel = new XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'button');
214
        $butt_cancel->setExtra('onclick="history.go(-1)"');
215
        $button_tray->addElement($butt_cancel);
216
    } else {
217
        $butt_create = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit');
218
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
219
        $button_tray->addElement($butt_create);
220
221
        $butt_delete = new XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit');
222
        $butt_delete->setExtra('onclick="this.form.elements.op.value=\'del\'"');
223
        $button_tray->addElement($butt_delete);
224
225
        $butt_cancel = new XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'button');
226
        $butt_cancel->setExtra('onclick="history.go(-1)"');
227
        $button_tray->addElement($butt_cancel);
228
    }
229
    $sform->addElement($button_tray);
230
    $sform->display();
231
232
    $result2 = $GLOBALS['xoopsDB']->query('SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat'));
233
    list($numrows) = $GLOBALS['xoopsDB']->fetchRow($result2);
0 ignored issues
show
Unused Code introduced by
The assignment to $numrows is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
234
}
235
236
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
237
if (!isset($_POST['op'])) {
238
    $op = isset($_GET['op']) ? $_GET['op'] : 'main';
239
} else {
240
    $op = isset($_POST['op']) ? $_POST['op'] : 'main';
241
}
242
*/
243
244
$op = XoopsRequest::getString('op', XoopsRequest::getString('op', 'main', 'POST'), 'GET');
245
246
switch ($op) {
247
    case 'move':
248
        if (!XoopsRequest::getCmd('ok', '', 'POST')) {
249
            $cid = XoopsRequest::getInt('cid', XoopsRequest::getInt('cid', 0, 'GET'), 'POST'); //(isset($_POST['cid'])) ? $_POST['cid'] : $_GET['cid'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
250
251
            xoops_cp_header();
252
            //xtubeRenderAdminMenu(_AM_XOOPSTUBE_MCATEGORY);
253
254
            include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
255
            $xoopstubetree = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
256
            $sform         = new XoopsThemeForm(_AM_XOOPSTUBE_CCATEGORY_MOVE, 'move', xoops_getenv('PHP_SELF'));
257
            ob_start();
258
            $xoopstubetree->makeMySelBox('title', 'title', 0, 0, 'target');
259
            $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_BMODIFY, ob_get_contents()));
260
            ob_end_clean();
261
            $create_tray = new XoopsFormElementTray('', '');
262
            $create_tray->addElement(new XoopsFormHidden('source', $cid));
263
            $create_tray->addElement(new XoopsFormHidden('ok', 1));
264
            $create_tray->addElement(new XoopsFormHidden('op', 'move'));
265
            $butt_save = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMOVE, 'submit');
266
            $butt_save->setExtra('onclick="this.form.elements.op.value=\'move\'"');
267
            $create_tray->addElement($butt_save);
268
            $butt_cancel = new XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'submit');
269
            $butt_cancel->setExtra('onclick="this.form.elements.op.value=\'cancel\'"');
270
            $create_tray->addElement($butt_cancel);
271
            $sform->addElement($create_tray);
272
            $sform->display();
273
            xoops_cp_footer();
274
        } else {
275
            $source = XoopsRequest::getString('source', '', 'POST'); //$_POST['source'];
276
            $target = XoopsRequest::getString('target', '', 'POST'); //$_POST['target'];
277
            if ($target === $source) {
278
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_XOOPSTUBE_CCATEGORY_MODIFY_FAILED);
279
            }
280
            if (!$target) {
281
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_XOOPSTUBE_CCATEGORY_MODIFY_FAILEDT);
282
            }
283
            $sql    = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' set cid = ' . $target . ' WHERE cid =' . $source;
284
            $result = $GLOBALS['xoopsDB']->queryF($sql);
285
            $error  = _AM_XOOPSTUBE_DBERROR . ': <br><br>' . $sql;
286
            if (!$result) {
287
                trigger_error($error, E_USER_ERROR);
288
            }
289
            redirect_header('category.php?op=default', 1, _AM_XOOPSTUBE_CCATEGORY_MODIFY_MOVED);
290
        }
291
        break;
292
293
    case 'addCat':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
294
295
        $groups       = XoopsRequest::getArray('groups', array(), 'POST'); //isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
296
        $cid          = XoopsRequest::getInt('cid', 0, 'POST'); //(isset($_REQUEST['cid'])) ? $_REQUEST['cid'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
297
        $pid          = XoopsRequest::getInt('pid', 0, 'POST'); //(isset($_REQUEST['pid'])) ? $_REQUEST['pid'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
298
        $weight       = (XoopsRequest::getInt('pid', 0, 'POST') > 0) ? XoopsRequest::getInt('pid', 0, 'POST') : 0; //(isset($_REQUEST['weight']) && $_REQUEST['weight'] > 0) ? $_REQUEST['weight'] : 0;
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...
299
        $spotlighthis = XoopsRequest::getInt('lid', 0, 'POST'); //(isset($_REQUEST['lid'])) ? $_REQUEST['lid'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
300
        $spotlighttop = (1 == XoopsRequest::getInt('spotlighttop', 0, 'POST')) ? 1 : 0; //($_REQUEST['spotlighttop'] == 1) ? 1 : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
301
        $title        = XoopsRequest::getString('title', '', 'POST'); //$xtubemyts->addslashes($_REQUEST['title']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% 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
        $descriptionb = XoopsRequest::getString('description', '', 'POST'); //$xtubemyts->addslashes($_REQUEST['description']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% 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...
303
        $imgurl       = XoopsRequest::getString('imgurl', '', 'POST'); // $_REQUEST['imgurl'] && $_REQUEST['imgurl'] != 'blank.gif') ? $xtubemyts->addslashes($_REQUEST['imgurl']) : '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
304
        $client_id    = XoopsRequest::getInt('client_id', 0, 'POST'); //(isset($_REQUEST['client_id'])) ? $_REQUEST['client_id'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
305
        if ($client_id > 0) {
306
            $banner_id = 0;
307
        } else {
308
            $banner_id = XoopsRequest::getInt('banner_id', 0, 'POST'); //(isset($_REQUEST['banner_id'])) ? $_REQUEST['banner_id'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
309
        }
310
        $nohtml   = XoopsRequest::getInt('nohtml', 0, 'POST'); //isset($_REQUEST['nohtml']) ? $_REQUEST['nohtml'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
311
        $nosmiley = XoopsRequest::getInt('nosmiley', 0, 'POST'); //isset($_REQUEST['nosmiley']) ? $_REQUEST['nosmiley'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
312
        $noxcodes = XoopsRequest::getInt('noxcodes', 0, 'POST'); //isset($_REQUEST['noxcodes']) ? $_REQUEST['noxcodes'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
313
        $noimages = XoopsRequest::getInt('noimages', 0, 'POST'); //isset($_REQUEST['noimages']) ? $_REQUEST['noimages'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
314
        $nobreak  = XoopsRequest::getInt('nobreak', 0, 'POST'); //isset($_REQUEST['nobreak']) ? $_REQUEST['nobreak'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% 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...
315
316
        if (!$cid) {
317
            $cid = 0;
318
            $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat')
319
                   . " (cid, pid, title, imgurl, description, nohtml, nosmiley, noxcodes, noimages, nobreak, weight, spotlighttop, spotlighthis, client_id, banner_id ) VALUES ($cid, $pid, '$title', '$imgurl', '$descriptionb', '$nohtml', '$nosmiley', '$noxcodes', '$noimages', '$nobreak', '$weight',  $spotlighttop, $spotlighthis, $client_id, $banner_id )";
320
            if ($cid == 0) {
321
                $newid = $GLOBALS['xoopsDB']->getInsertId();
322
            }
323
324
            // Notify of new category
325
326
            global $xoopsModule;
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...
327
            $tags                  = array();
328
            $tags['CATEGORY_NAME'] = $title;
329
            $tags['CATEGORY_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $newid;
330
            $notificationHandler   = xoops_getHandler('notification');
331
            $notificationHandler->triggerEvent('global', 0, 'new_category', $tags);
332
            $database_mess = _AM_XOOPSTUBE_CCATEGORY_CREATED;
333
        } else {
334
            if ($cid == $pid) {
335
                redirect_header('category.php', 1, _AM_XOOPSTUBE_ERROR_CATISCAT);
336
            }
337
            $sql           = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat')
338
                             . " SET title ='$title', imgurl='$imgurl', pid =$pid, description='$descriptionb', spotlighthis='$spotlighthis' , spotlighttop='$spotlighttop', nohtml='$nohtml', nosmiley='$nosmiley', noxcodes='$noxcodes', noimages='$noimages', nobreak='$nobreak', weight='$weight', client_id='$client_id', banner_id='$banner_id' WHERE cid="
339
                             . (int)$cid;
340
            $database_mess = _AM_XOOPSTUBE_CCATEGORY_MODIFIED;
341
        }
342
        if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
343
            XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
344
345
            return false;
346
        }
347
        redirect_header('category.php', 1, $database_mess);
348
        break;
349
350
    case 'del':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
351
352
        global $xoopsModule;
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...
353
354
        //        $cid = (isset($_POST['cid']) && is_numeric($_POST['cid'])) ? (int) $_POST['cid'] : (int) $_GET['cid'];
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...
355
        $cid = XoopsRequest::getInt('cid', XoopsRequest::getInt('cid', 0, 'GET'), 'POST');
356
        //        $ok            = (isset($_POST['ok']) && $_POST['ok'] == 1) ? (int) $_POST['ok'] : 0;
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...
357
        $ok            = (1 == XoopsRequest::getInt('ok', 0, 'POST')) ? 1 : 0;
358
        $xoopstubetree = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
359
360
        if ($ok == 1) {
361
            // get all subcategories under the specified category
362
            $arr    = $xoopstubetree->getAllChildId($cid);
363
            $lcount = count($arr);
364
365
            for ($i = 0; $i < $lcount; ++$i) {
366
                // get all links in each subcategory
367
                $result = $GLOBALS['xoopsDB']->query('SELECT lid FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE cid=' . (int)$arr[$i]);
368
                // now for each linkload, delete the text data and vote ata associated with the linkload
369 View Code Duplication
                while (false !== (list($lid) = $GLOBALS['xoopsDB']->fetchRow($result))) {
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...
370
                    $sql = sprintf('DELETE FROM %s WHERE lid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'), (int)$lid);
371
                    $GLOBALS['xoopsDB']->query($sql);
372
                    $sql = sprintf('DELETE FROM %s WHERE lid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_videos'), (int)$lid);
373
                    $GLOBALS['xoopsDB']->query($sql);
374
375
                    // delete comments
376
                    xoops_comment_delete($xoopsModule->getVar('mid'), $lid);
377
                }
378
                // all links for each subcategory is deleted, now delete the subcategory data
379
                $sql = sprintf('DELETE FROM %s WHERE cid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_cat'), (int)$arr[$i]);
380
                $GLOBALS['xoopsDB']->query($sql);
381
                // delete altcat entries
382
                $sql = sprintf('DELETE FROM %s WHERE cid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_altcat'), $arr[$i]);
383
                $GLOBALS['xoopsDB']->query($sql);
384
            }
385
            // all subcategory and associated data are deleted, now delete category data and its associated data
386
            $result = $GLOBALS['xoopsDB']->query('SELECT lid FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE cid=' . (int)$cid);
387 View Code Duplication
            while (false !== (list($lid) = $GLOBALS['xoopsDB']->fetchRow($result))) {
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...
388
                $sql = sprintf('DELETE FROM %s WHERE lid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_videos'), (int)$lid);
389
                $GLOBALS['xoopsDB']->query($sql);
390
                // delete comments
391
                xoops_comment_delete($xoopsModule->getVar('mid'), (int)$lid);
392
                $sql = sprintf('DELETE FROM %s WHERE lid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'), (int)$lid);
393
                $GLOBALS['xoopsDB']->query($sql);
394
            }
395
396
            // delete altcat entries
397
            $sql = sprintf('DELETE FROM %s WHERE cid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_altcat'), (int)$cid);
398
            $GLOBALS['xoopsDB']->query($sql);
399
400
            // delete category
401
            $sql   = sprintf('DELETE FROM %s WHERE cid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_cat'), (int)$cid);
402
            $error = _AM_XOOPSTUBE_DBERROR . ': <br><br>' . $sql;
403
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeCatPerm', (int)$cid);
404
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
405
                trigger_error($error, E_USER_ERROR);
406
            }
407
408
            // delete group permissions
409
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeCatPerm', $cid);
410
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
411
                trigger_error($error, E_USER_ERROR);
412
            }
413
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeSubPerm', $cid);
414
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
415
                trigger_error($error, E_USER_ERROR);
416
            }
417
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeAppPerm', $cid);
418
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
419
                trigger_error($error, E_USER_ERROR);
420
            }
421
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeAutoApp', $cid);
422
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
423
                trigger_error($error, E_USER_ERROR);
424
            }
425
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'XTubeRatePerms', $cid);
426
            if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
427
                trigger_error($error, E_USER_ERROR);
428
            }
429
430
            redirect_header('category.php', 1, _AM_XOOPSTUBE_CCATEGORY_DELETED);
431
        } else {
432
            xoops_cp_header();
433
            xoops_confirm(array(
434
                              'op'  => 'del',
435
                              'cid' => (int)$cid,
436
                              'ok'  => 1
437
                          ), 'category.php', _AM_XOOPSTUBE_CCATEGORY_AREUSURE);
438
            xoops_cp_footer();
439
        }
440
        break;
441
442
    case 'modCat':
443
        $cid = XoopsRequest::getInt('cid', 0, 'POST'); //(isset($_POST['cid'])) ? $_POST['cid'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
444
        xoops_cp_header();
445
        //xtubeRenderAdminMenu(_AM_XOOPSTUBE_MCATEGORY);
446
        createCategory($cid);
447
        include_once __DIR__ . '/admin_footer.php';
448
        break;
449
450
    case 'main':
451
    default:
452
        xoops_cp_header();
453
        //xtubeRenderAdminMenu(_AM_XOOPSTUBE_MCATEGORY);
454
455
        //        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
456
        $xoopstubetree = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
457
        $sform         = new XoopsThemeForm(_AM_XOOPSTUBE_CCATEGORY_MODIFY, 'category', xoops_getenv('PHP_SELF'));
458
        $totalcats     = XoopstubeUtilities::xtubeGetTotalCategoryCount();
459
460
        if ($totalcats > 0) {
461
            ob_start();
462
            $xoopstubetree->makeMySelBox('title', 'title');
463
            $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_CCATEGORY_MODIFY_TITLE, ob_get_contents()));
464
            ob_end_clean();
465
            $dup_tray = new XoopsFormElementTray('', '');
466
            $dup_tray->addElement(new XoopsFormHidden('op', 'modCat'));
467
            $butt_dup = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit');
468
            $butt_dup->setExtra('onclick="this.form.elements.op.value=\'modCat\'"');
469
            $dup_tray->addElement($butt_dup);
470
            $butt_move = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMOVE, 'submit');
471
            $butt_move->setExtra('onclick="this.form.elements.op.value=\'move\'"');
472
            $dup_tray->addElement($butt_move);
473
            $butt_dupct = new XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit');
474
            $butt_dupct->setExtra('onclick="this.form.elements.op.value=\'del\'"');
475
            $dup_tray->addElement($butt_dupct);
476
            $sform->addElement($dup_tray);
477
            $sform->display();
478
        }
479
        createCategory(0);
480
        include_once __DIR__ . '/admin_footer.php';
481
        break;
482
}
483