Passed
Push — master ( 5e790e...222087 )
by Michael
03:14
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\Request;
24
use XoopsModules\Adslight;
25
26
require_once __DIR__ . '/header.php';
27
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
28
//require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
29
require_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
30
//require_once __DIR__ . '/include/functions.php';
31
// require_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php';
32
33
$module_id = $xoopsModule->getVar('mid');
34
$groups    = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
35
/** @var \XoopsGroupPermHandler $grouppermHandler */
36
$grouppermHandler = xoops_getHandler('groupperm');
37
$perm_itemid      = Request::getInt('item_id', 0, 'POST');
38
39
if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) {
40
    redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM);
41
}
42
43
$premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id) ? 1 : 0;
44
45
//require_once XOOPS_ROOT_PATH . '/modules/adslight/class/Utility.php';
46
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
47
require_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php';
48
$mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
49
50
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) {
51
    redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST);
52
}
53
54
if (Request::hasVar('submit', 'POST')) {
55
    $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
56
57
    if (!$GLOBALS['xoopsSecurity']->check(true, $_REQUEST['token'])) {
58
        redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
59
    }
60
61
    //    xoops_load("xoopscaptcha");
62
    //    $xoopsCaptcha = XoopsCaptcha::getInstance();
63
    //    if ( !$xoopsCaptcha->verify() ) {
64
    //        redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() );
65
    //    }
66
    if (Request::hasVar('submit', 'POST')) {
67
        $moduleHandler = xoops_getHandler('module');
68
        $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

68
        /** @scrutinizer ignore-call */ 
69
        $myModule      = $moduleHandler->getByDirname('adslight');
Loading history...
69
        $myModule->setErrors('Could not connect to the database.');
70
    }
71
72
    $cid       = Request::getInt('cid', 0, 'POST');
73
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
74
    if (!in_array($cid, $cat_perms, true)) {
75
        redirect_header(XOOPS_URL, 2, _NOPERM);
76
    }
77
78
    $title = Request::getString('title', '', 'POST');
79
    //    $status    = $myts->addSlashes($_POST["status"]);
80
    $status    = (int)$status;
81
    $expire    = Request::getString('expire', '', 'POST');
82
    $type      = Request::getString('type', '', 'POST');
83
    $desctext  = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1);
84
    $tel       = Request::getString('tel', '', 'POST');
85
    $price     = str_replace([' '], '', Request::getFloat('price', 0, 'POST'));
86
    $typeprice = Request::getString('typeprice', '', 'POST');
87
    $typeusure = Request::getString('typeusure', '', 'POST');
88
    $date      = Request::getInt('date', 0, 'POST');
89
    $email     = Request::getString('email', '', 'POST');
90
    $submitter = Request::getString('submitter', '', 'POST');
91
    $usid      = Request::getString('usid', '', 'POST');
92
    $town      = Request::getString('town', '', 'POST');
93
    $country   = Request::getString('country', 0, 'POST');
94
    $contactby = Request::getString('contactby', '', 'POST');
95
    $premium   = Request::getString('premium', '', 'POST');
96
    $valid     = Request::getString('valid', '', 'POST');
97
    $date      = time();
98
    $newid     = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq');
99
100
    $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')",
101
                       $xoopsDB->prefix('adslight_listing'), $newid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid);
102
    $success = $xoopsDB->query($sql);
103
    if (!$success) {
104
        $moduleHandler = xoops_getHandler('module');
105
        $myModule      = $moduleHandler->getByDirname('adslight');
106
        $myModule->setErrors('Could not query the database.');
107
    }
108
109
    $lid = $xoopsDB->getInsertId();
110
111
    if ('Yes' === $valid) {
112
        /** @var \XoopsNotificationHandler $notificationHandler */
113
        $notificationHandler = xoops_getHandler('notification');
114
        //$lid = $xoopsDB->getInsertId();
115
        $tags                    = [];
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']            = Adslight\Utility::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
        /** @var \XoopsNotificationHandler $notificationHandler */
131
        $notificationHandler = xoops_getHandler('notification');
132
        $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags);
0 ignored issues
show
'new_listing' of type string is incompatible with the type integer expected by parameter $event of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

132
        $notificationHandler->triggerEvent('global', 0, /** @scrutinizer ignore-type */ 'new_listing', $tags);
Loading history...
'global' of type string is incompatible with the type integer expected by parameter $category of XoopsNotificationHandler::triggerEvent(). ( Ignorable by Annotation )

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

