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

admin/category.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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;
36
37
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
38
39
    include_once __DIR__ . '/header.php';
40
41
    //    loadModuleAdminMenu(1, "");
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
$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);
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']) {
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;
79
    }
80
    asort($filelist);
81 View Code Duplication
    while (list($key, $file) = each($filelist)) {
82
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
83
            if ($file === '.' || $file === '..') {
84
                $a = 1;
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;
154
155
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
156
157
    include_once __DIR__ . '/header.php';
158
159
    //    loadModuleAdminMenu(1, "");
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);
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') {
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;
197
    }
198
    asort($filelist);
199 View Code Duplication
    while (list($key, $file) = each($filelist)) {
200
        if (!preg_match('`gif$|jpg$|png$`i', $file)) {
201
            if ($file === '.' || $file === '..') {
202
                $a = 1;
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;
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) {
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;
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) {
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;
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, "");
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