Completed
Push — master ( 0424ea...923121 )
by Michael
03:57
created

admin/modify_ads.php (4 issues)

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
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
25
if (isset($_REQUEST['op'])) {
26
    $op = $_REQUEST['op'];
27
} else {
28
    $op = 'liste';
29
}
30
31
#  function Index
32
#####################################################
33
function Index()
0 ignored issues
show
The function Index() has been defined more than once; this definition is ignored, only the first definition in admin/main.php (L33-293) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
34
{
35
    global $hlpfile, $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $myts, $desctext, $moduleDirName, $admin_lang;
36
37
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
38
39
    include_once __DIR__ . '/header.php';
40
    xoops_cp_header();
41
    //    loadModuleAdminMenu(0, "");
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
43
    // photo dir setting checker
44
    $photo_dir         = $xoopsModuleConfig['adslight_path_upload'];
45
    $photo_thumb_dir   = $xoopsModuleConfig['adslight_path_upload'] . '/thumbs';
46
    $photo_resized_dir = $xoopsModuleConfig['adslight_path_upload'] . '/midsize';
47
    if (!is_dir($photo_dir)) {
48
        mkdir($photo_dir);
49
    }
50
    if (!is_dir($photo_thumb_dir)) {
51
        mkdir($photo_thumb_dir);
52
    }
53
    if (!is_dir($photo_resized_dir)) {
54
        mkdir($photo_resized_dir);
55
    }
56 View Code Duplication
    if (!is_writable($photo_dir) || !is_readable($photo_dir)) {
57
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
58
        echo "<font color='#FF0000'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_dir . "</b></font><br><br>\n";
59
        echo '</fieldset><br>';
60
    }
61
62 View Code Duplication
    if (!is_writable($photo_thumb_dir) || !is_readable($photo_thumb_dir)) {
63
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
64
        echo "<font color='#FF0000'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_thumb_dir . "</b></font><br><br>\n";
65
        echo '</fieldset><br>';
66
    }
67
68 View Code Duplication
    if (!is_writable($photo_resized_dir) || !is_readable($photo_resized_dir)) {
69
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
70
        echo "<font color='#FF0000'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_resized_dir . "</b></font><br><br>\n";
71
        echo '</fieldset><br>';
72
    }
73
74
    $result  =
75
        $xoopsDB->query('select lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, photo, usid from ' .
76
                        $xoopsDB->prefix('adslight_listing') .
77
                        " WHERE valid='no' order by lid");
78
    $numrows = $xoopsDB->getRowsNum($result);
79 View Code Duplication
    if ($numrows > 0) {
80
81
        ///////// Il y a [..] Annonces en attente d'être approuvées //////
82
        echo "<table class='outer' border=0 cellspacing=5 cellpadding=0><tr><td width=40>";
83
        echo "<img src='../assets/images/admin/error_button.png' border=0 /></td><td>";
84
        echo "<font color=\"#00B4C4\"><b>" . _AM_ADSLIGHT_THEREIS . "</b></font> <b>$numrows</b> <font color=\"#00B4C4\">" . _AM_ADSLIGHT_WAIT . '</b></font>';
85
        echo '</td></tr></table><br>';
86
    } else {
87
        echo "<table class='outer' width='50%' border='0'><tr><td width=40>";
88
        echo "<img src='../assets/images/admin/search_button_green_32.png' border=0 alt=\"._AM_ADSLIGHT_RELEASEOK.\" /></td><td>";
89
        echo "<font color='#00B4C4'><b>" . _AM_ADSLIGHT_NOANNVAL . '</b></font>';
90
        echo '</td></tr></table><br>';
91
    }
92
93
    // Modify Annonces
94
    list($numrows) = $xoopsDB->fetchRow($xoopsDB->query('select COUNT(*) FROM ' . $xoopsDB->prefix('adslight_listing') . ''));
95 View Code Duplication
    if ($numrows > 0) {
96
        echo "<table width='100%' border='0' class='outer'><tr class='bg4'><td valign='top'>";
97
        echo "<form method=\"post\" action=\"modify_ads.php\">" .
98
             '<b>' .
99
             _AM_ADSLIGHT_MODANN .
100
             '</b><br><br>' .
101
             '' .
102
             _AM_ADSLIGHT_NUMANN .
103
             " <input type=\"text\" name=\"lid\" size=\"12\" maxlength=\"11\">&nbsp;&nbsp;" .
104
             "<input type=\"hidden\" name=\"op\" value=\"ModifyAds\">" .
105
             "<input type=\"submit\" value=\"" .
106
             _AM_ADSLIGHT_MODIF .
107
             "\">" .
108
             '</form><br>';
109
        echo '</td></tr></table><br>';
110
    }
111
112
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #DFE0E0;'><tr class='bg4'><td valign='top'>";
113
    echo "<a href=\"map.php\">" . _AM_ADSLIGHT_GESTCAT . "</a> | <a href=\"../index.php\">" . _AM_ADSLIGHT_ACCESMYANN . '</a>';
114
    echo '</td></tr></table><br>';
115
116
    xoops_cp_footer();
117
}
118
119
#  function ModifyAds
120
#####################################################
121
/**
122
 * @param $lid
123
 */
