Passed
Push — master ( 978347...893ae4 )
by Michael
02:45
created
Labels
1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
use Xmf\Module\Helper\Permission;
24
use Xmf\Request;
25
use XoopsModules\Adslight;
26
27
$GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
28
29
require_once __DIR__ . '/header.php';
30
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
31
//require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
32
//require_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
33
//require_once __DIR__ . '/include/functions.php';
34
// require_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php';
35
36
$module_id = $xoopsModule->getVar('mid');
37
$groups    = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
38
/** @var \XoopsGroupPermHandler $grouppermHandler */
39
$grouppermHandler = xoops_getHandler('groupperm');
40
41
$permHelper = new Permission();
42
43
$perm_itemid = Request::getInt('item_id', 0, 'POST');
44
45
if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) {
46
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
47
}
48
49
$premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id) ? 1 : 0;
50
51
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
52
53
$mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
54
55
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) {
56
    redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST);
57
}
58
59
if (Request::hasVar('submit', 'POST')) {
60
    $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
61
62
    if (!$GLOBALS['xoopsSecurity']->check()) {
63
        redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
64
    }
65
66
    //    xoops_load("xoopscaptcha");
67
    //    $xoopsCaptcha = XoopsCaptcha::getInstance();
68
    //    if ( !$xoopsCaptcha->verify() ) {
69
    //        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
70
    //    }
71
    if (Request::hasVar('submit', 'POST')) {
72
        /** @var \XoopsModuleHandler $moduleHandler */
73
        $moduleHandler = xoops_getHandler('module');
74
        /** @var \XoopsModule $myModule */
75
        $myModule = $moduleHandler->getByDirname('adslight');
76
        $myModule->setErrors('Could not connect to the database.');
77
    }
78
79
    $cid       = Request::getInt('cid', 0, 'POST');
80
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
81
    if (!in_array($cid, $cat_perms)) {
82
        redirect_header(XOOPS_URL, 2, _NOPERM);
83
    }
84
85
    $title = Request::getString('title', '', 'POST');
86
    //    $status    = $myts->addSlashes($_POST["status"]);
87
    $status    = (int)$status;
88
    $expire    = Request::getString('expire', '', 'POST');
89
    $type      = Request::getString('type', '', 'POST');
90
    $desctext  = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1);
91
    $tel       = Request::getString('tel', '', 'POST');
92
    $price     = str_replace([' '], '', Request::getFloat('price', 0, 'POST'));
93
    $typeprice = Request::getString('typeprice', '', 'POST');
94
    $typeusure = Request::getString('typeusure', '', 'POST');
95
    $date      = Request::getInt('date', 0, 'POST');
96
    $email     = Request::getString('email', '', 'POST');
97
    $submitter = Request::getString('submitter', '', 'POST');
98
    $usid      = Request::getString('usid', '', 'POST');
99
    $town      = Request::getString('town', '', 'POST');
100
    $country   = Request::getString('country', 0, 'POST');
101
    $contactby = Request::getString('contactby', '', 'POST');
102
    $premium   = Request::getString('premium', '', 'POST');
103
    $valid     = Request::getString('valid', '', 'POST');
104
    $date      = time();
105
    $newid     = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq');
106
107
    $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')",
108
                       $xoopsDB->prefix('adslight_listing'), $newid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid);
109
    $success = $xoopsDB->query($sql);
110
    if (!$success) {
111
        $moduleHandler = xoops_getHandler('module');
112
        $myModule      = $moduleHandler->getByDirname('adslight');
0 ignored issues
show
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

112
        /** @scrutinizer ignore-call */ 
113
        $myModule      = $moduleHandler->getByDirname('adslight');
Loading history...
113
        $myModule->setErrors('Could not query the database.');
114
    }
115
116
    $lid = $xoopsDB->getInsertId();
117
118
    if ('Yes' === $valid) {
119
        /** @var \XoopsNotificationHandler $notificationHandler */
120
        $notificationHandler = xoops_getHandler('notification');
121
        //$lid = $xoopsDB->getInsertId();
122
        $tags                    = [];
123
        $tags['TITLE']           = $title;
124
        $tags['ADDED_TO_CAT']    = _ADSLIGHT_ADDED_TO_CAT;
125
        $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF;
126
        $tags['ERROR_NOTIF']     = _ADSLIGHT_ERROR_NOTIF;
127
        $tags['WEBMASTER']       = _ADSLIGHT_WEBMASTER;
128
        $tags['HELLO']           = _ADSLIGHT_HELLO;
129
        $tags['FOLLOW_LINK']     = _ADSLIGHT_FOLLOW_LINK;
130
        $tags['TYPE']            = Adslight\Utility::getNameType($type);
131
        $tags['LINK_URL']        = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid;
132
        $sql                     = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid);
