Passed
Push — master ( d51943...827974 )
by Michael
03:05
created
Labels
Severity
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
    Helper,
29
    Tree,
30
    Utility
31
};
32
33
/** @var Helper $helper */
34
35
$GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
36
require_once __DIR__ . '/header.php';
37
38
global $xoopsModule, $xoopsDB, $xoopsConfig;
39
40
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
41
42
$moduleId = $xoopsModule->getVar('mid');
43
$groups   = $GLOBALS['xoopsUser'] instanceof XoopsUser ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
44
/** @var \XoopsGroupPermHandler $grouppermHandler */
45
$grouppermHandler = xoops_getHandler('groupperm');
46
47
$permHelper = new Permission();
48
49
$perm_itemid = Request::getInt('item_id', 0, 'POST');
50
51
if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $moduleId)) {
52
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
53
}
54
55
$premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $moduleId) ? 1 : 0;
56
57
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
58
59
$mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
60
61
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) {
62
    redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST);
63
}
64
65
if (Request::hasVar('submit', 'POST')) {
66
    $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
67
68
    if (!$GLOBALS['xoopsSecurity']->check()) {
69
        redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
70
    }
71
72
    //    xoops_load("xoopscaptcha");
73
    //    $xoopsCaptcha = XoopsCaptcha::getInstance();
74
    //    if ( !$xoopsCaptcha->verify() ) {
75
    //        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
76
    //    }
77
    if (Request::hasVar('submit', 'POST')) {
78
        /** @var \XoopsModuleHandler $moduleHandler */
79
        $moduleHandler = xoops_getHandler('module');
80
        /** @var \XoopsModule $myModule */
81
        $myModule = $moduleHandler->getByDirname('adslight');
82
        $myModule->setErrors('Could not connect to the database.');
83
    }
84
85
    $cid       = Request::getInt('cid', 0, 'POST');
86
    $cat_perms = Utility::getMyItemIds('adslight_submit');
87
    if (!\in_array($cid, $cat_perms, true)) {
88
        redirect_header(XOOPS_URL, 2, _NOPERM);
89
    }
90
91
    $title         = Request::getString('title', '', 'POST');
92
    $status        = Request::getInt('status', 0, 'POST');
93
    $expire        = Request::getString('expire', '', 'POST');
94
    $type          = Request::getString('type', '', 'POST');
95
    $desctext      = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1);
96
    $tel           = Request::getString('tel', '', 'POST');
97
    $price         = Request::getFloat('price', 0, 'POST');
98
    $typeprice     = Request::getString('typeprice', '', 'POST');
99
    $typecondition = Request::getString('typecondition', '', 'POST');
100
    //$date_created  = Request::getInt('date_created', 0, 'POST');
101
    $email        = Request::getString('email', '', 'POST');
102
    $submitter    = Request::getString('submitter', '', 'POST');
103
    $usid         = Request::getString('usid', '', 'POST');
104
    $town         = Request::getString('town', '', 'POST');
105
    $country      = Request::getString('country', '', 'POST');
106
    $contactby    = Request::getString('contactby', '', 'POST');
107
    $premium      = Request::getString('premium', '', 'POST');
108
    $valid        = Request::getString('valid', '', 'POST');
109
    $date_created = time();
110
    $newid        = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq');
111
112
    $sql     = sprintf(
113
        "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')",
114
        $xoopsDB->prefix('adslight_listing'),
115
        $newid,
116
        $cid,
117
        $title,
118
        $status,
119
        $expire,
120
        $type,
121
        $desctext,
122
        $tel,
123
        $price,
124
        $typeprice,
125
        $typecondition,
126
        $date_created,
127
        $email,
128
        $submitter,
129
        $usid,
130
        $town,
131
        $country,
132
        $contactby,
133
        $premium,
134
        $valid
135
    );
136
    $success = $xoopsDB->query($sql);
137
    if (!$success) {
138
        $moduleHandler = xoops_getHandler('module');
139
        $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

139
        /** @scrutinizer ignore-call */ 
140
        $myModule      = $moduleHandler->getByDirname('adslight');
Loading history...
140
        $myModule->setErrors('Could not query the database.');
141
    }
142
143
    $lid = $xoopsDB->getInsertId();
144
145
    if ('Yes' === $valid) {
146
        /** @var \XoopsNotificationHandler $notificationHandler */
147
        $notificationHandler = xoops_getHandler('notification');
148
        //$lid = $xoopsDB->getInsertId();
149
        $tags                    = [];
150
        $tags['TITLE']           = $title;
151
        $tags['ADDED_TO_CAT']    = _ADSLIGHT_ADDED_TO_CAT;
152
        $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF;
153
        $tags['ERROR_NOTIF']     = _ADSLIGHT_ERROR_NOTIF;
154
        $tags['WEBMASTER']       = _ADSLIGHT_WEBMASTER;
155
        $tags['HELLO']           = _ADSLIGHT_HELLO;
156
        $tags['FOLLOW_LINK']     = _ADSLIGHT_FOLLOW_LINK;
157
        $tags['TYPE']            = Utility::getNameType($type);
158
        $tags['LINK_URL']        = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid;
159
        $sql                     = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $cid;
160
        /** @var \mysqli_result|bool $result2 */
161
        $result2 = $xoopsDB->query($sql);
162
        if ($result2 instanceof \mysqli_result) {
163
            $row = $xoopsDB->fetchArray($result2);
164
        }
165
        $tags['CATEGORY_TITLE'] = $row['title'];
166
        $tags['CATEGORY_URL']   = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes((string)$cid);
167
        /** @var \XoopsNotificationHandler $notificationHandler */
168
        $notificationHandler = xoops_getHandler('notification');
169
        $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
170
        $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags);
