adsModCatS()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 29
rs 9.8333
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 declare(strict_types=1);
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project (https://xoops.org)
15
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author       XOOPS Development Team
17
 * @author       Pascal Le Boustouller: original author ([email protected])
18
 * @author       Luc Bizet (www.frxoops.org)
19
 * @author       jlm69 (www.jlmzone.com)
20
 * @author       mamba (www.xoops.org)
21
 */
22
23
use Xmf\Request;
24
use XoopsModules\Adslight\{
25
    Helper,
26
    Tree,
27
    Utility
28
};
29
30
/** @var Helper $helper */
31
require_once __DIR__ . '/admin_header.php';
32
xoops_cp_header();
33
34
$op = Request::getString('op', 'list');
35
36
#  function adsNewCat
37
#####################################################
38
/**
39
 * @param $cid
40
 */
41
function adsNewCat($cid): void
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

41
function adsNewCat(/** @scrutinizer ignore-unused */ $cid): void

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...
42
{
43
    global $xoopsDB, $myts;
44
    $helper = Helper::getInstance();
45
    $mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
46
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_ADDSUBCAT . '</legend>';
47
    Utility::showImage();
48
    echo '<form method="post" action="category.php" name="imcat"><input type="hidden" name="op" value="AdsAddCat"></font><br><br>
49
        <table class="outer" border=0>
50
    <tr>
51
      <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;';
52
53
    $cid    = Request::getInt('cid', 0, 'GET');
54
    $sql    = 'SELECT cid, pid, title, cat_desc, cat_keywords, img, cat_order, affprice, cat_moderate, moderate_subcat FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid={$cid}";
55
    $result = $xoopsDB->query($sql);
56
    if (!$xoopsDB->isResultSet($result)) {
57
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
58
    }
59
    [$cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $cat_order, $affprice, $cat_moderate, $moderate_subcat] = $xoopsDB->fetchRow($result);
60
    $mytree->makeMySelBox('title', 'title', $cid, 1);
61
    echo '    </td>  </tr>';
62
    $cat_desc     = '';
63
    $cat_keywords = '';
64
65
    if ('1' === $helper->getConfig('adslight_cat_desc')) {
66
        echo '<tr><td class="even">'
67
             . _AM_ADSLIGHT_CAT_META_DESCRIPTION
68
             . " </td><td class=\"odd\" colspan=2>\n"
69
             . "    <input type=\"text\" name=\"cat_desc\" value=\"{$cat_desc}\" size=\"80\" maxlength=\"200\">\n"
70
             . "  </td></tr>\n"
71
             . '  <tr><td class="even">'
72
             . _AM_ADSLIGHT_CAT_META_KEYWORDS
73
             . " </td><td class=\"odd\" colspan=2>\n"
74
             . "    <input type=\"text\" name=\"cat_keywords\" value=\"{$cat_keywords}\" size=\"80\" maxlength=\"200\">\n"
75
             . "  </td></tr>\n";
76
    }
77
78
    echo "  <tr>\n" . '    <td class="even">' . _AM_ADSLIGHT_IMGCAT . '  </td><td class="odd" colspan=2><select name="img" onChange="showimage()">';
79
80
    $rep    = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat';
81
    $handle = opendir($rep);
82
    while ($file = readdir($handle)) {
83
        $filelist[] = $file;
84
    }
85
    asort($filelist);
86
    //    while (list($key, $file) = each($filelist)) {
87
    foreach ($filelist as $key => $file) {
88
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
89
            if ('.' === $file || '..' === $file) {
90
                $a = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
91
            }
92
        } elseif ('default.png' === $file) {
93
            echo "<option value=\"{$file}\" selected>{$file}</option>";
94
        } else {
95
            echo "<option value=\"{$file}\">{$file}</option>";
96
        }
97
    }
98
    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>';
99
    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>';
100
101
    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>';
102
103
    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>';
104
105
    if ('title' !== $helper->getConfig('adslight_csortorder')) {
106
        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>';
107
    } else {
108
        $cat_order = (int)$cat_order;
109
        echo "<input type=\"hidden\" name=\"cat_order\" value=\"{$cat_order}\">";
110
        echo '<tr><td class="foot" colspan=3><input type="submit" value="' . _AM_ADSLIGHT_ADD . '" ></td></tr>';
111
    }
112
113
    echo '</table></form><br></fieldset><br>';
114
    xoops_cp_footer();
115
}
116
117
#  function adsModCat
118
#####################################################
119
/**
120
 * @param $cid
121
 */
