Completed
Push — master ( bbda49...c5c3b2 )
by Michael
02:49
created

category.php ➔ createcat()   C

Complexity

Conditions 8
Paths 64

Size

Total Lines 175
Code Lines 137

Duplication

Lines 5
Ratio 2.86 %

Importance

Changes 0
Metric Value
cc 8
eloc 137
nc 64
nop 1
dl 5
loc 175
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 28 and the first side effect is on line 12.

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
 * $Id: category.php v 1.00 21 June 2005 John N Exp $
4
 * Module: WF-Links
5
 * Version: v1.0.3
6
 * Release Date: 21 June 2005
7
 * Developer: John N
8
 * Team: WF-Projects
9
 * Licence: GNU
10
 */
11
12
include 'admin_header.php';
13
include_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php';
14
15
$op = '';
16
17
if (isset($_POST)) {
18
    foreach ($_POST as $k => $v) {
19
        ${$k} = $v;
20
    }
21
}
22
if (isset($_GET)) {
23
    foreach ($_GET as $k => $v) {
24
        ${$k} = $v;
25
    }
26
}
27
28
function createcat($cid = 0)
29
{
30
    include_once '../class/wfl_lists.php';
31
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
32
33
    global $xoopsDB, $wfmyts, $xoopsModuleConfig, $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...
34
35
    $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...
36
    $title = '';
37
    $imgurl = '';
38
    $description = '';
39
    $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...
40
    $weight = 0;
41
    $nohtml = 0;
42
    $nosmiley = 0;
43
    $noxcodes = 0;
44
    $noimages = 0;
45
    $nobreak = 1;
46
    $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...
47
    $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...
48
    $client_id = 0;
49
    $banner_id = 0;
50
    $heading = _AM_WFL_CCATEGORY_CREATENEW;
51
    $totalcats = wfl_totalcategory();
52
53
    if ($cid) {
54
        $sql = "SELECT * FROM " . $xoopsDB -> prefix('wflinks_cat') . " WHERE cid=$cid";
55
        $cat_arr = $xoopsDB -> fetchArray($xoopsDB -> query($sql));
56
        $title = $wfmyts -> htmlSpecialChars($cat_arr['title']);
57
        $imgurl = $wfmyts -> htmlSpecialChars($cat_arr['imgurl']);
58
        $description = $wfmyts -> htmlSpecialChars($cat_arr['description']);
59
        $nohtml = intval($cat_arr['nohtml']);
60
        $nosmiley = intval($cat_arr['nosmiley']);
61
        $noxcodes = intval($cat_arr['noxcodes']);
62
        $noimages = intval($cat_arr['noimages']);
63
        $nobreak = intval($cat_arr['nobreak']);
64
        $spotlighthis = intval($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...
65
        $spotlighttop = intval($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...
66
        $weight = $cat_arr['weight'];
67
        $client_id = $cat_arr['client_id'];
68
        $banner_id = $cat_arr['banner_id'];
69
        $heading = _AM_WFL_CCATEGORY_MODIFY;
70
71
        $gperm_handler = & xoops_gethandler('groupperm');
72
        $groups = $gperm_handler -> getGroupIds('WFLinkCatPerm', $cid, $xoopsModule -> getVar('mid'));
73
        $groups = $groups;
0 ignored issues
show
Bug introduced by
Why assign $groups to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
74
    } else {
75
    $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...
76
    }
77
78
    $sform = new XoopsThemeForm($heading, "op", xoops_getenv('PHP_SELF'));
79
    $sform -> setExtra('enctype="multipart/form-data"');
80
81
    $sform -> addElement(new XoopsFormText(_AM_WFL_FCATEGORY_TITLE, 'title', 50, 80, $title), true);
82
    $sform -> addElement(new XoopsFormText(_AM_WFL_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false);
83
84
    if ($totalcats > 0 && $cid) {
85
       $mytreechose = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), "cid", "pid");
86
       ob_start();
87
          $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...
88
          $sform -> addElement(new XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_contents()));
89
       ob_end_clean();
90
    } else {
91
      $mytreechose = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), 'cid', 'pid');
