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

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__ . '/header.php';
24
$myts =& MyTextSanitizer::getInstance();// MyTextSanitizer object
25
require XOOPS_ROOT_PATH."/modules/adslight/include/gtickets.php";
26
include XOOPS_ROOT_PATH."/modules/adslight/class/classifiedstree.php";
27
include XOOPS_ROOT_PATH."/class/module.errorhandler.php";
28
include_once __DIR__ . '/include/functions.php';
29
// include_once XOOPS_ROOT_PATH."/class/captcha/xoopscaptcha.php";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
30
31
$erh = new ErrorHandler; //ErrorHandler object
32
33
 $module_id = $xoopsModule->getVar('mid');
34
 if (is_object($xoopsUser)) {
35
    $groups = $xoopsUser->getGroups();
36
    } else {
37
    $groups = XOOPS_GROUP_ANONYMOUS;
38
    }
39
    $gperm_handler =& xoops_gethandler('groupperm');
40 View Code Duplication
 if (isset($_POST['item_id'])) {
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...
41
    $perm_itemid = intval($_POST['item_id']);
42
    } else {
43
    $perm_itemid = 0;
44
    }
45 View Code Duplication
   if (!$gperm_handler->checkRight("adslight_submit", $perm_itemid, $groups, $module_id)) {
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...
46
    redirect_header(XOOPS_URL."/index.php", 3, _NOPERM);
47
    exit();
48
    }
49
 if (!$gperm_handler->checkRight("adslight_premium", $perm_itemid, $groups, $module_id)) {
50
    $premium = 0;
51
    } else {
52
    $premium = 1;
53
    }
54
55
    include_once XOOPS_ROOT_PATH."/modules/adslight/include/functions.php";
56
    include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
57
    include_once XOOPS_ROOT_PATH."/modules/adslight/class/classifiedstree.php";
58
    $mytree = new ClassifiedsTree($xoopsDB->prefix("adslight_categories"),"cid","pid");
59
60
    if (empty($xoopsUser)) {
61
    redirect_header(XOOPS_URL."/user.php",2,_ADS_MUSTREGFIRST);
62
    exit();
63
    }