122
function adsModCat($cid): void
123
{
124
    global $xoopsDB, $myts;
125
    $helper = Helper::getInstance();
126
    $mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
127
128
    //    require_once __DIR__ . '/admin_header.php';
129
130
    //    loadModuleAdminMenu(1, '');
131
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODIFCAT . '</legend>';
132
    //    ShowImg();
133
    Utility::showImage();
134
    $sql    = 'SELECT cid, pid, title, cat_desc, cat_keywords, img, cat_order, affprice, cat_moderate, moderate_subcat FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid={$cid}";
135
    $result = $xoopsDB->query($sql);
136
    if (!$xoopsDB->isResultSet($result)) {
137
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
138
    }
139
    [$cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $cat_order, $affprice, $cat_moderate, $moderate_subcat] = $xoopsDB->fetchRow($result);
140
141
    $title    = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5);
142
    $cat_desc = $GLOBALS['xoopsDB']->escape($cat_desc);
143
    echo '<form action="category.php" method="post" name="imcat">';
144
    echo $GLOBALS['xoopsSecurity']->getTokenHTML();
145
    echo '<table class="outer" border="0"><tr>
146
    <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;';
147
    $mytree->makeMySelBox('title', 'title', $pid, 1);
148
    echo '</td></tr>';
149
    if ('1' === $helper->getConfig('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)) {
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
        } elseif ($file === $imgs) {
175
            echo "<option value=\"{$file}\" selected>{$file}</option>";
176
        } else {
177
            echo "<option value=\"{$file}\">{$file}</option>";
178
        }
179
    }
180
    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>';
181
182
    echo '<tr><td class="even">' . _AM_ADSLIGHT_DISPLPRICE2 . ' </td><td class="odd" colspan=2><input type="radio" name="affprice" value="1"';
183
    if ('1' === $affprice) {
184
        echo 'checked';
185
    }
186
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="affprice" value="0"';
187
    if ('0' === $affprice) {
188
        echo 'checked';
189
    }
190
    echo '>' . _NO . ' (' . _AM_ADSLIGHT_INTHISCAT . ')</td></tr>';
191
192
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_CAT . ' </td><td class="odd" colspan=2><input type="radio" name="cat_moderate" value="1"';
193
    if ('1' === $cat_moderate) {
194
        echo 'checked';
195
    }
196
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="cat_moderate" value="0"';
197
    if ('0' === $cat_moderate) {
198
        echo 'checked';
199
    }
200
    echo '>' . _NO . '</td></tr>';
201
202
    echo '<tr><td class="even">' . _AM_ADSLIGHT_MODERATE_SUBCATS . ' </td><td class="odd" colspan=2><input type="radio" name="moderate_subcat" value="1"';
203
    if ('1' === $moderate_subcat) {
204
        echo 'checked';
205
    }
206
    echo '>' . _YES . '&nbsp;&nbsp; <input type="radio" name="moderate_subcat" value="0"';
207
    if ('0' === $moderate_subcat) {
208
        echo 'checked';
209
    }
210
    echo '>' . _NO . '</td></tr>';
211
212
    if ('title' !== $helper->getConfig('adslight_csortorder')) {
213
        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>";
214
    } else {
215
        $cat_order = (int)$cat_order;
216
        echo "<input type=\"hidden\" name=\"cat_order\" value=\"{$cat_order}\">";
217
    }
218
219
    echo '</table>';
220
221
    echo "<input type=\"hidden\" name=\"cidd\" value=\"{$cid}\">"
222
         . '<input type="hidden" name="op" value="AdsModCatS">'
223
         . '<table class="foot" border="0"><tr><td width="20%"><br>'
224
225
         . '<input type="submit" value="'
226
         . _AM_ADSLIGHT_SAVMOD
227
         . '"></form></td><td><br>'
228
         . '<form action="category.php" method="post">'
229
         . "<input type=\"hidden\" name=\"cid\" value=\"{$cid}\">"
230
         . '<input type="hidden" name="op" value="AdsDelCat">'
231
         . '<input type="submit" value="'
232
         . _AM_ADSLIGHT_DEL
233
         . '"></form></td></tr></table>';
234
    echo '</fieldset><br>';
235
    xoops_cp_footer();
236
}
237
238
#  function adsModCatS
239
#####################################################
240
/**
241
 * @param $cidd
242
 * @param $cid
243
 * @param $img
244
 * @param $title
245
 * @param $cat_desc
246
 * @param $cat_keywords
247
 * @param $cat_order
248
 * @param $affprice
249
 * @param $cat_moderate
250
 * @param $moderate_subcat
251
 */
252
function adsModCatS(
253
    $cidd,
254
    $cid,
255
    $img,
256
    $title,
257
    $cat_desc,
258
    $cat_keywords,
259
    $cat_order,
260
    $affprice,
261
    $cat_moderate,
262
    $moderate_subcat
263
): void {
264
    global $xoopsDB, $myts;
265
    $helper = Helper::getInstance();
266
    $title  = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5);
267
    $cidd   = (int)$cidd;
