Passed
Push — master ( 34ef5d...2f53de )
by Michael
04:04 queued 19s
created

add.php (3 issues)

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
    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
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
38
39
$module_id = $xoopsModule->getVar('mid');
40
$groups    = $GLOBALS['xoopsUser'] instanceof XoopsUser ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
41
/** @var \XoopsGroupPermHandler $grouppermHandler */
42
$grouppermHandler = xoops_getHandler('groupperm');
43
44
$permHelper = new Permission();
45
46
$perm_itemid = Request::getInt('item_id', 0, 'POST');
47
48
if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) {
49
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
50
}
51
52
$premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id) ? 1 : 0;
53
54
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
55
56
$mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
57
58
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) {
59
    redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST);
60
}
61
62
if (Request::hasVar('submit', 'POST')) {
63
    $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
64
65
    if (!$GLOBALS['xoopsSecurity']->check()) {
66
        redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
67
    }
68
69
    //    xoops_load("xoopscaptcha");
70
    //    $xoopsCaptcha = XoopsCaptcha::getInstance();
71
    //    if ( !$xoopsCaptcha->verify() ) {
72
    //        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
73
    //    }
74
    if (Request::hasVar('submit', 'POST')) {
75
        /** @var \XoopsModuleHandler $moduleHandler */
76
        $moduleHandler = xoops_getHandler('module');
77
        /** @var \XoopsModule $myModule */
78
        $myModule = $moduleHandler->getByDirname('adslight');
79
        $myModule->setErrors('Could not connect to the database.');
80
    }
81
82
    $cid       = Request::getInt('cid', 0, 'POST');
83
    $cat_perms = Utility::getMyItemIds('adslight_submit');
84
    if (!in_array($cid, $cat_perms, true)) {
85
        redirect_header(XOOPS_URL, 2, _NOPERM);
86
    }
87
88
    $title = Request::getString('title', '', 'POST');
89
    //    $status    = $myts->addSlashes($_POST["status"]);
90
    $status        = (int)$status;
91
    $expire        = Request::getString('expire', '', 'POST');
92
    $type          = Request::getString('type', '', 'POST');
93
    $desctext      = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1);
94
    $tel           = Request::getString('tel', '', 'POST');
95
    $price         = Request::getFloat('price', 0, 'POST');
96
    $typeprice     = Request::getString('typeprice', '', 'POST');
97
    $typecondition = Request::getString('typecondition', '', 'POST');
98
    //$date_created  = Request::getInt('date_created', 0, 'POST');
99
    $email        = Request::getString('email', '', 'POST');
100
    $submitter    = Request::getString('submitter', '', 'POST');
101
    $usid         = Request::getString('usid', '', 'POST');
102
    $town         = Request::getString('town', '', 'POST');
103
    $country      = Request::getString('country', 0, 'POST');
104
    $contactby    = Request::getString('contactby', '', 'POST');
105
    $premium      = Request::getString('premium', '', 'POST');
106
    $valid        = Request::getString('valid', '', 'POST');
107
    $date_created = time();
108
    $newid        = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq');
109
110
    $sql     = sprintf(
111
        "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')",
112
        $xoopsDB->prefix('adslight_listing'),
113
        $newid,
114
        $cid,
115
        $title,
116
        $status,
117
        $expire,
118
        $type,
119
        $desctext,
120
        $tel,
121
        $price,
122
        $typeprice,
123
        $typecondition,
124
        $date_created,
125
        $email,
126
        $submitter,
127
        $usid,
128
        $town,
129
        $country,
130
        $contactby,
131
        $premium,
132
        $valid
133
    );
134
    $success = $xoopsDB->query($sql);
135
    if (!$success) {
136
        $moduleHandler = xoops_getHandler('module');
137
        $myModule      = $moduleHandler->getByDirname('adslight');
138
        $myModule->setErrors('Could not query the database.');
139
    }
140
141
    $lid = $xoopsDB->getInsertId();
142
143
    if ('Yes' === $valid) {
144
        /** @var \XoopsNotificationHandler $notificationHandler */
145
        $notificationHandler = xoops_getHandler('notification');
146
        //$lid = $xoopsDB->getInsertId();
147
        $tags                    = [];
148
        $tags['TITLE']           = $title;
149
        $tags['ADDED_TO_CAT']    = _ADSLIGHT_ADDED_TO_CAT;
150
        $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF;
151
        $tags['ERROR_NOTIF']     = _ADSLIGHT_ERROR_NOTIF;
152
        $tags['WEBMASTER']       = _ADSLIGHT_WEBMASTER;
153
        $tags['HELLO']           = _ADSLIGHT_HELLO;
154
        $tags['FOLLOW_LINK']     = _ADSLIGHT_FOLLOW_LINK;
155
        $tags['TYPE']            = Utility::getNameType($type);
156
        $tags['LINK_URL']        = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid;
157
        $sql                     = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes((string)$cid);
158
        /** @var mysqli_result $result2 */
159
        $result2                = $xoopsDB->query($sql);
160
        $row                    = $xoopsDB->fetchArray($result2);
161
        $tags['CATEGORY_TITLE'] = $row['title'];
162
        $tags['CATEGORY_URL']   = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes((string)$cid);
163
        /** @var \XoopsNotificationHandler $notificationHandler */
164
        $notificationHandler = xoops_getHandler('notification');
165
        $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
166
        $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags);