92
       ob_start();
93
          $mytreechose -> makeMySelBox("title", "title", $cid, 1, "pid");
94
          $sform -> addElement(new XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_contents()));
95
       ob_end_clean();
96
    }
97
98
    $graph_array = & wflLists :: getListTypeAsArray(XOOPS_ROOT_PATH . "/" . $xoopsModuleConfig['catimage'], $type = "images");
99
    $indeximage_select = new XoopsFormSelect('', 'imgurl', $imgurl);
100
    $indeximage_select -> addOptionArray($graph_array);
101
    $indeximage_select -> setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $xoopsModuleConfig['catimage'] . "\", \"\", \"" . XOOPS_URL . "\")'");
102
    $indeximage_tray = new XoopsFormElementTray(_AM_WFL_FCATEGORY_CIMAGE, '&nbsp;');
103
    $indeximage_tray -> addElement($indeximage_select);
104 View Code Duplication
    if (!empty($imgurl)) {
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...
105
        $indeximage_tray -> addElement(new XoopsFormLabel('', "<br /><br /><img src='" . XOOPS_URL . "/" . $xoopsModuleConfig['catimage'] . "/" . $imgurl . "' name='image' id='image' alt='' />"));
106
    } else {
107
        $indeximage_tray -> addElement(new XoopsFormLabel('', "<br /><br /><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt='' />"));
108
    }
109
    $sform -> addElement($indeximage_tray);
110
111
    $editor = wfl_getWysiwygForm( _AM_WFL_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, '');
0 ignored issues
show
Unused Code introduced by
The call to wfl_getWysiwygForm() has too many arguments starting with 15.

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

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

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
112
    $sform -> addElement( $editor, false );
113
114
// Select Client/Sponsor
115
    $client_select = new XoopsFormSelect( _AM_WFL_CATSPONSOR, 'client_id', $client_id, false);
116
    $sql = "SELECT cid, name FROM " . $xoopsDB -> prefix('bannerclient') . " ORDER BY name ASC";
117
    $result = $xoopsDB -> query($sql);
118
    $client_array = array();
119
    $client_array[0] = '&nbsp;';
120
    while ($myrow = $xoopsDB -> fetchArray($result)) {
121
        $client_array[$myrow['cid']] = $myrow['name'];
122
    }
123
    $client_select -> addOptionArray($client_array);
124
    $client_select -> setDescription(_AM_WFL_CATSPONSORDSC);
125
    $sform -> addElement( $client_select );
126
127
// Select Banner
128
    $banner_select = new XoopsFormSelect( _AM_WFL_BANNERID, 'banner_id', $banner_id, false);
129
    $sql = "SELECT bid, cid FROM " . $xoopsDB -> prefix('banner') . " ORDER BY bid ASC";
130
    $result = $xoopsDB -> query($sql);
131
    $banner_array = array();
132
    $banner_array[0] = '&nbsp;';
133
    while ($myrow = $xoopsDB -> fetchArray($result)) {
134
        $banner_array[$myrow['bid']] = $myrow['bid'];
135
    }
136
    $banner_select -> addOptionArray($banner_array);
137
    $banner_select -> setDescription(_AM_WFL_BANNERIDDSC);
138
    $sform -> addElement( $banner_select );
139
140
    $options_tray = new XoopsFormElementTray(_AM_WFL_TEXTOPTIONS, '<br />');
141
142
    $html_checkbox = new XoopsFormCheckBox('', 'nohtml', $nohtml);
143
    $html_checkbox -> addOption(1, _AM_WFL_DISABLEHTML);
144
    $options_tray -> addElement($html_checkbox);
145
146
    $smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', $nosmiley);
147
    $smiley_checkbox -> addOption(1, _AM_WFL_DISABLESMILEY);
148
    $options_tray -> addElement($smiley_checkbox);
149
150
    $xcodes_checkbox = new XoopsFormCheckBox('', 'noxcodes', $noxcodes);
