Passed
Push — master ( 7fde14...e7cdb3 )
by Michael
02:25
created

adsModCatS()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
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
use Xmf\Request;
24
use XoopsModules\Adslight;
25
26
require_once __DIR__ . '/admin_header.php';
27
xoops_cp_header();
28
29
$op = Request::getString('op', 'liste');
30
31
#  function adsNewCat
32
#####################################################
33
/**
34
 * @param $cid
35
 */
36
function adsNewCat($cid)
0 ignored issues
show
Unused Code introduced by
The parameter $cid is not used and could be removed. ( Ignorable by Annotation )

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

36
function adsNewCat(/** @scrutinizer ignore-unused */ $cid)

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

Loading history...
37
{
38
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $moduleDirName;
39
40
    $mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
41
42
    //    require_once __DIR__ . '/header.php';
43
44
    //    loadModuleAdminMenu(1, "");
45
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_ADDSUBCAT . '</legend>';
46
    //    ShowImg();
47
    Adslight\Utility::showImage();
48
49
    echo '<form method="post" action="category.php" name="imcat"><input type="hidden" name="op" value="AdsAddCat"></font><br><br>
50
        <table class="outer" border=0>
51
    <tr>
52
      <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;';
53
54
    $cid = Request::getInt('cid', 0, 'GET');
55
56
    $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords, img, cat_order, affprice, cat_moderate, moderate_subcat FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid={$cid}");
57
    list($cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $cat_order, $affprice, $cat_moderate, $moderate_subcat) = $xoopsDB->fetchRow($result);
58
    $mytree->makeMySelBox('title', 'title', $cid, 1);
59
    echo "    </td>\n" . "  </tr>\n";
60
61
    $cat_desc     = '';
62
    $cat_keywords = '';
63
64
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_cat_desc']) {
65
        echo '<tr><td class="even">'
66
             . _AM_ADSLIGHT_CAT_META_DESCRIPTION
67
             . " </td><td class=\"odd\" colspan=2>\n"
68
             . "    <input type=\"text\" name=\"cat_desc\" value=\"$cat_desc\" size=\"80\" maxlength=\"200\">\n"
69
             . "  </td></tr>\n"
70
             . '  <tr><td class="even">'
71
             . _AM_ADSLIGHT_CAT_META_KEYWORDS
72
             . " </td><td class=\"odd\" colspan=2>\n"
73
             . "    <input type=\"text\" name=\"cat_keywords\" value=\"$cat_keywords\" size=\"80\" maxlength=\"200\">\n"
74
             . "  </td></tr>\n";
75
    }
76
77
    echo "  <tr>\n" . '    <td class="even">' . _AM_ADSLIGHT_IMGCAT . '  </td><td class="odd" colspan=2><select name="img" onChange="showimage()">';
78
79
    $rep    = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat';
80
    $handle = opendir($rep);
81
    while ($file = readdir($handle)) {
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

81
    while ($file = readdir(/** @scrutinizer ignore-type */ $handle)) {
Loading history...
82
        $filelist[] = $file;
83
    }
84
    asort($filelist);
85
    //    while (list($key, $file) = each($filelist)) {
86
    foreach ($filelist as $key => $file) {
87
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
88
            if ('.' === $file || '..' === $file) {
89
                $a = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
90
            }
91
        } else {
92
            if ('default.png' === $file) {
93
                echo "<option value=\"{$file}\" selected>{$file}</option>";
94
            } else {
95
                echo "<option value=\"{$file}\">{$file}</option>";
96
            }
97
        }
98
    }
99
    echo '</select>&nbsp;&nbsp;<img src="' . XOOPS_URL . '/modules/adslight/assets/images/img_cat/default.png" name="avatar" align="absmiddle"><br><b>' . _AM_ADSLIGHT_REPIMGCAT . '</b><br>../modules/adslight/assets/images/img_cat/..</td></tr>';
100
101
    echo '<tr><td class="even">' . _AM_ADSLIGHT_DISPLPRICE2 . ' </td><td class="odd" colspan=2><input type="radio" name="affprice" value="1" checked>' . _YES . '&nbsp;&nbsp; <input type="radio" name="affprice" value="0">' . _NO . ' (' . _AM_ADSLIGHT_INTHISCAT . ')</td></tr>';
