Passed
Push — master ( e8b784...3aca22 )
by Michael
15:11 queued 10:10
created
Labels
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    XOOPS Project (https://xoops.org)
17
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @author       XOOPS Development Team
19
 * @author       Pascal Le Boustouller: original author ([email protected])
20
 * @author       Luc Bizet (www.frxoops.org)
21
 * @author       jlm69 (www.jlmzone.com)
22
 * @author       mamba (www.xoops.org)
23
 */
24
25
use Xmf\Module\Helper\Permission;
26
use Xmf\Request;
27
use XoopsModules\Adslight;
28
29
$GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
30
31
require_once __DIR__ . '/header.php';
32
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
33
//require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
34
//require_once XOOPS_ROOT_PATH . '/modules/adslight/class/Tree.php';
35
//require_once __DIR__ . '/include/functions.php';
36
// require_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php';
37
38
$module_id = $xoopsModule->getVar('mid');
39
$groups    = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
40
/** @var \XoopsGroupPermHandler $grouppermHandler */
41
$grouppermHandler = xoops_getHandler('groupperm');
42
43
$permHelper = new Permission();
44
45
$perm_itemid = Request::getInt('item_id', 0, 'POST');
46
47
if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) {
48
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
49
}
50
51
$premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id) ? 1 : 0;
52
53
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
54
55
$mytree = new Adslight\Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
56
57
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) {
58
    redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST);
59
}
60
61
if (Request::hasVar('submit', 'POST')) {
62
    $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
63
64
    if (!$GLOBALS['xoopsSecurity']->check()) {
65
        redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
66
    }
67
68
    //    xoops_load("xoopscaptcha");
69
    //    $xoopsCaptcha = XoopsCaptcha::getInstance();
70
    //    if ( !$xoopsCaptcha->verify() ) {
71
    //        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
72
    //    }
73
    if (Request::hasVar('submit', 'POST')) {
74
        /** @var \XoopsModuleHandler $moduleHandler */
75
        $moduleHandler = xoops_getHandler('module');
76
        /** @var \XoopsModule $myModule */
77
        $myModule = $moduleHandler->getByDirname('adslight');
78
        $myModule->setErrors('Could not connect to the database.');
79
    }
80
81
    $cid       = Request::getInt('cid', 0, 'POST');
82
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
83
    if (!in_array($cid, $cat_perms)) {
84
        redirect_header(XOOPS_URL, 2, _NOPERM);
85
    }
86
87
    $title = Request::getString('title', '', 'POST');
88
    //    $status    = $myts->addSlashes($_POST["status"]);
89
    $status    = (int)$status;
90
    $expire    = Request::getString('expire', '', 'POST');
91
    $type      = Request::getString('type', '', 'POST');
92
    $desctext  = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1);
93
    $tel       = Request::getString('tel', '', 'POST');
94
    $price     = str_replace([' '], '', Request::getFloat('price', 0, 'POST'));
95
    $typeprice = Request::getString('typeprice', '', 'POST');
96
    $typecondition = Request::getString('typecondition', '', 'POST');
97
    $date_created      = Request::getInt('date_created', 0, 'POST');
98
    $email     = Request::getString('email', '', 'POST');
99
    $submitter = Request::getString('submitter', '', 'POST');
100
    $usid      = Request::getString('usid', '', 'POST');
101
    $town      = Request::getString('town', '', 'POST');
102
    $country   = Request::getString('country', 0, 'POST');
103
    $contactby = Request::getString('contactby', '', 'POST');
104
    $premium   = Request::getString('premium', '', 'POST');
105
    $valid     = Request::getString('valid', '', 'POST');
106
    $date_created      = time();
107
    $newid     = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq');
108
109
    $sql     = sprintf(
110
        "INSERT INTO `%s` (lid, cid, title, STATUS, EXPIRE, type, desctext, tel, price, typeprice, typecondition, date_created, 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')",
111
        $xoopsDB->prefix('adslight_listing'),
112
        $newid,
113
        $cid,
114
        $title,
115
        $status,
116
        $expire,
117
        $type,
118
        $desctext,
119
        $tel,
120
        $price,
121
        $typeprice,
122
        $typecondition,
123
        $date_created,
124
        $email,
125
        $submitter,
126
        $usid,
127
        $town,
128
        $country,
129
        $contactby,
130
        $premium,
131
        $valid
132
    );
133
    $success = $xoopsDB->query($sql);
134
    if (!$success) {
135
        $moduleHandler = xoops_getHandler('module');
136
        $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

136
        /** @scrutinizer ignore-call */ 
137
        $myModule      = $moduleHandler->getByDirname('adslight');
Loading history...
137
        $myModule->setErrors('Could not query the database.');
138
    }
139
140
    $lid = $xoopsDB->getInsertId();
