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 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl'; |
||||
27 | |||||
28 | require_once __DIR__ . '/header.php'; |
||||
29 | $myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object |
||||
30 | //require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php'; |
||||
31 | //require_once XOOPS_ROOT_PATH . '/modules/adslight/class/classifiedstree.php'; |
||||
32 | //require_once __DIR__ . '/include/functions.php'; |
||||
33 | // require_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php'; |
||||
34 | |||||
35 | $module_id = $xoopsModule->getVar('mid'); |
||||
36 | $groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||||
37 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||
38 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||
39 | |||||
40 | $permHelper = new \Xmf\Module\Helper\Permission(); |
||||
41 | |||||
42 | $perm_itemid = Request::getInt('item_id', 0, 'POST'); |
||||
43 | |||||
44 | if (!$grouppermHandler->checkRight('adslight_submit', $perm_itemid, $groups, $module_id)) { |
||||
45 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||||
46 | } |
||||
47 | |||||
48 | $premium = $grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $module_id) ? 1 : 0; |
||||
49 | |||||
50 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||
51 | |||||
52 | $mytree = new Adslight\ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||||
53 | |||||
54 | if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) { |
||||
55 | redirect_header(XOOPS_URL . '/user.php', 2, _MA_ADSLIGHT_MUSTREGFIRST); |
||||
56 | } |
||||
57 | |||||
58 | if (Request::hasVar('submit', 'POST')) { |
||||
59 | $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong']; |
||||
60 | |||||
61 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||
62 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||||
63 | } |
||||
64 | |||||
65 | // xoops_load("xoopscaptcha"); |
||||
66 | // $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||||
67 | // if ( !$xoopsCaptcha->verify() ) { |
||||
68 | // redirect_header( XOOPS_URL . "/modules/adslight/index.php", 2, $xoopsCaptcha->getMessage() ); |
||||
69 | // } |
||||
70 | if (Request::hasVar('submit', 'POST')) { |
||||
71 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||
72 | $moduleHandler = xoops_getHandler('module'); |
||||
73 | /** @var \XoopsModule $myModule */ |
||||
74 | $myModule = $moduleHandler->getByDirname('adslight'); |
||||
75 | $myModule->setErrors('Could not connect to the database.'); |
||||
76 | } |
||||
77 | |||||
78 | $cid = Request::getInt('cid', 0, 'POST'); |
||||
79 | $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit'); |
||||
80 | if (!in_array($cid, $cat_perms)) { |
||||
81 | redirect_header(XOOPS_URL, 2, _NOPERM); |
||||
82 | } |
||||
83 | |||||
84 | $title = Request::getString('title', '', 'POST'); |
||||
85 | // $status = $myts->addSlashes($_POST["status"]); |
||||
86 | $status = (int)$status; |
||||
87 | $expire = Request::getString('expire', '', 'POST'); |
||||
88 | $type = Request::getString('type', '', 'POST'); |
||||
89 | $desctext = Request::getText('desctext', '', 'POST'); // $myts->displayTarea($_POST['desctext'], 1, 1, 1); |
||||
90 | $tel = Request::getString('tel', '', 'POST'); |
||||
91 | $price = str_replace([' '], '', Request::getFloat('price', 0, 'POST')); |
||||
92 | $typeprice = Request::getString('typeprice', '', 'POST'); |
||||
93 | $typeusure = Request::getString('typeusure', '', 'POST'); |
||||
94 | $date = Request::getInt('date', 0, 'POST'); |
||||
95 | $email = Request::getString('email', '', 'POST'); |
||||
96 | $submitter = Request::getString('submitter', '', 'POST'); |
||||
97 | $usid = Request::getString('usid', '', 'POST'); |
||||
98 | $town = Request::getString('town', '', 'POST'); |
||||
99 | $country = Request::getString('country', 0, 'POST'); |
||||
100 | $contactby = Request::getString('contactby', '', 'POST'); |
||||
101 | $premium = Request::getString('premium', '', 'POST'); |
||||
102 | $valid = Request::getString('valid', '', 'POST'); |
||||
103 | $date = time(); |
||||
104 | $newid = $xoopsDB->genId($xoopsDB->prefix('adslight_listing') . '_lid_seq'); |
||||
105 | |||||
106 | $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')", |
||||
107 | $xoopsDB->prefix('adslight_listing'), $newid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid); |
||||
108 | $success = $xoopsDB->query($sql); |
||||
109 | if (!$success) { |
||||
110 | $moduleHandler = xoops_getHandler('module'); |
||||
111 | $myModule = $moduleHandler->getByDirname('adslight'); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
112 | $myModule->setErrors('Could not query the database.'); |
||||
113 | } |
||||
114 | |||||
115 | $lid = $xoopsDB->getInsertId(); |
||||
116 | |||||
117 | if ('Yes' === $valid) { |
||||
118 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||
119 | $notificationHandler = xoops_getHandler('notification'); |
||||
120 | //$lid = $xoopsDB->getInsertId(); |
||||
121 | $tags = []; |
||||
122 | $tags['TITLE'] = $title; |
||||
123 | $tags['ADDED_TO_CAT'] = _ADSLIGHT_ADDED_TO_CAT; |
||||
124 | $tags['RECIEVING_NOTIF'] = _ADSLIGHT_RECIEVING_NOTIF; |
||||
125 | $tags['ERROR_NOTIF'] = _ADSLIGHT_ERROR_NOTIF; |
||||
126 | $tags['WEBMASTER'] = _ADSLIGHT_WEBMASTER; |
||||
127 | $tags['HELLO'] = _ADSLIGHT_HELLO; |
||||
128 | $tags['FOLLOW_LINK'] = _ADSLIGHT_FOLLOW_LINK; |
||||
129 | $tags['TYPE'] = Adslight\Utility::getNameType($type); |
||||
130 | $tags['LINK_URL'] = XOOPS_URL . '/modules/adslight/viewads.php?' . '&lid=' . $lid; |
||||
131 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid); |
||||
132 | /** @var mysqli_result $result2 */ |
||||
133 | $result2 = $xoopsDB->query($sql); |
||||
134 | $row = $xoopsDB->fetchArray($result2); |
||||
135 | $tags['CATEGORY_TITLE'] = $row['title']; |
||||
136 | $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/adslight/viewcats.php?cid="' . addslashes($cid); |
||||
137 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||
138 | $notificationHandler = xoops_getHandler('notification'); |
||||
139 | $notificationHandler->triggerEvent('global', 0, 'new_listing', $tags); |
||||
140 | $notificationHandler->triggerEvent('category', $cid, 'new_listing', $tags); |
||||
141 | $notificationHandler->triggerEvent('listing', $lid, 'new_listing', $tags); |
||||
142 | } else { |
||||
143 | $tags = []; |
||||
144 | $subject = '' . _ADSLIGHT_NEW_WAITING_SUBJECT . ''; |
||||
145 | $tags['TITLE'] = $title; |
||||
146 | $tags['DESCTEXT'] = $desctext; |
||||
147 | $tags['ADMIN'] = _ADSLIGHT_ADMIN; |
||||
148 | $tags['NEW_WAITING'] = _ADSLIGHT_NEW_WAITING; |
||||
149 | $tags['PLEASE_CHECK'] = _ADSLIGHT_PLEASE_CHECK; |
||||
150 | $tags['WEBMASTER'] = _ADSLIGHT_WEBMASTER; |
||||
151 | $tags['HELLO'] = _ADSLIGHT_HELLO; |
||||
152 | $tags['FOLLOW_LINK'] = _ADSLIGHT_FOLLOW_LINK; |
||||
153 | $tags['TYPE'] = Adslight\Utility::getNameType($type); |
||||
154 | $tags['NEED_TO_LOGIN'] = _ADSLIGHT_NEED_TO_LOGIN; |
||||
155 | $tags['ADMIN_LINK'] = XOOPS_URL . '/modules/adslight/admin/validate_ads.php'; |
||||
156 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_categories') . ' WHERE cid=' . addslashes($cid); |
||||
157 | /** @var mysqli_result $result2 */ |
||||
158 | $result2 = $xoopsDB->query($sql); |
||||
159 | $row = $xoopsDB->fetchArray($result2); |
||||
160 | $tags['CATEGORY_TITLE'] = $row['title']; |
||||
161 | $tags['NEWAD'] = _ADSLIGHT_NEWAD; |
||||
162 | |||||
163 | $mail = xoops_getMailer(); |
||||
164 | //@todo - add check to see if directory (and file) exists, otherwise use english |
||||
165 | $mail->setTemplateDir(XOOPS_ROOT_PATH . '/modules/adslight/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||||
166 | $mail->setTemplate('listing_notify_admin.tpl'); |
||||
167 | $mail->useMail(); |
||||
168 | $mail->multimailer->isHTML(true); |
||||
169 | $mail->setFromName($xoopsConfig['sitename']); |
||||
170 | $mail->setFromEmail($xoopsConfig['adminmail']); |
||||
171 | $mail->setToEmails($xoopsConfig['adminmail']); |
||||
172 | $mail->setSubject($subject); |
||||
173 | $mail->assign($tags); |
||||
174 | $mail->send(); |
||||
175 | echo $mail->getErrors(); |
||||
176 | } |
||||
177 | |||||
178 | $addphotonow = Request::getInt('addphotonow', 0, 'POST'); |
||||
179 | if ($addphotonow) { |
||||
180 | //$lid = $xoopsDB->getInsertId(); |
||||
181 | redirect_header("view_photos.php?lid=$lid&uid=$usid", 3, _ADSLIGHT_ADSADDED); |
||||
182 | } else { |
||||
183 | redirect_header('index.php', 3, _ADSLIGHT_ADSADDED); |
||||
184 | } |
||||
185 | } else { |
||||
186 | $GLOBALS['xoopsOption']['template_main'] = 'adslight_addlisting.tpl'; |
||||
187 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||
188 | // require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||
189 | |||||
190 | $cid = Request::getInt('cide', 0, 'GET'); |
||||
191 | $cat_moderate = Request::getInt('cat_moderate', 0, 'POST'); |
||||
192 | $howlong = $GLOBALS['xoopsModuleConfig']['adslight_howlong']; |
||||
193 | $member_usid = $GLOBALS['xoopsUser']->getVar('uid', 'E'); |
||||
194 | $member_email = $GLOBALS['xoopsUser']->getVar('email', 'E'); |
||||
195 | $member_uname = $GLOBALS['xoopsUser']->getVar('uname', 'E'); |
||||
196 | |||||
197 | $result = $xoopsDB->query('SELECT id_type, nom_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type'); |
||||
198 | $result1 = $xoopsDB->query('SELECT id_price, nom_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price'); |
||||
199 | $result3 = $xoopsDB->query('SELECT id_usure, nom_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY id_usure'); |
||||
200 | |||||
201 | ob_start(); |
||||
202 | $form = new \XoopsThemeForm(_ADSLIGHT_ADD_LISTING, 'submitform', 'add.php', 'post', true); |
||||
203 | $form->setExtra('enctype="multipart/form-data"'); |
||||
204 | |||||
205 | // $GLOBALS['xoopsGTicket']->addTicketXoopsFormElement($form, __LINE__, 1800, 'token'); |
||||
206 | |||||
207 | //@todo - this 'if' code doesn't do anything, what should happen for premium accounts? |
||||
208 | if ($cat_moderate) { |
||||
209 | if ('0' != $premium) { |
||||
210 | echo ''; |
||||
211 | } else { |
||||
212 | echo ''; |
||||
213 | } |
||||
214 | } else { |
||||
215 | if ('0' != $premium) { |
||||
216 | echo ''; |
||||
217 | } else { |
||||
218 | echo ''; |
||||
219 | } |
||||
220 | } |
||||
221 | |||||
222 | if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) { |
||||
223 | $form->addElement(new \XoopsFormText(_ADSLIGHT_SUBMITTER, 'submitter', 50, 50, $member_uname), true); |
||||
224 | } else { |
||||
225 | $form->addElement(new \XoopsFormLabel(_ADSLIGHT_SUBMITTER, $member_uname)); |
||||
226 | $form->addElement(new \XoopsFormHidden('submitter', $member_uname), true); |
||||
227 | } |
||||
228 | if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) { |
||||
229 | $form->addElement(new \XoopsFormText(_ADSLIGHT_EMAIL, 'email', 50, 50, $member_email), true); |
||||
230 | } else { |
||||
231 | $form->addElement(new \XoopsFormLabel(_ADSLIGHT_EMAIL, $member_email)); |
||||
232 | $form->addElement(new \XoopsFormHidden('email', $member_email), true); |
||||
233 | } |
||||
234 | $form->addElement(new \XoopsFormText(_ADSLIGHT_TOWN, 'town', 50, 50, ''), false); |
||||
235 | if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_country']) { |
||||
236 | $form->addElement(new \XoopsFormText(_ADSLIGHT_COUNTRY, 'country', 50, 50, ''), false); |
||||
237 | } else { |
||||
238 | $form->addElement(new \XoopsFormHidden('country', ''), false); |
||||
239 | } |
||||
240 | $form->addElement(new \XoopsFormText(_ADSLIGHT_TEL, 'tel', 50, 50, ''), false); |
||||
241 | |||||
242 | // $cid = $_GET['cid']; |
||||
243 | $cid = 0; |
||||
244 | $cat_perms = Adslight\Utility::getMyItemIds('adslight_submit'); |
||||
245 | if (is_array($cat_perms) && count($cat_perms) > 0) { |
||||
246 | if (!in_array($cid, $cat_perms)) { |
||||
247 | //mb redirect_header(XOOPS_URL . '/modules/adslight/index.php', 3, _NOPERM); |
||||
248 | } |
||||
249 | |||||
250 | // Category select box |
||||
251 | ob_start(); |
||||
252 | $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
![]() |
|||||
253 | $form->addElement(new \XoopsFormLabel(_ADSLIGHT_CAT3, ob_get_clean()), true); |
||||
254 | |||||
255 | /** @var mysqli_result $category */ |
||||
256 | $category = $xoopsDB->query('SELECT title, cat_moderate FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid='" . $xoopsDB->escape($cid) . "'"); |
||||
257 | |||||
258 | list($cat_title, $cat_moderate) = $xoopsDB->fetchRow($category); |
||||
259 | |||||
260 | if ('1' == $premium) { |
||||
261 | $radio = new \XoopsFormRadio(_ADSLIGHT_STATUS, 'status', ''); |
||||
262 | $options['0'] = _ADSLIGHT_ACTIVE; |
||||
263 | $options['1'] = _ADSLIGHT_INACTIVE; |
||||
264 | $radio->addOptionArray($options); |
||||
265 | $form->addElement($radio, true); |
||||
266 | } else { |
||||
267 | $form->addElement(new \XoopsFormHidden('status', '0'), true); |
||||
268 | } |
||||
269 | |||||
270 | if (1 == $premium) { |
||||
271 | $form->addElement(new \XoopsFormText(_ADSLIGHT_HOW_LONG, 'expire', 3, 3, $GLOBALS['xoopsModuleConfig']['adslight_howlong']), true); |
||||
272 | } else { |
||||
273 | $form->addElement(new \XoopsFormLabel(_ADSLIGHT_WILL_LAST, $GLOBALS['xoopsModuleConfig']['adslight_howlong'])); |
||||
274 | $form->addElement(new \XoopsFormHidden('expire', $GLOBALS['xoopsModuleConfig']['adslight_howlong']), false); |
||||
275 | } |
||||
276 | |||||
277 | // Type |
||||
278 | $type_form = new \XoopsFormSelect(_ADSLIGHT_TYPE, 'type', '', '1'); |
||||
279 | while (false !== (list($nom_type, $id_type) = $xoopsDB->fetchRow($result))) { |
||||
280 | $type_form->addOption($nom_type, $id_type); |
||||
281 | } |
||||
282 | |||||
283 | // State of Object |
||||
284 | $usure_form = new \XoopsFormSelect(_ADSLIGHT_TYPE_USURE, 'typeusure', '', '1'); |
||||
285 | while (false !== (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result3))) { |
||||
286 | $usure_form->addOption($nom_usure, $id_usure); |
||||
287 | } |
||||
288 | |||||
289 | $form->addElement($type_form, true); |
||||
290 | $form->addElement($usure_form, true); |
||||
291 | |||||
292 | $form->addElement(new \XoopsFormText(_ADSLIGHT_TITLE2, 'title', 40, 50, ''), true); |
||||
293 | |||||
294 | $form->addElement(Adslight\Utility::getEditor(_ADSLIGHT_DESC, 'desctext', '', '100%', 40), true); |
||||
295 | |||||
296 | // $form->addElement(new \XoopsFormEditor(_ADSLIGHT_DESC, $GLOBALS['xoopsModuleConfig']['adslightEditorUser'], $options, $nohtml = FALSE, $onfailure = 'textarea')); |
||||
297 | // $optionsTrayNote->addElement($bodynote); |
||||
298 | |||||
299 | $form->addElement(new \XoopsFormText(_ADSLIGHT_PRICE2, 'price', 40, 50, ''), true); |
||||
300 | |||||
301 | // Price Type |
||||
302 | $sel_form = new \XoopsFormSelect(_ADSLIGHT_PRICETYPE, 'typeprice', '', '1'); |
||||
303 | while (false !== (list($nom_price, $id_price) = $xoopsDB->fetchRow($result1))) { |
||||
304 | $sel_form->addOption($nom_price, $id_price); |
||||
305 | } |
||||
306 | |||||
307 | $form->addElement($sel_form); |
||||
308 | |||||
309 | $contactby_form = new \XoopsFormSelect(_ADSLIGHT_CONTACTBY, 'contactby', '', '1'); |
||||
310 | $contactby_form->addOption(1, _ADSLIGHT_CONTACT_BY_EMAIL); |
||||
311 | $contactby_form->addOption(2, _ADSLIGHT_CONTACT_BY_PM); |
||||
312 | $contactby_form->addOption(3, _ADSLIGHT_CONTACT_BY_BOTH); |
||||
313 | $contactby_form->addOption(4, _ADSLIGHT_CONTACT_BY_PHONE); |
||||
314 | $form->addElement($contactby_form, true); |
||||
315 | $form->addElement(new \XoopsFormRadioYN(_ADSLIGHT_ADD_PHOTO_NOW, 'addphotonow', 1)); |
||||
316 | /* |
||||
317 | if ('1' == $GLOBALS['xoopsModuleConfig']["adslight_use_captcha"]) { |
||||
318 | $form->addElement(new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, "xoopscaptcha", false), true); |
||||
319 | } |
||||
320 | */ |
||||
321 | if ('0' != $premium) { |
||||
322 | $form->addElement(new \XoopsFormHidden('premium', 'yes'), false); |
||||
323 | } else { |
||||
324 | $form->addElement(new \XoopsFormHidden('premium', 'no'), false); |
||||
325 | } |
||||
326 | |||||
327 | if ('1' == $cat_moderate) { |
||||
328 | $form->addElement(new \XoopsFormHidden('valid', 'No'), false); |
||||
329 | $form->addElement(new \XoopsFormHidden('cat_moderate', '1'), false); |
||||
330 | } else { |
||||
331 | $form->addElement(new \XoopsFormHidden('valid', 'Yes'), false); |
||||
332 | } |
||||
333 | $form->addElement(new \XoopsFormHidden('usid', $member_usid), false); |
||||
334 | $form->addElement(new \XoopsFormHidden('date', time()), false); |
||||
335 | $form->addElement(new \XoopsFormButton('', 'submit', _ADSLIGHT_SUBMIT, 'submit')); |
||||
336 | $form->display(); |
||||
337 | $GLOBALS['xoopsTpl']->assign('submit_form', ob_get_clean()); |
||||
338 | } else { // User can't see any category |
||||
339 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||||
340 | } |
||||
341 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||||
342 | } |
||||
343 |