268
269
    $sql = 'UPDATE '
270
           . $xoopsDB->prefix('adslight_categories')
271
           . " 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}";
272
    $xoopsDB->query($sql);
273
274
    if (1 !== $moderate_subcat) {
275
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . " SET cat_moderate=0, moderate_subcat=0 WHERE pid={$cidd}");
276
    } else {
277
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . " SET cat_moderate=1, moderate_subcat=1 WHERE pid={$cidd}");
278
    }
279
280
    $helper->redirect('admin/map.php', 10, _AM_ADSLIGHT_CATSMOD);
281
}
282
283
#  function adsAddCat
284
#####################################################
285
/**
286
 * @param $title
287
 * @param $cat_desc
288
 * @param $cat_keywords
289
 * @param $cid
290
 * @param $img
291
 * @param $cat_order
292
 * @param $affprice
293
 * @param $cat_moderate
294
 * @param $moderate_subcat
295
 */
296
function adsAddCat(
297
    $title,
298
    $cat_desc,
299
    $cat_keywords,
300
    $cid,
301
    $img,
302
    $cat_order,
303
    $affprice,
304
    $cat_moderate,
305
    $moderate_subcat
306
): void {
307
    global $xoopsDB, $myts;
308
    $helper          = Helper::getInstance();
309
    $moderate_subcat = (int)$moderate_subcat;
310
    $title           = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5);
311
    if ('' === $title) {
312
        $title = '! ! ? ! !';
313
    }
314
315
    $sql = 'INSERT INTO ' . $xoopsDB->prefix('adslight_categories') . " VALUES (NULL, '{$cid}', '{$title}', '{$cat_desc}', '{$cat_keywords}', '{$img}', '{$cat_order}', '{$affprice}', '{$cat_moderate}', '{$moderate_subcat}')";
316
    $xoopsDB->query($sql);
317
318
    if (1 === $moderate_subcat) {
319
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=1 WHERE pid = ' . (int)$cid);
320
    } else {
321
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_categories') . ' SET cat_moderate=0 WHERE pid = ' . (int)$cid);
322
    }
323
324
    $helper->redirect('admin/map.php', 3, _AM_ADSLIGHT_CATADD);
325
}
326
327
#  function adsDelCat
328
#####################################################
329
/**
330
 * @param     $cid
331
 * @param int $ok
332
 */
333
function adsDelCat($cid, $ok = 0): void
334
{
335
    $helper = Helper::getInstance();
336
    $cid    = (int)$cid;
337
    if (1 === (int)$ok) {
338
        /** @var \XoopsMySQLDatabase $xoopsDB */
339
        $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
340
        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid={$cid} OR pid={$cid}");
341
        $xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE cid={$cid}");
342
343
        $helper->redirect('admin/map.php', 3, _AM_ADSLIGHT_CATDEL);
344
    } else {
345
        //        require_once __DIR__ . '/admin_header.php';
346
        //        loadModuleAdminMenu(1, '');
347
348
        OpenTable();
349
        echo '<br><div style="text-align: center;"><strong>' . _AM_ADSLIGHT_SURDELCAT . '</strong></div><br><br>';
350
        echo "[ <a href=\"category.php?op=AdsDelCat&cid={$cid}&ok=1\">" . _YES . '</a> | <a href="map.php">' . _NO . '</a> ]<br><br>';
351
        closeTable();
352
        xoops_cp_footer();
353
    }
354
}
355
356
#####################################################
357
//@todo REMOVE THIS ASAP!  This code is extremely unsafe
358
foreach ($_POST as $k => $v) {
359
    ${$k} = $v;
360
}
361
362
$ok  = Request::getInt('ok', 0, 'GET');
363
$cid = Request::getInt('cid', 0);
364
$op  = Request::getString('op', '');
365
366
switch ($op) {
367
    case 'AdsNewCat':
368
        adsNewCat($cid);
369
        break;
370
    case 'AdsAddCat':
371
        adsAddCat(
372
            $title,
373
            $cat_desc,
374
            $cat_keywords,
375
            $cid,
376
            $img,
377
            $cat_order,
378
            $affprice,
379
            $cat_moderate,
380
            $moderate_subcat
381
        );
382
        break;
383
    case 'AdsDelCat':
384
        adsDelCat($cid, $ok);
385
        break;
386
    case 'AdsModCat':
387
        adsModCat($cid);
388
        break;
389
    case 'AdsModCatS':
390
        adsModCatS(
391
            $cidd,
392
            $cid,
393
            $img,
394
            $title,
395
            $cat_desc,
396
            $cat_keywords,
397
            $cat_order,
398
            $affprice,
399
            $cat_moderate,
400
            $moderate_subcat
401
        );
402
        break;
403
    default:
404
        //        index();
405
        break;
406
}
407