141
142
    if ('Yes' === $valid) {
143
        /** @var \XoopsNotificationHandler $notificationHandler */
144
        $notificationHandler = xoops_getHandler('notification');
145
        //$lid = $xoopsDB->getInsertId();
146
        $tags                    = [];
147
        $tags['TITLE']           = $title;
148
        $tags['ADDED_TO_CAT']    = _ADSLIGHT_ADDED_TO_CAT;
149
        $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF;
150
        $tags['ERROR_NOTIF']     = _ADSLIGHT_ERROR_NOTIF;
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['LINK_URL']        = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid;
156
        $sql                     = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes((string)$cid);
157
        /** @var mysqli_result $result2 */
158
        $result2                = $xoopsDB->query($sql);
159
        $row                    = $xoopsDB->fetchArray($result2);
160
        $tags['CATEGORY_TITLE'] = $row['title'];
161
        $tags['CATEGORY_URL']   = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes((string)$cid);
162
        /** @var \XoopsNotificationHandler $notificationHandler */
163
        $notificationHandler = xoops_getHandler('notification');
164
        $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
165
        $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags);
166
        $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
167
    } else {
168
        $tags                  = [];
169
        $subject               = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . '';
170
        $tags['TITLE']         = $title;
171
        $tags['DESCTEXT']      = $desctext;
172
        $tags['ADMIN']         = _ADSLIGHT_ADMIN;
173
        $tags['NEW_WAITING']   = _ADSLIGHT_NEW_WAITING;
174
        $tags['PLEASE_CHECK']  = _ADSLIGHT_PLEASE_CHECK;
175
        $tags['WEBMASTER']     = _ADSLIGHT_WEBMASTER;
176
        $tags['HELLO']         = _ADSLIGHT_HELLO;
177
        $tags['FOLLOW_LINK']   = _ADSLIGHT_FOLLOW_LINK;
178
        $tags['TYPE']          = Adslight\Utility::getNameType($type);
179
        $tags['NEED_TO_LOGIN'] = _ADSLIGHT_NEED_TO_LOGIN;
180
        $tags['ADMIN_LINK']    = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
181
        $sql                   = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid);
182
        /** @var mysqli_result $result2 */
183
        $result2                = $xoopsDB->query($sql);
184
        $row                    = $xoopsDB->fetchArray($result2);
185
        $tags['CATEGORY_TITLE'] = $row['title'];
186
        $tags['NEWAD']          = _ADSLIGHT_NEWAD;
187
188
        $mail = xoops_getMailer();
189
        //@todo - add check to see if directory (and file) exists, otherwise use english
190
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/');
191
        $mail->setTemplate('listing_notify_admin.tpl');
192
        $mail->useMail();
193
        $mail->multimailer->isHTML(true);
194
        $mail->setFromName($xoopsConfig['sitename']);
195
        $mail->setFromEmail($xoopsConfig['adminmail']);
196
        $mail->setToEmails($xoopsConfig['adminmail']);
197
        $mail->setSubject($subject);
198
        $mail->assign($tags);
199
        $mail->send();
200
        echo $mail->getErrors();
201
    }
202
203
    $addphotonow = Request::getInt('addphotonow', 0, 'POST');
204
    if ($addphotonow) {
205
        //$lid = $xoopsDB->getInsertId();
206
        redirect_header("view_photos.php?lid=$lid&uid=$usid", 3, _ADSLIGHT_ADSADDED);
207
    } else {
208
        redirect_header('index.php', 3, _ADSLIGHT_ADSADDED);
209
    }
210
} else {
211
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
212
    require_once XOOPS_ROOT_PATH . '/header.php';
213
    //    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
214
215
    $cid          = Request::getInt('cide', 0, 'GET');
216
    $cat_moderate = Request::getInt('cat_moderate', 0, 'POST');
217
    $howlong      = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
218
    $member_usid  = $GLOBALS['xoopsUser']->getVar('uid', 'E');
219
    $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E');
220
    $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E');
221
222
    $result  = $xoopsDB->query('SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
223
    $result1 = $xoopsDB->query('SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
224
    $result3 = $xoopsDB->query('SELECT id_condition, nom_condition FROM ' . $xoopsDB->prefix('adslight_condition') . ' ORDER BY id_condition');
225
226
    ob_start();
227
    $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true);
228
    $form->setExtra('enctype="multipart/form-data"');
229
230
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) {
231
        $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true);
232
    } else {
233
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
234
        $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true);
235
    }
236
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) {
237
        $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true);
238
    } else {
239
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
240
        $form->addElement(new \XoopsFormHidden('email', $member_email), true);
241
    }
242
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false);
243
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_country']) {
244
        $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false);
245
    } else {
246
        $form->addElement(new \XoopsFormHidden('country', ''), false);
247
    }
248
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false);
249
250
    //     $cid = $_GET['cid'];
251
    $cid       = 0;
252
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
253
    if (is_array($cat_perms) && $cat_perms !== []) {
254
        if (!in_array($cid, $cat_perms)) {
255
            //mb            $helper->redirect('index.php', 3, _NOPERM);
256
        }
257
258
        // Category select box
259
        ob_start();
260
        $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\Tree::makeMySelBox(). ( Ignorable by Annotation )

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

260
        $mytree->makeMySelBox('title', 'title', $cid, /** @scrutinizer ignore-type */ 'cid');
Loading history...
261
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_clean()), true);
262
263
        /** @var mysqli_result $category */
