|
1
|
|
|
<?php |
|
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
|
|
|
* Module: randomquote |
|
15
|
|
|
* |
|
16
|
|
|
* @category Module |
|
17
|
|
|
* @package randomquote |
|
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <https://xoops.org> |
|
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
20
|
|
|
* @license GPL 2.0 or later |
|
21
|
|
|
* @link https://xoops.org/ |
|
22
|
|
|
* @since 1.0.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use Xmf\Module\Helper\Permission; |
|
26
|
|
|
use Xmf\Request; |
|
27
|
|
|
use Xoopsmodules\randomquote; |
|
|
|
|
|
|
28
|
|
|
use Xoopsmodules\randomquote\common; |
|
29
|
|
|
|
|
30
|
|
|
require_once __DIR__ . '/admin_header.php'; |
|
31
|
|
|
xoops_cp_header(); |
|
32
|
|
|
//It recovered the value of argument op in URL$ |
|
33
|
|
|
$op = Request::getString('op', 'list'); |
|
34
|
|
|
$order = Request::getString('order', 'desc'); |
|
35
|
|
|
$sort = Request::getString('sort', ''); |
|
36
|
|
|
|
|
37
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
|
38
|
|
|
/** @var Permission $permHelper */ |
|
39
|
|
|
$permHelper = new \Xmf\Module\Helper\Permission(); |
|
40
|
|
|
$uploadDir = XOOPS_UPLOAD_PATH . '/randomquote/images/'; |
|
41
|
|
|
$uploadUrl = XOOPS_UPLOAD_URL . '/randomquote/images/'; |
|
42
|
|
|
|
|
43
|
|
|
switch ($op) { |
|
44
|
|
|
case 'list': |
|
45
|
|
|
default: |
|
46
|
|
|
$adminObject->addItemButton(AM_RANDOMQUOTE_ADD_CATEGORY, 'category.php?op=new', 'add'); |
|
47
|
|
|
echo $adminObject->displayButton('left'); |
|
48
|
|
|
$start = Request::getInt('start', 0); |
|
49
|
|
|
$categoryPaginationLimit = $GLOBALS['xoopsModuleConfig']['userpager']; |
|
50
|
|
|
|
|
51
|
|
|
$criteria = new CriteriaCompo(); |
|
52
|
|
|
$criteria->setSort('id ASC, title'); |
|
53
|
|
|
$criteria->setOrder('ASC'); |
|
54
|
|
|
$criteria->setLimit($categoryPaginationLimit); |
|
55
|
|
|
$criteria->setStart($start); |
|
56
|
|
|
$categoryTempRows = $categoryHandler->getCount(); |
|
57
|
|
|
$categoryTempArray = $categoryHandler->getAll($criteria); |
|
58
|
|
|
|
|
59
|
|
|
// Display Page Navigation |
|
60
|
|
View Code Duplication |
if ($categoryTempRows > $categoryPaginationLimit) { |
|
|
|
|
|
|
61
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
62
|
|
|
|
|
63
|
|
|
$pagenav = new \XoopsPageNav($categoryTempRows, $categoryPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . ''); |
|
64
|
|
|
$GLOBALS['xoopsTpl']->assign('pagenav', null === $pagenav ? $pagenav->renderNav() : ''); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$GLOBALS['xoopsTpl']->assign('categoryRows', $categoryTempRows); |
|
68
|
|
|
$categoryArray = []; |
|
69
|
|
|
|
|
70
|
|
|
$criteria = new CriteriaCompo(); |
|
71
|
|
|
|
|
72
|
|
|
//$criteria->setOrder('DESC'); |
|
73
|
|
|
$criteria->setSort($sort); |
|
74
|
|
|
$criteria->setOrder($order); |
|
75
|
|
|
$criteria->setLimit($categoryPaginationLimit); |
|
76
|
|
|
$criteria->setStart($start); |
|
77
|
|
|
|
|
78
|
|
|
$categoryCount = $categoryHandler->getCount($criteria); |
|
79
|
|
|
$categoryTempArray = $categoryHandler->getAll($criteria); |
|
80
|
|
|
|
|
81
|
|
|
// for ($i = 0; $i < $fieldsCount; ++$i) { |
|
82
|
|
|
if ($categoryCount > 0) { |
|
83
|
|
|
foreach (array_keys($categoryTempArray) as $i) { |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
// $field = explode(':', $fields[$i]); |
|
87
|
|
|
|
|
88
|
|
|
$selectorid = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_ID, 'id'); |
|
89
|
|
|
$GLOBALS['xoopsTpl']->assign('selectorid', $selectorid); |
|
90
|
|
|
$categoryArray['id'] = $categoryTempArray[$i]->getVar('id'); |
|
91
|
|
|
|
|
92
|
|
|
$selectorpid = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_PID, 'pid'); |
|
93
|
|
|
$GLOBALS['xoopsTpl']->assign('selectorpid', $selectorpid); |
|
94
|
|
|
$categoryArray['pid'] = $categoryTempArray[$i]->getVar('pid'); |
|
95
|
|
|
|
|
96
|
|
|
$selectortitle = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_TITLE, 'title'); |
|
97
|
|
|
$GLOBALS['xoopsTpl']->assign('selectortitle', $selectortitle); |
|
98
|
|
|
$categoryArray['title'] = $categoryTempArray[$i]->getVar('title'); |
|
99
|
|
|
|
|
100
|
|
|
$selectordescription = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_DESCRIPTION, 'description'); |
|
101
|
|
|
$GLOBALS['xoopsTpl']->assign('selectordescription', $selectordescription); |
|
102
|
|
|
$categoryArray['description'] = $categoryTempArray[$i]->getVar('description'); |
|
103
|
|
|
|
|
104
|
|
|
$selectorimage = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_IMAGE, 'image'); |
|
105
|
|
|
$GLOBALS['xoopsTpl']->assign('selectorimage', $selectorimage); |
|
106
|
|
|
$categoryArray['image'] = "<img src='" . $uploadUrl . $categoryTempArray[$i]->getVar('image') . "' name='" . 'name' . "' id=" . 'id' . " alt='' style='max-width:100px'>"; |
|
107
|
|
|
|
|
108
|
|
|
$selectorweight = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_WEIGHT, 'weight'); |
|
109
|
|
|
$GLOBALS['xoopsTpl']->assign('selectorweight', $selectorweight); |
|
110
|
|
|
$categoryArray['weight'] = $categoryTempArray[$i]->getVar('weight'); |
|
111
|
|
|
|
|
112
|
|
|
$selectorcolor = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_COLOR, 'color'); |
|
113
|
|
|
$GLOBALS['xoopsTpl']->assign('selectorcolor', $selectorcolor); |
|
114
|
|
|
$categoryArray['color'] = $categoryTempArray[$i]->getVar('color'); |
|
115
|
|
|
|
|
116
|
|
|
$selectoronline = $utility::selectSorting(AM_RANDOMQUOTE_CATEGORY_ONLINE, 'online'); |
|
117
|
|
|
$GLOBALS['xoopsTpl']->assign('selectoronline', $selectoronline); |
|
118
|
|
|
$categoryArray['online'] = $categoryTempArray[$i]->getVar('online'); |
|
119
|
|
|
$categoryArray['edit_delete'] = "<a href='category.php?op=edit&id=" . $i . "'><img src=" . $pathIcon16 . "/edit.png alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
|
120
|
|
|
<a href='category.php?op=delete&id=" . $i . "'><img src=" . $pathIcon16 . "/delete.png alt='" . _DELETE . "' title='" . _DELETE . "'></a> |
|
121
|
|
|
<a href='category.php?op=clone&id=" . $i . "'><img src=" . $pathIcon16 . "/editcopy.png alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
|
122
|
|
|
|
|
123
|
|
|
$GLOBALS['xoopsTpl']->append_by_ref('categoryArrays', $categoryArray); |
|
124
|
|
|
unset($categoryArray); |
|
125
|
|
|
} |
|
126
|
|
|
unset($categoryTempArray); |
|
127
|
|
|
// Display Navigation |
|
128
|
|
View Code Duplication |
if ($categoryCount > $categoryPaginationLimit) { |
|
|
|
|
|
|
129
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
130
|
|
|
$pagenav = new \XoopsPageNav($categoryCount, $categoryPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . ''); |
|
131
|
|
|
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
echo $GLOBALS['xoopsTpl']->fetch(XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . '/templates/admin/randomquote_admin_category.tpl'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
break; |
|
138
|
|
|
|
|
139
|
|
View Code Duplication |
case 'new': |
|
|
|
|
|
|
140
|
|
|
$adminObject->addItemButton(AM_RANDOMQUOTE_CATEGORY_LIST, 'category.php', 'list'); |
|
141
|
|
|
echo $adminObject->displayButton('left'); |
|
142
|
|
|
|
|
143
|
|
|
$categoryObject = $categoryHandler->create(); |
|
144
|
|
|
$form = $categoryObject->getForm(); |
|
145
|
|
|
$form->display(); |
|
146
|
|
|
break; |
|
147
|
|
|
|
|
148
|
|
|
case 'save': |
|
149
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
150
|
|
|
redirect_header('category.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
151
|
|
|
} |
|
152
|
|
|
if (0 != Request::getInt('id', 0)) { |
|
153
|
|
|
$categoryObject = $categoryHandler->get(Request::getInt('id', 0)); |
|
154
|
|
|
} else { |
|
155
|
|
|
$categoryObject = $categoryHandler->create(); |
|
156
|
|
|
} |
|
157
|
|
|
// Form save fields |
|
158
|
|
|
$categoryObject->setVar('pid', Request::getVar('pid', '')); |
|
159
|
|
|
$categoryObject->setVar('title', Request::getVar('title', '')); |
|
160
|
|
|
$categoryObject->setVar('description', Request::getText('description', '')); |
|
161
|
|
|
|
|
162
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
163
|
|
|
$uploadDir = XOOPS_UPLOAD_PATH . '/randomquote/images/'; |
|
164
|
|
|
$uploader = new \XoopsMediaUploader($uploadDir, xoops_getModuleOption('mimetypes', 'randomquote'), xoops_getModuleOption('maxsize', 'randomquote'), null, null); |
|
165
|
|
|
if ($uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0])) { |
|
166
|
|
|
$uploader->setPrefix('image_'); |
|
167
|
|
|
$uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0]); |
|
168
|
|
|
if (!$uploader->upload()) { |
|
169
|
|
|
$errors = $uploader->getErrors(); |
|
170
|
|
|
redirect_header('javascript:history.go(-1)', 3, $errors); |
|
171
|
|
|
} else { |
|
172
|
|
|
$categoryObject->setVar('image', $uploader->getSavedFileName()); |
|
173
|
|
|
} |
|
174
|
|
|
} else { |
|
175
|
|
|
$categoryObject->setVar('image', Request::getVar('image', '')); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$categoryObject->setVar('weight', Request::getVar('weight', '')); |
|
179
|
|
|
$categoryObject->setVar('color', Request::getVar('color', '')); |
|
180
|
|
|
$categoryObject->setVar('online', ((1 == Request::getInt('online', 0)) ? '1' : '0')); |
|
181
|
|
|
//Permissions |
|
182
|
|
|
//=============================================================== |
|
183
|
|
|
|
|
184
|
|
|
$mid = $GLOBALS['xoopsModule']->mid(); |
|
185
|
|
|
/** @var XoopsGroupPermHandler $gpermHandler */ |
|
186
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
187
|
|
|
$id = Request::getInt('id', 0); |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @param $myArray |
|
191
|
|
|
* @param $permissionGroup |
|
192
|
|
|
* @param $id |
|
193
|
|
|
* @param $gpermHandler |
|
194
|
|
|
* @param $permissionName |
|
195
|
|
|
* @param $mid |
|
196
|
|
|
*/ |
|
197
|
|
|
function setPermissions($myArray, $permissionGroup, $id, $gpermHandler, $permissionName, $mid) |
|
|
|
|
|
|
198
|
|
|
{ |
|
199
|
|
|
$permissionArray = $myArray; |
|
200
|
|
|
if ($id > 0) { |
|
201
|
|
|
$sql = 'DELETE FROM `' . $GLOBALS['xoopsDB']->prefix('group_permission') . "` WHERE `gperm_name` = '" . $permissionName . "' AND `gperm_itemid`= $id;"; |
|
202
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
|
203
|
|
|
} |
|
204
|
|
|
//admin |
|
205
|
|
|
$gperm = $gpermHandler->create(); |
|
206
|
|
|
$gperm->setVar('gperm_groupid', XOOPS_GROUP_ADMIN); |
|
207
|
|
|
$gperm->setVar('gperm_name', $permissionName); |
|
208
|
|
|
$gperm->setVar('gperm_modid', $mid); |
|
209
|
|
|
$gperm->setVar('gperm_itemid', $id); |
|
210
|
|
|
$gpermHandler->insert($gperm); |
|
211
|
|
|
unset($gperm); |
|
212
|
|
|
//non-Admin groups |
|
213
|
|
|
if (is_array($permissionArray)) { |
|
214
|
|
|
foreach ($permissionArray as $key => $cat_groupperm) { |
|
215
|
|
View Code Duplication |
if ($cat_groupperm > 0) { |
|
|
|
|
|
|
216
|
|
|
$gperm = $gpermHandler->create(); |
|
217
|
|
|
$gperm->setVar('gperm_groupid', $cat_groupperm); |
|
218
|
|
|
$gperm->setVar('gperm_name', $permissionName); |
|
219
|
|
|
$gperm->setVar('gperm_modid', $mid); |
|
220
|
|
|
$gperm->setVar('gperm_itemid', $id); |
|
221
|
|
|
$gpermHandler->insert($gperm); |
|
222
|
|
|
unset($gperm); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
View Code Duplication |
} elseif ($permissionArray > 0) { |
|
|
|
|
|
|
226
|
|
|
$gperm = $gpermHandler->create(); |
|
227
|
|
|
$gperm->setVar('gperm_groupid', $permissionArray); |
|
228
|
|
|
$gperm->setVar('gperm_name', $permissionName); |
|
229
|
|
|
$gperm->setVar('gperm_modid', $mid); |
|
230
|
|
|
$gperm->setVar('gperm_itemid', $id); |
|
231
|
|
|
$gpermHandler->insert($gperm); |
|
232
|
|
|
unset($gperm); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
//setPermissions for View items |
|
237
|
|
|
$permissionGroup = 'groupsRead'; |
|
238
|
|
|
$permissionName = 'randomquote_view'; |
|
239
|
|
|
$permissionArray = Request::getArray($permissionGroup, ''); |
|
240
|
|
|
$permissionArray[] = XOOPS_GROUP_ADMIN; |
|
241
|
|
|
//setPermissions($permissionArray, $permissionGroup, $id, $gpermHandler, $permissionName, $mid); |
|
242
|
|
|
$permHelper->savePermissionForItem($permissionName, $id, $permissionArray); |
|
243
|
|
|
|
|
244
|
|
|
//setPermissions for Submit items |
|
245
|
|
|
$permissionGroup = 'groupsSubmit'; |
|
246
|
|
|
$permissionName = 'randomquote_submit'; |
|
247
|
|
|
$permissionArray = Request::getArray($permissionGroup, ''); |
|
248
|
|
|
$permissionArray[] = XOOPS_GROUP_ADMIN; |
|
249
|
|
|
//setPermissions($permissionArray, $permissionGroup, $id, $gpermHandler, $permissionName, $mid); |
|
250
|
|
|
$permHelper->savePermissionForItem($permissionName, $id, $permissionArray); |
|
251
|
|
|
|
|
252
|
|
|
//setPermissions for Approve items |
|
253
|
|
|
$permissionGroup = 'groupsModeration'; |
|
254
|
|
|
$permissionName = 'randomquote_approve'; |
|
255
|
|
|
$permissionArray = Request::getArray($permissionGroup, ''); |
|
256
|
|
|
$permissionArray[] = XOOPS_GROUP_ADMIN; |
|
257
|
|
|
//setPermissions($permissionArray, $permissionGroup, $id, $gpermHandler, $permissionName, $mid); |
|
258
|
|
|
$permHelper->savePermissionForItem($permissionName, $id, $permissionArray); |
|
259
|
|
|
|
|
260
|
|
|
if ($categoryHandler->insert($categoryObject)) { |
|
261
|
|
|
redirect_header('category.php?op=list', 2, AM_RANDOMQUOTE_FORMOK); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
echo $categoryObject->getHtmlErrors(); |
|
265
|
|
|
$form = $categoryObject->getForm(); |
|
266
|
|
|
$form->display(); |
|
267
|
|
|
break; |
|
268
|
|
|
|
|
269
|
|
View Code Duplication |
case 'edit': |
|
|
|
|
|
|
270
|
|
|
$adminObject->addItemButton(AM_RANDOMQUOTE_ADD_CATEGORY, 'category.php?op=new', 'add'); |
|
271
|
|
|
$adminObject->addItemButton(AM_RANDOMQUOTE_CATEGORY_LIST, 'category.php', 'list'); |
|
272
|
|
|
echo $adminObject->displayButton('left'); |
|
273
|
|
|
$categoryObject = $categoryHandler->get(Request::getString('id', '')); |
|
274
|
|
|
$form = $categoryObject->getForm(); |
|
275
|
|
|
$form->display(); |
|
276
|
|
|
break; |
|
277
|
|
|
|
|
278
|
|
View Code Duplication |
case 'delete': |
|
|
|
|
|
|
279
|
|
|
$categoryObject = $categoryHandler->get(Request::getString('id', '')); |
|
280
|
|
|
if (1 == Request::getInt('ok', 0)) { |
|
281
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
282
|
|
|
redirect_header('category.php', 3, implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
|
283
|
|
|
} |
|
284
|
|
|
if ($categoryHandler->delete($categoryObject)) { |
|
285
|
|
|
redirect_header('category.php', 3, AM_RANDOMQUOTE_FORMDELOK); |
|
286
|
|
|
} else { |
|
287
|
|
|
echo $categoryObject->getHtmlErrors(); |
|
288
|
|
|
} |
|
289
|
|
|
} else { |
|
290
|
|
|
xoops_confirm(['ok' => 1, 'id' => Request::getString('id', ''), 'op' => 'delete'], Request::getCmd('REQUEST_URI', '', 'SERVER'), sprintf(AM_RANDOMQUOTE_FORMSUREDEL, $categoryObject->getVar('title'))); |
|
291
|
|
|
} |
|
292
|
|
|
break; |
|
293
|
|
|
|
|
294
|
|
View Code Duplication |
case 'clone': |
|
|
|
|
|
|
295
|
|
|
|
|
296
|
|
|
$id_field = Request::getString('id', ''); |
|
297
|
|
|
|
|
298
|
|
|
if ($utility::cloneRecord('randomquote_category', 'id', $id_field)) { |
|
299
|
|
|
redirect_header('category.php', 3, AM_RANDOMQUOTE_CLONED_OK); |
|
300
|
|
|
} else { |
|
301
|
|
|
redirect_header('category.php', 3, AM_RANDOMQUOTE_CLONED_FAILED); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
break; |
|
305
|
|
|
} |
|
306
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
|
307
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: