Passed
Push — master ( 3101ac...81e6e3 )
by Goffy
03:23
created

admin/category.php (2 issues)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
13
/**
14
 * wgEvents module for xoops
15
 *
16
 * @copyright    2021 XOOPS Project (https://xoops.org)
17
 * @license      GPL 2.0 or later
18
 * @package      wgevents
19
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Wgevents;
24
use XoopsModules\Wgevents\Constants;
25
use XoopsModules\Wgevents\Common;
26
27
require __DIR__ . '/header.php';
28
// Get all request values
29
$op    = Request::getCmd('op', 'list');
30
$catId = Request::getInt('id');
31
$start = Request::getInt('start');
32
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
33
$GLOBALS['xoopsTpl']->assign('start', $start);
34
$GLOBALS['xoopsTpl']->assign('limit', $limit);
35
36
$moduleDirName = \basename(\dirname(__DIR__));
37
38
$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName);
39
40
switch ($op) {
41
    case 'list':
42
    default:
43
        $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/jquery-ui.min.js');
44
        $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/sortables.js');
45
        // Define Stylesheet
46
        $GLOBALS['xoTheme']->addStylesheet($style, null);
47
        $templateMain = 'wgevents_admin_category.tpl';
48
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('category.php'));
49
        $adminObject->addItemButton(\_AM_WGEVENTS_ADD_CATEGORY, 'category.php?op=new');
50
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
51
        $categoryCount = $categoryHandler->getCountCategories();
52
        $categoryAll = $categoryHandler->getAllCategories();
53
        $GLOBALS['xoopsTpl']->assign('categorieCount', $categoryCount);
54
        $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL);
55
        $GLOBALS['xoopsTpl']->assign('wgevents_upload_url', \WGEVENTS_UPLOAD_URL);
56
        $GLOBALS['xoopsTpl']->assign('wgevents_icons_url_16', \WGEVENTS_ICONS_URL_16);
57
        // Table view categories
58
        if ($categoryCount > 0) {
59
            foreach (\array_keys($categoryAll) as $i) {
60
                $category = $categoryAll[$i]->getValuesCategories();
61
                $GLOBALS['xoopsTpl']->append('categories_list', $category);
62
                unset($category);
63
            }
64
        } else {
65
            $GLOBALS['xoopsTpl']->assign('error', \_AM_WGEVENTS_THEREARENT_CATEGORIES);
66
        }
67
        break;
68
    case 'new':
69
        $templateMain = 'wgevents_admin_category.tpl';
70
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('category.php'));
71
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_CATEGORIES, 'category.php', 'list');
72
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
73
        // Form Create
74
        $categoryObj = $categoryHandler->create();
75
        $form = $categoryObj->getForm();
76
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
77
        break;
78
    case 'clone':
79
        $templateMain = 'wgevents_admin_category.tpl';
80
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('category.php'));
81
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_CATEGORIES, 'category.php', 'list');
82
        $adminObject->addItemButton(\_AM_WGEVENTS_ADD_CATEGORY, 'category.php?op=new');
83
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
84
        // Request source
85
        $catIdSource = Request::getInt('id_source');
86
        // Get Form
87
        $categoryObjSource = $categoryHandler->get($catIdSource);
88
        $categoryObj = $categoryObjSource->xoopsClone();
89
        $form = $categoryObj->getForm();
90
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
91
        break;
92
    case 'save':
93
        // Security Check
94
        if (!$GLOBALS['xoopsSecurity']->check()) {
95
            \redirect_header('category.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
96
        }
97
        if ($catId > 0) {
98
            $categoryObj = $categoryHandler->get($catId);
99
        } else {
100
            $categoryObj = $categoryHandler->create();
101
        }
102
        // Set Vars
103
        $uploaderErrors = '';
104
        $categoryObj->setVar('pid', Request::getInt('pid'));
105
        $categoryObj->setVar('name', Request::getString('name'));
106
        $categoryObj->setVar('desc', Request::getText('desc'));
107
        // Set Var cat_logo
108
        require_once \XOOPS_ROOT_PATH . '/class/uploader.php';
109
        $logoname       = $_FILES['logo']['name'];
110
        $logoMimetype    = $_FILES['logo']['type'];
111
        $logoNameDef     = Request::getString('name');
112
        $uploader = new \XoopsMediaUploader(\WGEVENTS_UPLOAD_CATLOGOS_PATH . '/',
113
                                                    $helper->getConfig('mimetypes_image'), 
114
                                                    $helper->getConfig('maxsize_image'), null, null);
115
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
116
            $extension = \preg_replace('/^.+\.([^.]+)$/sU', '', $logoname);
117
            $imgName = \str_replace(' ', '', $logoNameDef) . '.' . $extension;
118
            $uploader->setPrefix($imgName);
119
            $uploader->fetchMedia($_POST['xoops_upload_file'][0]);
120
            if ($uploader->upload()) {
121
                $savedLogoname = $uploader->getSavedFileName();
122
                $maxwidth  = (int)$helper->getConfig('maxwidth_image');
123
                $maxheight = (int)$helper->getConfig('maxheight_image');
124
                if ($maxwidth > 0 && $maxheight > 0) {
125
                    // Resize image
126
                    $imgHandler                = new Wgevents\Common\Resizer();
127
                    $imgHandler->sourceFile    = \WGEVENTS_UPLOAD_CATLOGOS_PATH . '/' . $savedLogoname;
128
                    $imgHandler->endFile       = \WGEVENTS_UPLOAD_CATLOGOS_PATH . '/' . $savedLogoname;
129
                    $imgHandler->imageMimetype = $logoMimetype;
130
                    $imgHandler->maxWidth      = $maxwidth;
131
                    $imgHandler->maxHeight     = $maxheight;
132
                    $result                    = $imgHandler->resizeImage();
133
                }
134
                $categoryObj->setVar('logo', $savedLogoname);
135
            } else {
136
                $uploaderErrors .= '<br>' . $uploader->getErrors();
137
            }
138
        } else {
139
            if ($logoname > '') {
140
                $uploaderErrors .= '<br>' . $uploader->getErrors();
141
            }
142
            $categoryObj->setVar('logo', Request::getString('logo'));
143
        }
144
        // Set Var cat_image
145
        $filename       = $_FILES['image']['name'];
146
        $imgMimetype    = $_FILES['image']['type'];
147
        $imgNameDef     = Request::getString('name');
148
        $uploader = new \XoopsMediaUploader(\WGEVENTS_UPLOAD_CATIMAGES_PATH . '/',
149
            $helper->getConfig('mimetypes_image'),
150
            $helper->getConfig('maxsize_image'), null, null);
151
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) {
152
            $extension = \preg_replace('/^.+\.([^.]+)$/sU', '', $filename);
153
            $imgName = \str_replace(' ', '', $imgNameDef) . '.' . $extension;
154
            $uploader->setPrefix($imgName);
155
            $uploader->fetchMedia($_POST['xoops_upload_file'][1]);
156
            if ($uploader->upload()) {
157
                $savedImagename = $uploader->getSavedFileName();
158
                $maxwidth  = (int)$helper->getConfig('maxwidth_image');
159
                $maxheight = (int)$helper->getConfig('maxheight_image');
160
                if ($maxwidth > 0 && $maxheight > 0) {
161
                    // Resize image
162
                    $imgHandler                = new Wgevents\Common\Resizer();
163
                    $imgHandler->sourceFile    = \WGEVENTS_UPLOAD_CATIMAGES_PATH . '/' . $savedImagename;
164
                    $imgHandler->endFile       = \WGEVENTS_UPLOAD_CATIMAGES_PATH . '/' . $savedImagename;
165
                    $imgHandler->imageMimetype = $imgMimetype;
166
                    $imgHandler->maxWidth      = $maxwidth;
167
                    $imgHandler->maxHeight     = $maxheight;
168
                    $result                    = $imgHandler->resizeImage();
169
                }
170
                $categoryObj->setVar('image', $savedImagename);
171
            } else {
172
                $uploaderErrors .= '<br>' . $uploader->getErrors();
173
            }
174
        } else {
175
            if ($filename > '') {
176
                $uploaderErrors .= '<br>' . $uploader->getErrors();
177
            }
178
            $categoryObj->setVar('image', Request::getString('image'));
179
        }
180
        $categoryObj->setVar('color', Request::getString('color'));
181
        $categoryObj->setVar('bordercolor', Request::getString('bordercolor'));
182
        $categoryObj->setVar('bgcolor', Request::getString('bgcolor'));
183
        $categoryObj->setVar('othercss', Request::getString('othercss'));
184
        $categoryObj->setVar('identifier', Request::getString('identifier'));
185
        $categoryObj->setVar('type', Request::getInt('type'));
186
        $categoryObj->setVar('status', Request::getInt('status'));
187
        $categoryObj->setVar('weight', Request::getInt('weight'));
188
        $categoryDatecreatedObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('datecreated'));
189
        $categoryObj->setVar('datecreated', $categoryDatecreatedObj->getTimestamp());
190
        $categoryObj->setVar('submitter', Request::getInt('submitter'));
191
        // Insert Data
192
        if ($categoryHandler->insert($categoryObj)) {
193
            $newCatId = $categoryObj->getNewInsertedIdCategories();
194
            $permId = isset($_REQUEST['id']) ? $catId : $newCatId;
195
            $grouppermHandler = \xoops_getHandler('groupperm');
196
            $mid = $GLOBALS['xoopsModule']->getVar('mid');
197
            // Permission to view_cat_events
198
            $grouppermHandler->deleteByModule($mid, 'wgevents_view_cat_events', $permId);
0 ignored issues
show
The method deleteByModule() does not exist on XoopsObjectHandler. Did you maybe mean delete()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

198
            $grouppermHandler->/** @scrutinizer ignore-call */ 
