Completed
Push — master ( 5ea37d...ce95ba )
by Michael
02:32
created

admin/view_ads.php (2 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
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
25
include_once __DIR__ . '/admin_header.php';
26
27
$op = Request::getInt('op', 'liste');
28
29
#  function index
30
#####################################################
31
function index()
32
{
33
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $desctext, $moduleDirName, $admin_lang;
34
35
    //  $mytree = new ClassifiedsTree($xoopsDB->prefix("adslight_categories"),"cid","pid");
36
    $photo3 = '';
37
    //    include_once __DIR__ . '/header.php';
38
    xoops_cp_header();
39
    //    loadModuleAdminMenu(0, "");
40
41
    // photo dir setting checker
42
    $photo_dir         = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'];
43
    $photo_thumb_dir   = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'] . '/thumbs';
44
    $photo_resized_dir = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'] . '/midsize';
45
    if (!is_dir($photo_dir)) {
46
        mkdir($photo_dir);
47
    }
48
    if (!is_dir($photo_thumb_dir)) {
49
        mkdir($photo_thumb_dir);
50
    }
51
    if (!is_dir($photo_resized_dir)) {
52
        mkdir($photo_resized_dir);
53
    }
54 View Code Duplication
    if (!is_writable($photo_dir) || !is_readable($photo_dir)) {
55
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
56
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_dir . "</b></span><br><br>\n";
57
        echo '</fieldset><br>';
58
    }
59
60 View Code Duplication
    if (!is_writable($photo_thumb_dir) || !is_readable($photo_thumb_dir)) {
61
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
62
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_thumb_dir . "</b></span><br><br>\n";
63
        echo '</fieldset><br>';
64
    }
65
66 View Code Duplication
    if (!is_writable($photo_resized_dir) || !is_readable($photo_resized_dir)) {
67
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_CHECKER . '</legend><br>';
68
        echo "<span style='color: #FF0000;'><b>" . _AM_ADSLIGHT_DIRPERMS . '' . $photo_resized_dir . "</b></span><br><br>\n";
69
        echo '</fieldset><br>';
70
    }
71
72
    $result  = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, photo, usid FROM '
73
                               . $xoopsDB->prefix('adslight_listing')
74
                               . " WHERE valid='Yes' ORDER BY lid");
75
    $numrows = $xoopsDB->getRowsNum($result);
76
    if ($numrows > 0) {
77
78
        // Il y a [..] Annonces en attente d'être approuvées //////
79
        echo "<table class='outer' border=0 cellspacing=5 cellpadding=0><tr><td width=40>";
80
        echo "<img src='../assets/images/admin/error_button.png' border=0 /></td><td>";
81
        echo "<span style='color:#00B4C4;'><b>" . _AM_ADSLIGHT_THEREIS . "</b></span> <b>$numrows</b> <b><span style='color:#00B4C4;'>" . _AM_ADSLIGHT_ADSVALIDE . '</b></span>';
82
        echo '</td></tr></table><br>';
83
84
        // Liste des ID  ///// Soumis par /////  Titre   /////  Description  /////  Date d'ajout
85
        echo "<table width='100%' border='0' class='outer'>";
86
        $rank = 1;
87
88
        while (list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $photo, $usid) = $xoopsDB->fetchRow($result)) {
89
            $title    = $myts->htmlSpecialChars($title);
90
            $desctext = $myts->displayTarea($desctext, 1, 0, 1, 1, 1);
91
92 View Code Duplication
            if (strlen($desctext) >= 200) {
93
                $desctext = substr($desctext, 0, 199) . '...';
94
            } else {
95
                $desctext = $myts->displayTarea($desctext, 1, 1, 1);
96
            }
97
            $date2 = formatTimestamp($date, 's');
98
99
            if (is_int($rank / 2)) {
100
                $color = '#ffffff';
101
            } else {
102
                $color = 'head';
103
            }
104
105
            $status = $myts->htmlSpecialChars($status);
106
            $expire = $myts->htmlSpecialChars($expire);
107
            $type   = $myts->htmlSpecialChars($type);
108
            $tel    = $myts->htmlSpecialChars($tel);
109
            //      $price = number_format($price, 2, ",", " ");
110
            $typeprice = $myts->htmlSpecialChars($typeprice);
111
            $typeusure = $myts->htmlSpecialChars($typeusure);
112
            $submitter = $myts->htmlSpecialChars($submitter);
113
            $town      = $myts->htmlSpecialChars($town);
114
            $country   = $myts->htmlSpecialChars($country);
115
            $contactby = $myts->htmlSpecialChars($contactby);
116
            $premium   = $myts->htmlSpecialChars($premium);
117
118
            $updir   = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'];
119
            $sql     = 'SELECT cod_img, lid, uid_owner, url FROM '
120
                       . $xoopsDB->prefix('adslight_pictures')
121
                       . ' WHERE  uid_owner='
122
                       . $xoopsDB->escape($usid)
123
                       . ' AND lid='
124
                       . $xoopsDB->escape($lid)
125
                       . ' ORDER BY date_added ASC LIMIT 1';
126
            $resultp = $xoopsDB->query($sql);
127 View Code Duplication
            while (list($cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($resultp)) {
128
                if ($photo) {
129
                    $photo3 = "<a href='"
130
                              . XOOPS_URL
131
                              . '/modules/adslight/viewads.php?lid='
132
                              . $lid
133
                              . "'><img class=\"thumb\" src=\"$updir/thumbs/thumb_$url\" align=\"left\" width=\"100px\" alt=\"$title\"></a>";
134
                }
135
            }
136
            if ($photo > 0) {
137
            } else {
138
                $photo3 = "<a href=\"index.php?op=IndexView&lid=$lid\"><img class=\"thumb\" src=\""
139
                          . XOOPS_URL
140
                          . "/modules/adslight/assets/images/nophoto.jpg\" align=\"left\" width=\"100px\" alt=\"$title\"></a>";
141
            }
142
143
            if ($photo > 0) {
144
                $photo4 = "$photo";
145
            } else {
146
                $photo4 = '0';
147
            }
148
149
            $result7 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . " WHERE id_type='" . $xoopsDB->escape($type) . "'");
150
            list($nom_type) = $xoopsDB->fetchRow($result7);
151
152
            $result8 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . " WHERE id_price='" . $xoopsDB->escape($typeprice) . "'");
153
            list($nom_price) = $xoopsDB->fetchRow($result8);
154
155
            echo "<form action=\"view_ads.php\" method=\"post\">";
156
            echo "<tr><th align='left'>"
157
                 . _AM_ADSLIGHT_LID
158
                 . ": $lid</th><th align='left'>$photo4 "
159
                 . _AM_ADSLIGHT_NBR_PHOTO
160
                 . "</th><th align='left'>"
161
                 . _AM_ADSLIGHT_TITLE
162
                 . ":</th><th align='left'>"
163
                 . _AM_ADSLIGHT_DESC
164
                 . "</th><th align='left'><!--"
165
                 . _AM_ADSLIGHT_ACTIONS
166
                 . '--></th></tr>';
167
168
            echo "<tr><td class='even' width='3%'></td>";
169
            echo "<td class='odd' width='10%' >$photo3</td>";
170
            echo "<td class='even' width='20%'><b>$title</b><br><br>$nom_type<br>$price " . $GLOBALS['xoopsModuleConfig']['adslight_money'] . " $nom_price<br>";
171
            echo "$town - $country<br>";
172
            echo '<b>' . _AM_ADSLIGHT_SUBMITTER . ":</b> $submitter<br>";
173
            echo '<b>' . _AM_ADSLIGHT_DATE . ":</b> $date2</td>";
174
            echo "<td class='even' width='35%'>$desctext</td><td class='even' width='2%' align=right></td>";
175
            echo "</tr><tr><td width='5%'></td><td>";
176
177
            echo "<select name=\"op\">
178
        <option value=\"ModifyAds\"> " . _AM_ADSLIGHT_MODIF . "
179
        <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . "
180
        </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\">";
181
182
            echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">";
183
            echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
184
            echo "<input type=\"hidden\" name=\"cid\" value=\"$cid\">";
185
            echo "<input type=\"hidden\" name=\"title\" value=\"$title\">";
186
            echo "<input type=\"hidden\" name=\"status\" value=\"$status\">";
187
            echo "<input type=\"hidden\" name=\"expire\" value=\"$expire\">";
188
            echo "<input type=\"hidden\" name=\"type\" value=\"$type\">";
189
            echo "<input type=\"hidden\" name=\"desctext\" value=\"$desctext\">";
190
            echo "<input type=\"hidden\" name=\"tel\" value=\"$tel\">";
191
            echo "<input type=\"hidden\" name=\"price\" value=\"$price\">";
192
            echo "<input type=\"hidden\" name=\"typeprice\" value=\"$typeprice\">";
193
            echo "<input type=\"hidden\" name=\"typeusure\" value=\"$typeusure\">";
194
            echo "<input type=\"hidden\" name=\"date\" value=\"$date\">";
195
            echo "<input type=\"hidden\" name=\"email\" value=\"$email\">";
196
            echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">";
197
            echo "<input type=\"hidden\" name=\"town\" value=\"$town\">";
198
            echo "<input type=\"hidden\" name=\"country\" value=\"$country\">";
199
            echo "<input type=\"hidden\" name=\"contactby\" value=\"$contactby\">";
200
            echo "<input type=\"hidden\" name=\"premium\" value=\"$premium\">";
201
            echo "<input type=\"hidden\" name=\"photo\" value=\"$photo\">";
202
            echo '</form><br></td></tr>';
203
            ++$rank;
204
        }
205
206
        echo '</td></tr></table>
207
              <br><br>';
208
    } else {
209
        echo "<table class='outer' width='50%' border='0'><tr><td width=40>";
210
        echo "<img src='../assets/images/admin/search_button_green_32.png' border=0 /></td><td>";
211
        echo "<span style='color: #00B4C4;'><b>" . _AM_ADSLIGHT_NOANNVALADS . '</b></span>';
212
        echo '</td></tr></table><br>';
213
    }
214
215
    xoops_cp_footer();
216
}
217
218
#  function IndexView
219
#####################################################
220
/**
221
 * @param $lid
222
 */
223
function indexView($lid = null)
224
{
225
    global $xoopsDB, $xoopsModule, $xoopsConfig, $myts, $desctext, $moduleDirName, $admin_lang;
226
227
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
228
229
    //    include_once __DIR__ . '/header.php';
230
    xoops_cp_header();
231
    //    loadModuleAdminMenu(0, "");
232
233
    $result  = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, photo FROM '
234
                               . $xoopsDB->prefix('adslight_listing')
235
                               . " WHERE valid='No' AND lid='$lid'");
236
    $numrows = $xoopsDB->getRowsNum($result);
237
    if ($numrows > 0) {
238
        echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #DFE0E0;'><tr class='bg4'><td valign='top'>";
239
        echo '<b>' . _AM_ADSLIGHT_WAIT . '</b><br><br>';
240
241
        list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $photo) = $xoopsDB->fetchRow($result);
