Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
created

subscription.php (14 issues)

Upgrade to new PHP Analysis Engine

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 - ( http://www.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
 *  Version : $Id: subscription.php 12559 2014-06-02 08:10:39Z beckmi $
26
 * ****************************************************************************
27
 */
28
29
$currentFile = basename(__FILE__);
30
include_once __DIR__ . "/header.php";
31
32
$op            = XoopsRequest::getString('op', 'list_subscriptions');
33
$activationKey = XoopsRequest::getString('actkey', '');
34
$subscr_id     = XoopsRequest::getInt('subscr_id', 0);
35
$subscr_email  = ($op != 'unsub') ? XoopsRequest::getString('subscr_email', '') : '';
36
$ip            =  xoops_getenv('REMOTE_ADDR');
37
38
if ($op == 'save_subscription' || $activationKey != '') {
39
    $xoopsOption['template_main'] = 'xnewsletter_subscription_result.tpl';
40
} else {
41
    $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl';
42
}
43
if (isset($_REQUEST['addnew'])) {
44
    $op = 'addnew_subscription';
45
}
46
if ($activationKey && $op != 'delete_subscription_confirmed' && $op != 'unsub') {
47
    $op = 'save_subscription';
48
}
49
if ($op == 'delete_subscription_confirmed') {
50
    $op = 'delete_subscription';
51
}
52
if ($op == 'unsub') {
53
    $op = 'list_subscriptions';
54
    $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl';
55
    $_SESSION['redirect_mail'] = XoopsRequest::getString('email', '');
56
    $_SESSION['unsub'] = '1';
57
}
58
59
//to avoid errors in debug when xn_groups_change_other
60
$subscr_sex = '';
61
$subscr_firstname = '';
62
$subscr_lastname = '';
63
64
$count_ok = 0;
65
$count_err = 0;
66
$actionProts_ok = array(); // IN PROGRESS: remove from here
67
$actionProts_error = array(); // IN PROGRESS: remove from here
68
69
switch ($op) {
70
    case "resend_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
71
        $actionProts_ok = array();
72
        $actionProts_error = array();
73
        $xoopsOption['template_main'] = 'xnewsletter_subscription_result.tpl';
74
        include_once XOOPS_ROOT_PATH . "/header.php";
75
76
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
77
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
78
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
79
80
        // Breadcrumb
81
        $breadcrumb = new XnewsletterBreadcrumb();
82
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
83
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
84
85
        // resend the email with the confirmation code
86
        $subscr_id = XoopsRequest::getInt('subscr_id', 0);
87
        $subscrCriteria = new CriteriaCompo();
88
        $subscrCriteria->add(new Criteria('subscr_id', $subscr_id));
89
        $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria);
90
        if ($subscrCount > 0) {
91
            $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
92
            $subscr_email = $subscrObj->getVar('subscr_email');
93
            $xoopsMailer = xoops_getMailer();
94
            $xoopsMailer->reset();
95
            $xoopsMailer->setTemplateDir();
96
            $xoopsMailer->useMail();
97
            $xoopsMailer->setTemplate('activate.tpl');
98
            $xoopsMailer->setToEmails($subscr_email);
99
            if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
100
            if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']);
101
            $xoopsMailer->assign('SEX', $subscrObj->getVar('subscr_sex'));
102
            $xoopsMailer->assign('EMAIL', $subscr_email);
103
            $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar('subscr_firstname'));
104
            $xoopsMailer->assign('LASTNAME', $subscrObj->getVar('subscr_lastname'));
105
            $xoopsMailer->assign('IP', $ip);
106
            $activationKey = base64_encode(XOOPS_URL . "||addnew||{$subscr_id}||{$subscrObj->getVar("subscr_actkey")}||{$subscr_email}");
107
            $xoopsMailer->assign('ACTLINK', XOOPS_URL . "/modules/xnewsletter/{$currentFile}?actkey={$activationKey}");
108
            $subject = _MA_XNEWSLETTER_SUBSCRIPTIONSUBJECT . $GLOBALS['xoopsConfig']['sitename'];
109
            $xoopsMailer->setSubject($subject);
110
            if (!$xoopsMailer->send()) {
111
                $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . "<br />" . $xoopsMailer->getErrors();
112
            }
113
            $actionProts_ok[] = str_replace ("%nl", $cat_name, _MA_XNEWSLETTER_SENDMAIL_REG_OK);
114
        } else {
115
            // IN PROGRESS
116
            redirect_header($currentFile, 5, "IN PROGRESS: error");
117
        }
118
        $xoopsTpl->assign('actionProts_ok', $actionProts_ok);
119
        $xoopsTpl->assign('actionProts_error', $actionProts_error);
120
        break;
121
122
    case "save_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
123
        include_once XOOPS_ROOT_PATH . "/header.php";
124
125
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
126
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
127
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
128
129
        // Breadcrumb
130
        $breadcrumb = new XnewsletterBreadcrumb();