124 View Code Duplication
function ModifyAds($lid)
125
{
126
    global $xoopsDB, $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $myts, $desctext, $moduleDirName, $admin_lang;
127
128
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
129
130
    include_once __DIR__ . '/header.php';
131
    xoops_cp_header();
132
    //    loadModuleAdminMenu(0, "");
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...
133
    $id_price  = '';
134
    $nom_price = '';
135
136
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODANN . '</legend>';
137
138
    $result =
139
        $xoopsDB->query('select lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, valid, photo from ' .
140
                        $xoopsDB->prefix('adslight_listing') .
141
                        " where lid=$lid");
142
143
    while (list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo) =
144
        $xoopsDB->fetchRow($result)) {
145
        $title     = $myts->htmlSpecialChars($title);
146
        $status    = $myts->htmlSpecialChars($status);
147
        $expire    = $myts->htmlSpecialChars($expire);
148
        $type      = $myts->htmlSpecialChars($type);
149
        $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
150
        $tel       = $myts->htmlSpecialChars($tel);
151
        $price     = number_format($price, 2, ',', ' ');
152
        $typeprice = $myts->htmlSpecialChars($typeprice);
153
        $typeusure = $myts->htmlSpecialChars($typeusure);
154
        $submitter = $myts->htmlSpecialChars($submitter);
155
        $town      = $myts->htmlSpecialChars($town);
156
        $country   = $myts->htmlSpecialChars($country);
157
        $contactby = $myts->htmlSpecialChars($contactby);
158
        $premium   = $myts->htmlSpecialChars($premium);
159
160
        $date2 = formatTimestamp($date, 's');
161
162
        echo "<form action=\"modify_ads.php\" method=post>
163
            <table border=0><tr class='head' border='1'>
164
            <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>$lid &nbsp;" . _AM_ADSLIGHT_ADDED_ON . "&nbsp; $date2</td>
165
            </tr><tr class='head' border='1'>
166
            <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>$submitter</td>
167
            </tr><tr class='head' border='1'>
168
            <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$email\"></td>
169
            </tr><tr class='head' border='1'>
170
            <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\"></td>
171
            </tr><tr class='head' border='1'>
172
            <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"$town\"></td>
173
            </tr><tr class='head' border='1'>
174
            <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"$country\"></td>
175
            </tr></tr><tr class='head' border='1'>";
176
177
        if ($contactby == 1) {
178
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_EMAIL;
179
        }
180
        if ($contactby == 2) {
181
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PM;
182
        }
183
        if ($contactby == 3) {
184
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_BOTH;
185
        }
186
        if ($contactby == 4) {
187
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PHONE;
188
        }
189
190
        echo " <td class='head'>" . _AM_ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\">
191
    <option value=\"" . $contactby . "\">" . $contactselect . "</option>
192
    <option value=\"1\">" . _AM_ADSLIGHT_CONTACT_BY_EMAIL . "</option>
193
    <option value=\"2\">" . _AM_ADSLIGHT_CONTACT_BY_PM . "</option>
194
    <option value=\"3\">" . _AM_ADSLIGHT_CONTACT_BY_BOTH . "</option>
195
    <option value=\"4\">" . _AM_ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>';
196
197
        echo "<tr><td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\"";
198
        if ($status == '0') {
199
            echo 'checked';
200
        }
201
        echo '>' . _AM_ADSLIGHT_ACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"1\"";
202
        if ($status == '1') {
203
            echo 'checked';
204
        }
205
        echo '>' . _AM_ADSLIGHT_INACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"2\"";
206
        if ($status == '2') {
207
            echo 'checked';
208
        }
209
        echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>';
210
211
        echo "<tr class='head' border='1'>
212
            <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"$title\"></td>
213
            </tr><tr class='head' border='1'>
214
            <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"$premium\"></td>
215
            </tr><tr class='head' border='1'>
216
            <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"$expire\"></td>
217
            </tr>";
218
        ////// Type d'annonce
219
        echo "<tr class='head' border='1'>
220
            <td>" . _AM_ADSLIGHT_TYPE . " </td><td><select name=\"type\">";
221
222
        $result5 = $xoopsDB->query('select nom_type, id_type from ' . $xoopsDB->prefix('adslight_type') . ' order by nom_type');
223
        while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) {
224
            $sel = '';
225
            if ($id_type == $type) {
226
                $sel = 'selected';
227
            }
228
            echo "<option value=\"$id_type\" $sel>$nom_type</option>";
229
        }