242
243
        $date2    = formatTimestamp($date, 's');
244
        $title    = $myts->htmlSpecialChars($title);
245
        $status   = $myts->htmlSpecialChars($status);
246
        $expire   = $myts->htmlSpecialChars($expire);
247
        $type     = $myts->htmlSpecialChars($type);
248
        $desctext = $myts->displayTarea($desctext, 1, 1, 1);
249
        $tel      = $myts->htmlSpecialChars($tel);
250
        //      $price = number_format($price, 2, ",", " ");
251
        $typeprice = $myts->htmlSpecialChars($typeprice);
252
        $typeusure = $myts->htmlSpecialChars($typeusure);
253
        $submitter = $myts->htmlSpecialChars($submitter);
254
        $town      = $myts->htmlSpecialChars($town);
255
        $country   = $myts->htmlSpecialChars($country);
256
        $contactby = $myts->htmlSpecialChars($contactby);
257
        $premium   = $myts->htmlSpecialChars($premium);
258
259
        echo "<form action=\"index.php\" method=\"post\">
260
            <table><tr class='head' border='1'>
261
            <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>$lid &nbsp;&nbsp;&nbsp;&nbsp;   " . _AM_ADSLIGHT_ADDED_ON . " &nbsp;&nbsp;&nbsp;&nbsp; $date2</td>
262
            </tr><tr class='head' border='1'>
263
            <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>$submitter</td>
264
            </tr><tr class='head' border='1'>
265
            <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$email\"></td>
266
            </tr><tr class='head' border='1'>
267
            <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\"></td>
268
            </tr><tr class='head' border='1'>
269
            <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"$town\"></td>
270
            </tr><tr class='head' border='1'>
271
            <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"$country\"></td>
272
            </tr><tr class='head' border='1'>
273
            <td>" . _AM_ADSLIGHT_CONTACTBY . " </td><td><input type=\"text\" name=\"contactby\" size=\"40\" value=\"$contactby\"></td>
274
            </tr>";
275
276
        echo "<tr>
277
            <td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\"";
278
        if ($status == '0') {
279
            echo 'checked';
280
        }
281
        echo '>' . _AM_ADSLIGHT_ACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"1\"";