131
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
132
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
133
134
        // check right to subscribe directly
135
        $submitterUid = is_object($xoopsUser) ? (int) $xoopsUser->getVar('uid') : 0;
136
        $allowedWithoutActivationKey = false;
137
        if ($submitterUid > 0) {
138
            // user logged in
139
            $submitter_email = $xoopsUser->email();
140 View Code Duplication
            foreach ($xoopsUser->getGroups() as $group) {
141
                if (in_array($group, $xnewsletter->getConfig('xn_groups_without_actkey')) || XOOPS_GROUP_ADMIN == $group) {
142
                    $allowedWithoutActivationKey = true;
143
                    break;
144
                }
145
            }
146
        } else {
0 ignored issues
show
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
147
            // user not logged in
148
            // NOP
149
        }
150
151
        if (!$activationKey) {
152
            // activation key doesn't exist
153
            if (!$GLOBALS["xoopsSecurity"]->check()) {
154
                redirect_header($currentFile, 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
155
            }
156
            if ($subscr_email == '') {
157
                redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL);
158
            }
159
            if (!xnewsletter_checkEmail($subscr_email))
160
                redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL);
161
162
163
            // read current selections and create code for actkey
164
            $cat_selections = array();
165
            $code_selections = '';
166
            $catCriteria = new CriteriaCompo();
167
            $catCriteria->setSort('cat_id');
168
            $catCriteria->setOrder('ASC');
169
            $catObjs = $xnewsletter->getHandler('cat')->getAll($catCriteria);
170
171
            foreach ($catObjs as $cat_id => $catObj) {
172
                // create selection code: cat_id - cat selected - old catsubcr_id - old catsubscr_quited
173
                $code_selections .= ($code_selections == '') ? '' : '|';
174
                $code_selections .= $cat_id . "-";
175
                $code_selections .= (isset($_REQUEST["letter_cats_{$cat_id}"])) ? '1' : '0';
176
                $code_selections .= "-";
177
                $old_catsubcr_id = XoopsRequest::getInt("letter_cats_old_catsubcr_id_{$cat_id}", 0);
178
                $code_selections .= $old_catsubcr_id;
179
                $code_selections .= "-";
180
                $old_catsubcr_quited = XoopsRequest::getInt("letter_cats_old_catsubscr_quited_{$cat_id}", 0);
181
                $code_selections .= $old_catsubcr_quited;
182
            }
183
184
            // save subscriber first
185
            if ($subscr_id > 0) {
186
                $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
187
                $saveType = 'update';
188
            } else {
189
                $subscrObj = $xnewsletter->getHandler('subscr')->create();
190
                $saveType = 'addnew';
191
            }
192
193
            if ($subscr_id < 1 || $allowedWithoutActivationKey) {
194
                // form subscr_email
195
                $subscrObj->setVar('subscr_email', $subscr_email);
196
                // form subscr_uid
197
                $subscr_uid = 0;
198
                $sql = "SELECT `uid` FROM {$xoopsDB->prefix('users')}";
199
                $sql .= " WHERE (`email`='{$subscr_email}')";
200
                $sql .= " LIMIT 1";
201
                if ($user = $xoopsDB->query($sql)) {
202
                    $row_user = $xoopsDB->fetchRow($user);
203
                    $subscr_uid = $row_user[0];
204
                }
205
                $subscrObj->setVar('subscr_uid', (int) $subscr_uid);
206
                // form subscr_submitter
207
                $subscrObj->setVar('subscr_submitter', $submitterUid);
208
            }
209
210
            $subscr_actkey = xoops_makepass();
211
            $subscrObj->setVar('subscr_actkey', $subscr_actkey);
212
            // form subscr_created
213
            //$subscrObj->setVar("subscr_created", time()); //kann eigentlich immer gespeichert werden
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
            //$subscrObj->setVar("subscr_ip", $ip); //kann eigentlich immer gespeichert werden
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
215
            //Nicht speichern, sondern nur beim anlegen und 1. Bestaetigen
216
            if ($subscr_id < 1) {
217
                $subscrObj->setVar('subscr_created', time());
218
                $subscrObj->setVar('subscr_ip', $ip);
219
                $subscrObj->setVar('subscr_activated', 0);
220
            }
221
222
            if ($activationKey || $allowedWithoutActivationKey) {
223
                // subscr_firstname
224
                $subscrObj->setVar('subscr_firstname', XoopsRequest::getString('subscr_firstname', ''));
225
                // subscr_lastname
226
                $subscrObj->setVar('subscr_lastname',  XoopsRequest::getString('subscr_lastname', ''));
227
                // subscr_sex
228
                $subscrObj->setVar('subscr_sex', XoopsRequest::getString('subscr_sex', ''));
229
                // subscr_actoptions
230
                $subscrObj->setVar('subscr_actoptions', '');
231
            } else {
232
                //format subscr_actoptions: selected_newsletters||firstname||lastname||sex
233
                $code_options = array();
234
                $code_options[0] = $code_selections;
235
                $code_options[1] = XoopsRequest::getString('subscr_firstname', '');
236
                $code_options[2] = XoopsRequest::getString('subscr_lastname', '');
237
                $code_options[3] = XoopsRequest::getString('subscr_sex', '');
238
                $code_options[4] = time();
239
                $code_options[5] = $ip;
240
                $subscrObj->setVar('subscr_actoptions', serialize($code_options));
241
            }
