Completed
Push — master ( 923121...f83415 )
by Michael
02:52
created

category.php ➔ AdsModCat()   F

Complexity

Conditions 15
Paths 2560

Size

Total Lines 122
Code Lines 88

Duplication

Lines 22
Ratio 18.03 %

Importance

Changes 0
Metric Value
cc 15
eloc 88
nc 2560
nop 1
dl 22
loc 122
rs 2
c 0
b 0
f 0

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

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
include_once __DIR__ . '/admin_header.php';
24
xoops_cp_header();
25
26
$op = XoopsRequest::getCmd('op', 'liste');
27
28
#  function AdsNewCat
29
#####################################################
30
/**
31
 * @param $cat
32
 */
33
function AdsNewCat($cat)
34
{
35
    global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $myts, $moduleDirName;
1 ignored issue
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...
36
37
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
38
39
    include_once __DIR__ . '/header.php';
40
41
    //    loadModuleAdminMenu(1, "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_ADDSUBCAT . '</legend>';
43
    ShowImg();
44
45
    echo "<form method=\"post\" action=\"category.php\" name=\"imcat\"><input type=\"hidden\" name=\"op\" value=\"AdsAddCat\"></font><br><br>
46
        <table class=\"outer\" border=0>
47
    <tr>
48
      <td class=\"even\">" . _AM_ADSLIGHT_CATNAME . " </td><td class=\"odd\" colspan=2><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"100\">&nbsp; " . _AM_ADSLIGHT_IN . ' &nbsp;';
49
50
    $cid = XoopsRequest::getInt('cid', 0, 'GET');
0 ignored issues
show
Unused Code introduced by
$cid 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...
51
52
    $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords, img, ordre, affprice, cat_moderate, moderate_subcat FROM '
53
                              . $xoopsDB->prefix('adslight_categories')
54
                              . " WHERE cid=$cat");
55
    list($cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $ordre, $affprice, $cat_moderate, $moderate_subcat) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $pid 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...
Unused Code introduced by
The assignment to $title 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...
Unused Code introduced by
The assignment to $cat_desc 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...
Unused Code introduced by
The assignment to $cat_keywords 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...
Unused Code introduced by
The assignment to $imgs 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...
Unused Code introduced by
The assignment to $affprice 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...
Unused Code introduced by
The assignment to $cat_moderate 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...
Unused Code introduced by
The assignment to $moderate_subcat 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...
Unused Code introduced by
The assignment to $cat_id 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...
56
    $mytree->makeMySelBox('title', 'title', $cat, 1);
57
    echo '</td>
58
    </tr>';
59
    $cat_desc     = '';
60
    $cat_keywords = '';
61
62 View Code Duplication
    if ('1' == $xoopsModuleConfig['adslight_cat_desc']) {
1 ignored issue
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...
63
        echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_DESCRIPTION . " </td><td class=\"odd\" colspan=2>";
64
        echo "<input type=\"text\" name=\"cat_desc\" value=\"$cat_desc\" size=\"80\" maxlength=\"200\">";
65
        echo '</td></tr>';
66
67
        echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_KEYWORDS . " </td><td class=\"odd\" colspan=2>";
68
        echo "<input type=\"text\" name=\"cat_keywords\" value=\"$cat_keywords\" size=\"80\" maxlength=\"200\">";
69
        echo '</td></tr>';
70
    }
71
72
    echo "<tr>
73
      <td class=\"even\">" . _AM_ADSLIGHT_IMGCAT . "  </td><td class=\"odd\" colspan=2><select name=\"img\" onChange=\"showimage()\">";
74
75
    $rep    = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat';
76
    $handle = opendir($rep);
77
    while ($file = readdir($handle)) {
78
        $filelist[] = $file;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$filelist was never initialized. Although not strictly required by PHP, it is generally a good practice to add $filelist = 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...
79
    }
80
    asort($filelist);