282
        if ($status == '1') {
283
            echo 'checked';
284
        }
285
        echo '>' . _AM_ADSLIGHT_INACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"2\"";
286
        if ($status == '2') {
287
            echo 'checked';
288
        }
289
        echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>';
290
291
        echo "<tr class='head' border='1'>
292
            <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"$title\"></td>
293
            </tr><tr class='head' border='1'>
294
            <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"$premium\"></td>
295
            </tr><tr class='head' border='1'>
296
            <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"$expire\"></td>
297
            </tr><tr class='head' border='1'>
298
            <td>" . _AM_ADSLIGHT_TYPE . " </td><td><select name=\"type\">";
299
300
        $result5 = $xoopsDB->query('SELECT nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
301
        while (list($nom_type) = $xoopsDB->fetchRow($result5)) {
302
            $sel = '';
303
            if ($nom_type == $type) {
304
                $sel = 'selected';
305
            }
306
            echo "<option value=\"$nom_type\" $sel>$nom_type</option>";
307
        }
308
309
        echo '</select></td></tr>';
310
311
        ////// Etat d'usure
312
        echo "<tr class='head' border='1'>
313
            <td>" . _AM_ADSLIGHT_TYPE_USURE . " </td><td><select name=\"typeusure\">";
314
315
        $result6 = $xoopsDB->query('SELECT nom_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure');
316
        while (list($nom_usure) = $xoopsDB->fetchRow($result6)) {
317
            $sel = '';
318
            if ($nom_usure == $typeusure) {
319
                $sel = 'selected';
320
            }
321
            echo "<option value=\"$nom_usure\" $sel>$nom_usure</option>";
322
        }
323
        echo '</select></td></tr>';
324
325
        echo "<tr class='head' border='1'><td>"
326
             . _AM_ADSLIGHT_PRICE2
327
             . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\"> "
328
             . $GLOBALS['xoopsModuleConfig']['adslight_money']
329
             . '';
330
        $result3 = $xoopsDB->query('SELECT nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
331
        echo " <select name=\"typeprice\"><option value=\"$typeprice\">$typeprice</option>";
332
        while (list($nom_price) = $xoopsDB->fetchRow($result3)) {
333
            echo "<option value=\"$nom_price\">$nom_price</option>";
334
        }
335
        echo '</select></td></tr>';
336
337
        echo "<tr class='head' border='1'>
338
            <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"40\" value=\"$photo\"></td>
339
            </tr>";
340
        echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_DESC . '</td><td>';
341
        $wysiwyg_text_area = AdslightUtilities::getEditor(_AM_ADSLIGHT_DESC, 'desctext', $desctext, '100%', '200px', 'small');
342
        echo $wysiwyg_text_area->render();
343
        echo '</td></tr>';
344
        echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_CAT . ' </td><td>';
345
        $mytree->makeMySelBox('title', 'title', $cid);
346
        echo "</td>
347
        </tr><tr class='head' border='1'>
348
        <td>&nbsp;</td><td><select name=\"op\">
349
        <option value=\"ListingValid\"> " . _AM_ADSLIGHT_OK . "
350
        <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . "
351
        </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\"></td>
352
        </tr></table>";
353
        echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">";
354
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
355
        echo "<input type=\"hidden\" name=\"date\" value=\"$date\">";
356
        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">
357
            </form>";
358
359
        echo '</td></tr></table>';
360
        echo '<br>';
361
    }
362
363
    xoops_cp_footer();
364
}
365
366
#  function modifyAds
367
#####################################################
368
/**
369
 * @param $lid
370
 */
371
function modifyAds($lid)
372
{
373
    global $xoopsDB, $xoopsModule, $xoopsConfig, $myts, $desctext, $moduleDirName, $admin_lang;
374
375
    $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
376
377
    //    include_once __DIR__ . '/header.php';
378
    xoops_cp_header();
379
    //    loadModuleAdminMenu(0, "");
380
    $id_price  = '';
381
    $nom_price = '';
382
    $contactselect = '';
383
384
    echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODANN . '</legend>';
385
386
    $result = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, valid, photo FROM '
387
                              . $xoopsDB->prefix('adslight_listing')
388
                              . " WHERE lid=$lid");