167
        $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
168
    } else {
169
        $tags                  = [];
170
        $subject               = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . '';
171
        $tags['TITLE']         = $title;
172
        $tags['DESCTEXT']      = $desctext;
173
        $tags['ADMIN']         = _ADSLIGHT_ADMIN;
174
        $tags['NEW_WAITING']   = _ADSLIGHT_NEW_WAITING;
175
        $tags['PLEASE_CHECK']  = _ADSLIGHT_PLEASE_CHECK;
176
        $tags['WEBMASTER']     = _ADSLIGHT_WEBMASTER;
177
        $tags['HELLO']         = _ADSLIGHT_HELLO;
178
        $tags['FOLLOW_LINK']   = _ADSLIGHT_FOLLOW_LINK;
179
        $tags['TYPE']          = Utility::getNameType($type);
180
        $tags['NEED_TO_LOGIN'] = _ADSLIGHT_NEED_TO_LOGIN;
181
        $tags['ADMIN_LINK']    = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
182
        $sql                   = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid);
183
        /** @var mysqli_result|bool $result2 */
184
        $result2                = $xoopsDB->query($sql);
185
        $row                    = $xoopsDB->fetchArray($result2);
186
        $tags['CATEGORY_TITLE'] = $row['title'];
187
        $tags['NEWAD']          = _ADSLIGHT_NEWAD;
188
189
        $mail = xoops_getMailer();
190
        //@todo - add check to see if directory (and file) exists, otherwise use english
191
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/');
192
        $mail->setTemplate('listing_notify_admin.tpl');
193
        $mail->useMail();
194
        $mail->multimailer->isHTML(true);
195
        $mail->setFromName($xoopsConfig['sitename']);
196
        $mail->setFromEmail($xoopsConfig['adminmail']);
197
        $mail->setToEmails($xoopsConfig['adminmail']);
198
        $mail->setSubject($subject);
199
        $mail->assign($tags);
200
        $mail->send();
201
        echo $mail->getErrors();
202
    }
203
204
    $addphotonow = Request::getInt('addphotonow', 0, 'POST');
205
    if ($addphotonow) {
206
        //$lid = $xoopsDB->getInsertId();
207
        $helper->redirect("view_photos.php?lid=${lid}&uid=${usid}", 3, _ADSLIGHT_ADSADDED);
208
    } else {
209
        $helper->redirect('index.php', 3, _ADSLIGHT_ADSADDED);
210
    }
211
} else {
212
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl';
213
    require_once XOOPS_ROOT_PATH . '/header.php';
214
    //    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
215
216
    $cid          = Request::getInt('cide', 0, 'GET');
217
    $cat_moderate = Request::getInt('cat_moderate', 0, 'POST');
218
    $howlong      = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
219
    $member_usid  = $GLOBALS['xoopsUser']->getVar('uid', 'E');
220
    $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E');
221
    $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E');
222
223
    $result  = $xoopsDB->query('SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
224
    $result1 = $xoopsDB->query('SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
225
    $result3 = $xoopsDB->query('SELECT id_condition, nom_condition FROM ' . $xoopsDB->prefix('adslight_condition') . ' ORDER BY id_condition');
226
227
    ob_start();
228
    $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true);
229
    $form->setExtra('enctype="multipart/form-data"');
230
    //    $GLOBALS['xoopsGTicket']->addTicketXoopsFormElement($form, __LINE__, 1800, 'token');
231
    //@todo - this 'if' code doesn't do anything, what should happen for premium accounts?
232
    if ($cat_moderate) {
233
        if (0 !== $premium) {
234
            echo '';
235
        } else {
236
            echo '';
237
        }
238
    } elseif (0 !== $premium) {
239
        echo '';
240
    } else {
241
        echo '';
242
    }
243
244
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) {
245
        $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true);
246
    } else {
247
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
248
        $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true);
249
    }
250
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) {
251
        $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true);
252
    } else {
253
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
254
        $form->addElement(new \XoopsFormHidden('email', $member_email), true);
255
    }
256
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false);
257
    if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_use_country']) {
258
        $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false);
259
    } else {
260
        $form->addElement(new \XoopsFormHidden('country', ''), false);
261
    }
262
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false);
263
264
    //     $cid = $_GET['cid'];
265
    $cid       = 0;
266
    $cat_perms = Utility::getMyItemIds('adslight_submit');