132
        $notificationHandler->triggerEvent(/** @scrutinizer ignore-type */ 'global', 0, 'new_listing', $tags);
Loading history...
133
        $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags);
134
        $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags);
135
    } else {
136
        $tags                   = [];
137
        $subject                = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . '';
138
        $tags['TITLE']          = $title;
139
        $tags['DESCTEXT']       = $desctext;
140
        $tags['ADMIN']          = _ADSLIGHT_ADMIN;
141
        $tags['NEW_WAITING']    = _ADSLIGHT_NEW_WAITING;
142
        $tags['PLEASE_CHECK']   = _ADSLIGHT_PLEASE_CHECK;
143
        $tags['WEBMASTER']      = _ADSLIGHT_WEBMASTER;
144
        $tags['HELLO']          = _ADSLIGHT_HELLO;
145
        $tags['FOLLOW_LINK']    = _ADSLIGHT_FOLLOW_LINK;
146
        $tags['TYPE']           = Adslight\Utility::getNameType($type);
147
        $tags['NEED_TO_LOGIN']  = _ADSLIGHT_NEED_TO_LOGIN;
148
        $tags['ADMIN_LINK']     = XOOPS_URL . '/modules/adslight/admin/validate_ads.php';
149
        $sql                    = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid);
150
        $result2                = $xoopsDB->query($sql);
151
        $row                    = $xoopsDB->fetchArray($result2);
152
        $tags['CATEGORY_TITLE'] = $row['title'];
153
        $tags['NEWAD']          = _ADSLIGHT_NEWAD;
154
155
        $mail = xoops_getMailer();
156
        //@todo - add check to see if directory (and file) exists, otherwise use english
157
        $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/');
158
        $mail->setTemplate('listing_notify_admin.tpl');
159
        $mail->useMail();
160
        $mail->multimailer->isHTML(true);
161
        $mail->setFromName($xoopsConfig['sitename']);
162
        $mail->setFromEmail($xoopsConfig['adminmail']);
163
        $mail->setToEmails($xoopsConfig['adminmail']);
164
        $mail->setSubject($subject);
165
        $mail->assign($tags);
166
        $mail->send();
167
        echo $mail->getErrors();
168
    }
169
170
    $addphotonow = Request::getInt('addphotonow', 0, 'POST');
171
    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
    require_once XOOPS_ROOT_PATH . '/header.php';
180
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
181
182
    $cid          = Request::getInt('cide', 0, 'GET');
183
    $cat_moderate = Request::getInt('cat_moderate', 0, 'POST');
184
    $howlong      = $GLOBALS['xoopsModuleConfig']['adslight_howlong'];
185
    $member_usid  = $GLOBALS['xoopsUser']->getVar('uid', 'E');
186
    $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E');
187
    $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E');
188
189
    $result  = $xoopsDB->query('SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type');
190
    $result1 = $xoopsDB->query('SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price');
191
    $result3 = $xoopsDB->query('SELECT id_usure, nom_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY id_usure');
192
193
    ob_start();
194
    $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true);
195
    $form->setExtra('enctype="multipart/form-data"');
196
197
    //    $GLOBALS['xoopsGTicket']->addTicketXoopsFormElement($form, __LINE__, 1800, 'token');
198
199
    //@todo - this 'if' code doesn't do anything, what should happen for premium accounts?
200
    if ($cat_moderate) {
201
        if ('0' != $premium) {
202
            echo '';
203
        } else {
204
            echo '';
205
        }
206
    } else {
207
        if ('0' != $premium) {
208
            echo '';
209
        } else {
210
            echo '';
211
        }
212
    }
213
214
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) {
215
        $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true);
216
    } else {
217
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname));
218
        $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true);
219
    }
220
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) {
221
        $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true);
222
    } else {
223
        $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email));
224
        $form->addElement(new \XoopsFormHidden('email', $member_email), true);
225
    }
226
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false);
227
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_country']) {
228
        $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false);
229
    } else {
230
        $form->addElement(new \XoopsFormHidden('country', ''), false);
231
    }
232
    $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false);
233
234
    // $cat_id = $_GET['cid'];
235
    $cid       = 1;
236
    $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit');
237
    if (is_array($cat_perms) && count($cat_perms) > 0) {
238
        if (!in_array($cid, $cat_perms, true)) {
239
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM);
240
        }
241
242
        // Category select box
243
        ob_start();
244
        $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

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