These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * **************************************************************************** |
||
4 | * - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
||
5 | * **************************************************************************** |
||
6 | * XNEWSLETTER - MODULE FOR XOOPS |
||
7 | * Copyright (c) 2007 - 2012 |
||
8 | * Goffy ( wedega.com ) |
||
9 | * |
||
10 | * You may not change or alter any portion of this comment or credits |
||
11 | * of supporting developers from this source code or any supporting |
||
12 | * source code which is considered copyrighted (c) material of the |
||
13 | * original comment or credit authors. |
||
14 | * |
||
15 | * This program is distributed in the hope that it will be useful, |
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | * GNU General Public License for more details. |
||
19 | * --------------------------------------------------------------------------- |
||
20 | * @copyright Goffy ( wedega.com ) |
||
21 | * @license GPL 2.0 |
||
22 | * @package xnewsletter |
||
23 | * @author Goffy ( [email protected] ) |
||
24 | * |
||
25 | * **************************************************************************** |
||
26 | */ |
||
27 | |||
28 | $currentFile = basename(__FILE__); |
||
29 | include_once __DIR__ . '/header.php'; |
||
30 | |||
31 | $op = XoopsRequest::getString('op', 'list_subscriptions'); |
||
32 | $activationKey = XoopsRequest::getString('actkey', ''); |
||
33 | $subscr_id = XoopsRequest::getInt('subscr_id', 0); |
||
34 | $subscr_email = ($op !== 'unsub') ? XoopsRequest::getString('subscr_email', '') : ''; |
||
35 | $ip = xoops_getenv('REMOTE_ADDR'); |
||
36 | |||
37 | if ($op === 'save_subscription' || $activationKey != '') { |
||
38 | $xoopsOption['template_main'] = 'xnewsletter_subscription_result.tpl'; |
||
39 | } else { |
||
40 | $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl'; |
||
41 | } |
||
42 | if (isset($_REQUEST['addnew'])) { |
||
43 | $op = 'addnew_subscription'; |
||
44 | } |
||
45 | if ($activationKey && $op !== 'delete_subscription_confirmed' && $op !== 'unsub') { |
||
46 | $op = 'save_subscription'; |
||
47 | } |
||
48 | if ($op === 'delete_subscription_confirmed') { |
||
49 | $op = 'delete_subscription'; |
||
50 | } |
||
51 | if ($op === 'unsub') { |
||
52 | $op = 'list_subscriptions'; |
||
53 | $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl'; |
||
54 | $_SESSION['redirect_mail'] = XoopsRequest::getString('email', ''); |
||
55 | $_SESSION['unsub'] = '1'; |
||
56 | } |
||
57 | |||
58 | //to avoid errors in debug when xn_groups_change_other |
||
59 | $subscr_sex = ''; |
||
60 | $subscr_firstname = ''; |
||
61 | $subscr_lastname = ''; |
||
62 | |||
63 | $count_ok = 0; |
||
64 | $count_err = 0; |
||
65 | $actionProts_ok = []; // IN PROGRESS: remove from here |
||
66 | $actionProts_error = []; // IN PROGRESS: remove from here |
||
67 | |||
68 | switch ($op) { |
||
69 | case 'resend_subscription' : |
||
70 | $actionProts_ok = []; |
||
71 | $actionProts_error = []; |
||
72 | $xoopsOption['template_main'] = 'xnewsletter_subscription_result.tpl'; |
||
73 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
74 | |||
75 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
76 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
77 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
78 | |||
79 | // Breadcrumb |
||
80 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
81 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
82 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
83 | |||
84 | // resend the email with the confirmation code |
||
85 | $subscr_id = XoopsRequest::getInt('subscr_id', 0); |
||
86 | $subscrCriteria = new CriteriaCompo(); |
||
87 | $subscrCriteria->add(new Criteria('subscr_id', $subscr_id)); |
||
88 | $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria); |
||
89 | if ($subscrCount > 0) { |
||
90 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
91 | $subscr_email = $subscrObj->getVar('subscr_email'); |
||
92 | $xoopsMailer = xoops_getMailer(); |
||
93 | $xoopsMailer->reset(); |
||
94 | $xoopsMailer->setTemplateDir(); |
||
95 | $xoopsMailer->useMail(); |
||
96 | $xoopsMailer->setTemplate('activate.tpl'); |
||
97 | $xoopsMailer->setToEmails($subscr_email); |
||
98 | if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
99 | if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
100 | $xoopsMailer->assign('SEX', $subscrObj->getVar('subscr_sex')); |
||
101 | $xoopsMailer->assign('EMAIL', $subscr_email); |
||
102 | $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar('subscr_firstname')); |
||
103 | $xoopsMailer->assign('LASTNAME', $subscrObj->getVar('subscr_lastname')); |
||
104 | $xoopsMailer->assign('IP', $ip); |
||
105 | $activationKey = base64_encode(XOOPS_URL . "||addnew||{$subscr_id}||{$subscrObj->getVar('subscr_actkey')}||{$subscr_email}"); |
||
106 | $xoopsMailer->assign('ACTLINK', XOOPS_URL . "/modules/xnewsletter/{$currentFile}?actkey={$activationKey}"); |
||
107 | $subject = _MA_XNEWSLETTER_SUBSCRIPTIONSUBJECT . $GLOBALS['xoopsConfig']['sitename']; |
||
108 | $xoopsMailer->setSubject($subject); |
||
109 | if (!$xoopsMailer->send()) { |
||
110 | $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . '<br />' . $xoopsMailer->getErrors(); |
||
111 | } |
||
112 | $actionProts_ok[] = str_replace ('%nl', $cat_name, _MA_XNEWSLETTER_SENDMAIL_REG_OK); |
||
113 | } else { |
||
114 | // IN PROGRESS |
||
115 | redirect_header($currentFile, 5, 'IN PROGRESS: error'); |
||
116 | } |
||
117 | $xoopsTpl->assign('actionProts_ok', $actionProts_ok); |
||
118 | $xoopsTpl->assign('actionProts_error', $actionProts_error); |
||
119 | break; |
||
120 | |||
121 | case 'save_subscription' : |
||
122 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
123 | |||
124 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
125 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
126 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
127 | |||
128 | // Breadcrumb |
||
129 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
130 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
131 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
132 | |||
133 | // check right to subscribe directly |
||
134 | $submitterUid = is_object($xoopsUser) ? (int) $xoopsUser->getVar('uid') : 0; |
||
135 | $allowedWithoutActivationKey = false; |
||
136 | if ($submitterUid > 0) { |
||
137 | // user logged in |
||
138 | $submitter_email = $xoopsUser->email(); |
||
139 | View Code Duplication | foreach ($xoopsUser->getGroups() as $group) { |
|
0 ignored issues
–
show
|
|||
140 | if (in_array($group, $xnewsletter->getConfig('xn_groups_without_actkey')) || XOOPS_GROUP_ADMIN == $group) { |
||
141 | $allowedWithoutActivationKey = true; |
||
142 | break; |
||
143 | } |
||
144 | } |
||
145 | } else { |
||
146 | // user not logged in |
||
147 | // NOP |
||
148 | } |
||
149 | |||
150 | if (!$activationKey) { |
||
151 | // activation key doesn't exist |
||
152 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
153 | redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
154 | } |
||
155 | if ($subscr_email == '') { |
||
156 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL); |
||
157 | } |
||
158 | if (!xnewsletter_checkEmail($subscr_email)) |
||
159 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL); |
||
160 | |||
161 | |||
162 | // read current selections and create code for actkey |
||
163 | $cat_selections = []; |
||
164 | $code_selections = ''; |
||
165 | $catCriteria = new CriteriaCompo(); |
||
166 | $catCriteria->setSort('cat_id'); |
||
167 | $catCriteria->setOrder('ASC'); |
||
168 | $catObjs = $xnewsletter->getHandler('cat')->getAll($catCriteria); |
||
169 | |||
170 | foreach ($catObjs as $cat_id => $catObj) { |
||
171 | // create selection code: cat_id - cat selected - old catsubcr_id - old catsubscr_quited |
||
172 | $code_selections .= ($code_selections == '') ? '' : '|'; |
||
173 | $code_selections .= $cat_id . '-'; |
||
174 | $code_selections .= (isset($_REQUEST["letter_cats_{$cat_id}"])) ? '1' : '0'; |
||
175 | $code_selections .= '-'; |
||
176 | $old_catsubcr_id = XoopsRequest::getInt("letter_cats_old_catsubcr_id_{$cat_id}", 0); |
||
177 | $code_selections .= $old_catsubcr_id; |
||
178 | $code_selections .= '-'; |
||
179 | $old_catsubcr_quited = XoopsRequest::getInt("letter_cats_old_catsubscr_quited_{$cat_id}", 0); |
||
180 | $code_selections .= $old_catsubcr_quited; |
||
181 | } |
||
182 | |||
183 | // save subscriber first |
||
184 | if ($subscr_id > 0) { |
||
185 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
186 | $saveType = 'update'; |
||
187 | } else { |
||
188 | $subscrObj = $xnewsletter->getHandler('subscr')->create(); |
||
189 | $saveType = 'addnew'; |
||
190 | } |
||
191 | |||
192 | if ($subscr_id < 1 || $allowedWithoutActivationKey) { |
||
193 | // form subscr_email |
||
194 | $subscrObj->setVar('subscr_email', $subscr_email); |
||
195 | // form subscr_uid |
||
196 | $subscr_uid = 0; |
||
197 | $sql = "SELECT `uid` FROM {$xoopsDB->prefix('users')}"; |
||
198 | $sql .= " WHERE (`email`='{$subscr_email}')"; |
||
199 | $sql .= ' LIMIT 1'; |
||
200 | View Code Duplication | if ($user = $xoopsDB->query($sql)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
201 | $row_user = $xoopsDB->fetchRow($user); |
||
202 | $subscr_uid = $row_user[0]; |
||
203 | } |
||
204 | $subscrObj->setVar('subscr_uid', (int) $subscr_uid); |
||
205 | // form subscr_submitter |
||
206 | $subscrObj->setVar('subscr_submitter', $submitterUid); |
||
207 | } |
||
208 | |||
209 | $subscr_actkey = xoops_makepass(); |
||
210 | $subscrObj->setVar('subscr_actkey', $subscr_actkey); |
||
211 | // form subscr_created |
||
212 | //$subscrObj->setVar("subscr_created", time()); //kann eigentlich immer gespeichert werden |
||
213 | //$subscrObj->setVar("subscr_ip", $ip); //kann eigentlich immer gespeichert werden |
||
214 | //Nicht speichern, sondern nur beim anlegen und 1. Bestaetigen |
||
215 | if ($subscr_id < 1) { |
||
216 | $subscrObj->setVar('subscr_created', time()); |
||
217 | $subscrObj->setVar('subscr_ip', $ip); |
||
218 | $subscrObj->setVar('subscr_activated', 0); |
||
219 | } |
||
220 | |||
221 | if ($activationKey || $allowedWithoutActivationKey) { |
||
222 | // subscr_firstname |
||
223 | $subscrObj->setVar('subscr_firstname', XoopsRequest::getString('subscr_firstname', '')); |
||
224 | // subscr_lastname |
||
225 | $subscrObj->setVar('subscr_lastname', XoopsRequest::getString('subscr_lastname', '')); |
||
226 | // subscr_sex |
||
227 | $subscrObj->setVar('subscr_sex', XoopsRequest::getString('subscr_sex', '')); |
||
228 | // subscr_actoptions |
||
229 | $subscrObj->setVar('subscr_actoptions', ''); |
||
230 | } else { |
||
231 | //format subscr_actoptions: selected_newsletters||firstname||lastname||sex |
||
232 | $code_options = []; |
||
233 | $code_options[0] = $code_selections; |
||
234 | $code_options[1] = XoopsRequest::getString('subscr_firstname', ''); |
||
235 | $code_options[2] = XoopsRequest::getString('subscr_lastname', ''); |
||
236 | $code_options[3] = XoopsRequest::getString('subscr_sex', ''); |
||
237 | $code_options[4] = time(); |
||
238 | $code_options[5] = $ip; |
||
239 | $subscrObj->setVar('subscr_actoptions', serialize($code_options)); |
||
240 | } |
||
241 | |||
242 | if ($xnewsletter->getHandler('subscr')->insert($subscrObj)) { |
||
243 | if ($subscr_id < 1) { |
||
244 | $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_OK; |
||
245 | } else { |
||
246 | $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_UPDATE_OK; |
||
247 | } |
||
248 | $subscr_id = $subscrObj->getVar('subscr_id'); |
||
249 | |||
250 | if ($allowedWithoutActivationKey) { |
||
251 | $isValid = true; |
||
252 | $cat_selections = explode('|', $code_selections); |
||
253 | } else { |
||
254 | $isValid = false; |
||
255 | $xoopsMailer = xoops_getMailer(); |
||
256 | $xoopsMailer->reset(); |
||
257 | $xoopsMailer->setTemplateDir(); |
||
258 | $xoopsMailer->useMail(); |
||
259 | if ($saveType === 'update') { |
||
260 | $xoopsMailer->setTemplate('update.tpl'); |
||
261 | } else { |
||
262 | $xoopsMailer->setTemplate('activate.tpl'); |
||
263 | } |
||
264 | $xoopsMailer->setToEmails($subscr_email); |
||
265 | if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
266 | if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
267 | $xoopsMailer->assign('SEX', $subscrObj->getVar('subscr_sex')); |
||
268 | $xoopsMailer->assign('EMAIL', $subscr_email); |
||
269 | $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar('subscr_firstname')); |
||
270 | $xoopsMailer->assign('LASTNAME', $subscrObj->getVar('subscr_lastname')); |
||
271 | $xoopsMailer->assign('IP', $ip); |
||
272 | $activationKey = base64_encode(XOOPS_URL . "||{$saveType}||{$subscr_id}||{$subscr_actkey}||{$subscr_email}"); |
||
273 | $xoopsMailer->assign('ACTLINK', XOOPS_URL . "/modules/xnewsletter/{$currentFile}?actkey={$activationKey}"); |
||
274 | $subject = _MA_XNEWSLETTER_SUBSCRIPTIONSUBJECT . $GLOBALS['xoopsConfig']['sitename']; |
||
275 | $xoopsMailer->setSubject($subject); |
||
276 | if (!$xoopsMailer->send()) { |
||
277 | redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . '<br />' . $xoopsMailer->getErrors()); |
||
278 | } |
||
279 | $actionProts_ok[] = _MA_XNEWSLETTER_SENDMAIL_REG_OK; |
||
280 | } |
||
281 | } else { |
||
282 | redirect_header($currentFile, 20, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVESUBSCR . '<br />' . $subscrObj->getHtmlErrors()); |
||
283 | } |
||
284 | } else { |
||
285 | // activation key exist |
||
286 | $activationKey_array = explode('||', base64_decode($activationKey)); |
||
287 | $isValid = false; |
||
288 | if ($activationKey_array[0] == XOOPS_URL) { // from here |
||
289 | if (trim($activationKey_array[1]) != '') { // savetype ok |
||
290 | if ((int) $activationKey_array[2] > 0) { // user is ok |
||
291 | if (trim($activationKey_array[3]) != '') { |
||
292 | $isValid = true; |
||
293 | } |
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | |||
298 | if (!$isValid) { |
||
299 | redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_INVALIDKEY); |
||
300 | } else { |
||
301 | $saveType = trim($activationKey_array[1]); |
||
302 | $subscr_id = (int) $activationKey_array[2]; |
||
303 | $subscr_actkey = trim($activationKey_array[3]); |
||
304 | |||
305 | //check given data with table subscr |
||
306 | $subscrCriteria = new CriteriaCompo(); |
||
307 | $subscrCriteria->add(new Criteria('subscr_id', $subscr_id)); |
||
308 | $subscrCriteria->add(new Criteria('subscr_actkey', $subscr_actkey)); |
||
309 | $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria); |
||
310 | if ($subscrCount == 0) |
||
311 | redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NODATAKEY); |
||
312 | |||
313 | //read data from table subscr |
||
314 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
315 | $actoptions = unserialize(trim($subscrObj->getVar('subscr_actoptions', 'N'))); |
||
316 | //format subscr_actoptions:selected_newsletters||firstname||lastname||sex||date||ip |
||
317 | $cat_selections = explode('|', trim($actoptions[0])); |
||
318 | $subscr_firstname = trim($actoptions[1]); |
||
319 | $subscr_lastname = trim($actoptions[2]); |
||
320 | $subscr_sex = trim($actoptions[3]); |
||
321 | if ((int) $actoptions[4] < time() - 86400) { //Zeit checken -> 24 Stunden ?? |
||
322 | //Zeit abgelaufen |
||
323 | $subscrObj->setVar('subscr_actkey', ''); |
||
324 | $subscrObj->setVar('subscr_actoptions', ''); |
||
325 | $xnewsletter->getHandler('subscr')->insert($subscrObj); |
||
326 | redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NODATAKEY); |
||
327 | } |
||
328 | } |
||
329 | } |
||
330 | |||
331 | if ($isValid) { |
||
332 | // update xnewsletter_subscr |
||
333 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
334 | if (!$allowedWithoutActivationKey) { |
||
335 | if ($subscr_actkey != $subscrObj->getVar('subscr_actkey')) { |
||
336 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOVALIDKEY); |
||
337 | } |
||
338 | } |
||
339 | if ($subscrObj->getVar('subscr_activated') == 0) { |
||
340 | $subscrObj->setVar('subscr_created', time()); |
||
341 | $subscrObj->setVar('subscr_ip', $ip); |
||
342 | $subscrObj->setVar('subscr_activated', 1); |
||
343 | } |
||
344 | $subscrObj->setVar('subscr_actkey', ''); |
||
345 | $subscrObj->setVar('subscr_actoptions', ''); |
||
346 | |||
347 | if ($activationKey) { |
||
348 | $subscrObj->setVar('subscr_sex', $subscr_sex); |
||
349 | $subscrObj->setVar('subscr_firstname', $subscr_firstname); |
||
350 | $subscrObj->setVar('subscr_lastname', $subscr_lastname); |
||
351 | } |
||
352 | if (!$xnewsletter->getHandler('subscr')->insert($subscrObj)) { |
||
353 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVESUBSCR); |
||
354 | } else { |
||
355 | if ($saveType === 'addnew') { |
||
356 | $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_CLOSED; |
||
357 | } else { |
||
358 | $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_UPDATE_CLOSED; |
||
359 | } |
||
360 | } |
||
361 | // handle current selections |
||
362 | foreach ($cat_selections as $sel) { |
||
363 | $selection = []; |
||
364 | if ($sel == '') $sel = '0-0-0-0'; |
||
365 | $selection = explode('-', $sel); |
||
366 | $cat_id = $selection[0]; |
||
367 | $catsubcr = $selection[1]; |
||
368 | $catsubcr_id_old = (int) $selection[2]; |
||
369 | $catsubcr_quited_old = (int) $selection[3]; |
||
370 | $catObj = $xnewsletter->getHandler('cat')->get($cat_id); |
||
371 | $cat_mailinglist = $catObj->getVar('cat_mailinglist'); |
||
372 | $cat_name = $catObj->getVar('cat_name'); |
||
373 | if ($catsubcr == '1' && $catsubcr_id_old == 0) { |
||
374 | // subscribe |
||
375 | $catsubscrObj = $xnewsletter->getHandler('catsubscr')->create(); |
||
376 | //Form catsubscr_catid |
||
377 | $catsubscrObj->setVar('catsubscr_catid', $cat_id); |
||
378 | //Form catsubscr_subscrid |
||
379 | $catsubscrObj->setVar('catsubscr_subscrid', $subscr_id); |
||
380 | //Form catsubscr_submitter |
||
381 | $catsubscrObj->setVar('catsubscr_submitter', $submitterUid); |
||
382 | //Form catsubscr_submitter |
||
383 | $catsubscrObj->setVar('catsubscr_created', time()); |
||
384 | if ($xnewsletter->getHandler('catsubscr')->insert($catsubscrObj)) { |
||
385 | $count_ok++; |
||
386 | if ($catsubcr_id_old > 0) { |
||
387 | $actionProts_ok[] = str_replace('%nl', $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_NO_CHANGE); |
||
388 | } else { |
||
389 | $actionProts_ok[] = str_replace('%nl', $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_SUBSCRIBE); |
||
390 | } |
||
391 | //handle mailinglists |
||
392 | if ($cat_mailinglist > 0) { |
||
393 | require_once XOOPS_ROOT_PATH . '/modules/xnewsletter/include/mailinglist.php'; |
||
394 | subscribingMLHandler(1, $subscr_id, $cat_mailinglist); |
||
395 | } |
||
396 | } else { |
||
397 | $count_err++; |
||
398 | $actionProts_error[]= _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors(); |
||
399 | } |
||
400 | } elseif ($catsubcr == '0' && $catsubcr_id_old > 0) { |
||
401 | // unsubscribe / delete old subscription |
||
402 | $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubcr_id_old); |
||
403 | if ($xnewsletter->getHandler('catsubscr')->delete($catsubscrObj, true)) { |
||
404 | //handle mailinglists |
||
405 | if ($cat_mailinglist > 0) { |
||
406 | require_once XOOPS_ROOT_PATH . '/modules/xnewsletter/include/mailinglist.php'; |
||
407 | subscribingMLHandler(0, $subscr_id, $cat_mailinglist); |
||
408 | } |
||
409 | } else { |
||
410 | $count_err++; |
||
411 | $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors(); |
||
412 | } |
||
413 | |||
414 | if ($count_err > 0) { |
||
415 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELNOTOK); |
||
416 | } |
||
417 | $actionProts_ok[] = str_replace ('%nl', $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_UNSUBSCRIBE); |
||
418 | } elseif ($catsubcr_id_old > 0 && $catsubcr_quited_old > 0) { |
||
419 | // newsletter stay selected, but catsubscr_quited will be removed |
||
420 | $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubcr_id_old); |
||
421 | //Form catsubscr_quited |
||
422 | $catsubscrObj->setVar('catsubscr_quited', '0'); |
||
423 | |||
424 | if ($xnewsletter->getHandler('catsubscr')->insert($catsubscrObj)) { |
||
425 | $count_ok++; |
||
426 | $actionProts_ok[] = str_replace ('%nl', $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_DAT_QUITED_REMOVED); |
||
427 | } else { |
||
428 | $count_err++; |
||
429 | $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors(); |
||
430 | } |
||
431 | } elseif ($catsubcr_id_old > 0) { |
||
432 | // newsletter still subscribed |
||
433 | $actionProts_ok[] = str_replace ('%nl', $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_NO_CHANGE); |
||
434 | } else { |
||
435 | // nothing to do |
||
436 | } |
||
437 | } |
||
438 | } |
||
439 | |||
440 | |||
441 | |||
442 | if (isset($submitter_email) && ($submitter_email != '') && ($submitter_email != $subscr_email)) { |
||
443 | //send infomail to subscriber, because current user is not the subscriber |
||
444 | if ($subscr_sex == '' && $subscr_firstname == '' && $subscr_lastname == '') { |
||
445 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
446 | $subscr_sex = $subscrObj->getVar('subscr_sex'); |
||
447 | $subscr_firstname = $subscrObj->getVar('subscr_firstname'); |
||
448 | $subscr_lastname = $subscrObj->getVar('subscr_lastname'); |
||
449 | } |
||
450 | $xoopsMailer = xoops_getMailer(); |
||
451 | $xoopsMailer->reset(); |
||
452 | $xoopsMailer->setTemplateDir(); |
||
453 | $xoopsMailer->useMail(); |
||
454 | $xoopsMailer->setHTML(); |
||
455 | $xoopsMailer->setTemplate('info_change.tpl'); |
||
456 | $xoopsMailer->setToEmails($subscr_email); |
||
457 | if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
458 | if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
459 | $xoopsMailer->assign('SEX', $subscr_sex); |
||
460 | $xoopsMailer->assign('EMAIL', $subscr_email); |
||
461 | $xoopsMailer->assign('FIRSTNAME', $subscr_firstname); |
||
462 | $xoopsMailer->assign('LASTNAME', $subscr_lastname); |
||
463 | |||
464 | $xoopsMailer->assign('IP', $ip); |
||
465 | $actlink = XOOPS_URL . "/modules/xnewsletter/{$currentFile}?subscr_email={$subscr_email}"; |
||
466 | $xoopsMailer->assign('ACTLINK', $actlink); |
||
467 | $user_link = XOOPS_URL . '/userinfo.php?uid=' . $xoopsUser->uid(); |
||
468 | $user_name = $xoopsUser->name(); |
||
469 | $xoopsMailer->assign('USERLINK', $user_link); |
||
470 | $xoopsMailer->assign('USERNAME', $user_name); |
||
471 | $subject_change = _MA_XNEWSLETTER_SUBSCRIPTION_SUBJECT_CHANGE . $GLOBALS['xoopsConfig']['sitename']; |
||
472 | $xoopsMailer->setSubject($subject_change); |
||
473 | if ($xoopsMailer->send()) { |
||
474 | $actionProts_ok[] = str_replace('%e', $subscr_email, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_SENT_INFO); |
||
475 | } else { |
||
476 | redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . '<br />' . $xoopsMailer->getErrors()); |
||
477 | } |
||
478 | } |
||
479 | |||
480 | $xoopsTpl->assign('actionProts_ok', $actionProts_ok); |
||
481 | |||
482 | if ($count_err > 0) { |
||
483 | $xoopsTpl->assign('subscription_result', _MA_XNEWSLETTER_SUBSCRIPTION_ERROR); |
||
484 | $xoopsTpl->assign('actionProts_error', $actionProts_error); |
||
485 | } else { |
||
486 | $xoopsTpl->assign('subscription_result', _MA_XNEWSLETTER_SUBSCRIPTION_OK); |
||
487 | } |
||
488 | break; |
||
489 | |||
490 | |||
491 | |||
492 | case 'add_subscription' : |
||
493 | case 'create_subscription' : |
||
494 | $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl'; |
||
495 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
496 | |||
497 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
498 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
499 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
500 | |||
501 | // Breadcrumb |
||
502 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
503 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
504 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
505 | |||
506 | // get create subscr form |
||
507 | if ($subscr_email != '') { |
||
508 | //existing email |
||
509 | if (!xnewsletter_checkEmail($subscr_email)) { |
||
510 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL); |
||
511 | } |
||
512 | } elseif (is_object($xoopsUser) && isset($xoopsUser)) { |
||
513 | //take actual xoops user |
||
514 | $subscr_email = $xoopsUser->email(); |
||
515 | } else { |
||
516 | $subscr_email = ''; |
||
517 | } |
||
518 | $subscrObj = $xnewsletter->getHandler('subscr')->create(); |
||
519 | $subscrObj->setVar('subscr_email', $subscr_email); |
||
520 | $subscrForm = $subscrObj->getForm(); |
||
521 | $xoopsTpl->assign('xnewsletter_content', $subscrForm->render()); |
||
522 | break; |
||
523 | |||
524 | |||
525 | |||
526 | case 'edit_subscription' : |
||
527 | $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl'; |
||
528 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
529 | |||
530 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
531 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
532 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
533 | |||
534 | // Breadcrumb |
||
535 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
536 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
537 | $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, XNEWSLETTER_URL . '/subscription.php?op=list_subscriptions'); |
||
538 | $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIPTION_EDIT, ''); |
||
539 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
540 | |||
541 | // get edit subscr form |
||
542 | $subscr_id = XoopsRequest::getInt('subscr_id', 0); |
||
543 | if ($subscr_id <= 0) { |
||
544 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOID); |
||
545 | } |
||
546 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
547 | $subscrForm = $subscrObj->getForm(); |
||
548 | $xoopsTpl->assign('xnewsletter_content', $subscrForm->render()); |
||
549 | break; |
||
550 | |||
551 | |||
552 | |||
553 | case 'delete_subscription' : |
||
554 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
555 | |||
556 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
557 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
558 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
559 | |||
560 | // Breadcrumb |
||
561 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
562 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
563 | $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, XNEWSLETTER_URL . '/subscription.php?op=list_subscriptions'); |
||
564 | $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIPTION_DELETE, ''); |
||
565 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
566 | |||
567 | if (!$activationKey) { |
||
568 | if ($subscr_id < 1) { |
||
569 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOID); |
||
570 | } |
||
571 | } |
||
572 | |||
573 | if ((isset($_POST['ok']) && $_POST['ok'] == true) || $activationKey) { |
||
574 | $count_err = 0; |
||
575 | $actionProts_error = ''; |
||
576 | |||
577 | // check right to unsubscribe directly |
||
578 | $submitterUid = is_object($xoopsUser) ? (int) $xoopsUser->getVar('uid') : 0; |
||
579 | if ($submitterUid == 0) { |
||
580 | // user not logged in |
||
581 | $allowedWithoutActivationKey = false; |
||
582 | } else { |
||
583 | // user logged in |
||
584 | $allowedWithoutActivationKey = false; |
||
585 | View Code Duplication | foreach ($xoopsUser->getGroups() as $group) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
586 | if (in_array($group, $xnewsletter->getConfig('xn_groups_without_actkey')) || XOOPS_GROUP_ADMIN == $group) { |
||
587 | $allowedWithoutActivationKey = true; |
||
588 | break; |
||
589 | } |
||
590 | } |
||
591 | } |
||
592 | |||
593 | if ($activationKey || $allowedWithoutActivationKey) { |
||
594 | // got actkey or user is allowed to delete without actkey |
||
595 | $isValid = false; |
||
596 | if ($activationKey) { |
||
597 | $activationKey_array = explode('||', base64_decode($activationKey)); |
||
598 | $subscr_id = (int) $activationKey_array[1]; |
||
599 | $subscr_actkey = trim($activationKey_array[2]); |
||
600 | $subscr_email = trim($activationKey_array[3]); |
||
601 | // check activation key |
||
602 | if (($activationKey_array[0] == XOOPS_URL) && ((int) $activationKey_array[1] > 0) && (trim($activationKey_array[2]) != '')) |
||
603 | $isValid = true; |
||
604 | } elseif ($allowedWithoutActivationKey) { |
||
605 | $isValid = true; |
||
606 | } else { |
||
607 | $isValid = false; |
||
608 | } |
||
609 | |||
610 | if ($isValid) { |
||
611 | $subscrCriteria = new CriteriaCompo(); |
||
612 | $subscrCriteria->add(new Criteria('subscr_email', $subscr_email)); |
||
613 | $subscrCriteria->add(new Criteria('subscr_id', $subscr_id)); |
||
614 | if ($activationKey) |
||
615 | $subscrCriteria->add(new Criteria('subscr_actkey', $subscr_actkey)); |
||
616 | $subscrCriteria->setLimit(1); |
||
617 | $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria); |
||
618 | |||
619 | if ($subscrCount != 1) { |
||
620 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR); |
||
621 | } |
||
622 | |||
623 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
624 | /* |
||
625 | $sql = "SELECT subscr_id"; |
||
626 | $sql.= " FROM {$xoopsDB->prefix("xnewsletter_subscr")}"; |
||
627 | $sql.= " WHERE (subscr_email='{$subscr_email}' AND subscr_id={$subscr_id}"; |
||
628 | if ($activationKey) |
||
629 | $sql .= " AND subscr_actkey='{$code}'"; |
||
630 | $sql .= ") LIMIT 1;"; |
||
631 | $subscr_id_test = 0; |
||
632 | if ($user = $xoopsDB->query($sql)) { |
||
633 | $row_user = $xoopsDB->fetchRow($user); |
||
634 | $subscr_id_test = $row_user[0]; |
||
635 | } |
||
636 | if ($subscr_id != $subscr_id_test) { |
||
637 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR); |
||
638 | } |
||
639 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
640 | */ |
||
641 | // delete subscriber |
||
642 | View Code Duplication | if (!$xnewsletter->getHandler('subscr')->delete($subscrObj, true)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
643 | $actionProts_error = $subscrObj->getHtmlErrors() . '<br/><br/><br/>'; |
||
644 | $count_err++; |
||
645 | } |
||
646 | //delete subscription |
||
647 | $catsubscrCriteria = new CriteriaCompo(); |
||
648 | $catsubscrCriteria->add(new Criteria('catsubscr_subscrid', $subscr_id)); |
||
649 | $catsubscrCount = $xnewsletter->getHandler('catsubscr')->getCount($catsubscrCriteria); |
||
650 | View Code Duplication | if ($catsubscrCount > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
651 | $catsubscrObjs = $xnewsletter->getHandler('catsubscr')->getAll($catsubscrCriteria); |
||
652 | foreach (array_keys($catsubscrObjs) as $cat) { |
||
653 | $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubscrObjs[$cat]->getVar('catsubscr_id')); |
||
654 | $catObj = $xnewsletter->getHandler('cat')->get($catsubscrObjs[$cat]->getVar('catsubscr_catid')); |
||
655 | $cat_mailinglist = $catObj->getVar('cat_mailinglist'); |
||
656 | |||
657 | if ($xnewsletter->getHandler('catsubscr')->delete($catsubscrObj, true)) { |
||
658 | //handle mailinglists |
||
659 | if ($cat_mailinglist > 0) { |
||
660 | require_once XOOPS_ROOT_PATH . '/modules/xnewsletter/include/mailinglist.php'; |
||
661 | subscribingMLHandler(0, $subscr_id, $cat_mailinglist); |
||
662 | } |
||
663 | } else { |
||
664 | $actionProts_error .= $catsubscrObj->getHtmlErrors(); |
||
665 | $count_err++; |
||
666 | } |
||
667 | } |
||
668 | } |
||
669 | } else { |
||
670 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR); |
||
671 | } |
||
672 | |||
673 | |||
674 | if ($count_err == 0) { |
||
675 | redirect_header('index.php', 3, _AM_XNEWSLETTER_FORMDELOK); |
||
676 | } else { |
||
677 | echo $actionProts_error; |
||
678 | } |
||
679 | } else { |
||
680 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
681 | redirect_header('subscr.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
682 | } |
||
683 | |||
684 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
685 | $subscr_actkey = xoops_makepass(); |
||
686 | $subscrObj->setVar('subscr_actkey', $subscr_actkey); |
||
687 | if (!$xnewsletter->getHandler('subscr')->insert($subscrObj)) { |
||
688 | redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR); |
||
689 | } |
||
690 | if (!$allowedWithoutActivationKey) { |
||
691 | $xoopsMailer = xoops_getMailer(); |
||
692 | $xoopsMailer->reset(); |
||
693 | $xoopsMailer->setTemplateDir(); |
||
694 | $xoopsMailer->useMail(); |
||
695 | $xoopsMailer->setTemplate('delete.tpl'); |
||
696 | $xoopsMailer->setToEmails($subscrObj->getVar('subscr_email')); |
||
697 | if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
698 | if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
699 | $xoopsMailer->assign('SEX', $subscrObj->getVar('subscr_sex')); |
||
700 | $xoopsMailer->assign('EMAIL', $subscrObj->getVar('subscr_email')); |
||
701 | $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar('subscr_firstname')); |
||
702 | $xoopsMailer->assign('LASTNAME', $subscrObj->getVar('subscr_lastname')); |
||
703 | $xoopsMailer->assign('IP', $ip); |
||
704 | $activationKey = base64_encode(XOOPS_URL . "||{$subscrObj->getVar('subscr_id')}||{$subscrObj->getVar('subscr_actkey')}||{$subscrObj->getVar('subscr_email')}"); |
||
705 | $actLink = XOOPS_URL . "/modules/xnewsletter/{$currentFile}?op=delete_subscription_confirmed&actkey={$activationKey}"; |
||
706 | $xoopsMailer->assign('ACTLINK', $actLink); |
||
707 | $subject_delete = _MA_XNEWSLETTER_DELETESUBJECT . $GLOBALS['xoopsConfig']['sitename']; |
||
708 | $xoopsMailer->setSubject($subject_delete); |
||
709 | if (!$xoopsMailer->send()) { |
||
710 | redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR . '<br />' . $xoopsMailer->getErrors()); |
||
711 | } |
||
712 | } |
||
713 | redirect_header('index.php', 3, _MA_XNEWSLETTER_SENDMAIL_UNREG_OK); |
||
714 | } |
||
715 | } else { |
||
716 | $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id); |
||
717 | xoops_confirm(['ok' => true, 'subscr_id' => $subscr_id, 'subscr_email' => $subscr_email, 'op' => 'delete_subscription'], $currentFile, sprintf(_MA_XNEWSLETTER_SUBSCRIPTION_DELETE_SURE)); |
||
718 | } |
||
719 | break; |
||
720 | |||
721 | case 'list_subscriptions' : |
||
722 | default : |
||
723 | $xoopsOption['template_main'] = 'xnewsletter_subscription_list_subscriptions.tpl'; |
||
724 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
725 | |||
726 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
727 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
728 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
729 | |||
730 | // Breadcrumb |
||
731 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
732 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
733 | $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, ''); |
||
734 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
735 | |||
736 | $showSubscrSearchForm = true; |
||
737 | $showSubscrForm = false; |
||
738 | |||
739 | $subscr_id = 0; |
||
740 | // get subscr email |
||
741 | $subscr_email = XoopsRequest::getString('subscr_email', ''); |
||
742 | if ($subscr_email != '') { |
||
743 | // existing email from search form |
||
744 | if (!xnewsletter_checkEmail($subscr_email)) |
||
745 | redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL); |
||
746 | xoops_load('captcha'); |
||
747 | $xoopsCaptcha = XoopsCaptcha::getinstance(); |
||
748 | if (!$xoopsCaptcha->verify()) { |
||
749 | $_SESSION['redirect_mail'] = $subscr_email; |
||
750 | redirect_header($currentFile, 3, $xoopsCaptcha->getMessage()); |
||
751 | } else { |
||
752 | $showSubscrSearchForm = false; |
||
753 | } |
||
754 | } elseif (is_object($xoopsUser) && isset($xoopsUser)) { |
||
755 | // take actual xoops user email |
||
756 | $subscr_email = $xoopsUser->email(); |
||
757 | $showSubscrSearchForm = false; |
||
758 | } else { |
||
759 | $subscr_email = ''; |
||
760 | } |
||
761 | |||
762 | // show search subscr form |
||
763 | $xoopsTpl->assign('showSubscrSearchForm', $showSubscrSearchForm); |
||
764 | if ($showSubscrSearchForm) { |
||
765 | // show form search |
||
766 | $subscrObj = $xnewsletter->getHandler('subscr')->create(); |
||
767 | $redirect_mail = (isset($_SESSION['redirect_mail'])) ? $_SESSION['redirect_mail'] : ''; |
||
768 | if ($redirect_mail != '') { |
||
769 | $subscrObj->setVar('subscr_email', $redirect_mail); |
||
770 | $subscr_email = $redirect_mail; |
||
771 | } |
||
772 | $subscrObj->setVar('subscr_email', $subscr_email); |
||
773 | $xoopsTpl->assign('subscrSearchForm', $subscrObj->getSearchForm()->render()); |
||
774 | } |
||
775 | |||
776 | if (isset($_SESSION['redirect_mail'])) { |
||
777 | if (!isset($_SESSION['unsub'])) { |
||
778 | $subscr_email = ''; |
||
779 | } else { |
||
780 | unset($_SESSION['unsub']); |
||
781 | } |
||
782 | unset($_SESSION['redirect_mail']); |
||
783 | } |
||
784 | |||
785 | if ($subscr_email != '') { |
||
786 | // look for existing subscriptions |
||
787 | $subscrCriteria = new CriteriaCompo(); |
||
788 | $subscrCriteria->add(new Criteria('subscr_email', $subscr_email)); |
||
789 | $subscrCriteria->setSort('subscr_id'); |
||
790 | $subscrCriteria->setOrder('ASC'); |
||
791 | $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria); |
||
792 | $xoopsTpl->assign('subscrCount', $subscrCount); |
||
793 | |||
794 | if ($subscrCount > 0) { |
||
795 | $subscrObjs = $xnewsletter->getHandler('subscr')->getAll($subscrCriteria); |
||
796 | foreach ($subscrObjs as $subscr_id => $subscrObj) { |
||
797 | $subscr_array = $subscrObj->toArray(); |
||
798 | $subscr_array['subscr_created_timestamp'] = formatTimestamp($subscrObj->getVar('subscr_created'), $xnewsletter->getConfig('dateformat')); |
||
799 | |||
800 | $catsubscrCriteria = new CriteriaCompo(); |
||
801 | $catsubscrCriteria->add(new Criteria('catsubscr_subscrid', $subscr_id)); |
||
802 | $catsubscrCriteria->setSort('catsubscr_id'); |
||
803 | $catsubscrCriteria->setOrder('ASC'); |
||
804 | $catsubscrCount = $xnewsletter->getHandler('catsubscr')->getCount($catsubscrCriteria); |
||
805 | $catsubscrObjs = $xnewsletter->getHandler('catsubscr')->getAll($catsubscrCriteria); |
||
806 | foreach ($catsubscrObjs as $catsubscr_id => $catsubscrObj) { |
||
807 | $catsubscr_array = $catsubscrObj->toArray(); |
||
808 | $catObj = $xnewsletter->getHandler('cat')->get($catsubscrObj->getVar('catsubscr_catid')); |
||
809 | $cat_array = $catObj->toArray(); |
||
810 | $catsubscr_array['cat'] = $cat_array; |
||
811 | $subscr_array['catsubscrs'][] = $catsubscr_array; |
||
812 | unset($catsubscr_array); |
||
813 | unset($cat_array); |
||
814 | } |
||
815 | $xoopsTpl->append('subscrs', $subscr_array); |
||
816 | } |
||
817 | } else { |
||
818 | // show subscr form |
||
819 | $xoopsTpl->assign('showSubscrForm', true); |
||
820 | $subscrObj = $xnewsletter->getHandler('subscr')->create(); |
||
821 | $subscrObj->setVar('subscr_email', $subscr_email); |
||
822 | $form = $subscrObj->getForm($currentFile); |
||
823 | $xoopsTpl->assign('subscrForm', $form->render()); |
||
824 | } |
||
825 | } |
||
826 | break; |
||
827 | } |
||
828 | |||
829 | include __DIR__ . '/footer.php'; |
||
830 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.