389
390
    while (list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo) = $xoopsDB->fetchRow($result)) {
391
        $title    = $myts->htmlSpecialChars($title);
392
        $status   = $myts->htmlSpecialChars($status);
393
        $expire   = $myts->htmlSpecialChars($expire);
394
        $type     = $myts->htmlSpecialChars($type);
395
        $desctext = $myts->displayTarea($desctext, 1, 1, 1);
396
        $tel      = $myts->htmlSpecialChars($tel);
397
        //      $price = number_format($price, 2, ",", " ");
398
        $typeprice = $myts->htmlSpecialChars($typeprice);
399
        $typeusure = $myts->htmlSpecialChars($typeusure);
400
        $submitter = $myts->htmlSpecialChars($submitter);
401
        $town      = $myts->htmlSpecialChars($town);
402
        $country   = $myts->htmlSpecialChars($country);
403
        $contactby = $myts->htmlSpecialChars($contactby);
404
        $premium   = $myts->htmlSpecialChars($premium);
405
406
        $date2 = formatTimestamp($date, 's');
407
408
        echo "<form action=\"view_ads.php\" method=post>
409
            <table border=0><tr class='head' border='1'>
410
            <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>$lid &nbsp;" . _AM_ADSLIGHT_ADDED_ON . "&nbsp; $date2</td>
411
            </tr><tr class='head' border='1'>
412
            <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>$submitter</td>
413
            </tr><tr class='head' border='1'>
414
            <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$email\"></td>
415
            </tr><tr class='head' border='1'>
416
            <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\"></td>
417
            </tr><tr class='head' border='1'>
418
            <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"$town\"></td>
419
            </tr><tr class='head' border='1'>
420
            <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"$country\"></td>
421
            </tr>
422
            <tr class='head' border='1'>";
423
424
        if ($contactby == 1) {
425
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_EMAIL;
426
        }
427
        if ($contactby == 2) {
428
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PM;
429
        }
430
        if ($contactby == 3) {
431
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_BOTH;
432
        }
433
        if ($contactby == 4) {
434
            $contactselect = _AM_ADSLIGHT_CONTACT_BY_PHONE;
435
        }
436
437
        echo " <td class='head'>" . _AM_ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\">
438
           <option value=\"" . $contactby . "\">" . $contactselect . "</option>
439
           <option value=\"1\">" . _AM_ADSLIGHT_CONTACT_BY_EMAIL . "</option>
440
           <option value=\"2\">" . _AM_ADSLIGHT_CONTACT_BY_PM . "</option>
441
           <option value=\"3\">" . _AM_ADSLIGHT_CONTACT_BY_BOTH . "</option>
442
           <option value=\"4\">" . _AM_ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>';
443
444
        echo "<tr><td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\"";
445
        if ($status == '0') {
446
            echo 'checked';
447
        }
448
        echo '>' . _AM_ADSLIGHT_ACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"1\"";
449
        if ($status == '1') {
450
            echo 'checked';
451
        }
452
        echo '>' . _AM_ADSLIGHT_INACTIVE . "&nbsp;&nbsp; <input type=\"radio\" name=\"status\" value=\"2\"";
453
        if ($status == '2') {
454
            echo 'checked';
455
        }
456
        echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>';
457
458
        echo "<tr class='head' border='1'>
459
            <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"$title\"></td>
460
            </tr><tr class='head' border='1'>
461
            <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"$premium\"></td>
462
            </tr><tr class='head' border='1'>
463
            <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"$expire\"></td>
464
            </tr>";
465
        ////// Type d'annonce
466
        echo "<tr class='head' border='1'>
467
            <td>" . _AM_ADSLIGHT_TYPE . " </td><td><select name=\"type\">";
468
469
        $result5 = $xoopsDB->query('SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
470
        while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) {
471
            $sel = '';
472
            if ($id_type == $type) {
473
                $sel = 'selected';
474
            }
475
            echo "<option value=\"$id_type\" $sel>$nom_type</option>";
476
        }
477
        echo '</select></td></tr>';
478
479
        ////// Etat d'usure
480
        echo "<tr class='head' border='1'>
481
            <td>" . _AM_ADSLIGHT_TYPE_USURE . " </td><td><select name=\"typeusure\">";
482
483
        $result6 = $xoopsDB->query('SELECT nom_usure, id_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure');
484
        while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) {
485
            $sel = '';
486
            if ($id_usure == $typeusure) {
487
                $sel = 'selected';
488
            }
489
            echo "<option value=\"$id_usure\" $sel>$nom_usure</option>";
490
        }
491
        echo '</select></td></tr>';
492
493
        /////// Price
494
        echo "<tr class='head' border='1'><td>"
495
             . _AM_ADSLIGHT_PRICE2