81 View Code Duplication
    while (list($key, $file) = each($filelist)) {
1 ignored issue
show
Unused Code introduced by
The assignment to $key 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...
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...
82
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
83
            if ($file === '.' || $file === '..') {
84
                $a = 1;
0 ignored issues
show
Unused Code introduced by
$a 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...
85
            }
86
        } else {
87
            if ($file === 'default.png') {
88
                echo "<option value=$file selected>$file</option>";
89
            } else {
90
                echo "<option value=$file>$file</option>";
91
            }
92
        }
93
    }
94
    echo "</select>&nbsp;&nbsp;<img src=\""
95
         . XOOPS_URL
96
         . "/modules/adslight/assets/images/img_cat/default.png\" name=\"avatar\" align=\"absmiddle\"><br><b>"
97
         . _AM_ADSLIGHT_REPIMGCAT
98
         . '</b><br>../modules/adslight/assets/images/img_cat/..</td></tr>';
99
100
    echo "<tr><td class=\"even\">"
101
         . _AM_ADSLIGHT_DISPLPRICE2
102
         . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"affprice\" value=\"1\" checked>"
103
         . _AM_ADSLIGHT_OUI
104
         . "&nbsp;&nbsp; <input type=\"radio\" name=\"affprice\" value=\"0\">"
105
         . _AM_ADSLIGHT_NON
106
         . ' ('
107
         . _AM_ADSLIGHT_INTHISCAT
108
         . ')</td></tr>';
109
110
    echo "<tr><td class=\"even\">"
111
         . _AM_ADSLIGHT_MODERATE_CAT
112
         . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"cat_moderate\" value=\"1\"checked>"
113
         . _AM_ADSLIGHT_OUI
114
         . "&nbsp;&nbsp; <input type=\"radio\" name=\"cat_moderate\" value=\"0\">"
115
         . _AM_ADSLIGHT_NON
116
         . '</td></tr>';
117
118
    echo "<tr><td class=\"even\">"
119
         . _AM_ADSLIGHT_MODERATE_SUBCATS
120
         . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"moderate_subcat\" value=\"1\"checked>"
121
         . _AM_ADSLIGHT_OUI
122
         . "&nbsp;&nbsp; <input type=\"radio\" name=\"moderate_subcat\" value=\"0\">"
123
         . _AM_ADSLIGHT_NON
124
         . '</td></tr>';
125
126
    if ($xoopsModuleConfig['adslight_csortorder'] !== 'title') {
127
        echo '<tr><td>'
128
             . _AM_ADSLIGHT_ORDRE
129
             . " </td><td><input type=\"text\" name=\"ordre\" size=\"4\" value=\"0\" /></td><td class=\"foot\"><input type=\"submit\" value=\""
130
             . _AM_ADSLIGHT_ADD
131
             . "\" /></td></tr>";
132
    } else {
133
        $ordre = (int)$ordre;
134
        echo "<input type=\"hidden\" name=\"ordre\" value=\"$ordre\">";
135
        echo "<tr><td class=\"foot\" colspan=3><input type=\"submit\" value=\"" . _AM_ADSLIGHT_ADD . "\" /></td></tr>";
136
    }
137
138
    echo '</table>
139
        </form>';
140
    echo '<br>';
141
142
    echo '</fieldset><br>';
143
    xoops_cp_footer();
144
}
145
146
#  function AdsModCat
147
#####################################################
148
/**
149
 * @param $cid
150
 */
151
function AdsModCat($cid)
152
{
153
    global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $myts, $moduleDirName;
1 ignored issue
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...
154
155
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
156
157
    include_once __DIR__ . '/header.php';
158
159
    //    loadModuleAdminMenu(1, "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
160
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODIFCAT . '</legend>';
161
    ShowImg();
162
163
    $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords, img, ordre, affprice, cat_moderate, moderate_subcat FROM '
164
                              . $xoopsDB->prefix('adslight_categories')
165
                              . " WHERE cid=$cid");