242
243
            if ($xnewsletter->getHandler('subscr')->insert($subscrObj)) {
244
                if ($subscr_id < 1) {
245
                    $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_OK;
246
                } else {
247
                    $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_UPDATE_OK;
248
                }
249
                $subscr_id = $subscrObj->getVar('subscr_id');
250
251
                if ($allowedWithoutActivationKey) {
252
                    $isValid = true;
253
                    $cat_selections = explode('|', $code_selections);
254
                } else {
255
                    $isValid = false;
256
                    $xoopsMailer = xoops_getMailer();
257
                    $xoopsMailer->reset();
258
                    $xoopsMailer->setTemplateDir();
259
                    $xoopsMailer->useMail();
260
                    if ($saveType == 'update') {
261
                        $xoopsMailer->setTemplate('update.tpl');
262
                    } else {
263
                        $xoopsMailer->setTemplate('activate.tpl');
264
                    }
265
                    $xoopsMailer->setToEmails($subscr_email);
266
                    if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
267
                    if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']);
268
                    $xoopsMailer->assign('SEX', $subscrObj->getVar("subscr_sex"));
269
                    $xoopsMailer->assign('EMAIL', $subscr_email);
270
                    $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar("subscr_firstname"));
271
                    $xoopsMailer->assign('LASTNAME', $subscrObj->getVar("subscr_lastname"));
272
                    $xoopsMailer->assign('IP', $ip);
273
                    $activationKey = base64_encode(XOOPS_URL . "||{$saveType}||{$subscr_id}||{$subscr_actkey}||{$subscr_email}");
274
                    $xoopsMailer->assign('ACTLINK', XOOPS_URL . "/modules/xnewsletter/{$currentFile}?actkey={$activationKey}");
275
                    $subject = _MA_XNEWSLETTER_SUBSCRIPTIONSUBJECT . $GLOBALS['xoopsConfig']['sitename'];
276
                    $xoopsMailer->setSubject($subject);
277
                    if (!$xoopsMailer->send()) {
278
                        redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . "<br />" . $xoopsMailer->getErrors());
279
                    }
280
                    $actionProts_ok[] = _MA_XNEWSLETTER_SENDMAIL_REG_OK;
281
                }
282
            } else {
283
                redirect_header($currentFile, 20, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVESUBSCR . "<br />" . $subscrObj->getHtmlErrors());
284
            }
285
        } else {
286
            // activation key exist
287
            $activationKey_array = explode('||', base64_decode($activationKey));
288
            $isValid = false;
289
            if ($activationKey_array[0] == XOOPS_URL) { // from here
290
                if (trim($activationKey_array[1]) != '') { // savetype ok
291
                    if ((int) $activationKey_array[2] > 0) { // user is ok
292
                        if (trim($activationKey_array[3]) != '') {
293
                            $isValid = true;
294
                        }
295
                    }
296
                }
297
            }
298
299
            if (!$isValid) {
300
                redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_INVALIDKEY);
301
            } else {
302
                $saveType = trim($activationKey_array[1]);
303
                $subscr_id = (int) $activationKey_array[2];
304
                $subscr_actkey = trim($activationKey_array[3]);
305
306
                //check given data with table subscr
307
                $subscrCriteria = new CriteriaCompo();
308
                $subscrCriteria->add(new Criteria('subscr_id', $subscr_id));
309
                $subscrCriteria->add(new Criteria('subscr_actkey', $subscr_actkey));
310
                $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria);
311
                if ($subscrCount == 0)
312
                    redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NODATAKEY);
313
314
                //read data from table subscr
315
                $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
316
                $actoptions = unserialize(trim($subscrObj->getVar('subscr_actoptions', 'N')));
317
                //format subscr_actoptions:selected_newsletters||firstname||lastname||sex||date||ip
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
318
                $cat_selections = explode('|', trim($actoptions[0]));
319
                $subscr_firstname = trim($actoptions[1]);
320
                $subscr_lastname = trim($actoptions[2]);
321
                $subscr_sex = trim($actoptions[3]);
322
                if ((int) $actoptions[4] < time() - 86400) { //Zeit checken -> 24 Stunden ??
323
                    //Zeit abgelaufen
324
                    $subscrObj->setVar('subscr_actkey', '');
325
                    $subscrObj->setVar('subscr_actoptions', '');
326
                    $xnewsletter->getHandler('subscr')->insert($subscrObj);
327
                    redirect_header($currentFile, 5, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NODATAKEY);
328
                }