199
                               deleteByModule($mid, 'wgevents_view_cat_events', $permId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
199
            if (isset($_POST['groups_view_cat_events'])) {
200
                foreach ($_POST['groups_view_cat_events'] as $onegroupId) {
201
                    $grouppermHandler->addRight('wgevents_view_cat_events', $permId, $onegroupId, $mid);
0 ignored issues
show
The method addRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

201
                    $grouppermHandler->/** @scrutinizer ignore-call */ 
202
                                       addRight('wgevents_view_cat_events', $permId, $onegroupId, $mid);
Loading history...
202
                }
203
            }
204
            // Permission to submit_cat_events
205
            $grouppermHandler->deleteByModule($mid, 'wgevents_submit_cat_events', $permId);
206
            if (isset($_POST['groups_submit_cat_events'])) {
207
                foreach ($_POST['groups_submit_cat_events'] as $onegroupId) {
208
                    $grouppermHandler->addRight('wgevents_submit_cat_events', $permId, $onegroupId, $mid);
209
                }
210
            }
211
            // Permission to approve_cat_events
212
            $grouppermHandler->deleteByModule($mid, 'wgevents_approve_cat_events', $permId);
213
            if (isset($_POST['groups_approve_cat_events'])) {
214
                foreach ($_POST['groups_approve_cat_events'] as $onegroupId) {
215
                    $grouppermHandler->addRight('wgevents_approve_cat_events', $permId, $onegroupId, $mid);
216
                }
217
            }
218
            // Permission to view_cat_regs
219
            $grouppermHandler->deleteByModule($mid, 'wgevents_view_cat_regs', $permId);
220
            if (isset($_POST['groups_view_cat_regs'])) {
221
                foreach ($_POST['groups_view_cat_regs'] as $onegroupId) {
222
                    $grouppermHandler->addRight('wgevents_view_cat_regs', $permId, $onegroupId, $mid);
223
                }
224
            }
225
            // Permission to submit_cat_regs
226
            $grouppermHandler->deleteByModule($mid, 'wgevents_submit_cat_regs', $permId);
227
            if (isset($_POST['groups_submit_cat_regs'])) {
228
                foreach ($_POST['groups_submit_cat_regs'] as $onegroupId) {
229
                    $grouppermHandler->addRight('wgevents_submit_cat_regs', $permId, $onegroupId, $mid);
230
                }
231
            }
232
            // Permission to approve_cat_regs
233
            $grouppermHandler->deleteByModule($mid, 'wgevents_approve_cat_regs', $permId);
234
            if (isset($_POST['groups_approve_cat_regs'])) {
235
                foreach ($_POST['groups_approve_cat_regs'] as $onegroupId) {
236
                    $grouppermHandler->addRight('wgevents_approve_cat_regs', $permId, $onegroupId, $mid);
237
                }
238
            }
239
            if ('' !== $uploaderErrors) {
240
                \redirect_header('category.php?op=edit&id=' . $catId, 5, $uploaderErrors);
241
            } else {
242
                \redirect_header('category.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_MA_WGEVENTS_FORM_OK);
243
            }
244
        }
245
        // Get Form
246
        $GLOBALS['xoopsTpl']->assign('error', $categoryObj->getHtmlErrors());
247
        $form = $categoryObj->getForm();
248
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
249
        break;
250
    case 'edit':
251
        $templateMain = 'wgevents_admin_category.tpl';
252
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('category.php'));
253
        $adminObject->addItemButton(\_AM_WGEVENTS_ADD_CATEGORY, 'category.php?op=new');
