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

class/cat.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 - ( 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
 *
21
 * @copyright  Goffy ( wedega.com )
22
 * @license    GPL 2.0
23
 * @package    xnewsletter
24
 * @author     Goffy ( [email protected] )
25
 *
26
 *  Version : $Id $
27
 * ****************************************************************************
28
 */
29
30
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
31
include_once dirname(__DIR__) . '/include/common.php';
32
33
/**
34
 * Class XnewsletterCat
35
 */
36
class XnewsletterCat extends XoopsObject
37
{
38
    /**
39
     * @var xnewsletter
40
     * @access public
41
     */
42
    public $xnewsletter = null;
43
44
    //Constructor
45
    /**
46
     *
47
     */
48 View Code Duplication
    public function __construct()
0 ignored issues
show
This method seems to be duplicated in 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...
49
    {
50
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
51
        $this->db          = XoopsDatabaseFactory::getDatabaseConnection();
52
        $this->initVar("cat_id", XOBJ_DTYPE_INT, null, false, 8);
53
        $this->initVar("cat_name", XOBJ_DTYPE_TXTBOX, null, false, 100);
54
        $this->initVar("cat_info", XOBJ_DTYPE_TXTAREA, null, false);
55
        $this->initVar("cat_mailinglist", XOBJ_DTYPE_INT, null, false, 8);
56
        $this->initVar("cat_submitter", XOBJ_DTYPE_INT, null, false, 10);
57
        $this->initVar("cat_created", XOBJ_DTYPE_INT, null, false, 10);
58
    }
59
60
    /**
61
     * @param bool $action
62
     *
63
     * @return XoopsThemeForm
64
     */
65
    public function getForm($action = false)
66
    {
67
        global $xoopsDB;
68
69
        $gperm_handler = xoops_gethandler('groupperm');
70
71
        if ($action === false) {
72
            $action = $_SERVER["REQUEST_URI"];
73
        }
74
75
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_CAT_ADD) : sprintf(_AM_XNEWSLETTER_CAT_EDIT);
76
77
        include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
78
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
79
        $form->setExtra('enctype="multipart/form-data"');
80
81
        $form->addElement(new XoopsFormText(_AM_XNEWSLETTER_CAT_NAME, "cat_name", 50, 255, $this->getVar("cat_name", 'e')), true);
82
        $form->addElement(new XoopsFormDhtmlTextArea(_AM_XNEWSLETTER_CAT_INFO, "cat_info", $this->getVar("cat_info", 'e')), false);
83
84
        $member_handler = xoops_gethandler('member');
85
        $userGroups     = $member_handler->getGroupList();
86
87
        // create admin checkbox
88
        foreach ($userGroups as $group_id => $group_name) {
89
            if ($group_id == XOOPS_GROUP_ADMIN) {
90
                $group_id_admin   = $group_id;
91
                $group_name_admin = $group_name;
92
            }
93
        }
94
        $select_perm_admin = new XoopsFormCheckBox("", "admin", XOOPS_GROUP_ADMIN);
95
        $select_perm_admin->addOption($group_id_admin, $group_name_admin);
96
        $select_perm_admin->setExtra("disabled='disabled'");
97
98
        // ********************************************************
99
        // permission read cat
100
        $cat_gperms_read     = $gperm_handler->getGroupIds('newsletter_read_cat', $this->getVar("cat_id"), $this->xnewsletter->getModule()->mid());
101
        $arr_cat_gperms_read = $this->isNew() ? "0" : $cat_gperms_read;
102
103
        $perms_tray = new XoopsFormElementTray(_AM_XNEWSLETTER_CAT_GPERMS_READ, '');
104
        // checkbox webmaster
105
        $perms_tray->addElement($select_perm_admin, false);
106
        // checkboxes other groups
107
        $select_perm = new XoopsFormCheckBox("", "cat_gperms_read", $arr_cat_gperms_read);
108
        foreach ($userGroups as $group_id => $group_name) {
109
            if ($group_id != XOOPS_GROUP_ADMIN) {
110
                $select_perm->addOption($group_id, $group_name);
111
            }
112
        }
113
        $perms_tray->addElement($select_perm, false);
114
        $form->addElement($perms_tray, false);
115
        unset($perms_tray);
116
        unset($select_perm);
117
118
        // ********************************************************
119
        // permission create cat
120
        $cat_gperms_create     = $gperm_handler->getGroupIds('newsletter_create_cat', $this->getVar("cat_id"), $this->xnewsletter->getModule()->mid());
121
        $arr_cat_gperms_create = $this->isNew() ? "0" : $cat_gperms_create;
122
123
        $perms_tray = new XoopsFormElementTray(_AM_XNEWSLETTER_CAT_GPERMS_CREATE . _AM_XNEWSLETTER_CAT_GPERMS_CREATE_DESC, '');
124
        // checkbox webmaster
125
        $perms_tray->addElement($select_perm_admin, false);
126
        // checkboxes other groups
127
        $select_perm = new XoopsFormCheckBox("", "cat_gperms_create", $arr_cat_gperms_create);
128 View Code Duplication
        foreach ($userGroups as $group_id => $group_name) {
129
            if ($group_id != XOOPS_GROUP_ADMIN && $group_id != XOOPS_GROUP_ANONYMOUS) {
130
                $select_perm->addOption($group_id, $group_name);
131
            }
132
        }
133
        $perms_tray->addElement($select_perm, false);
134
        $form->addElement($perms_tray, false);
135
        unset($perms_tray);
136
        unset($select_perm);
137
138
        // ********************************************************
139
        // permission admin cat
140
        $cat_gperms_admin     = $gperm_handler->getGroupIds('newsletter_admin_cat', $this->getVar("cat_id"), $this->xnewsletter->getModule()->mid());
141
        $arr_cat_gperms_admin = $this->isNew() ? "0" : $cat_gperms_admin;
142
143
        $perms_tray = new XoopsFormElementTray(_AM_XNEWSLETTER_CAT_GPERMS_ADMIN . _AM_XNEWSLETTER_CAT_GPERMS_ADMIN_DESC, '');
144
        // checkbox webmaster
145
        $perms_tray->addElement($select_perm_admin, false);
146
        // checkboxes other groups
147
        $select_perm = new XoopsFormCheckBox("", "cat_gperms_admin", $arr_cat_gperms_admin);
148 View Code Duplication
        foreach ($userGroups as $group_id => $group_name) {
149
            if ($group_id != XOOPS_GROUP_ADMIN && $group_id != XOOPS_GROUP_ANONYMOUS) {
150
                $select_perm->addOption($group_id, $group_name);
151
            }
152
        }
153
        $perms_tray->addElement($select_perm, false);
154
        $form->addElement($perms_tray, false);
155
        unset($perms_tray);
156
        unset($select_perm);
157
158
        // ********************************************************
159
        // permission list subscriber of this cat
160
        $cat_gperms_list      = $gperm_handler->getGroupIds('newsletter_list_cat', $this->getVar("cat_id"), $this->xnewsletter->getModule()->mid());
161
        $arr_cat_gperms_admin = $this->isNew() ? "0" : $cat_gperms_list;
162
163
        $perms_tray = new XoopsFormElementTray(_AM_XNEWSLETTER_CAT_GPERMS_LIST, '');
164
        // checkbox webmaster
165
        $perms_tray->addElement($select_perm_admin, false);
166
        // checkboxes other groups
167
        $select_perm = new XoopsFormCheckBox("", "cat_gperms_list", $arr_cat_gperms_admin);
168 View Code Duplication
        foreach ($userGroups as $group_id => $group_name) {
169
            if ($group_id != XOOPS_GROUP_ADMIN && $group_id != XOOPS_GROUP_ANONYMOUS) {
170
                $select_perm->addOption($group_id, $group_name);
171
            }
172
        }
173
        $perms_tray->addElement($select_perm, false);
174
        $form->addElement($perms_tray, false);
175
        unset($perms_tray);
176
        unset($select_perm);
177
178
        $cat_mailinglist  = $this->isNew() ? "0" : $this->getVar("cat_mailinglist");
179
        $mailinglistCriteria = new CriteriaCompo();
180
        $mailinglistCriteria->setSort("mailinglist_id");
181
        $mailinglistCriteria->setOrder("ASC");
182
        $numrows_mailinglist = $this->xnewsletter->getHandler('mailinglist')->getCount();
183
        if ($numrows_mailinglist > 0) {
184
            $opt_mailinglist = new XoopsFormRadio(_AM_XNEWSLETTER_LETTER_MAILINGLIST, "cat_mailinglist", $cat_mailinglist);
185
            $opt_mailinglist->addOption("0", _AM_XNEWSLETTER_LETTER_MAILINGLIST_NO);
186
            $mailinglistObjs = $this->xnewsletter->getHandler('mailinglist')->getAll($mailinglistCriteria);
187
            foreach ($mailinglistObjs as $mailinglist_id => $mailinglistObj) {
188
                $opt_mailinglist->addOption($mailinglist_id, $mailinglistObj->getVar("mailinglist_name"));
189
            }
190
            $form->addElement($opt_mailinglist);
191
        }
192
193
        $time = ($this->isNew()) ? time() : $this->getVar("cat_created");
194
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_ACCOUNTS_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
195
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_ACCOUNTS_CREATED, formatTimestamp($time, 's')));
196
197
        $form->addElement(new XoopsFormHidden("op", "save_cat"));
198
        $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
199
200
        return $form;
201
    }
202
}
203
204
/**
205
 * Class XnewsletterCatHandler
206
 */
207 View Code Duplication
class XnewsletterCatHandler extends XoopsPersistableObjectHandler
208
{
209
    /**
210
     * @var xnewsletterxnewsletter
211
     * @access public
212
     */
213
    public $xnewsletter = null;
214
215
    /**
216
     * @param null|object $db
217
     */
218
    public function __construct(&$db)
219
    {
220
        parent::__construct($db, "xnewsletter_cat", "XnewsletterCat", "cat_id", "cat_name");
221
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
222
    }
223
}
224