329
            }
330
        }
331
332
        if ($isValid) {
333
            // update xnewsletter_subscr
334
            $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
335
            if (!$allowedWithoutActivationKey) {
336
                if ($subscr_actkey != $subscrObj->getVar('subscr_actkey')) {
337
                    redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOVALIDKEY);
338
                }
339
            }
340
            if ($subscrObj->getVar('subscr_activated') == 0) {
341
                $subscrObj->setVar('subscr_created', time());
342
                $subscrObj->setVar('subscr_ip', $ip);
343
                $subscrObj->setVar('subscr_activated', 1);
344
            }
345
            $subscrObj->setVar('subscr_actkey', '');
346
            $subscrObj->setVar('subscr_actoptions', '');
347
348
            if ($activationKey) {
349
                $subscrObj->setVar('subscr_sex', $subscr_sex);
350
                $subscrObj->setVar('subscr_firstname', $subscr_firstname);
351
                $subscrObj->setVar('subscr_lastname', $subscr_lastname);
352
            }
353
            if (!$xnewsletter->getHandler('subscr')->insert($subscrObj)) {
354
                redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVESUBSCR);
355
            } else {
356
                if ($saveType == 'addnew') {
357
                    $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_CLOSED;
358
                } else {
359
                    $actionProts_ok[] = _MA_XNEWSLETTER_SUBSCRIPTION_REG_UPDATE_CLOSED;
360
                }
361
            }
362
            // handle current selections
363
            foreach ($cat_selections as $sel) {
364
                $selection = array();
365
                if ($sel == '') $sel = '0-0-0-0';
366
                $selection = explode('-', $sel);
367
                $cat_id = $selection[0];
368
                $catsubcr = $selection[1];
369
                $catsubcr_id_old = (int) $selection[2];
370
                $catsubcr_quited_old = (int) $selection[3];
371
                $catObj = $xnewsletter->getHandler('cat')->get($cat_id);
372
                $cat_mailinglist = $catObj->getVar('cat_mailinglist');
373
                $cat_name = $catObj->getVar('cat_name');
374
                if ($catsubcr == '1' && $catsubcr_id_old == 0) {
375
                    // subscribe
376
                    $catsubscrObj = $xnewsletter->getHandler('catsubscr')->create();
377
                    //Form catsubscr_catid
378
                    $catsubscrObj->setVar("catsubscr_catid", $cat_id);
379
                    //Form catsubscr_subscrid
380
                    $catsubscrObj->setVar("catsubscr_subscrid", $subscr_id);
381
                    //Form catsubscr_submitter
382
                    $catsubscrObj->setVar("catsubscr_submitter", $submitterUid);
383
                    //Form catsubscr_submitter
384
                    $catsubscrObj->setVar("catsubscr_created", time());
385
                    if ($xnewsletter->getHandler('catsubscr')->insert($catsubscrObj)) {
386
                        $count_ok++;
387
                        if ($catsubcr_id_old > 0) {
388
                            $actionProts_ok[] = str_replace("%nl", $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_NO_CHANGE);
389
                        } else {
390
                            $actionProts_ok[] = str_replace("%nl", $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_SUBSCRIBE);
391
                        }
392
                        //handle mailinglists
393
                        if ($cat_mailinglist > 0) {
394
                            require_once XOOPS_ROOT_PATH . "/modules/xnewsletter/include/mailinglist.php";
395
                            subscribingMLHandler(1, $subscr_id, $cat_mailinglist);
396
                        }
397
                    } else {
398
                        $count_err++;
399
                        $actionProts_error[]= _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors();
400
                    }
401
                } elseif ($catsubcr == '0' && $catsubcr_id_old > 0) {
402
                    // unsubscribe / delete old subscription
403
                    $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubcr_id_old);
404
                    if ($xnewsletter->getHandler('catsubscr')->delete($catsubscrObj, true)) {
405
                        //handle mailinglists
406
                        if ($cat_mailinglist > 0) {
407
                            require_once XOOPS_ROOT_PATH . "/modules/xnewsletter/include/mailinglist.php";
408
                            subscribingMLHandler(0, $subscr_id, $cat_mailinglist);
409
                        }
410
                    } else {
411
                        $count_err++;
412
                        $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors();
413
                    }
414
415
                    if ($count_err > 0) {
416
                        redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELNOTOK);
417
                    }
418
                    $actionProts_ok[] = str_replace ("%nl", $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_UNSUBSCRIBE);
419
                } elseif ($catsubcr_id_old > 0 && $catsubcr_quited_old > 0) {
420
                    // newsletter stay selected, but catsubscr_quited will be removed
421
                    $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubcr_id_old);
422
                    //Form catsubscr_quited
423
                    $catsubscrObj->setVar('catsubscr_quited', '0');