64
65
    if (!empty($_POST['submit'])) {
66
    $howlong=$xoopsModuleConfig["adslight_howlong"];
67
68
    if ( ! $xoopsGTicket->check( true , 'token' ) ) {
69
        redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
70
    }
71
72
//    xoops_load("xoopscaptcha");
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
73
//    $xoopsCaptcha = XoopsCaptcha::getInstance();
74
//    if ( !$xoopsCaptcha->verify() ) {
75
//        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
76
//    }
77
78
if ($_POST["title"]=="") {
79
           $erh->show("1001");
80
       }
81
82 View Code Duplication
 if ( !empty($_POST['cid']) ) {
83
          $cid = intval($_POST['cid']);
84
    } else {
85
        $cid = 0;
86
    }
87
    $cat_perms = adslight_MygetItemIds("adslight_submit");
88
    if (!in_array($cid, $cat_perms)) {
89
        redirect_header(XOOPS_URL, 2, _NOPERM);
90
        exit();
91
    }
92
93
    $title = $myts->addSlashes($_POST["title"]);
94
    $status = $myts->addSlashes($_POST["status"]);
95
    $expire = $myts->addSlashes($_POST["expire"]);
96
    $type = $myts->addSlashes($_POST["type"]);
97
    $desctext = $myts->displayTarea($_POST["desctext"],1,1,1);
98
    $tel = $myts->addSlashes($_POST["tel"]);
99
    $price = str_replace(array(' '), '', $_POST["price"]);
100
    $typeprice = $myts->addSlashes($_POST["typeprice"]);
101
    $typeusure = $myts->addSlashes($_POST["typeusure"]);
102
    $date = $myts->addSlashes($_POST["date"]);
103
    $email = $myts->addSlashes($_POST["email"]);
104
    $submitter = $myts->addSlashes($_POST["submitter"]);
105
    $usid = $myts->addSlashes($_POST["usid"]);
106
    $town = $myts->addSlashes($_POST["town"]);
107
    $country = $myts->addSlashes($_POST["country"]);
108
    $contactby = $myts->addSlashes($_POST["contactby"]);
109
    $premium = $myts->addSlashes($_POST["premium"]);
110
    $valid = $myts->addSlashes($_POST["valid"]);
111
    $date = time();
112
    $newid = $xoopsDB->genId($xoopsDB->prefix("adslight_listing")."_lid_seq");
113
114
    $sql = sprintf("INSERT INTO %s (lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, usid, town, country, contactby, premium, valid) VALUES (%u, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $xoopsDB->prefix("adslight_listing"), $newid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid);
115
    $xoopsDB->query($sql) || $erh->show("0013");
116
117
    $lid = $xoopsDB->getInsertId();
118
119 View Code Duplication
if ($valid == 'Yes') {
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...
120
121
    $notification_handler =& xoops_gethandler('notification');
122
    //$lid = $xoopsDB->getInsertId();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
123
    $tags=array();
124
    $tags['TITLE'] = $title;
125
    $tags['ADDED_TO_CAT'] = _ADSLIGHT_ADDED_TO_CAT;
126
    $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF;
127
    $tags['ERROR_NOTIF'] = _ADSLIGHT_ERROR_NOTIF;
128
    $tags['WEBMASTER'] = _ADSLIGHT_WEBMASTER;
129
    $tags['HELLO'] = _ADSLIGHT_HELLO;
130
    $tags['FOLLOW_LINK'] = _ADSLIGHT_FOLLOW_LINK;
131
    $tags['TYPE'] = adslight_NameType($type);
132
    $tags['LINK_URL'] = XOOPS_URL . '/modules/adslight/viewads.php?'. '&lid=' . $lid;
133
    $sql = "SELECT title FROM " . $xoopsDB->prefix("adslight_categories") . " WHERE cid=" . addslashes($cid);
134
    $result2 = $xoopsDB->query($sql);
135
    $row = $xoopsDB->fetchArray($result2);
136
    $tags['CATEGORY_TITLE'] = $row['title'];
137
    $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes($cid);
138
    $notification_handler =& xoops_gethandler('notification');
139
    $notification_handler->triggerEvent('global', 0, 'new_listing', $tags);
140
    $notification_handler->triggerEvent('category', $cid, 'new_listing', $tags);
141
    $notification_handler->triggerEvent ('listing', $lid, 'new_listing', $tags );
142
143
} else {
144
145
    $tags =array();
146
    $subject =  ""._ADSLIGHT_NEW_WAITING_SUBJECT."";
147
    $tags['TITLE'] = $title;
148
    $tags['DESCTEXT'] = $desctext;
149
    $tags['ADMIN'] = _ADSLIGHT_ADMIN;
150
    $tags['NEW_WAITING'] = _ADSLIGHT_NEW_WAITING;
151
    $tags['PLEASE_CHECK'] = _ADSLIGHT_PLEASE_CHECK;
152
    $tags['WEBMASTER'] = _ADSLIGHT_WEBMASTER;
153
    $tags['HELLO'] = _ADSLIGHT_HELLO;
154
    $tags['FOLLOW_LINK'] = _ADSLIGHT_FOLLOW_LINK;
155
    $tags['TYPE'] = adslight_NameType($type);
156
    $tags['NEED_TO_LOGIN'] = _ADSLIGHT_NEED_TO_LOGIN;
157
    $tags['ADMIN_LINK'] = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
158
    $sql = "SELECT title FROM " . $xoopsDB->prefix("adslight_categories") . " WHERE cid=" . addslashes($cid);
159
    $result2 = $xoopsDB->query($sql);
160
    $row = $xoopsDB->fetchArray($result2);
161
    $tags['CATEGORY_TITLE'] = $row['title'];
162
    $tags['NEWAD'] = _ADSLIGHT_NEWAD;
163
164
        $mail =& xoops_getMailer();
165
        $mail->setTemplateDir(XOOPS_ROOT_PATH."/modules/adslight/language/".$xoopsConfig['language']."/mail_template/");
166
        $mail->setTemplate("listing_notify_admin.tpl");
167
        $mail->useMail();
168
        $mail->multimailer->isHTML(true);
169
        $mail->setFromName($xoopsConfig['sitename']);
170
        $mail->setFromEmail($xoopsConfig['adminmail']);
171
        $mail->setToEmails($xoopsConfig['adminmail']);
172
        $mail->setSubject($subject);
173
        $mail->assign($tags);
174
        $mail->send();
175
        echo $mail->getErrors();
176
        }
177
178 View Code Duplication
if ( !empty($_POST['addphotonow']) ) {
179
           $addphotonow = intval($_POST['addphotonow']);
180
    } else {
181
        $addphotonow = "0";
182
    }
183
184 View Code Duplication
if ($addphotonow) {
185
    //$lid = $xoopsDB->getInsertId();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
186
    redirect_header("view_photos.php?lid=$lid&uid=$usid",3,_ADSLIGHT_ADSADDED);
187
} else {
188
    redirect_header("index.php",3,_ADSLIGHT_ADSADDED);
189
    }
190
    exit();
191
192
} else {
193
    $xoopsOption['template_main'] = "adslight_addlisting.tpl";
194
    include XOOPS_ROOT_PATH."/header.php";
195
    include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
196
197 View Code Duplication
    if ( !empty($_POST['cid']) ) {
198
           $cid = intval($_POST['cid']);
199
    } else {
200
        $cid = 0;
201
    }
202
203 View Code Duplication
    if ( !empty($_POST['cat_moderate']) ) {
204
           $cat_moderate = intval($_POST['cat_moderate']);
205
    } else {
206
        $cat_moderate = 0;
207
    }
208
209
    $howlong=$xoopsModuleConfig["adslight_howlong"];
210
    $member_usid = $xoopsUser->getVar("uid", "E");
211
    $member_email =$xoopsUser->getVar("email", "E");
212
    $member_uname =$xoopsUser->getVar("uname", "E");
213
214
    $result = $xoopsDB->query("select id_type, nom_type from ".$xoopsDB->prefix("adslight_type")." order by nom_type");
215
    $result1 = $xoopsDB->query("select id_price, nom_price from ".$xoopsDB->prefix("adslight_price")." order by id_price");
216
    $result3 = $xoopsDB->query("select id_usure, nom_usure from ".$xoopsDB->prefix("adslight_usure")." order by id_usure");
217
218
    ob_start();
219
    $form = new XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php');
220
    $form->setExtra('enctype="multipart/form-data"');
221
222
$GLOBALS['xoopsGTicket']->addTicketXoopsFormElement( $form , __LINE__ , 1800 , 'token' ) ;
223
224 View Code Duplication
if ($cat_moderate) {
225
if ($premium != "0") {
226
    echo "";
227
        } else {
228
    echo "";
229
    }
230
    } else {
231
if ($premium != "0") {
232
    echo "";
233
    } else {
234
    echo "";
235
    }
236
    }
237
238 View Code Duplication
if ($xoopsModuleConfig["adslight_diff_name"] == "1") {
239
    $form->addElement(new XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50,50, $member_uname), true);
240
    } else {
241
    $form->addElement(new XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
242
    $form->addElement(new XoopsFormHidden('submitter',$member_uname), true);
243
    }
244 View Code Duplication
if ($xoopsModuleConfig["adslight_diff_email"] == "1") {
245
    $form->addElement(new XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50,50, $member_email), true);
246
    } else {
247
    $form->addElement(new XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
248
    $form->addElement(new XoopsFormHidden('email',$member_email), true);
249
    }
250
    $form->addElement(new XoopsFormText(_ADSLIGHT_TOWN, 'town', 50,50, ""), false);
251 View Code Duplication
if ($xoopsModuleConfig["adslight_use_country"] == "1") {
252
    $form->addElement(new XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50,50, ""), false);
253
    } else {
254
    $form->addElement(new XoopsFormHidden('country',""), false);
255
    }
256
    $form->addElement(new XoopsFormText(_ADSLIGHT_TEL, "tel", 50, 50, ""), false);
257
258
// $cat_id = $_GET['cid'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
259
$cid = 1;
260
$cat_perms = adslight_MygetItemIds('adslight_submit');
261
    if (is_array($cat_perms) && count($cat_perms) > 0) {
262
    if (!in_array($cid, $cat_perms)) {
263
        redirect_header(XOOPS_URL."/modules/adslight/index.php", 3, _NOPERM);
264
        exit();
265
    }
266
//// D�but Menu d�roulant /////
267
ob_start();
268
    $mytree->makeMySelBox('title','title', $cid,'cid');
269
    $form->addElement(new XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_contents()), true);
270
     ob_end_clean();
271
//// Fin Menu d�roulant /////
272
273
$category = $xoopsDB->query("select title, cat_moderate from ".$xoopsDB->prefix("adslight_categories")." where cid=".mysql_real_escape_string($cid)."");
274
275
list($cat_title, $cat_moderate) = $xoopsDB->fetchRow($category);
276
277 View Code Duplication
if ($premium == "1") {
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...
278
    $radio = new XoopsFormRadio(_ADSLIGHT_STATUS, 'status', "");
279
    $options["0"]=_ADSLIGHT_ACTIVE;
280
    $options["1"]=_ADSLIGHT_INACTIVE;
281
    $radio->addOptionArray($options);
282
    $form->addElement($radio,true);
283
    } else {
284
    $form->addElement(new XoopsFormHidden("status","0"), true);
285
    }
286
287 View Code Duplication
if ($premium == 1) {
288
    $form->addElement(new XoopsFormText(_ADSLIGHT_HOW_LONG, "expire", 3, 3, $xoopsModuleConfig["adslight_howlong"]), true);
289
        } else {
290
    $form->addElement(new XoopsFormLabel(_ADSLIGHT_WILL_LAST, $xoopsModuleConfig["adslight_howlong"]));
291
    $form->addElement(new XoopsFormHidden("expire",$xoopsModuleConfig["adslight_howlong"]), false);
292
    }
293
294
/// Type d'annonce
295
    $type_form= new XoopsFormSelect(_ADSLIGHT_TYPE, "type", "", "1");
296
    while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result)) {
297
    $type_form->addOption($nom_type, $id_type);
298
    }
