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

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