267
    if (is_iterable($cat_perms) && $cat_perms !== []) {
268
        if (!in_array($cid, $cat_perms, true)) {
269
            //mb            $helper->redirect('index.php', 3, _NOPERM);
270
        }
271
272
        // Category select box
273
        ob_start();
274
        $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

274
        $mytree->makeMySelBox('title', 'title', $cid, /** @scrutinizer ignore-type */ 'cid');
Loading history...
275
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_clean()), true);
276
        $sql = 'SELECT title, cat_moderate FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid='" . $xoopsDB->escape($cid) . "'";
277
        /** @var mysqli_result|bool $category */
278
        $category = $xoopsDB->query($sql);
279
        if ($category instanceof \mysqli_result) {
280
            [$cat_title, $cat_moderate] = $xoopsDB->fetchRow($category);
281
        }
282
        if ('1' === $premium) {
0 ignored issues
show
The condition '1' === $premium is always false.
Loading history...
283
            $radio        = new \XoopsFormRadio(_ADSLIGHT_STATUS, 'status', '');
284
            $options['0'] = _ADSLIGHT_ACTIVE;
285
            $options['1'] = _ADSLIGHT_INACTIVE;
286
            $radio->addOptionArray($options);
287
            $form->addElement($radio, true);
288
        } else {
289
            $form->addElement(new \XoopsFormHidden('status', '0'), true);
290
        }
291
        if (1 === $premium) {
292
            $form->addElement(new \XoopsFormText(_ADSLIGHT_HOW_LONG, 'expire', 3, 3, $GLOBALS['xoopsModuleConfig']['adslight_howlong']), true);
293
        } else {
294
            $form->addElement(new \XoopsFormLabel(_ADSLIGHT_WILL_LAST, $GLOBALS['xoopsModuleConfig']['adslight_howlong']));
295
            $form->addElement(new \XoopsFormHidden('expire', $GLOBALS['xoopsModuleConfig']['adslight_howlong']), false);
296
        }
297
298
        // Type
299
        $type_form = new \XoopsFormSelect(_ADSLIGHT_TYPE, 'type', '', '1');
300
        while ([$nom_type, $id_type] = $xoopsDB->fetchRow($result)) {
301
            $type_form->addOption($nom_type, $id_type);
302
        }
303
304
        // Item Condition
305
        $condition_form = new \XoopsFormSelect(_ADSLIGHT_TYPE_CONDITION, 'typecondition', '', '1');
306
        while (false !== [$nom_condition, $id_condition] = $xoopsDB->fetchRow($result3)) {
307
            $condition_form->addOption($nom_condition, $id_condition);
308
        }
309
310
        $form->addElement($type_form, true);
311
        $form->addElement($condition_form, true);
312
313
        $form->addElement(new \XoopsFormText(_ADSLIGHT_TITLE2, 'title', 40, 50, ''), true);
314
315
        $form->addElement(Utility::getEditor($helper), true);
316
317
        //        $form->addElement(new \XoopsFormEditor(_ADSLIGHT_DESC, $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = FALSE, $onfailure = 'textarea'));
318
        //        $optionsTrayNote->addElement($bodynote);
319
320
        $form->addElement(new \XoopsFormText(_ADSLIGHT_PRICE2, 'price', 40, 50, ''), true);
321
322
        // Price Type
323
        $sel_form = new \XoopsFormSelect(_ADSLIGHT_PRICETYPE, 'typeprice', '', '1');
324
        while ([$nom_price, $id_price] = $xoopsDB->fetchRow($result1)) {
325
            $sel_form->addOption($nom_price, $id_price);
326
        }
327
328
        $form->addElement($sel_form);
329
330
        $contactby_form = new \XoopsFormSelect(_ADSLIGHT_CONTACTBY, 'contactby', '', '1');
331
        $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL);
332
        $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM);
333
        $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH);
334
        $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE);
335
        $form->addElement($contactby_form, true);
336
        $form->addElement(new \XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', 1));
337
        /*
338
                if ('1' == $GLOBALS['xoopsModuleConfig']["adslight_use_captcha"]) {
339
                    $form->addElement(new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true);
340
                }
341
        */
342
        if ('0' !== (int)$premium) {
0 ignored issues
show
The condition '0' !== (int)$premium is always true.
Loading history...
343
            $form->addElement(new \XoopsFormHidden('premium', 'yes'), false);
344
        } else {
345
            $form->addElement(new \XoopsFormHidden('premium', 'no'), false);
346
        }
347
        if ('1' === $cat_moderate) {
348
            $form->addElement(new \XoopsFormHidden('valid', 'No'), false);
349
            $form->addElement(new \XoopsFormHidden('cat_moderate', '1'), false);
350
        } else {
351
            $form->addElement(new \XoopsFormHidden('valid', 'Yes'), false);
352
        }
353
        $form->addElement(new \XoopsFormHidden('usid', $member_usid), false);
354
        $form->addElement(new \XoopsFormHidden('date_created', time()), false);
355
        $form->addElement(new \XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit'));
356
        $form->display();
357
        $GLOBALS['xoopsTpl']->assign('submit_form', ob_get_clean());
358
    } else {    // User can't see any category
359
        redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
360
    }
361
    require_once XOOPS_ROOT_PATH . '/footer.php';
362
}
363