299
/// Etat de l'objet
300
    $usure_form= new XoopsFormSelect(_ADSLIGHT_TYPE_USURE, "typeusure", "", "1");
301
    while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result3)) {
302
    $usure_form->addOption($nom_usure, $id_usure);
303
    }
304
305
    $form->addElement($type_form, true);
306
    $form->addElement($usure_form, true);
307
308
    $form->addElement(new XoopsFormText(_ADSLIGHT_TITLE2, "title", 40, 50, ""), true);
309
    $form->addElement(adslight_getEditor(_ADSLIGHT_DESC, "desctext", "", 5, 40), true);
310
    $form->addElement(new XoopsFormText(_ADSLIGHT_PRICE2 , "price", 40, 50, ""), true);
311
312
/// Type de prix
313
    $sel_form= new XoopsFormSelect(_ADSLIGHT_PRICETYPE, "typeprice", "", "1");
314
    while (list($nom_price, $id_price) = $xoopsDB->fetchRow($result1)) {
315
    $sel_form->addOption($nom_price, $id_price);
316
    }
317
318
    $form->addElement($sel_form);
319
320
    $contactby_form= new XoopsFormSelect(_ADSLIGHT_CONTACTBY, "contactby", "", "1");
321
    $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL);
322
    $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM);
323
    $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH);
