Completed
Pull Request — master (#27)
by Michael
01:42
created

admin/mailinglist.php (1 issue)

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 - ( 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    GNU General Public License 2.0
22
 * @package    xnewsletter
23
 * @author     Goffy ( [email protected] )
24
 *
25
 * ****************************************************************************
26
 */
27
28
use Xmf\Request;
29
30
$currentFile = basename(__FILE__);
31
require_once __DIR__ . '/admin_header.php';
32
xoops_cp_header();
33
34
// We recovered the value of the argument op in the URL$
35
$op = \Xmf\Request::getString('op', 'list');
36
37
switch ($op) {
38
    case 'list':
39
    default:
40
        $adminObject->displayNavigation($currentFile);
41
        $adminObject->addItemButton(_AM_XNEWSLETTER_NEWMAILINGLIST, '?op=new_mailinglist', 'add');
42
        $adminObject->displayButton('left');
43
        $limit               = $helper->getConfig('adminperpage');
44
        $mailinglistCriteria = new \CriteriaCompo();
45
        $mailinglistCriteria->setSort('mailinglist_id ASC, mailinglist_email');
46
        $mailinglistCriteria->setOrder('ASC');
47
        $mailinglistCount = $helper->getHandler('Mailinglist')->getCount();
48
        $start            = \Xmf\Request::getInt('start', 0);
49
        $mailinglistCriteria->setStart($start);
50
        $mailinglistCriteria->setLimit($limit);
51
        $mailinglistObjs = $helper->getHandler('Mailinglist')->getAll($mailinglistCriteria);
52 View Code Duplication
        if ($mailinglistCount > $limit) {
53
            require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
54
            $pagenav = new \XoopsPageNav($mailinglistCount, $limit, $start, 'start', 'op=list');
55
            $pagenav = $pagenav->renderNav(4);
56
        } else {
57
            $pagenav = '';
58
        }
59
60
        // View Table
61
        echo "
62
        <table class='outer width100' cellspacing='1'>
63
            <tr>
64
                <th>" . _AM_XNEWSLETTER_MAILINGLIST_ID . '</th>
65
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_NAME . '</th>
66
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_EMAIL . '</th>
67
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_LISTNAME . '</th>
68
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_SUBSCRIBE . '</th>
69
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_UNSUBSCRIBE . '</th>
70
                <th>' . _AM_XNEWSLETTER_MAILINGLIST_CREATED . '</th>
71
                <th>' . _AM_XNEWSLETTER_FORMACTION . '</th>
72
            </tr>
73
            ';
74
        if ($mailinglistCount > 0) {
75
            $class = 'odd';
76
            foreach ($mailinglistObjs as $mailinglist_id => $mailinglistObj) {
77
                echo "<tr class='{$class}'>";
78
                $class = ('even' === $class) ? 'odd' : 'even';
79
                echo '<td>' . $mailinglist_id . '</td>';
80
                echo '<td>' . $mailinglistObj->getVar('mailinglist_name') . '</td>';
81
                echo '<td>' . $mailinglistObj->getVar('mailinglist_email') . '</td>';
82
                echo '<td>' . $mailinglistObj->getVar('mailinglist_listname') . '</td>';
83
                echo '<td>' . $mailinglistObj->getVar('mailinglist_subscribe') . '</td>';
84
                echo '<td>' . $mailinglistObj->getVar('mailinglist_unsubscribe') . '</td>';
85
                echo '<td>' . formatTimestamp($mailinglistObj->getVar('mailinglist_created'), 'S') . '</td>';
86
                echo '<td>';
87
                echo "    <a href='?op=edit_mailinglist&mailinglist_id=" . $mailinglist_id . "'><img src=" . XNEWSLETTER_ICONS_URL . "/xn_edit.png alt='" . _EDIT . "' title='" . _EDIT . "'></a>";
88
                echo "    <a href='?op=delete_mailinglist&mailinglist_id=" . $mailinglist_id . "'><img src=" . XNEWSLETTER_ICONS_URL . "/xn_delete.png alt='" . _DELETE . "' title='" . _DELETE . "'></a>";
89
                echo '</td>';
90
                echo '</tr>';
91
            }
92
        }
93
        echo '</table>';
94
        echo '<br>';
95
        echo "<div>{$pagenav}</div>";
96
        echo '<br>';
97
        break;
98
    case 'new_mailinglist':
99
        $adminObject->displayNavigation($currentFile);
100
        $adminObject->addItemButton(_AM_XNEWSLETTER_MAILINGLISTLIST, '?op=list', 'list');
101
        $adminObject->displayButton('left');
102
103
        $mailinglistObj = $helper->getHandler('Mailinglist')->create();
104
        $form           = $mailinglistObj->getForm();
105
        $form->display();
106
        break;
107
    case 'save_mailinglist':
108
        if (!$GLOBALS['xoopsSecurity']->check()) {
109
            redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
110
        }
111 View Code Duplication
        if (\Xmf\Request::hasVar('mailinglist_id', 'REQUEST')) {
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.

Loading history...
112
            $mailinglistObj = $helper->getHandler('Mailinglist')->get($_REQUEST['mailinglist_id']);
113
        } else {
114
            $mailinglistObj = $helper->getHandler('Mailinglist')->create();
115
        }
116
        $mailinglistObj->setVar('mailinglist_name', $_REQUEST['mailinglist_name']);
117
        $mailinglistObj->setVar('mailinglist_email', $_REQUEST['mailinglist_email']);
118
        $mailinglistObj->setVar('mailinglist_listname', $_REQUEST['mailinglist_listname']);
119
        $mailinglistObj->setVar('mailinglist_subscribe', $_REQUEST['mailinglist_subscribe']);
120
        $mailinglistObj->setVar('mailinglist_unsubscribe', $_REQUEST['mailinglist_unsubscribe']);
121
        $mailinglistObj->setVar('mailinglist_submitter', $_REQUEST['mailinglist_submitter']);
122
        $mailinglistObj->setVar('mailinglist_created', $_REQUEST['mailinglist_created']);
123
124
        if ($helper->getHandler('Mailinglist')->insert($mailinglistObj)) {
125
            redirect_header('?op=list', 3, _AM_XNEWSLETTER_FORMOK);
126
        }
127
128
        echo $mailinglistObj->getHtmlErrors();
129
        $form = $mailinglistObj->getForm();
130
        $form->display();
131
        break;
132 View Code Duplication
    case 'edit_mailinglist':
133
        $adminObject->displayNavigation($currentFile);
134
        $adminObject->addItemButton(_AM_XNEWSLETTER_NEWMAILINGLIST, '?op=new_mailinglist', 'add');
135
        $adminObject->addItemButton(_AM_XNEWSLETTER_MAILINGLISTLIST, '?op=list', 'list');
136
        $adminObject->displayButton('left');
137
138
        $mailinglistObj = $helper->getHandler('Mailinglist')->get($_REQUEST['mailinglist_id']);
139
        $form           = $mailinglistObj->getForm();
140
        $form->display();
141
        break;
142 View Code Duplication
    case 'delete_mailinglist':
143
        $mailinglistObj = $helper->getHandler('Mailinglist')->get($_REQUEST['mailinglist_id']);
144
        if (true === \Xmf\Request::getBool('ok', false, 'POST')) {
145
            if (!$GLOBALS['xoopsSecurity']->check()) {
146
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
147
            }
148
            if ($helper->getHandler('Mailinglist')->delete($mailinglistObj)) {
149
                redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELOK);
150
            } else {
151
                echo $mailinglistObj->getHtmlErrors();
152
            }
153
        } else {
154
            xoops_confirm([
155
                              'ok'             => true,
156
                              'mailinglist_id' => $_REQUEST['mailinglist_id'],
157
                              'op'             => 'delete_mailinglist',
158
                          ], $_SERVER['REQUEST_URI'], sprintf(_AM_XNEWSLETTER_FORMSUREDEL, $mailinglistObj->getVar('mailinglist_email')));
159
        }
160
        break;
161
}
162
require_once __DIR__ . '/admin_footer.php';
163