102
103
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_CAT . ' </td><td class="odd" colspan=2><input type="radio" name="cat_moderate" value="1"checked>' . _YES . '&nbsp;&nbsp; <input type="radio" name="cat_moderate" value="0">' . _NO . '</td></tr>';
104
105
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_SUBCATS . ' </td><td class="odd" colspan=2><input type="radio" name="moderate_subcat" value="1"checked>' . _YES . '&nbsp;&nbsp; <input type="radio" name="moderate_subcat" value="0">' . _NO . '</td></tr>';
106
107
    if ('title' !== $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) {
108
        echo '<tr><td>' . _AM_ADSLIGHT_ORDER . ' </td><td><input type="text" name="cat_order" size="4" value="0" ></td><td class="foot"><input type="submit" value="' . _AM_ADSLIGHT_ADD . '" ></td></tr>';
109
    } else {
110
        $cat_order = (int)$cat_order;
111
        echo "<input type=\"hidden\" name=\"cat_order\" value=\"$cat_order\">";
112
        echo '<tr><td class="foot" colspan=3><input type="submit" value="' . _AM_ADSLIGHT_ADD . '" ></td></tr>';
113
    }
114
115
    echo "</table>\n" . "</form>\n" . "<br>\n" . "</fieldset><br>\n";
116
    xoops_cp_footer();
117
}
118
119
#  function adsModCat
120
#####################################################
121
/**
122
 * @param $cid
123
 */
124
function adsModCat($cid)
125
{
126
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $moduleDirName;
127
128
    $mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
129
130
    //    require_once __DIR__ . '/admin_header.php';
131
132
    //    loadModuleAdminMenu(1, '');
133
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODIFCAT . '</legend>';
134
    //    ShowImg();
135
    Adslight\Utility::showImage();
136
137
    $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords, img, cat_order, affprice, cat_moderate, moderate_subcat FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid=$cid");
138
    list($cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $cat_order, $affprice, $cat_moderate, $moderate_subcat) = $xoopsDB->fetchRow($result);
139
140
    $title    = $myts->htmlSpecialChars($title);
141
    $cat_desc = $myts->addSlashes($cat_desc);
142
    echo '<form action="category.php" method="post" name="imcat">';
143
    echo $GLOBALS['xoopsSecurity']->getTokenHTML();
144
    echo '<table class="outer" border="0"><tr>
145
    <td class="even">' . _AM_ADSLIGHT_CATNAME . "   </td><td class=\"odd\"><input type=\"text\" name=\"title\" value=\"{$title}\" size=\"50\" maxlength=\"100\">&nbsp; " . _AM_ADSLIGHT_IN . ' &nbsp;';
146
    $mytree->makeMySelBox('title', 'title', $pid, 1);
147
    echo '</td></tr>';
148
149
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_cat_desc']) {
150
        echo '<tr><td class="even">' . _AM_ADSLIGHT_CAT_META_DESCRIPTION . ' </td><td class="odd" colspan=2>';
151
        echo "<input type=\"text\" name=\"cat_desc\" value=\"{$cat_desc}\" size=\"80\" maxlength=\"200\">";
152
        echo '</td></tr>';
153
154
        echo '<tr><td class="even">' . _AM_ADSLIGHT_CAT_META_KEYWORDS . ' </td><td class="odd" colspan=2>';
155
        echo "<input type=\"text\" name=\"cat_keywords\" value=\"{$cat_keywords}\" size=\"80\" maxlength=\"200\">";
156
        echo '</td></tr>';
157
    }
158
159
    echo '<tr>
160
    <td class="even">' . _AM_ADSLIGHT_IMGCAT . '  </td><td class="odd"><select name="img" onChange="showimage()">';
161
162
    $rep    = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat';
163
    $handle = opendir($rep);
164
    while ($file = readdir($handle)) {
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

164
    while ($file = readdir(/** @scrutinizer ignore-type */ $handle)) {
Loading history...
165
        $filelist[] = $file;
166
    }
167
    asort($filelist);
168
    //    while (list($key, $file) = each($filelist)) {
169
    foreach ($filelist as $key => $file) {
170
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
171
            if ('.' === $file || '..' === $file) {
172
                $a = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
173
            }
174
        } else {
175
            if ($file == $imgs) {
176
                echo "<option value=\"{$file}\" selected>{$file}</option>";
177
            } else {
178
                echo "<option value=\"{$file}\">{$file}</option>";
179
            }
180
        }
181
    }