171
        $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
172
    } else {
173
        $tags                  = [];
174
        $subject               = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . '';
175
        $tags['TITLE']         = $title;
176
        $tags['DESCTEXT']      = $desctext;
177
        $tags['ADMIN']         = _ADSLIGHT_ADMIN;
178
        $tags['NEW_WAITING']   = _ADSLIGHT_NEW_WAITING;
179
        $tags['PLEASE_CHECK']  = _ADSLIGHT_PLEASE_CHECK;
180
        $tags['WEBMASTER']     = _ADSLIGHT_WEBMASTER;
181
        $tags['HELLO']         = _ADSLIGHT_HELLO;
182
        $tags['FOLLOW_LINK']   = _ADSLIGHT_FOLLOW_LINK;
183
        $tags['TYPE']          = Utility::getNameType($type);
184
        $tags['NEED_TO_LOGIN'] = _ADSLIGHT_NEED_TO_LOGIN;
185
        $tags['ADMIN_LINK']    = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
186
        $sql                   = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . $cid;
187
        /** @var \mysqli_result|bool $result2 */
188
        $result2                = $xoopsDB->query($sql);
189
        if ($result2 instanceof \mysqli_result) {
190
            $row = $xoopsDB->fetchArray($result2);
191
        }
192
        $tags['CATEGORY_TITLE'] = $row['title'];
193
        $tags['NEWAD']          = _ADSLIGHT_NEWAD;
194
195
        $mail = xoops_getMailer();
196
        //@todo - add check to see if directory (and file) exists, otherwise use english
197
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/');
198
        $mail->setTemplate('listing_notify_admin.tpl');
199
        $mail->useMail();
200
        $mail->multimailer->isHTML(true);
201
        $mail->setFromName($xoopsConfig['sitename']);
202
        $mail->setFromEmail($xoopsConfig['adminmail']);
203
        $mail->setToEmails($xoopsConfig['adminmail']);
204
        $mail->setSubject($subject);
205
        $mail->assign($tags);
206
        $mail->send();
207
        echo $mail->getErrors();
208
    }
209
210
    $addphotonow = Request::getInt('addphotonow', 0, 'POST');
211
    if ($addphotonow) {
212
        //$lid = $xoopsDB->getInsertId();
213
        $helper->redirect("view_photos.php?lid=${lid}&uid=${usid}", 3, _ADSLIGHT_ADSADDED);
214
    } else {
215
        $helper->redirect('index.php', 3, _ADSLIGHT_ADSADDED);
216
    }
217
} else {
218
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
219
    require_once XOOPS_ROOT_PATH . '/header.php';
220
    //    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
221
222
    $cid          = Request::getInt('cide', 0, 'GET');
223
    $cat_moderate = Request::getInt('cat_moderate', 0, 'POST');
224
    $howlong      = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
225
    $member_usid  = $GLOBALS['xoopsUser']->getVar('uid', 'E');
226
    $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E');
227
    $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E');
228
229
    $sql     = 'SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type';
230
    $result  = $xoopsDB->query($sql);
231
    $sql2    = 'SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price';
232
    $result2 = $xoopsDB->query($sql2);
233
    $sql3    = 'SELECT id_condition, nom_condition FROM ' . $xoopsDB->prefix('adslight_condition') . ' ORDER BY id_condition';
234
    $result3 = $xoopsDB->query($sql3);
235
236
    ob_start();
237
    $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true);
238
    $form->setExtra('enctype="multipart/form-data"');
239
    //    $GLOBALS['xoopsGTicket']->addTicketXoopsFormElement($form, __LINE__, 1800, 'token');
240
    //@todo - this 'if' code doesn't do anything, what should happen for premium accounts?
241
    if ($cat_moderate) {
242
        if (0 !== $premium) {
243
            echo '';
244
        } else {
245
            echo '';
246
        }
247
    } elseif (0 !== $premium) {
248
        echo '';
249
    } else {
250
        echo '';
251
    }
252
253
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) {
254
        $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true);
255
    } else {
256
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
257
        $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true);
258
    }
259
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) {
260
        $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true);
261
    } else {
262
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
263
        $form->addElement(new \XoopsFormHidden('email', $member_email), true);
264
    }
265
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false);
266
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_use_country']) {
267
        $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false);
268
    } else {
269
        $form->addElement(new \XoopsFormHidden('country', ''), false);
270
    }
271
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false);
272
273
    //     $cid = $_GET['cid'];
274
    $cid       = 0;