151
    $xcodes_checkbox -> addOption(1, _AM_WFL_DISABLEXCODE);
152
    $options_tray -> addElement($xcodes_checkbox);
153
154
    $noimages_checkbox = new XoopsFormCheckBox('', 'noimages', $noimages);
155
    $noimages_checkbox -> addOption(1, _AM_WFL_DISABLEIMAGES);
156
    $options_tray -> addElement($noimages_checkbox);
157
158
    $breaks_checkbox = new XoopsFormCheckBox('', 'nobreak', $nobreak);
159
    $breaks_checkbox -> addOption(1, _AM_WFL_DISABLEBREAK);
160
    $options_tray -> addElement($breaks_checkbox);
161
    $sform -> addElement($options_tray);
162
163
//    $sform -> addElement(new XoopsFormSelectGroup(_AM_WFL_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...
164
165
    $sform -> addElement(new XoopsFormHidden('cid', $cid));
166
167
    $sform -> addElement(new XoopsFormHidden('spotlighttop', $cid));
168
169
    $button_tray = new XoopsFormElementTray('', '');
170
    $hidden = new XoopsFormHidden('op', 'save');
171
    $button_tray -> addElement($hidden);
172
173
    if (!$cid) {
174
        $butt_create = new XoopsFormButton('', '', _AM_WFL_BSAVE, 'submit');
175
        $butt_create -> setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
176
        $button_tray -> addElement($butt_create);
177
178
        $butt_clear = new XoopsFormButton('', '', _AM_WFL_BRESET, 'reset');
179
        $button_tray -> addElement($butt_clear);
180
181
        $butt_cancel = new XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button');
182
        $butt_cancel -> setExtra('onclick="history.go(-1)"');
183
        $button_tray -> addElement($butt_cancel);
184
    } else {
185
        $butt_create = new XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit');
186
        $butt_create -> setExtra('onclick="this.form.elements.op.value=\'addCat\'"');
187
        $button_tray -> addElement($butt_create);
188
189
        $butt_delete = new XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit');
190
        $butt_delete -> setExtra('onclick="this.form.elements.op.value=\'del\'"');
191
        $button_tray -> addElement($butt_delete);
192
193
        $butt_cancel = new XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button');
194
        $butt_cancel -> setExtra('onclick="history.go(-1)"');
195
        $button_tray -> addElement($butt_cancel);
196
    }
197
    $sform -> addElement($button_tray);
198
    $sform -> display();
199
200
    $result2 = $xoopsDB -> query("SELECT COUNT(*) FROM " . $xoopsDB -> prefix('wflinks_cat') . "");
201
    list($numrows) = $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...
202
}
203
204
if (!isset($_POST['op'])) {
205
    $op = isset($_GET['op']) ? $_GET['op'] : 'main';
206
   } else {
207
    $op = isset($_POST['op']) ? $_POST['op'] : 'main';
208
   }
209
210
switch ($op) {
211
    case "move":
212
        if (!isset($_POST['ok'])) {
213
            $cid = (isset($_POST['cid'])) ? $_POST['cid'] : $_GET['cid'];
214
215
            xoops_cp_header();
216
            //wfl_adminmenu(_AM_WFL_MCATEGORY);
217
218
            include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
219
            $mytree = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), "cid", "pid");
220
            $sform = new XoopsThemeForm( _AM_WFL_CCATEGORY_MOVE, "move", xoops_getenv('PHP_SELF'));
221
            ob_start();
222
              $mytree -> makeMySelBox( "title", "title", 0 , 0, "target" );
223
              $sform -> addElement(new XoopsFormLabel(_AM_WFL_BMODIFY, ob_get_contents()));
224
            ob_end_clean();
225
            $create_tray = new XoopsFormElementTray('', '');
226
            $create_tray -> addElement(new XoopsFormHidden('source', $cid));
227
            $create_tray -> addElement(new XoopsFormHidden('ok', 1));
228
            $create_tray -> addElement(new XoopsFormHidden('op', 'move'));