264
        $category = $xoopsDB->query('SELECT title, cat_moderate FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid='" . $xoopsDB->escape($cid) . "'");
265
266
        [$cat_title, $cat_moderate] = $xoopsDB->fetchRow($category);
267
268
        if ('1' == $premium) {
269
            $radio        = new \XoopsFormRadio(_ADSLIGHT_STATUS, 'status', '');
270
            $options['0'] = _ADSLIGHT_ACTIVE;
271
            $options['1'] = _ADSLIGHT_INACTIVE;
272
            $radio->addOptionArray($options);
273
            $form->addElement($radio, true);
274
        } else {
275
            $form->addElement(new \XoopsFormHidden('status', '0'), true);
276
        }
277
278
        if (1 == $premium) {
279
            $form->addElement(new \XoopsFormText(_ADSLIGHT_HOW_LONG, 'expire', 3, 3, $GLOBALS['xoopsModuleConfig']['adslight_howlong']), true);
280
        } else {
281
            $form->addElement(new \XoopsFormLabel(_ADSLIGHT_WILL_LAST, $GLOBALS['xoopsModuleConfig']['adslight_howlong']));
282
            $form->addElement(new \XoopsFormHidden('expire', $GLOBALS['xoopsModuleConfig']['adslight_howlong']), false);
283
        }
284
285
        // Type
286
        $type_form = new \XoopsFormSelect(_ADSLIGHT_TYPE, 'type', '', '1');
287
        while (false !== (list($nom_type, $id_type) = $xoopsDB->fetchRow($result))) {
288
            $type_form->addOption($nom_type, $id_type);
289
        }
290
291
        // State of Object
292
        $condition_form = new \XoopsFormSelect(_ADSLIGHT_TYPE_CONDITION, 'typecondition', '', '1');
293
        while (false !== (list($nom_condition, $id_condition) = $xoopsDB->fetchRow($result3))) {
294
            $condition_form->addOption($nom_condition, $id_condition);
295
        }
296
297
        $form->addElement($type_form, true);
298
        $form->addElement($condition_form, true);
299
300
        $form->addElement(new \XoopsFormText(_ADSLIGHT_TITLE2, 'title', 40, 50, ''), true);
301
302
        $form->addElement(Adslight\Utility::getEditor(_ADSLIGHT_DESC, 'desctext', '', '100%', '300px', ''), true);
0 ignored issues
show
The method getEditor() does not exist on XoopsModules\Adslight\Utility. ( Ignorable by Annotation )

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

302
        $form->addElement(Adslight\Utility::/** @scrutinizer ignore-call */ getEditor(_ADSLIGHT_DESC, 'desctext', '', '100%', '300px', ''), true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
303
304
        //        $form->addElement(new \XoopsFormEditor(_ADSLIGHT_DESC, $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = FALSE, $onfailure = 'textarea'));
305
        //        $optionsTrayNote->addElement($bodynote);
306
307
        $form->addElement(new \XoopsFormText(_ADSLIGHT_PRICE2, 'price', 40, 50, ''), true);
308
309
        // Price Type
310
        $sel_form = new \XoopsFormSelect(_ADSLIGHT_PRICETYPE, 'typeprice', '', '1');
311
        while (false !== (list($nom_price, $id_price) = $xoopsDB->fetchRow($result1))) {
312
            $sel_form->addOption($nom_price, $id_price);
313
        }
314
315
        $form->addElement($sel_form);
316
317
        $contactby_form = new \XoopsFormSelect(_ADSLIGHT_CONTACTBY, 'contactby', '', '1');
318
        $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL);
319
        $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM);
320
        $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH);
321
        $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE);
322
        $form->addElement($contactby_form, true);
323
        $form->addElement(new \XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', 1));
324
        /*
325
                if ('1' == $GLOBALS['xoopsModuleConfig']["adslight_use_captcha"]) {
326
                    $form->addElement(new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true);
327
                }
328
        */
329
        if ('0' != $premium) {
330
            $form->addElement(new \XoopsFormHidden('premium', 'yes'), false);
331
        } else {
332
            $form->addElement(new \XoopsFormHidden('premium', 'no'), false);
333
        }
334
335
        if ('1' == $cat_moderate) {
336
            $form->addElement(new \XoopsFormHidden('valid', 'No'), false);
337
            $form->addElement(new \XoopsFormHidden('cat_moderate', '1'), false);
338
        } else {
339
            $form->addElement(new \XoopsFormHidden('valid', 'Yes'), false);
340
        }
341
        $form->addElement(new \XoopsFormHidden('usid', $member_usid), false);
342
        $form->addElement(new \XoopsFormHidden('date_created', time()), false);
343
        $form->addElement(new \XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit'));
344
        $form->display();
345
        $GLOBALS['xoopsTpl']->assign('submit_form', ob_get_clean());
346
    } else {    // User can't see any category
347
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
348
    }
349
    require_once XOOPS_ROOT_PATH . '/footer.php';
350
}
351