166
    list($cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $ordre, $affprice, $cat_moderate, $moderate_subcat) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $cat_id 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...
167
168
    $title    = $myts->htmlSpecialChars($title);
169
    $cat_desc = $myts->addSlashes($cat_desc);
170
    echo "<form action=\"category.php\" method=\"post\" name=\"imcat\">
171
        <table class=\"outer\" border=\"0\"><tr>
172
    <td class=\"even\">"
173
         . _AM_ADSLIGHT_CATNAME
174
         . "   </td><td class=\"odd\"><input type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\" />&nbsp; "
175
         . _AM_ADSLIGHT_IN
176
         . ' &nbsp;';
177
    $mytree->makeMySelBox('title', 'title', $pid, 1);
178
    echo '</td></tr>';
179
180 View Code Duplication
    if ($xoopsModuleConfig['adslight_cat_desc'] = '1') {
1 ignored issue
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...
181
        echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_DESCRIPTION . " </td><td class=\"odd\" colspan=2>";
182
        echo "<input type=\"text\" name=\"cat_desc\" value=\"$cat_desc\" size=\"80\" maxlength=\"200\">";
183
        echo '</td></tr>';
184
185
        echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_KEYWORDS . " </td><td class=\"odd\" colspan=2>";
186
        echo "<input type=\"text\" name=\"cat_keywords\" value=\"$cat_keywords\" size=\"80\" maxlength=\"200\">";
187
        echo '</td></tr>';
188
    }
189
190
    echo "<tr>
191
    <td class=\"even\">" . _AM_ADSLIGHT_IMGCAT . "  </td><td class=\"odd\"><select name=\"img\" onChange=\"showimage()\">";
192
193
    $rep    = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat';
194
    $handle = opendir($rep);
195
    while ($file = readdir($handle)) {
196
        $filelist[] = $file;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$filelist was never initialized. Although not strictly required by PHP, it is generally a good practice to add $filelist = 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...
197
    }
198
    asort($filelist);
199 View Code Duplication
    while (list($key, $file) = each($filelist)) {
1 ignored issue
show
Unused Code introduced by
The assignment to $key 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...
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...
200
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
201
            if ($file === '.' || $file === '..') {
202
                $a = 1;
0 ignored issues
show
Unused Code introduced by
$a 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...
203
            }
204
        } else {
205
            if ($file == $imgs) {
206
                echo "<option value=$file selected>$file</option>";
207
            } else {
208
                echo "<option value=$file>$file</option>";
209
            }
210
        }
211
    }
212
    echo "</select>&nbsp;&nbsp;<img src=\""
213
         . XOOPS_URL
214
         . "/modules/adslight/assets/images/img_cat/$imgs\" name=\"avatar\" align=\"absmiddle\"><br><b>"
215
         . _AM_ADSLIGHT_REPIMGCAT
216
         . '</b><br>../modules/adslight/assets/images/img_cat/..</td></tr>';
217
218
    echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_DISPLPRICE2 . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"affprice\" value=\"1\"";
219
    if ($affprice == '1') {
220
        echo 'checked';
221
    }
222
    echo '>' . _AM_ADSLIGHT_OUI . "&nbsp;&nbsp; <input type=\"radio\" name=\"affprice\" value=\"0\"";
223
    if ($affprice == '0') {
224
        echo 'checked';
225
    }
226
    echo '>' . _AM_ADSLIGHT_NON . ' (' . _AM_ADSLIGHT_INTHISCAT . ')</td></tr>';
227
228
    echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_MODERATE_CAT . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"cat_moderate\" value=\"1\"";
229
    if ($cat_moderate == '1') {
230
        echo 'checked';
231
    }
232
    echo '>' . _AM_ADSLIGHT_OUI . "&nbsp;&nbsp; <input type=\"radio\" name=\"cat_moderate\" value=\"0\"";