133
        /** @var mysqli_result $result2 */
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
        /** @var \XoopsNotificationHandler $notificationHandler */
139
        $notificationHandler = xoops_getHandler('notification');
140
        $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
141
        $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags);
142
        $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
143
    } else {
144
        $tags                   = [];
145
        $subject                = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . '';
146
        $tags['TITLE']          = $title;
147
        $tags['DESCTEXT']       = $desctext;
148
        $tags['ADMIN']          = _ADSLIGHT_ADMIN;
149
        $tags['NEW_WAITING']    = _ADSLIGHT_NEW_WAITING;
150
        $tags['PLEASE_CHECK']   = _ADSLIGHT_PLEASE_CHECK;
151
        $tags['WEBMASTER']      = _ADSLIGHT_WEBMASTER;
152
        $tags['HELLO']          = _ADSLIGHT_HELLO;
153
        $tags['FOLLOW_LINK']    = _ADSLIGHT_FOLLOW_LINK;
154
        $tags['TYPE']           = Adslight\Utility::getNameType($type);
155
        $tags['NEED_TO_LOGIN']  = _ADSLIGHT_NEED_TO_LOGIN;
156
        $tags['ADMIN_LINK']     = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
157
        $sql                    = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid);
158
        /** @var mysqli_result $result2 */
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
        //@todo - add check to see if directory (and file) exists, otherwise use english
166
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/');
167
        $mail->setTemplate('listing_notify_admin.tpl');
168
        $mail->useMail();
169
        $mail->multimailer->isHTML(true);
170
        $mail->setFromName($xoopsConfig['sitename']);
171
        $mail->setFromEmail($xoopsConfig['adminmail']);
172
        $mail->setToEmails($xoopsConfig['adminmail']);
173
        $mail->setSubject($subject);
174
        $mail->assign($tags);
175
        $mail->send();
176
        echo $mail->getErrors();
177
    }
178
179
    $addphotonow = Request::getInt('addphotonow', 0, 'POST');
180
    if ($addphotonow) {
181
        //$lid = $xoopsDB->getInsertId();
182
        redirect_header("view_photos.php?lid=$lid&uid=$usid", 3, _ADSLIGHT_ADSADDED);
183
    } else {
184
        redirect_header('index.php', 3, _ADSLIGHT_ADSADDED);
185
    }
186
} else {
187
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
188
    require_once XOOPS_ROOT_PATH . '/header.php';
189
//    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
190
191
    $cid          = Request::getInt('cide', 0, 'GET');
192
    $cat_moderate = Request::getInt('cat_moderate', 0, 'POST');
193
    $howlong      = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
194
    $member_usid  = $GLOBALS['xoopsUser']->getVar('uid', 'E');
195
    $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E');
196
    $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E');
197
198
    $result  = $xoopsDB->query('SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
199
    $result1 = $xoopsDB->query('SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
200
    $result3 = $xoopsDB->query('SELECT id_usure, nom_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY id_usure');
201
202
    ob_start();
203
    $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true);
204
    $form->setExtra('enctype="multipart/form-data"');
205
206
    //    $GLOBALS['xoopsGTicket']->addTicketXoopsFormElement($form, __LINE__, 1800, 'token');
207
208
    //@todo - this 'if' code doesn't do anything, what should happen for premium accounts?
209
    if ($cat_moderate) {
210
        if ('0' != $premium) {
211
            echo '';
212
        } else {
213
            echo '';
214
        }
215
    } else {
216
        if ('0' != $premium) {
217
            echo '';
218
        } else {
219
            echo '';
220
        }
221
    }
222
223
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) {
224
        $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true);
225
    } else {
226
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
227
        $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true);
228
    }
229
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) {
230
        $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true);
231
    } else {
232
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
233
        $form->addElement(new \XoopsFormHidden('email', $member_email), true);
234
    }
235
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false);
236
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_country']) {
237
        $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false);
238
    } else {
239
        $form->addElement(new \XoopsFormHidden('country', ''), false);
240
    }
241
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false);
242
243
    //     $cid = $_GET['cid'];
244
    $cid       = 0;
245
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
246
    if (is_array($cat_perms) && count($cat_perms) > 0) {
247
        if (!in_array($cid, $cat_perms)) {
248
            //mb            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM);
249
        }
250
251
        // Category select box
252
        ob_start();
253
        $mytree->makeMySelBox('title', 'title', $cid, 'cid');
0 ignored issues
show
'cid' of type string is incompatible with the type integer expected by parameter $none of XoopsModules\Adslight\Cl...edsTree::makeMySelBox(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

253
        $mytree->makeMySelBox('title', 'title', $cid, /** @scrutinizer ignore-type */ 'cid');
Loading history...
254
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_clean()), true);
255
256
        /** @var mysqli_result $category */