229
            $butt_save = new XoopsFormButton('', '', _AM_WFL_BMOVE, 'submit');
230
            $butt_save -> setExtra('onclick="this.form.elements.op.value=\'move\'"');
231
            $create_tray -> addElement($butt_save);
232
            $butt_cancel = new XoopsFormButton('', '', _AM_WFL_BCANCEL, 'submit');
233
            $butt_cancel -> setExtra('onclick="this.form.elements.op.value=\'cancel\'"');
234
            $create_tray -> addElement($butt_cancel);
235
            $sform -> addElement($create_tray);
236
            $sform -> display();
237
            xoops_cp_footer();
238
        } else {
239
            global $xoopsDB;
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...
240
241
            $source = $_POST['source'];
242
            $target = $_POST['target'];
243
            if ($target == $source) {
244
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_WFL_CCATEGORY_MODIFY_FAILED);
245
            }
246
            if (!$target) {
247
                redirect_header("category.php?op=move&ok=0&cid=$source", 5, _AM_WFL_CCATEGORY_MODIFY_FAILEDT);
248
            }
249
            $sql = "UPDATE " . $xoopsDB -> prefix('wflinks_links') . " set cid = " . $target . " WHERE cid =" . $source;
250
            $result = $xoopsDB -> queryF($sql);
251
            $error = _AM_WFL_DBERROR . ": <br /><br />" . $sql;
252
            if (!$result) {
253
                trigger_error($error, E_USER_ERROR);
254
            }
255
            redirect_header("category.php?op=default", 1, _AM_WFL_CCATEGORY_MODIFY_MOVED);
256
            exit();
257
        }
258
        break;
259
260
    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...
261
262
        $groups = isset( $_REQUEST['groups'] ) ? $_REQUEST['groups'] : array();
263
        $cid = ( isset( $_REQUEST["cid"] ) ) ? $_REQUEST["cid"] : 0;
264
        $pid = ( isset( $_REQUEST["pid"] ) ) ? $_REQUEST["pid"] : 0;
265
        $weight = ( isset( $_REQUEST["weight"] ) && $_REQUEST["weight"] > 0 ) ? $_REQUEST["weight"] : 0;
266
        $spotlighthis = ( isset( $_REQUEST["lid"] ) ) ? $_REQUEST["lid"] : 0;
267
        $spotlighttop = ( $_REQUEST["spotlighttop"] == 1 ) ? 1 : 0;
268
        $title = $wfmyts -> addslashes( $_REQUEST["title"] );
269
        $descriptionb = $wfmyts -> addslashes( $_REQUEST["description"] );
270
        $imgurl = ( $_REQUEST["imgurl"] && $_REQUEST["imgurl"] != "blank.gif" ) ? $wfmyts -> addslashes( $_REQUEST["imgurl"] ) : "";
271
        $client_id = ( isset( $_REQUEST["client_id"] ) ) ? $_REQUEST["client_id"] : 0;
272
        if ($client_id > 0) {
273
          $banner_id = 0;
274
        } else {
275
          $banner_id = ( isset( $_REQUEST["banner_id"] ) ) ? $_REQUEST["banner_id"] : 0;
276
        }
277
278
        $nohtml = ( isset( $_REQUEST["nohtml"] ) ) ? $_REQUEST["nohtml"] : 0;
279
        $nosmiley = ( isset( $_REQUEST["nosmiley"] ) ) ? $_REQUEST["nosmiley"] : 0;
280
        $noxcodes = ( isset( $_REQUEST["noxcodes"] ) ) ? $_REQUEST["noxcodes"] : 0;
281
        $noimages = ( isset( $_REQUEST["noimages"] ) ) ? $_REQUEST["noimages"] : 0;
282
        $nobreak = isset( $_REQUEST['nobreak'] );