254
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_CATEGORIES, 'category.php', 'list');
255
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
256
        // Get Form
257
        $categoryObj = $categoryHandler->get($catId);
258
        $categoryObj->start = $start;
259
        $categoryObj->limit = $limit;
260
        $form = $categoryObj->getForm();
261
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
262
        break;
263
    case 'delete':
264
        $templateMain = 'wgevents_admin_category.tpl';
265
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('category.php'));
266
        $categoryObj = $categoryHandler->get($catId);
267
        $catName = $categoryObj->getVar('name');
268
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
269
            if (!$GLOBALS['xoopsSecurity']->check()) {
270
                \redirect_header('category.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
271
            }
272
            if ($categoryHandler->delete($categoryObj)) {
273
                \redirect_header('category.php', 3, \_MA_WGEVENTS_FORM_DELETE_OK);
274
            } else {
275
                $GLOBALS['xoopsTpl']->assign('error', $categoryObj->getHtmlErrors());
276
            }
277
        } else {
278
            $customConfirm = new Common\Confirm(
279
                ['ok' => 1, 'id' => $catId, 'start' => $start, 'limit' => $limit, 'op' => 'delete'],
280
                $_SERVER['REQUEST_URI'],
281
                \sprintf(\_MA_WGEVENTS_FORM_SURE_DELETE, $categoryObj->getVar('name')));
282
            $form = $customConfirm->getFormConfirm();
283
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
284
        }
285
        break;
286
    case 'order':
287
        $order = $_POST['order'];
288
        for ($i = 0, $iMax = \count($order); $i < $iMax; $i++) {
289
            $categoryObj = $categoryHandler->get($order[$i]);
290
            $categoryObj->setVar('weight', $i + 1);
291
            $categoryHandler->insert($categoryObj);
292
        }
293
        break;
294
}
295
require __DIR__ . '/footer.php';
296