257
        $category = $xoopsDB->query('SELECT title, cat_moderate FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid='" . $xoopsDB->escape($cid) . "'");
258
259
        [$cat_title, $cat_moderate] = $xoopsDB->fetchRow($category);
260
261
        if ('1' == $premium) {
262
            $radio        = new \XoopsFormRadio(_ADSLIGHT_STATUS, 'status', '');
263
            $options['0'] = _ADSLIGHT_ACTIVE;
264
            $options['1'] = _ADSLIGHT_INACTIVE;
265
            $radio->addOptionArray($options);
266
            $form->addElement($radio, true);
267
        } else {
268
            $form->addElement(new \XoopsFormHidden('status', '0'), true);
269
        }
270
271
        if (1 == $premium) {
272
            $form->addElement(new \XoopsFormText(_ADSLIGHT_HOW_LONG, 'expire', 3, 3, $GLOBALS['xoopsModuleConfig']['adslight_howlong']), true);
273
        } else {
274
            $form->addElement(new \XoopsFormLabel(_ADSLIGHT_WILL_LAST, $GLOBALS['xoopsModuleConfig']['adslight_howlong']));
275
            $form->addElement(new \XoopsFormHidden('expire', $GLOBALS['xoopsModuleConfig']['adslight_howlong']), false);
276
        }
277
278
        // Type
279
        $type_form = new \XoopsFormSelect(_ADSLIGHT_TYPE, 'type', '', '1');
280
        while (false !== (list($nom_type, $id_type) = $xoopsDB->fetchRow($result))) {
281
            $type_form->addOption($nom_type, $id_type);
282
        }
283
284
        // State of Object
285
        $usure_form = new \XoopsFormSelect(_ADSLIGHT_TYPE_USURE, 'typeusure', '', '1');
286
        while (false !== (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result3))) {
287
            $usure_form->addOption($nom_usure, $id_usure);
288
        }
289
290
        $form->addElement($type_form, true);
291
        $form->addElement($usure_form, true);
292
293
        $form->addElement(new \XoopsFormText(_ADSLIGHT_TITLE2, 'title', 40, 50, ''), true);
294
295
        $form->addElement(Adslight\Utility::getEditor(_ADSLIGHT_DESC, 'desctext', '', '100%', 40), true);
296
297
        //        $form->addElement(new \XoopsFormEditor(_ADSLIGHT_DESC, $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = FALSE, $onfailure = 'textarea'));
298
        //        $optionsTrayNote->addElement($bodynote);
299
300
        $form->addElement(new \XoopsFormText(_ADSLIGHT_PRICE2, 'price', 40, 50, ''), true);
301
302
        // Price Type
303
        $sel_form = new \XoopsFormSelect(_ADSLIGHT_PRICETYPE, 'typeprice', '', '1');
304
        while (false !== (list($nom_price, $id_price) = $xoopsDB->fetchRow($result1))) {
305
            $sel_form->addOption($nom_price, $id_price);
306
        }
307
308
        $form->addElement($sel_form);
309
310
        $contactby_form = new \XoopsFormSelect(_ADSLIGHT_CONTACTBY, 'contactby', '', '1');
311
        $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL);
312
        $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM);
313
        $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH);
314
        $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE);
315
        $form->addElement($contactby_form, true);
316
        $form->addElement(new \XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', 1));
317
        /*
318
                if ('1' == $GLOBALS['xoopsModuleConfig']["adslight_use_captcha"]) {
319
                    $form->addElement(new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true);
320
                }
321
        */
322
        if ('0' != $premium) {
323
            $form->addElement(new \XoopsFormHidden('premium', 'yes'), false);
324
        } else {
325
            $form->addElement(new \XoopsFormHidden('premium', 'no'), false);
326
        }
327
328
        if ('1' == $cat_moderate) {
329
            $form->addElement(new \XoopsFormHidden('valid', 'No'), false);
330
            $form->addElement(new \XoopsFormHidden('cat_moderate', '1'), false);
331
        } else {
332
            $form->addElement(new \XoopsFormHidden('valid', 'Yes'), false);
333
        }
334
        $form->addElement(new \XoopsFormHidden('usid', $member_usid), false);
335
        $form->addElement(new \XoopsFormHidden('date', time()), false);
336
        $form->addElement(new \XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit'));
337
        $form->display();
338
        $GLOBALS['xoopsTpl']->assign('submit_form', ob_get_clean());
339
    } else {    // User can't see any category
340
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
341
    }
342
    require_once XOOPS_ROOT_PATH . '/footer.php';
343
}
344