182
    echo '</select>&nbsp;&nbsp;<img src="' . XOOPS_URL . "/modules/adslight/assets/images/img_cat/{$imgs}\" name=\"avatar\" align=\"absmiddle\"><br><b>" . _AM_ADSLIGHT_REPIMGCAT . '</b><br>../modules/adslight/assets/images/img_cat/..</td></tr>';
183
184
    echo '<tr><td class="even">' . _AM_ADSLIGHT_DISPLPRICE2 . ' </td><td class="odd" colspan=2><input type="radio" name="affprice" value="1"';
185
    if ('1' == $affprice) {
186
        echo 'checked';
187
    }
188
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="affprice" value="0"';
189
    if ('0' == $affprice) {
190
        echo 'checked';
191
    }
192
    echo '>' . _NO . ' (' . _AM_ADSLIGHT_INTHISCAT . ')</td></tr>';
193
194
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_CAT . ' </td><td class="odd" colspan=2><input type="radio" name="cat_moderate" value="1"';
195
    if ('1' == $cat_moderate) {
196
        echo 'checked';
197
    }
198
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="cat_moderate" value="0"';
199
    if ('0' == $cat_moderate) {
200
        echo 'checked';
201
    }
202
    echo '>' . _NO . '</td></tr>';
203
204
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_SUBCATS . ' </td><td class="odd" colspan=2><input type="radio" name="moderate_subcat" value="1"';
205
    if ('1' == $moderate_subcat) {
206
        echo 'checked';
207
    }
208
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="moderate_subcat" value="0"';
209
    if ('0' == $moderate_subcat) {
210
        echo 'checked';
211
    }
212
    echo '>' . _NO . '</td></tr>';
213
214
    if ('title' !== $GLOBALS['xoopsModuleConfig']['adslight_csortorder']) {
215
        echo '<tr><td class="even">' . _AM_ADSLIGHT_ORDER . " </td><td class=\"odd\"><input type=\"text\" name=\"cat_order\" size=\"4\" value=\"$cat_order\"></td></tr>";
216
    } else {
217
        $cat_order = (int)$cat_order;
218
        echo "<input type=\"hidden\" name=\"cat_order\" value=\"{$cat_order}\">";
219
    }
220
221
    echo '</table>';
222
223
    echo "<input type=\"hidden\" name=\"cidd\" value=\"{$cid}\">"
224
         . '<input type="hidden" name="op" value="AdsModCatS">'
225
         . '<table class="foot" border="0"><tr><td width="20%"><br>'
226
227
         . '<input type="submit" value="'
228
         . _AM_ADSLIGHT_SAVMOD
229
         . '"></form></td><td><br>'
230
         . '<form action="category.php" method="post">'
231
         . "<input type=\"hidden\" name=\"cid\" value=\"{$cid}\">"
232
         . '<input type="hidden" name="op" value="AdsDelCat">'
233
         . '<input type="submit" value="'
234
         . _AM_ADSLIGHT_DEL
235
         . '"></form></td></tr></table>';
236
    echo '</fieldset><br>';
237
    xoops_cp_footer();
238
}
239
240
#  function adsModCatS
241
#####################################################
242
/**
243
 * @param $cidd
244
 * @param $cid
245
 * @param $img
246
 * @param $title
247
 * @param $cat_desc
248
 * @param $cat_keywords
249
 * @param $cat_order
250
 * @param $affprice
251
 * @param $cat_moderate
252
 * @param $moderate_subcat
253
 */
254
function adsModCatS($cidd, $cid, $img, $title, $cat_desc, $cat_keywords, $cat_order, $affprice, $cat_moderate, $moderate_subcat)
255
{
256
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName;
257
258
    $title = $myts->htmlSpecialChars($title);
259
    $cidd  = (int)$cidd;
260
261
    $xoopsDB->query('UPDATE '
262
                    . $xoopsDB->prefix('adslight_categories')
263
                    . " SET title='$title', cat_desc='$cat_desc', cat_keywords='$cat_keywords', pid='$cid', img='$img', cat_order='$cat_order', affprice='$affprice', cat_moderate='$cat_moderate', moderate_subcat='$moderate_subcat' WHERE cid={$cidd}");
264
265
    if (1 != $moderate_subcat) {
266
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . " SET cat_moderate=0, moderate_subcat=0 WHERE pid={$cidd}");
267
    } else {
268
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . " SET cat_moderate=1, moderate_subcat=1 WHERE pid={$cidd}");
269
    }