424
425
                    if ($xnewsletter->getHandler('catsubscr')->insert($catsubscrObj)) {
426
                        $count_ok++;
427
                        $actionProts_ok[] = str_replace ("%nl", $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_DAT_QUITED_REMOVED);
428
                    } else {
429
                        $count_err++;
430
                        $actionProts_error[] = _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SAVECATSUBSCR . $catsubscrObj->getHtmlErrors();
431
                    }
432
                } elseif ($catsubcr_id_old > 0) {
433
                    // newsletter still subscribed
434
                    $actionProts_ok[] = str_replace ("%nl", $cat_name, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_NO_CHANGE);
435
                } else {
0 ignored issues
show
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
436
                    // nothing to do
437
                }
438
            }
439
        }
440
441
442
443
        if (isset($submitter_email) && ($submitter_email != '') && ($submitter_email != $subscr_email)) {
444
            //send infomail to subscriber, because current user is not the subscriber
445
            if ($subscr_sex == '' && $subscr_firstname == '' && $subscr_lastname == '') {
446
                $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
447
                $subscr_sex = $subscrObj->getVar('subscr_sex');
448
                $subscr_firstname = $subscrObj->getVar('subscr_firstname');
449
                $subscr_lastname = $subscrObj->getVar('subscr_lastname');
450
            }
451
            $xoopsMailer = xoops_getMailer();
452
            $xoopsMailer->reset();
453
            $xoopsMailer->setTemplateDir();
454
            $xoopsMailer->useMail();
455
            $xoopsMailer->setHTML();
456
            $xoopsMailer->setTemplate('info_change.tpl');
457
            $xoopsMailer->setToEmails($subscr_email);
458
            if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
459
            if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']);
460
            $xoopsMailer->assign('SEX', $subscr_sex);
461
            $xoopsMailer->assign('EMAIL', $subscr_email);
462
            $xoopsMailer->assign('FIRSTNAME', $subscr_firstname);
463
            $xoopsMailer->assign('LASTNAME', $subscr_lastname);
464
465
            $xoopsMailer->assign('IP', $ip);
466
            $actlink = XOOPS_URL . "/modules/xnewsletter/{$currentFile}?subscr_email={$subscr_email}";
467
            $xoopsMailer->assign('ACTLINK', $actlink);
468
            $user_link = XOOPS_URL . "/userinfo.php?uid=" . $xoopsUser->uid();
469
            $user_name = $xoopsUser->name();
470
            $xoopsMailer->assign('USERLINK', $user_link);
471
            $xoopsMailer->assign('USERNAME', $user_name);
472
            $subject_change = _MA_XNEWSLETTER_SUBSCRIPTION_SUBJECT_CHANGE . $GLOBALS['xoopsConfig']['sitename'];
473
            $xoopsMailer->setSubject($subject_change);
474
            if ($xoopsMailer->send()) {
475
                $actionProts_ok[] = str_replace("%e", $subscr_email, _MA_XNEWSLETTER_SUBSCRIPTION_PROT_SENT_INFO);
476
            } else {
477
                redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_SENDACTKEY . "<br />" . $xoopsMailer->getErrors());
478
            }
479
        }
480
481
        $xoopsTpl->assign('actionProts_ok', $actionProts_ok);
482
483
        if ($count_err > 0) {
484
            $xoopsTpl->assign('subscription_result', _MA_XNEWSLETTER_SUBSCRIPTION_ERROR);
485
            $xoopsTpl->assign('actionProts_error', $actionProts_error);
486
        } else {
487
            $xoopsTpl->assign('subscription_result', _MA_XNEWSLETTER_SUBSCRIPTION_OK);
488
        }
489
        break;
490
491
492
493
    case "add_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
494
    case "create_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
495
        $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl';
496
        include_once XOOPS_ROOT_PATH . "/header.php";
497
498
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
499
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
500
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
501
502
        // Breadcrumb
503
        $breadcrumb = new XnewsletterBreadcrumb();
504
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
505
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
506
507
        // get create subscr form
508
        if ($subscr_email != '') {
509
            //existing email
510
            if (!xnewsletter_checkEmail($subscr_email)) {
511
                redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL);
512
            }
513
        } elseif (is_object($xoopsUser) && isset($xoopsUser)) {
514
            //take actual xoops user
515
            $subscr_email = $xoopsUser->email();
516
        } else {
517
            $subscr_email = '';
518
        }
519
        $subscrObj = $xnewsletter->getHandler('subscr')->create();
520
        $subscrObj->setVar('subscr_email', $subscr_email);
521
        $subscrForm = $subscrObj->getForm();
522
        $xoopsTpl->assign('xnewsletter_content', $subscrForm->render());
523
        break;
524
525
526
527
    case "edit_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
528
        $xoopsOption['template_main'] = 'xnewsletter_subscription.tpl';
529
        include_once XOOPS_ROOT_PATH . "/header.php";
530
531
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
532
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
533
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
534
535
        // Breadcrumb
536
        $breadcrumb = new XnewsletterBreadcrumb();