283
284
        if (!$cid) {
285
            $cid = 0;
286
            $sql = "INSERT INTO " . $xoopsDB -> prefix( 'wflinks_cat' ) . " (cid, pid, title, imgurl, description, nohtml, nosmiley, noxcodes, noimages, nobreak, weight, spotlighttop, spotlighthis, client_id, banner_id ) VALUES ('', $pid, '$title', '$imgurl', '$descriptionb', '$nohtml', '$nosmiley', '$noxcodes', '$noimages', '$nobreak', '$weight',  '$spotlighttop', '$spotlighthis', '$client_id', '$banner_id' )";
287
            if ($cid == 0) {
288
                $newid = $xoopsDB -> getInsertId();
289
            }
290
291
            // Notify of new category
292
293
            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...
294
            $tags = array();
295
            $tags['CATEGORY_NAME'] = $title;
296
            $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule -> getVar( 'dirname' ) . '/viewcat.php?cid=' . $newid;
297
            $notification_handler = &xoops_gethandler( 'notification' );
298
            $notification_handler -> triggerEvent( 'global', 0, 'new_category', $tags );
299
            $database_mess = _AM_WFL_CCATEGORY_CREATED;
300
        } else {
301
          if ($cid == $pid) {
302
            redirect_header("category.php", 1, _AM_WFL_ERROR_CATISCAT);
303
            exit();
304
            }
305
            $sql = "UPDATE " . $xoopsDB -> prefix( 'wflinks_cat' ) . " 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=" . $cid;
306
            $database_mess = _AM_WFL_CCATEGORY_MODIFIED;
307
        }
308
        if ( !$result = $xoopsDB -> query( $sql ) ) {
309
            XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
310
311
            return false;
312
        }
313
        redirect_header( "category.php", 1, $database_mess );
314
        break;
315
316
    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...
317
318
        global $xoopsDB, $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...
319
320
        $cid = (isset($_POST['cid']) && is_numeric($_POST['cid'])) ? intval($_POST['cid']) : intval($_GET['cid']);
321
        $ok = (isset($_POST['ok']) && $_POST['ok'] == 1) ? intval($_POST['ok']) : 0;
322
        $mytree = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), "cid", "pid");
323
324
        if ($ok == 1) {
325
            // get all subcategories under the specified category
326
            $arr = $mytree -> getAllChildId($cid);
327
            $lcount = count($arr);
328
329
            for ($i = 0; $i < $lcount; ++$i) {
330
                // get all links in each subcategory
331
                $result = $xoopsDB -> query("SELECT lid FROM " . $xoopsDB -> prefix('wflinks_links') . " WHERE cid=" . $arr[$i] . "");
332
                // now for each linkload, delete the text data and vote ata associated with the linkload
333 View Code Duplication
                while (list($lid) = $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...
334
                    $sql = sprintf("DELETE FROM %s WHERE lid = %u", $xoopsDB -> prefix('wflinks_votedata'), $lid);
335
                    $xoopsDB -> query($sql);
336
                    $sql = sprintf("DELETE FROM %s WHERE lid = %u", $xoopsDB -> prefix('wflinks_links'), $lid);
337
                    $xoopsDB -> query($sql);
338
339
                    // delete comments
340
                    xoops_comment_delete($xoopsModule -> getVar('mid'), $lid);
341
                }
342
                // all links for each subcategory are deleted, now delete the subcategory data
343
                $sql = sprintf("DELETE FROM %s WHERE cid = %u", $xoopsDB -> prefix('wflinks_cat'), $arr[$i]);
344
                $xoopsDB -> query($sql);
345
                // delete altcat entries
346
                $sql = sprintf("DELETE FROM %s WHERE cid = %u", $xoopsDB -> prefix('wflinks_altcat'), $arr[$i]);
347
                $xoopsDB -> query($sql);
348
            }
349
            // all subcategory and associated data are deleted, now delete category data and its associated data
350
            $result = $xoopsDB -> query("SELECT lid FROM " . $xoopsDB -> prefix('wflinks_links') . " WHERE cid=" . $cid . "");
351 View Code Duplication
            while (list($lid) = $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...
352
                $sql = sprintf("DELETE FROM %s WHERE lid = %u", $xoopsDB -> prefix('wflinks_links'), $lid);
353
                $xoopsDB -> query($sql);
354
                // delete comments
355
                xoops_comment_delete($xoopsModule -> getVar('mid'), $lid);
356
                $sql = sprintf("DELETE FROM %s WHERE lid = %u", $xoopsDB -> prefix('wflinks_votedata'), $lid);
357
                $xoopsDB -> query($sql);
358
            }
359
            // delete altcat entries
360
            $sql = sprintf("DELETE FROM %s WHERE cid = %u", $xoopsDB -> prefix('wflinks_altcat'), $cid);
361
            $xoopsDB -> query($sql);
362
            // delete category
363
            $sql = sprintf("DELETE FROM %s WHERE cid = %u", $xoopsDB -> prefix('wflinks_cat'), $cid);
364
            $error = _AM_WFL_DBERROR . ": <br /><br />" . $sql;
365
366
            // delete group permissions
367
            xoops_groupperm_deletebymoditem ($xoopsModule -> getVar('mid'), 'WFLinkCatPerm', $cid);
368
            if (!$result = $xoopsDB -> query($sql)) {
369
                trigger_error($error, E_USER_ERROR);
370
            }
371
372
            redirect_header("category.php", 1, _AM_WFL_CCATEGORY_DELETED);
373
            exit();
374
        } else {
375
            xoops_cp_header();
376
            xoops_confirm(array('op' => 'del', 'cid' => $cid, 'ok' => 1), 'category.php', _AM_WFL_CCATEGORY_AREUSURE);
377
            xoops_cp_footer();
378
        }