233
    if ($cat_moderate == '0') {
234
        echo 'checked';
235
    }
236
    echo '>' . _AM_ADSLIGHT_NON . '</td></tr>';
237
238
    echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_MODERATE_SUBCATS . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"moderate_subcat\" value=\"1\"";
239
    if ($moderate_subcat == '1') {
240
        echo 'checked';
241
    }
242
    echo '>' . _AM_ADSLIGHT_OUI . "&nbsp;&nbsp; <input type=\"radio\" name=\"moderate_subcat\" value=\"0\"";
243
    if ($moderate_subcat == '0') {
244
        echo 'checked';
245
    }
246
    echo '>' . _AM_ADSLIGHT_NON . '</td></tr>';
247
248
    if ($xoopsModuleConfig['adslight_csortorder'] !== 'title') {
249
        echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_ORDRE . " </td><td class=\"odd\"><input type=\"text\" name=\"ordre\" size=\"4\" value=\"$ordre\"></td></tr>";
250
    } else {
251
        $ordre = (int)$ordre;
252
        echo "<input type=\"hidden\" name=\"ordre\" value=\"$ordre\">";
253
    }
254
255
    echo '</table>';
256
257
    echo "<input type=\"hidden\" name=\"cidd\" value=\"$cid\">"
258
         . "<input type=\"hidden\" name=\"op\" value=\"AdsModCatS\">"
259
         . "<table class=\"foot\" border=\"0\"><tr><td width=\"20%\"><br>"
260
261
         . "<input type=\"submit\" value=\""
262
         . _AM_ADSLIGHT_SAVMOD
263
         . "\"></form></td><td><br>"
264
         . "<form action=\"category.php\" method=\"post\">"
265
         . "<input type=\"hidden\" name=\"cid\" value=\"$cid\">"
266
         . "<input type=\"hidden\" name=\"op\" value=\"AdsDelCat\">"
267
         . "<input type=\"submit\" value=\""
268
         . _AM_ADSLIGHT_DEL
269
         . "\"></form></td></tr></table>";
270
    echo '</fieldset><br>';
271
    xoops_cp_footer();
272
}
273
274
#  function AdsModCatS
275
#####################################################
276
/**
277
 * @param $cidd
278
 * @param $cid
279
 * @param $img
280
 * @param $title
281
 * @param $cat_desc
282
 * @param $cat_keywords
283
 * @param $ordre
284
 * @param $affprice
285
 * @param $cat_moderate
286
 * @param $moderate_subcat
287
 */
288
function AdsModCatS(
289
    $cidd,
290
    $cid,
291
    $img,
292
    $title,
293
    $cat_desc,
294
    $cat_keywords,
295
    $ordre,
296
    $affprice,
297
    $cat_moderate,
298
    $moderate_subcat
299
) {
300
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName;
1 ignored issue
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...
301
302
    $title = $myts->htmlSpecialChars($title);
303
    $cidd  = (int)$cidd;
304
305
    $xoopsDB->query('UPDATE '
306
                    . $xoopsDB->prefix('adslight_categories')
307
                    . " SET title='$title', cat_desc='$cat_desc', cat_keywords='$cat_keywords', pid='$cid', img='$img', ordre='$ordre', affprice='$affprice', cat_moderate='$cat_moderate', moderate_subcat='$moderate_subcat' WHERE cid=$cidd");
308
309 View Code Duplication
    if ($moderate_subcat != 1) {
1 ignored issue
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...
310
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=0, moderate_subcat=0 WHERE pid = ' . $xoopsDB->escape($cidd) . '');
311
    } else {
312
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=1, moderate_subcat=1 WHERE pid = ' . $xoopsDB->escape($cidd) . '');
313
    }
314
315
    redirect_header('map.php', 10, _AM_ADSLIGHT_CATSMOD);
316
}
317
318
#  function AdsAddCat
319
#####################################################
320
/**
321
 * @param $title
322
 * @param $cat_desc
323
 * @param $cat_keywords
324
 * @param $cid
325
 * @param $img
326
 * @param $ordre
327
 * @param $affprice
328
 * @param $cat_moderate
329
 * @param $moderate_subcat
330
 */