537
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
538
        $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, XNEWSLETTER_URL . '/subscription.php?op=list_subscriptions');
539
        $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIPTION_EDIT, '');
540
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
541
542
        // get edit subscr form
543
        $subscr_id = XoopsRequest::getInt('subscr_id', 0);
544
        if ($subscr_id <= 0) {
545
            redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOID);
546
        }
547
        $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
548
        $subscrForm = $subscrObj->getForm();
549
        $xoopsTpl->assign('xnewsletter_content', $subscrForm->render());
550
        break;
551
552
553
554
    case "delete_subscription" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
555
        include_once XOOPS_ROOT_PATH . "/header.php";
556
557
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
558
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
559
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
560
561
        // Breadcrumb
562
        $breadcrumb = new XnewsletterBreadcrumb();
563
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
564
        $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, XNEWSLETTER_URL . '/subscription.php?op=list_subscriptions');
565
        $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIPTION_DELETE, '');
566
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
567
568
        if (!$activationKey) {
569
            if ($subscr_id < 1) {
570
                redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOID);
571
            }
572
        }
573
574
        if ((isset($_POST['ok']) && $_POST['ok'] == true) || $activationKey) {
575
            $count_err = 0;
576
            $actionProts_error = '';
577
578
            // check right to unsubscribe directly
579
            $submitterUid = is_object($xoopsUser) ? (int) $xoopsUser->getVar('uid') : 0;
580
            if ($submitterUid == 0) {
581
                // user not logged in
582
                $allowedWithoutActivationKey = false;
583
            } else {
584
                // user logged in
585
                $allowedWithoutActivationKey = false;
586 View Code Duplication
                foreach ($xoopsUser->getGroups() as $group) {
587
                    if (in_array($group, $xnewsletter->getConfig('xn_groups_without_actkey')) || XOOPS_GROUP_ADMIN == $group) {
588
                        $allowedWithoutActivationKey = true;
589
                        break;
590
                    }
591
                }
592
            }
593
594
            if ($activationKey || $allowedWithoutActivationKey) {
595
                // got actkey or user is allowed to delete without actkey
596
                $isValid = false;
597
                if ($activationKey) {
598
                    $activationKey_array = explode('||', base64_decode($activationKey));
599
                    $subscr_id = (int) $activationKey_array[1];
600
                    $subscr_actkey = trim($activationKey_array[2]);
601
                    $subscr_email = trim($activationKey_array[3]);
602
                    // check activation key
603
                    if (($activationKey_array[0] == XOOPS_URL) && ((int) $activationKey_array[1] > 0) && (trim($activationKey_array[2]) != ''))
604
                        $isValid = true;
605
                } elseif ($allowedWithoutActivationKey) {
606
                    $isValid = true;
607
                } else {
608
                    $isValid = false;
609
                }
610
611
                if ($isValid) {
612
                    $subscrCriteria = new CriteriaCompo();
613
                    $subscrCriteria->add(new Criteria('subscr_email', $subscr_email));
614
                    $subscrCriteria->add(new Criteria('subscr_id', $subscr_id));
615
                    if ($activationKey)
616
                        $subscrCriteria->add(new Criteria('subscr_actkey', $subscr_actkey));
617
                    $subscrCriteria->setLimit(1);
618
                    $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria);
619
620
                    if ($subscrCount != 1) {
621
                        redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR);
622
                    }
623
624
                    $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
625
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
626
                    $sql = "SELECT subscr_id";
627
                    $sql.= " FROM {$xoopsDB->prefix("xnewsletter_subscr")}";
628
                    $sql.= " WHERE (subscr_email='{$subscr_email}' AND subscr_id={$subscr_id}";
629
                    if ($activationKey)
630
                        $sql .= " AND subscr_actkey='{$code}'";
631
                    $sql .= ") LIMIT 1;";
632
                    $subscr_id_test = 0;
633
                    if ($user = $xoopsDB->query($sql)) {
634
                        $row_user = $xoopsDB->fetchRow($user);
635
                        $subscr_id_test = $row_user[0];
636
                    }
637
                    if ($subscr_id != $subscr_id_test) {
638
                        redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR);
639
                    }
640
                    $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
641
*/
642
                    // delete subscriber
643 View Code Duplication
                    if (!$xnewsletter->getHandler('subscr')->delete($subscrObj, true)) {
644
                        $actionProts_error = $subscrObj->getHtmlErrors() . "<br/><br/><br/>";
645
                        $count_err++;
646
                    }
647
                    //delete subscription
648
                    $catsubscrCriteria = new CriteriaCompo();
649
                    $catsubscrCriteria->add(new Criteria('catsubscr_subscrid', $subscr_id));
650
                    $catsubscrCount = $xnewsletter->getHandler('catsubscr')->getCount($catsubscrCriteria);