379
        break;
380
381
    case "modCat":
382
        $cid = (isset($_POST['cid'])) ? $_POST['cid'] : 0;
383
        xoops_cp_header();
384
        //wfl_adminmenu(_AM_WFL_MCATEGORY);
385
        createcat($cid);
386
        xoops_cp_footer();
387
        break;
388
389
    case 'main':
390
        default:
391
        xoops_cp_header();
392
        //wfl_adminmenu(_AM_WFL_MCATEGORY);
393
        $indexAdmin = new ModuleAdmin();
394
        echo $indexAdmin->addNavigation('category.php');
395
        $indexAdmin->addItemButton(_MI_WFL_ADD_LINK, 'main.php?op=edit', 'add', '');
396
        $indexAdmin->addItemButton(_MI_WFL_ADD_CATEGORY, 'category.php', 'add', '');
397
        echo $indexAdmin->renderButton('right', '');
398
399
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
400
        $mytree = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), "cid", "pid");
401
        $sform = new XoopsThemeForm(_AM_WFL_CCATEGORY_MODIFY, "category", xoops_getenv('PHP_SELF'));
402
        $totalcats = wfl_totalcategory();
403
404
        if ($totalcats > 0) {
405
            ob_start();
406
            $mytree -> makeMySelBox("title", "title");
407
            $sform -> addElement(new XoopsFormLabel(_AM_WFL_CCATEGORY_MODIFY_TITLE, ob_get_contents()));
408
            ob_end_clean();
409
            $dup_tray = new XoopsFormElementTray('', '');
410
            $dup_tray -> addElement(new XoopsFormHidden('op', 'modCat'));
411
            $butt_dup = new XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit');
412
            $butt_dup -> setExtra('onclick="this.form.elements.op.value=\'modCat\'"');
413
            $dup_tray -> addElement($butt_dup);
414
            $butt_move = new XoopsFormButton('', '', _AM_WFL_BMOVE, 'submit');
415
            $butt_move -> setExtra('onclick="this.form.elements.op.value=\'move\'"');
416
            $dup_tray -> addElement($butt_move);
417
            $butt_dupct = new XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit');
418
            $butt_dupct -> setExtra('onclick="this.form.elements.op.value=\'del\'"');
419
            $dup_tray -> addElement($butt_dupct);
420
            $sform -> addElement($dup_tray);
421
            $sform -> display();
422
        }
423
        createcat(0);
424
        include_once 'admin_footer.php';
425
        break;
426
}
427