496
             . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\"> "
497
             . $GLOBALS['xoopsModuleConfig']['adslight_money']
498
             . '';
499
500
        //////// Price type
501
502
        $resultx = $xoopsDB->query('SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY nom_price');
503
504
        echo " <select name=\"typeprice\"><option value=\"$id_price\">$nom_price</option>";
505
        while (list($nom_price, $id_price) = $xoopsDB->fetchRow($resultx)) {
506
            $sel = '';
507
            if ($id_price == $typeprice) {
508
                $sel = 'selected';
509
            }
510
511
            echo "<option value=\"$id_price\" $sel>$nom_price</option>";
512
        }
513
        echo '</select></td>';
514
515
        /////// Category
516
517
        echo "<tr class='head' border='1'>
518
            <td>" . _AM_ADSLIGHT_CAT2 . ' </td><td>';
519
        $mytree->makeMySelBox('title', 'title', $cid);
520
        echo "</td>
521
            </tr><tr class='head' border='1'>
522
            <td>" . _AM_ADSLIGHT_DESC . ' </td><td>';
523
524
        $wysiwyg_text_area = AdslightUtilities::getEditor('', 'desctext', $desctext, '100%', '200px', 'small');
525
        echo $wysiwyg_text_area->render();
526
527
        echo '</td></tr>';
528
529
        echo "<tr class='head' border='1'>
530
            <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"50\" value=\"$photo\"></td>
531
            </tr><tr>";
532
        $time = time();
533
        echo "</tr><tr class='head' border='1'>
534
            <td>&nbsp;</td><td><select name=\"op\">
535
            <option value=\"ModifyAdsS\"> " . _AM_ADSLIGHT_MODIF . "
536
            <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . "
537
            </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\"></td>
538
            </tr></table>";
539
        echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">";
540
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
541
        echo "<input type=\"hidden\" name=\"date\" value=\"$time\">";
542
        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">
543
        </form><br>";
544
        echo '</fieldset><br>';
545
        xoops_cp_footer();
546
    }
547
}
548
549
#  function modifyAdsS
550
#####################################################
551
552
/**
553
 * @param $lid
554
 * @param $cat
555
 * @param $title
556
 * @param $status
557
 * @param $expire
558
 * @param $type
559
 * @param $desctext
560
 * @param $tel
561
 * @param $price
562
 * @param $typeprice
563
 * @param $typeusure
564
 * @param $date
565
 * @param $email
566
 * @param $submitter
567
 * @param $town
568
 * @param $country
569
 * @param $contactby
570
 * @param $premium
571
 * @param $valid
572
 * @param $photo
573
 */
574
function modifyAdsS(
575
    $lid,
576
    $cat,
577
    $title,
578
    $status,
579
    $expire,
580
    $type,
581
    $desctext,
582
    $tel,
583
    $price,
584
    $typeprice,
585
    $typeusure,
586
    $date,
587
    $email,
588
    $submitter,
589
    $town,
590
    $country,
591
    $contactby,
592
    $premium,
593
    $valid,
594
    $photo
595
) {
596
    global $xoopsDB, $xoopsConfig, $myts, $moduleDirName, $admin_lang;
597
598
    $title     = $myts->htmlSpecialChars($title);
599
    $status    = $myts->htmlSpecialChars($status);
600
    $expire    = $myts->htmlSpecialChars($expire);
601
    $type      = $myts->htmlSpecialChars($type);
602
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
603
    $tel       = $myts->htmlSpecialChars($tel);
604
    $price     = str_replace(array(' '), '', $price);
605
    $typeprice = $myts->htmlSpecialChars($typeprice);
606
    $typeusure = $myts->htmlSpecialChars($typeusure);
607
    $submitter = $myts->htmlSpecialChars($submitter);
608
    $town      = $myts->htmlSpecialChars($town);
609
    $country   = $myts->htmlSpecialChars($country);
610
    $contactby = $myts->htmlSpecialChars($contactby);
611
    $premium   = $myts->htmlSpecialChars($premium);
612
613
    $xoopsDB->query('UPDATE '
614
                    . $xoopsDB->prefix('adslight_listing')
615
                    . " 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");
616
617
    redirect_header('view_ads.php', 1, _AM_ADSLIGHT_ANNMOD);
618
}
619
620
#  function listingDel
621
#####################################################
622
/**
623
 * @param $lid
624
 * @param $photo
625
 */