651 View Code Duplication
                    if ($catsubscrCount > 0) {
652
                        $catsubscrObjs = $xnewsletter->getHandler('catsubscr')->getAll($catsubscrCriteria);
653
                        foreach (array_keys($catsubscrObjs) as $cat) {
654
                            $catsubscrObj = $xnewsletter->getHandler('catsubscr')->get($catsubscrObjs[$cat]->getVar("catsubscr_id"));
655
                            $catObj = $xnewsletter->getHandler('cat')->get($catsubscrObjs[$cat]->getVar("catsubscr_catid"));
656
                            $cat_mailinglist = $catObj->getVar("cat_mailinglist");
657
658
                            if ($xnewsletter->getHandler('catsubscr')->delete($catsubscrObj, true)) {
659
                                //handle mailinglists
660
                                if ($cat_mailinglist > 0) {
661
                                    require_once XOOPS_ROOT_PATH . "/modules/xnewsletter/include/mailinglist.php";
662
                                    subscribingMLHandler(0, $subscr_id, $cat_mailinglist);
663
                                }
664
                            } else {
665
                                $actionProts_error .= $catsubscrObj->getHtmlErrors();
666
                                $count_err++;
667
                            }
668
                        }
669
                    }
670
                } else {
671
                    redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR);
672
                }
673
674
675
                if ($count_err == 0) {
676
                    redirect_header('index.php', 3, _AM_XNEWSLETTER_FORMDELOK);
677
                } else {
678
                    echo $actionProts_error;
679
                }
680
            } else {
681
                if (!$GLOBALS['xoopsSecurity']->check()) {
682
                    redirect_header('subscr.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
683
                }
684
685
                $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
686
                $subscr_actkey = xoops_makepass();
687
                $subscrObj->setVar('subscr_actkey', $subscr_actkey);
688
                if (!$xnewsletter->getHandler('subscr')->insert($subscrObj)) {
689
                    redirect_header($currentFile, 2, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR);
690
                }
691
                if (!$allowedWithoutActivationKey) {
692
                    $xoopsMailer = xoops_getMailer();
693
                    $xoopsMailer->reset();
694
                    $xoopsMailer->setTemplateDir();
695
                    $xoopsMailer->useMail();
696
                    $xoopsMailer->setTemplate('delete.tpl');
697
                    $xoopsMailer->setToEmails($subscrObj->getVar('subscr_email'));
698
                    if (isset($xoopsConfig['adminmail'])) $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
699
                    if (isset($xoopsConfig['sitename'])) $xoopsMailer->setFromName($xoopsConfig['sitename']);
700
                    $xoopsMailer->assign('SEX', $subscrObj->getVar('subscr_sex'));
701
                    $xoopsMailer->assign('EMAIL', $subscrObj->getVar('subscr_email'));
702
                    $xoopsMailer->assign('FIRSTNAME', $subscrObj->getVar('subscr_firstname'));
703
                    $xoopsMailer->assign('LASTNAME', $subscrObj->getVar('subscr_lastname'));
704
                    $xoopsMailer->assign('IP', $ip);
705
                    $activationKey = base64_encode(XOOPS_URL . "||{$subscrObj->getVar('subscr_id')}||{$subscrObj->getVar('subscr_actkey')}||{$subscrObj->getVar('subscr_email')}");
706
                    $actLink = XOOPS_URL . "/modules/xnewsletter/{$currentFile}?op=delete_subscription_confirmed&actkey={$activationKey}";
707
                    $xoopsMailer->assign('ACTLINK', $actLink);
708
                    $subject_delete = _MA_XNEWSLETTER_DELETESUBJECT . $GLOBALS['xoopsConfig']['sitename'];
709
                    $xoopsMailer->setSubject($subject_delete);
710
                    if (!$xoopsMailer->send()) {
711
                        redirect_header($currentFile, 10, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR . "<br />" . $xoopsMailer->getErrors());
712
                    }
713
                }
714
                redirect_header('index.php', 3, _MA_XNEWSLETTER_SENDMAIL_UNREG_OK);
715
            }
716
        } else {
717
            $subscrObj = $xnewsletter->getHandler('subscr')->get($subscr_id);
718
            xoops_confirm(array('ok' => true, 'subscr_id' => $subscr_id, 'subscr_email' => $subscr_email, 'op' => 'delete_subscription'), $currentFile, sprintf(_MA_XNEWSLETTER_SUBSCRIPTION_DELETE_SURE));
719
        }
720
        break;
721
722
    case "list_subscriptions" :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
723
    default :
0 ignored issues
show
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
724
        $xoopsOption['template_main'] = 'xnewsletter_subscription_list_subscriptions.tpl';
725
        include_once XOOPS_ROOT_PATH . "/header.php";
726
727
        $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css');
728
        $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page
729
        $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description
730
731
        // Breadcrumb
732
        $breadcrumb = new XnewsletterBreadcrumb();
733
        $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL);
734
        $breadcrumb->addLink(_MD_XNEWSLETTER_SUBSCRIBE, '');