275
    $cat_perms = Utility::getMyItemIds('adslight_submit');
276
    if (is_array($cat_perms) && $cat_perms !== []) {
277
        if (!\in_array($cid, $cat_perms, true)) {
278
            //mb            $helper->redirect('index.php', 3, _NOPERM);
279
        }
280
281
        // Category select box
282
        ob_start();
283
        $mytree->makeMySelBox('title', 'title', $cid, 1, 'cid');
284
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_clean())??'', true);
285
        $sql = 'SELECT title, cat_moderate FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid='" . $xoopsDB->escape($cid) . "'";
286
        /** @var \mysqli_result|bool $category */
287
        $category = $xoopsDB->query($sql);
288
        if ($category instanceof \mysqli_result) {
289
            [$cat_title, $cat_moderate] = $xoopsDB->fetchRow($category);
290
        }
291
        if (1 === (int)$premium) {
292
            $radio        = new \XoopsFormRadio(_ADSLIGHT_STATUS, 'status', '');
293
            $options['0'] = _ADSLIGHT_ACTIVE;
294
            $options['1'] = _ADSLIGHT_INACTIVE;
295
            $radio->addOptionArray($options);
296
            $form->addElement($radio, true);
297
        } else {
298
            $form->addElement(new \XoopsFormHidden('status', '0'), true);
299
        }
300
        if (1 === $premium) {
301
            $form->addElement(new \XoopsFormText(_ADSLIGHT_HOW_LONG, 'expire', 3, 3, $GLOBALS['xoopsModuleConfig']['adslight_howlong']), true);
302
        } else {
303
            $form->addElement(new \XoopsFormLabel(_ADSLIGHT_WILL_LAST, $GLOBALS['xoopsModuleConfig']['adslight_howlong']));
304
            $form->addElement(new \XoopsFormHidden('expire', $GLOBALS['xoopsModuleConfig']['adslight_howlong']), false);
305
        }
306
307
        // Type
308
        $type_form = new \XoopsFormSelect(_ADSLIGHT_TYPE, 'type', '', 1);
309
        while ([$nom_type, $id_type] = $xoopsDB->fetchRow($result)) {
310
            $type_form->addOption($nom_type, $id_type);
311
        }
312
313
        // Item Condition
314
        $condition_form = new \XoopsFormSelect(_ADSLIGHT_TYPE_CONDITION, 'typecondition', '', 1);
315
        while (false !== [$nom_condition, $id_condition] = $xoopsDB->fetchRow($result3)) {
316
            $condition_form->addOption($nom_condition, $id_condition);
317
        }
318
319
        $form->addElement($type_form, true);
320
        $form->addElement($condition_form, true);
321
322
        $form->addElement(new \XoopsFormText(_ADSLIGHT_TITLE2, 'title', 40, 50, ''), true);
323
324
        $form->addElement(Utility::getEditor($helper), true);
325
326
        //        $form->addElement(new \XoopsFormEditor(_ADSLIGHT_DESC, $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = FALSE, $onfailure = 'textarea'));
327
        //        $optionsTrayNote->addElement($bodynote);
328
329
        $form->addElement(new \XoopsFormText(_ADSLIGHT_PRICE2, 'price', 40, 50, ''), true);
330
331
        // Price Type
332
        $sel_form = new \XoopsFormSelect(_ADSLIGHT_PRICETYPE, 'typeprice', '', 1);
333
        while ([$nom_price, $id_price] = $xoopsDB->fetchRow($result2)) {
334
            $sel_form->addOption($nom_price, $id_price);
335
        }
336
337
        $form->addElement($sel_form);
338
339
        $contactby_form = new \XoopsFormSelect(_ADSLIGHT_CONTACTBY, 'contactby', '', 1);
340
        $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL);
341
        $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM);
342
        $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH);
343
        $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE);
344
        $form->addElement($contactby_form, true);
345
        $form->addElement(new \XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', _YES));
346
        /*
347
                if ('1' == $GLOBALS['xoopsModuleConfig']["adslight_use_captcha"]) {
348
                    $form->addElement(new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true);
349
                }
350
        */
351
        if (0 !== (int)$premium) {
352
            $form->addElement(new \XoopsFormHidden('premium', 'yes'), false);
353
        } else {
354
            $form->addElement(new \XoopsFormHidden('premium', 'no'), false);
355
        }
356
        if ('1' === $cat_moderate) {
357
            $form->addElement(new \XoopsFormHidden('valid', 'No'), false);
358
            $form->addElement(new \XoopsFormHidden('cat_moderate', '1'), false);
359
        } else {
360
            $form->addElement(new \XoopsFormHidden('valid', 'Yes'), false);
361
        }
362
        $form->addElement(new \XoopsFormHidden('usid', $member_usid), false);
363
        $form->addElement(new \XoopsFormHidden('date_created', time()), false);
364
        $form->addElement(new \XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit'));
365
        $form->display();
366
        $GLOBALS['xoopsTpl']->assign('submit_form', ob_get_clean());
367
    } else {    // User can't see any category
368
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
369
    }
370
    require_once XOOPS_ROOT_PATH . '/footer.php';
371
}
372