Completed
Push — master ( 67bb37...e20777 )
by Michael
02:35
created

admin/validate_ads.php (1 issue)

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