Completed
Push — master ( a25b3b...67bb37 )
by Michael
02:44
created

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