Passed
Push — master ( 0405fd...a3f27c )
by Michael
02:30
created

admin/category.php (1 issue)

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