230
        echo '</select></td></tr>';
231
232
        ////// Etat d'usure
233
        echo "<tr class='head' border='1'>
234
            <td>" . _AM_ADSLIGHT_TYPE_USURE . " </td><td><select name=\"typeusure\">";
235
236
        $result6 = $xoopsDB->query('select nom_usure, id_usure from ' . $xoopsDB->prefix('adslight_usure') . ' order by nom_usure');
237
        while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) {
238
            $sel = '';
239
            if ($id_usure == $typeusure) {
240
                $sel = 'selected';
241
            }
242
            echo "<option value=\"$id_usure\" $sel>$nom_usure</option>";
243
        }
244
        echo '</select></td></tr>';
245
246
        /////// Price
247
        echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_PRICE2 . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\"> " . $xoopsModuleConfig['adslight_money'] . '';
248
249
        //////// Price type
250
251
        $resultx = $xoopsDB->query('select nom_price, id_price from ' . $xoopsDB->prefix('adslight_price') . ' order by nom_price');
252
253
        echo " <select name=\"typeprice\"><option value=\"$id_price\">$nom_price</option>";
254
        while (list($nom_price, $id_price) = $xoopsDB->fetchRow($resultx)) {
255
            $sel = '';
256
            if ($id_price == $typeprice) {
257
                $sel = 'selected';
258
            }
259
260
            echo "<option value=\"$id_price\" $sel>$nom_price</option>";
261
        }
262
        echo '</select></td>';
263
264
        /////// Category
265
266
        echo "<tr class='head' border='1'>
267
            <td>" . _AM_ADSLIGHT_CAT2 . ' </td><td>';
268
        $mytree->makeMySelBox('title', 'title', $cid);
269
        echo "</td>
270
            </tr><tr class='head' border='1'>
271
            <td>" . _AM_ADSLIGHT_DESC . ' </td><td>';
272
273
        $wysiwyg_text_area = adslight_adminEditor('', 'desctext', $desctext, '100%', '200px', 'small');
274
        echo $wysiwyg_text_area->render();
275
276
        echo '</td></tr>';
277
278
        echo "<tr class='head' border='1'>
279
            <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"50\" value=\"$photo\"></td>
280
            </tr><tr>";
281
        $time = time();
282
        echo "</tr><tr class='head' border='1'>
283
            <td>&nbsp;</td><td><select name=\"op\">
284
            <option value=\"ModifyAdsS\"> " . _AM_ADSLIGHT_MODIF . "
285
            <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . "
286
            </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\"></td>
287
            </tr></table>";
288
        echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">";
289
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
290
        echo "<input type=\"hidden\" name=\"date\" value=\"$time\">";
291
        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">
292
        </form><br>";
293
        echo '</fieldset><br>';
294
        xoops_cp_footer();
295
    }
296
}
297
298
#  function ModifyAdsS
299
#####################################################
300
301
/**
302
 * @param $lid
303
 * @param $cat
304
 * @param $title
305
 * @param $status
306
 * @param $expire
307
 * @param $type
308
 * @param $desctext
309
 * @param $tel
310
 * @param $price
311
 * @param $typeprice
312
 * @param $typeusure
313
 * @param $date
314
 * @param $email
315
 * @param $submitter
316
 * @param $town
317
 * @param $country
318
 * @param $contactby
319
 * @param $premium
320
 * @param $valid
321
 * @param $photo
322
 */