626 View Code Duplication
function listingDel($lid, $photo)
627
{
628
    global $xoopsDB, $moduleDirName, $admin_lang;
629
630
    $result2 = $xoopsDB->query('SELECT p.url FROM '
631
                               . $xoopsDB->prefix('adslight_listing')
632
                               . ' l LEFT JOIN '
633
                               . $xoopsDB->prefix('adslight_pictures')
634
                               . ' p  ON l.lid=p.lid WHERE l.lid='
635
                               . $xoopsDB->escape($lid));
636
637
    while (list($purl) = $xoopsDB->fetchRow($result2)) {
638
        if ($purl) {
639
            $destination = XOOPS_ROOT_PATH . '/uploads/AdsLight';
640
            if (file_exists("$destination/$purl")) {
641
                unlink("$destination/$purl");
642
            }
643
            $destination2 = XOOPS_ROOT_PATH . '/uploads/AdsLight/thumbs';
644
            if (file_exists("$destination2/thumb_$purl")) {
645
                unlink("$destination2/thumb_$purl");
646
            }
647
            $destination3 = XOOPS_ROOT_PATH . '/uploads/AdsLight/midsize';
648
            if (file_exists("$destination3/resized_$purl")) {
649
                unlink("$destination3/resized_$purl");
650
            }
651
            $xoopsDB->query('DELETE FROM ' . $xoopsDB->prefix('adslight_pictures') . " WHERE lid=$lid");
652
        }
653
    }
654
655
    $xoopsDB->query('DELETE FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid=$lid");
656
657
    redirect_header('view_ads.php', 1, _AM_ADSLIGHT_ANNDEL);
658
}
659
660
#  function listingValid
661
#####################################################
662
/**
663
 * @param $lid
664
 * @param $cat
665
 * @param $title
666
 * @param $status
667
 * @param $expire
668
 * @param $type
669
 * @param $desctext
670
 * @param $tel
671
 * @param $price
672
 * @param $typeprice
673
 * @param $typeusure
674
 * @param $date
675
 * @param $email
676
 * @param $submitter
677
 * @param $town
678
 * @param $country
679
 * @param $contactby
680
 * @param $premium
681
 * @param $valid
682
 * @param $photo
683
 */
684
function listingValid(
685
    $lid,
686
    $cat,
687
    $title,
688
    $status,
689
    $expire,
690
    $type,
691
    $desctext,
692
    $tel,
693
    $price,
694
    $typeprice,
695
    $typeusure,
696
    $date,
697
    $email,
698
    $submitter,
699
    $town,
700
    $country,
701
    $contactby,
702
    $premium,
703
    $valid,
704
    $photo
705
) {
706
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $meta, $moduleDirName, $admin_lang;
707
708
    $title     = $myts->htmlSpecialChars($title);
709
    $status    = $myts->htmlSpecialChars($status);
710
    $expire    = $myts->htmlSpecialChars($expire);
711
    $type      = $myts->htmlSpecialChars($type);
712
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1);
713
    $tel       = $myts->htmlSpecialChars($tel);
714
    $price     = str_replace(array(' '), '', $price);
715
    $typeprice = $myts->htmlSpecialChars($typeprice);
716
    $typeusure = $myts->htmlSpecialChars($typeusure);
717
    $submitter = $myts->htmlSpecialChars($submitter);
718
    $town      = $myts->htmlSpecialChars($town);
719
    $country   = $myts->htmlSpecialChars($country);
720
    $contactby = $myts->htmlSpecialChars($contactby);
721
    $premium   = $myts->htmlSpecialChars($premium);
722
    $now       = time();
723
    $xoopsDB->query('UPDATE '
724
                    . $xoopsDB->prefix('adslight_listing')
725
                    . " SET cid='$cat', title='$title', status='$status', expire='$expire', type='$type', desctext='$desctext', tel='$tel', price='$price', typeprice='$typeprice', typeusure='$typeusure', date='$now', email='$email', submitter='$submitter', town='$town', country='$country', contactby='$contactby', premium='$premium', valid='$valid', photo='$photo' WHERE lid=$lid");
726
727
    if ($email == '') {
728
    } else {
729
        $tags               = array();
730
        $tags['TITLE']      = $title;
731
        $tags['TYPE']       = AdslightUtilities::getNameType($type);
732
        $tags['SUBMITTER']  = $submitter;
733
        $tags['DESCTEXT']   = stripslashes($desctext);
734
        $tags['EMAIL']      = _AM_ADSLIGHT_EMAIL;
735
        $tags['TEL']        = _AM_ADSLIGHT_TEL;
736
        $tags['HELLO']      = _AM_ADSLIGHT_HELLO;
737
        $tags['VEDIT_AD']   = _AM_ADSLIGHT_VEDIT_AD;
738
        $tags['ANNACCEPT']  = _AM_ADSLIGHT_ANNACCEPT;
739
        $tags['CONSULTTO']  = _AM_ADSLIGHT_CONSULTTO;
740
        $tags['THANKS']     = _ADSLIGHT_THANKS;
741
        $tags['TEAMOF']     = _AM_ADSLIGHT_TEAMOF;
742
        $tags['META_TITLE'] = $meta['title'];
743
        $tags['LINK_URL']   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewads.php?lid=' . $lid . '';
744
        $tags['YOUR_AD']    = _AM_ADSLIGHT_YOUR_AD;
745
        $tags['WEBMASTER']  = _AM_ADSLIGHT_WEBMASTER;
746
        $tags['YOUR_AD_ON'] = _AM_ADSLIGHT_YOUR_AD_ON;
747
        $tags['APPROVED']   = _AM_ADSLIGHT_APPROVED;
748
749
        $subject = '' . _AM_ADSLIGHT_ANNACCEPT . '';
750
        $mail    =& getMailer();
751
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
752
        $mail->setTemplate('listing_approve.tpl');
753
        $mail->useMail();
754
        $mail->multimailer->isHTML(true);
755
        $mail->setFromName($meta['title']);
756
        $mail->setFromEmail($xoopsConfig['adminmail']);
757
        $mail->setToEmails($email);
758
        $mail->setSubject($subject);
759
        $mail->assign($tags);
760
        $mail->send();
761
        echo $mail->getErrors();
762
    }
763
764
    $tags                    = array();
765
    $tags['TITLE']           = $title;
766
    $tags['ADDED_TO_CAT']    = _AM_ADSLIGHT_ADDED_TO_CAT;
767
    $tags['RECIEVING_NOTIF'] = _AM_ADSLIGHT_RECIEVING_NOTIF;
768
    $tags['ERROR_NOTIF']     = _AM_ADSLIGHT_ERROR_NOTIF;
769
    $tags['WEBMASTER']       = _AM_ADSLIGHT_WEBMASTER;
770
    $tags['HELLO']           = _AM_ADSLIGHT_HELLO;
771
    $tags['FOLLOW_LINK']     = _AM_ADSLIGHT_FOLLOW_LINK;
772
    $tags['TYPE']            = AdslightUtilities::getNameType($type);
773
    $tags['LINK_URL']        = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid;
774
    $sql                     = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cat);