331
function AdsAddCat($title, $cat_desc, $cat_keywords, $cid, $img, $ordre, $affprice, $cat_moderate, $moderate_subcat)
332
{
333
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName;
1 ignored issue
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...
334
335
    $title           = $myts->htmlSpecialChars($title);
336
    $moderate_subcat = (int)$moderate_subcat;
337
    if ($title == '') {
338
        $title = '! ! ? ! !';
339
    }
340
341
    $xoopsDB->query('insert into '
342
                    . $xoopsDB->prefix('adslight_categories')
343
                    . " values (NULL, '$cid', '$title', '$cat_desc', '$cat_keywords', '$img', '$ordre', '$affprice', '$cat_moderate', '$moderate_subcat')");
344
345 View Code Duplication
    if ($moderate_subcat = 1) {
1 ignored issue
show
Unused Code introduced by
$moderate_subcat 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...
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...
346
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=1 WHERE pid = ' . $xoopsDB->escape($cid) . '');
347
    } else {
348
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=0 WHERE pid = ' . $xoopsDB->escape($cid) . '');
349
    }
350
351
    redirect_header('map.php', 3, _AM_ADSLIGHT_CATADD);
352
}
353
354
#  function AdsDelCat
355
#####################################################
356
/**
357
 * @param     $cid
358
 * @param int $ok
359
 */
360
function AdsDelCat($cid, $ok = 0)
361
{
362
    global $xoopsDB, $xoopsConfig, $xoopsModule, $moduleDirName;
1 ignored issue
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...
363
364
    if ((int)$ok == 1) {
365
        $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
366
        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid=$cid or pid=$cid");
367
        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE cid=$cid");
368
369
        redirect_header('map.php', 1, _AM_ADSLIGHT_CATDEL);
370
    } else {
371
        include_once __DIR__ . '/header.php';
372
        //        loadModuleAdminMenu(1, "");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
373
374
        OpenTable();
375
        echo '<br><center><b>' . _AM_ADSLIGHT_SURDELCAT . '</b><br><br>';
376
        echo "[ <a href=\"category.php?op=AdsDelCat&cid=$cid&ok=1\">" . _AM_ADSLIGHT_OUI . "</a> | <a href=\"map.php\">" . _AM_ADSLIGHT_NON . '</a> ]<br><br>';
377
        CloseTable();
378
        xoops_cp_footer();
379
    }
380
}
381
382
#####################################################
383
//@todo REMOVE THIS ASAP!  This code is extremely unsafe
384
foreach ($_POST as $k => $v) {
385
    ${$k} = $v;
386
}
387
388
$ok  = XoopsRequest::getString('ok', '', 'GET');
389
$cid = XoopsRequest::getInt('cid', 0);
390
$op  = XoopsRequest::getCmd('op', '');
391
392
switch ($op) {
393
394
    case 'AdsNewCat':
395
        AdsNewCat($cid);
396
        break;
397
398
    case 'AdsAddCat':
399
        AdsAddCat($title, $cat_desc, $cat_keywords, $cid, $img, $ordre, $affprice, $cat_moderate, $moderate_subcat);
400
        break;
401
402
    case 'AdsDelCat':
403
        AdsDelCat($cid, $ok);
404
        break;
405
406
    case 'AdsModCat':
407
        AdsModCat($cid);
408
        break;
409
410
    case 'AdsModCatS':
411
        AdsModCatS($cidd, $cid, $img, $title, $cat_desc, $cat_keywords, $ordre, $affprice, $cat_moderate, $moderate_subcat);
412
        break;
413
414
    default:
415
        Index();
416
        break;
417
418
}
419