323 View Code Duplication
function ModifyAdsS($lid, $cat, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo)
324
{
325
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName, $admin_lang;
326
327
    $title     = $myts->htmlSpecialChars($title);
328
    $status    = $myts->htmlSpecialChars($status);
329
    $expire    = $myts->htmlSpecialChars($expire);
330
    $type      = $myts->htmlSpecialChars($type);
331
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
332
    $tel       = $myts->htmlSpecialChars($tel);
333
    $price     = str_replace(array(' '), '', $price);
334
    $typeprice = $myts->htmlSpecialChars($typeprice);
335
    $typeusure = $myts->htmlSpecialChars($typeusure);
336
    $submitter = $myts->htmlSpecialChars($submitter);
337
    $town      = $myts->htmlSpecialChars($town);
338
    $country   = $myts->htmlSpecialChars($country);
339
    $contactby = $myts->htmlSpecialChars($contactby);
340
    $premium   = $myts->htmlSpecialChars($premium);
341
342
    $xoopsDB->query('update ' .
343
                    $xoopsDB->prefix('adslight_listing') .
344
                    " set cid='$cat', title='$title', status='$status', expire='$expire', type='$type', desctext='$desctext', tel='$tel', price='$price', typeprice='$typeprice', typeusure='$typeusure', date='$date', email='$email', submitter='$submitter', town='$town', country='$country', contactby='$contactby', premium='$premium', valid='$valid', photo='$photo' where lid=$lid");
345
346
    redirect_header('modify_ads.php', 1, _AM_ADSLIGHT_ANNMOD);
347
}
348
349
#  function ListingDel
350
#####################################################
351
/**
352
 * @param $lid
353
 * @param $photo
354
 */
355 View Code Duplication
function ListingDel($lid, $photo)
356
{
357
    global $xoopsDB, $moduleDirName, $admin_lang;
358
359
    $result2 = $xoopsDB->query('select p.url FROM ' .
360
                               $xoopsDB->prefix('adslight_listing') .
361
                               ' l LEFT JOIN ' .
362
                               $xoopsDB->prefix('adslight_pictures') .
363
                               ' p  ON l.lid=p.lid where l.lid=' .
364
                               $xoopsDB->escape($lid) .
365
                               '');
366
367
    while (list($purl) = $xoopsDB->fetchRow($result2)) {
368
        if ($purl) {
369
            $destination = XOOPS_ROOT_PATH . '/uploads/AdsLight';
370
            if (file_exists("$destination/$purl")) {
371
                unlink("$destination/$purl");
372
            }
373
            $destination2 = XOOPS_ROOT_PATH . '/uploads/AdsLight/thumbs';
374
            if (file_exists("$destination2/thumb_$purl")) {
375
                unlink("$destination2/thumb_$purl");
376
            }
377
            $destination3 = XOOPS_ROOT_PATH . '/uploads/AdsLight/midsize';
378
            if (file_exists("$destination3/resized_$purl")) {
379
                unlink("$destination3/resized_$purl");
380
            }
381
            $xoopsDB->query('delete from ' . $xoopsDB->prefix('adslight_pictures') . " where lid=$lid");
382
        }
383
    }
384
385
    $xoopsDB->query('delete from ' . $xoopsDB->prefix('adslight_listing') . " where lid=$lid");
386
387
    redirect_header('modify_ads.php', 1, _AM_ADSLIGHT_ANNDEL);
388
}
389
390
#####################################################
391
#####################################################
392
393
foreach ($_POST as $k => $v) {
394
    ${$k} = $v;
395
}
396
397
$pa = isset($_GET['pa']) ? $_GET['pa'] : '';
398
399
if (!isset($_POST['lid']) && isset($_GET['lid'])) {
400
    $lid = $_GET['lid'];
401
}
402
if (!isset($_POST['op']) && isset($_GET['op'])) {
403
    $op = $_GET['op'];
404
}
405
if (!isset($op)) {
406
    $op = '';
407
}
408
409
switch ($op) {
410
411
    case 'IndexView':
412
        IndexView($lid);
413
        break;
414
415
    case 'ListingDel':
416
        ListingDel($lid, $photo);
417
        break;
418
419
    case 'ModifyAds':
420
        ModifyAds($lid);
421
        break;
422
423
    case 'ModifyAdsS':
424
        ModifyAdsS($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo);
425
        break;
426
427
    default:
428
        Index();
429
        break;
430
431
}
432