775
    $result                  = $xoopsDB->query($sql);
776
    $row                     = $xoopsDB->fetchArray($result);
777
    $tags['CATEGORY_TITLE']  = $row['title'];
778
    $tags['CATEGORY_URL']    = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes($cat);
779
    /** @var XoopsNotificationHandler $notificationHandler*/
780
    $notificationHandler    = xoops_getHandler('notification');
781
    $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
782
    $notificationHandler->triggerEvent('category', $cat, 'new_listing', $tags);
783
    $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
784
785
    redirect_header('view_ads.php', 3, _AM_ADSLIGHT_ANNVALID);
786
}
787
788
#####################################################
789
#####################################################
790
791
foreach ($_POST as $k => $v) {
792
    ${$k} = $v;
793
}
794
795
$pa      = Request::getInt('pa', '', 'GET');
796
797 View Code Duplication
if (!Request::hasVar('lid', 'POST') && Request::hasVar('lid', 'GET')) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
798
    $lid = Request::getInt('lid', 0, 'GET');
799
}
800
801 View Code Duplication
if (!Request::hasVar('op', 'POST') && Request::hasVar('op', 'GET')) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
802
    $op = Request::getString('op', '', 'GET');
803
}
804
805
if (!isset($op)) {
806
    $op = '';
807
}
808
809 View Code Duplication
switch ($op) {
810
811
    case 'IndexView':
812
        indexView($lid);
813
        break;
814
815
    case 'ListingDel':
816
        listingDel($lid, $photo);
817
        break;
818
819
    case 'ListingValid':
820
        listingValid($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo);
821
        break;
822
823
    case 'ModifyAds':
824
        modifyAds($lid);
825
        break;
826
827
    case 'ModifyAdsS':
828
        modifyAdsS($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo);
829
        break;
830
831
    default:
832
        index();
833
        break;
834
835
}
836