270
271
    redirect_header('map.php', 10, _AM_ADSLIGHT_CATSMOD);
272
}
273
274
#  function adsAddCat
275
#####################################################
276
/**
277
 * @param $title
278
 * @param $cat_desc
279
 * @param $cat_keywords
280
 * @param $cid
281
 * @param $img
282
 * @param $cat_order
283
 * @param $affprice
284
 * @param $cat_moderate
285
 * @param $moderate_subcat
286
 */
287
function adsAddCat($title, $cat_desc, $cat_keywords, $cid, $img, $cat_order, $affprice, $cat_moderate, $moderate_subcat)
288
{
289
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName;
290
291
    $moderate_subcat = (int)$moderate_subcat;
292
    $title           = $myts->htmlSpecialChars($title);
293
    if ('' == $title) {
294
        $title = '! ! ? ! !';
295
    }
296
297
    $xoopsDB->query('INSERT INTO ' . $xoopsDB->prefix('adslight_categories') . " VALUES (NULL, '$cid', '$title', '$cat_desc', '$cat_keywords', '$img', '$cat_order', '$affprice', '$cat_moderate', '$moderate_subcat')");
298
299
    if (1 == $moderate_subcat) {
300
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=1 WHERE pid = ' . (int)$cid . '');
301
    } else {
302
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=0 WHERE pid = ' . (int)$cid . '');
303
    }
304
305
    redirect_header('map.php', 3, _AM_ADSLIGHT_CATADD);
306
}
307
308
#  function adsDelCat
309
#####################################################
310
/**
311
 * @param     $cid
312
 * @param int $ok
313
 */
314
function adsDelCat($cid, $ok = 0)
315
{
316
    global $xoopsDB, $xoopsConfig, $xoopsModule, $moduleDirName;
317
318
    $cid = (int)$cid;
319
    if (1 == (int)$ok) {
320
        $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
321
        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid={$cid} OR pid={$cid}");
322
        $xoopsDB->queryf('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE cid={$cid}");
323
324
        redirect_header('map.php', 3, _AM_ADSLIGHT_CATDEL);
325
    } else {
326
        //        require_once __DIR__ . '/admin_header.php';
327
        //        loadModuleAdminMenu(1, '');
328
329
        OpenTable();
330
        echo '<br><div style="text-align: center;"><strong>' . _AM_ADSLIGHT_SURDELCAT . '</strong></div><br><br>';
331
        echo "[ <a href=\"category.php?op=AdsDelCat&cid={$cid}&ok=1\">" . _YES . '</a> | <a href="map.php">' . _NO . '</a> ]<br><br>';
332
        closeTable();
333
        xoops_cp_footer();
334
    }
335
}
336
337
#####################################################
338
//@todo REMOVE THIS ASAP!  This code is extremely unsafe
339
foreach ($_POST as $k => $v) {
340
    ${$k} = $v;
341
}
342
343
$ok  = Request::getString('ok', '', 'GET');
344
$cid = Request::getInt('cid', 0);
345
$op  = Request::getString('op', '');
346
347
switch ($op) {
348
    case 'AdsNewCat':
349
        adsNewCat($cid);
350
        break;
351
    case 'AdsAddCat':
352
        adsAddCat($title, $cat_desc, $cat_keywords, $cid, $img, $cat_order, $affprice, $cat_moderate, $moderate_subcat);
353
        break;
354
    case 'AdsDelCat':
355
        adsDelCat($cid, $ok);
0 ignored issues
show
Bug introduced by
$ok of type string is incompatible with the type integer expected by parameter $ok of adsDelCat(). ( Ignorable by Annotation )

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

355
        adsDelCat($cid, /** @scrutinizer ignore-type */ $ok);
Loading history...
356
        break;
357
    case 'AdsModCat':
358
        adsModCat($cid);
359
        break;
360
    case 'AdsModCatS':
361
        adsModCatS($cidd, $cid, $img, $title, $cat_desc, $cat_keywords, $cat_order, $affprice, $cat_moderate, $moderate_subcat);
362
        break;
363
    default:
364
        //        index();
365
        break;
366
}
367