324
    $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE);
325
    $form->addElement($contactby_form, true);
326
    $form->addElement(new XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', 1));
327
328
//if ($xoopsModuleConfig["adslight_use_captcha"] == '1') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
329
//	$form->addElement(new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true);
330
//}
331
332 View Code Duplication
if ($premium != "0") {
333
    $form->addElement(new XoopsFormHidden("premium","yes"), false);
334
    } else {
335
    $form->addElement(new XoopsFormHidden("premium","no"), false);
336
    }
337
338 View Code Duplication
if ($cat_moderate =="1") {
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...
339
    $form->addElement(new XoopsFormHidden("valid","No"), false);
340
    $form->addElement(new XoopsFormHidden("cat_moderate","1"), false);
341
    } else {
342
    $form->addElement(new XoopsFormHidden("valid","Yes"), false);
343
    }
344
    $form->addElement(new XoopsFormHidden('usid',$member_usid), false);
345
    $form->addElement(new XoopsFormHidden('date',time()), false);
346
    $form->addElement(new XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit'));
347
    $form->display();
348
    $xoopsTpl->assign('submit_form', ob_get_contents());
349
    ob_end_clean();
350
} else {    // User can't see any category
351
    redirect_header(XOOPS_URL.'/index.php', 3, _NOPERM);
352
    exit();
353
    }
354
    include XOOPS_ROOT_PATH.'/footer.php';
355
}
356