735
        $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render());
736
737
        $showSubscrSearchForm = true;
738
        $showSubscrForm = false;
739
740
        $subscr_id = 0;
741
        // get subscr email
742
        $subscr_email = XoopsRequest::getString('subscr_email', '');
743
        if ($subscr_email != '') {
744
            // existing email from search form
745
            if (!xnewsletter_checkEmail($subscr_email))
746
                redirect_header($currentFile, 3, _MA_XNEWSLETTER_SUBSCRIPTION_ERROR_NOEMAIL);
747
            xoops_load("captcha");
748
            $xoopsCaptcha = XoopsCaptcha::getinstance();
749
            if (!$xoopsCaptcha->verify()) {
750
                $_SESSION['redirect_mail'] = $subscr_email;
751
                redirect_header($currentFile, 3, $xoopsCaptcha->getMessage());
752
            } else {
753
                $showSubscrSearchForm = false;
754
            }
755
        } elseif (is_object($xoopsUser) && isset($xoopsUser)) {
756
            // take actual xoops user email
757
            $subscr_email = $xoopsUser->email();
758
            $showSubscrSearchForm = false;
759
        } else {
760
            $subscr_email = '';
761
        }
762
763
        // show search subscr form
764
        $xoopsTpl->assign('showSubscrSearchForm', $showSubscrSearchForm);
765
        if ($showSubscrSearchForm) {
766
            // show form search
767
            $subscrObj = $xnewsletter->getHandler('subscr')->create();
768
            $redirect_mail = (isset($_SESSION['redirect_mail'])) ? $_SESSION['redirect_mail'] : '';
769
            if ($redirect_mail != '') {
770
                $subscrObj->setVar('subscr_email', $redirect_mail);
771
                $subscr_email = $redirect_mail;
772
            }
773
            $subscrObj->setVar('subscr_email', $subscr_email);
774
            $xoopsTpl->assign('subscrSearchForm', $subscrObj->getSearchForm()->render());
775
        }
776
777
        if (isset($_SESSION['redirect_mail'])) {
778
            if (!isset($_SESSION['unsub'])) {
779
                $subscr_email = '';
780
            } else {
781
                unset($_SESSION['unsub']);
782
            }
783
            unset($_SESSION['redirect_mail']);
784
        }
785
786
        if ($subscr_email != '') {
787
            // look for existing subscriptions
788
            $subscrCriteria = new CriteriaCompo();
789
            $subscrCriteria->add(new Criteria('subscr_email', $subscr_email));
790
            $subscrCriteria->setSort('subscr_id');
791
            $subscrCriteria->setOrder('ASC');
792
            $subscrCount = $xnewsletter->getHandler('subscr')->getCount($subscrCriteria);
793
            $xoopsTpl->assign('subscrCount', $subscrCount);
794
795
            if ($subscrCount > 0) {
796
                $subscrObjs = $xnewsletter->getHandler('subscr')->getAll($subscrCriteria);
797
                foreach ($subscrObjs as $subscr_id => $subscrObj) {
798
                    $subscr_array = $subscrObj->toArray();
799
                    $subscr_array['subscr_created_timestamp'] = formatTimestamp($subscrObj->getVar('subscr_created'), $xnewsletter->getConfig('dateformat'));
800
801
                    $catsubscrCriteria = new CriteriaCompo();
802
                    $catsubscrCriteria->add(new Criteria('catsubscr_subscrid', $subscr_id));
803
                    $catsubscrCriteria->setSort('catsubscr_id');
804
                    $catsubscrCriteria->setOrder('ASC');
805
                    $catsubscrCount = $xnewsletter->getHandler('catsubscr')->getCount($catsubscrCriteria);
806
                    $catsubscrObjs = $xnewsletter->getHandler('catsubscr')->getAll($catsubscrCriteria);
807
                    foreach ($catsubscrObjs as $catsubscr_id => $catsubscrObj) {
808
                        $catsubscr_array = $catsubscrObj->toArray();
809
                        $catObj = $xnewsletter->getHandler('cat')->get($catsubscrObj->getVar('catsubscr_catid'));
810
                        $cat_array = $catObj->toArray();
811
                        $catsubscr_array['cat'] = $cat_array;
812
                        $subscr_array['catsubscrs'][] = $catsubscr_array;
813
                        unset($catsubscr_array);
814
                        unset($cat_array);
815
                    }
816
                    $xoopsTpl->append('subscrs', $subscr_array);
817
                }
818
            } else {
819
                // show subscr form
820
                $xoopsTpl->assign('showSubscrForm', true);
821
                $subscrObj = $xnewsletter->getHandler('subscr')->create();
822
                $subscrObj->setVar('subscr_email', $subscr_email);
823
                $form = $subscrObj->getForm($currentFile);
824
                $xoopsTpl->assign('subscrForm', $form->render());
825
            }
826
        }
827
        break;
828
}
829
830
include __DIR__ . '/footer.php';
831