|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* Module: SmarttPartner |
|
6
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
|
7
|
|
|
* Licence: GNU |
|
8
|
|
|
* @param $categoryObj |
|
9
|
|
|
* @param int $level |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
function displayCategory($categoryObj, $level = 0) |
|
13
|
|
|
{ |
|
14
|
|
|
global $xoopsModule, $smartPartnerCategoryHandler, $pathIcon16; |
|
|
|
|
|
|
15
|
|
|
$description = $categoryObj->description(); |
|
16
|
|
|
if (!XOOPS_USE_MULTIBYTES) { |
|
17
|
|
|
if (strlen($description) >= 100) { |
|
18
|
|
|
$description = substr($description, 0, 100 - 1) . '...'; |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
$modify = "<a href='category.php?op=mod&categoryid=" |
|
22
|
|
|
. $categoryObj->categoryid() |
|
23
|
|
|
. '&parentid=' |
|
24
|
|
|
. $categoryObj->parentid() |
|
25
|
|
|
. "'><img src='" |
|
26
|
|
|
. $pathIcon16 |
|
27
|
|
|
. '/edit.png' |
|
28
|
|
|
. "' title='" |
|
29
|
|
|
. _AM_SPARTNER_CATEGORY_EDIT |
|
30
|
|
|
. "' alt='" |
|
31
|
|
|
. _AM_SPARTNER_CATEGORY_EDIT |
|
32
|
|
|
. "' /></a>"; |
|
33
|
|
|
$delete = "<a href='category.php?op=del&categoryid=" |
|
34
|
|
|
. $categoryObj->categoryid() |
|
35
|
|
|
. "'><img src='" |
|
36
|
|
|
. $pathIcon16 |
|
37
|
|
|
. '/delete.png' |
|
38
|
|
|
. "' title='" |
|
39
|
|
|
. _AM_SPARTNER_CATEGORY_DELETE |
|
40
|
|
|
. "' alt='" |
|
41
|
|
|
. _AM_SPARTNER_CATEGORY_DELETE |
|
42
|
|
|
. "' /></a>"; |
|
43
|
|
|
|
|
44
|
|
|
$spaces = ''; |
|
45
|
|
|
for ($j = 0; $j < $level; ++$j) { |
|
46
|
|
|
$spaces .= ' '; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
echo '<tr>'; |
|
50
|
|
|
echo "<td class='even' align='lefet'>" |
|
51
|
|
|
. $spaces |
|
52
|
|
|
. "<a href='" |
|
53
|
|
|
. $categoryObj->getCategoryUrl() |
|
54
|
|
|
. "'><img src='" |
|
55
|
|
|
. XOOPS_URL |
|
56
|
|
|
. "/modules/smartpartner/assets/images/icon/subcat.gif' alt='' /> " |
|
57
|
|
|
. $categoryObj->name() |
|
58
|
|
|
. '</a></td>'; |
|
59
|
|
|
echo "<td class='even' align='center'>" . $categoryObj->weight() . '</td>'; |
|
60
|
|
|
echo "<td class='even' align='center'> $modify $delete </td>"; |
|
61
|
|
|
echo '</tr>'; |
|
62
|
|
|
$subCategoriesObj = $smartPartnerCategoryHandler->getCategories(0, 0, $categoryObj->categoryid()); |
|
63
|
|
|
if (count($subCategoriesObj) > 0) { |
|
64
|
|
|
++$level; |
|
65
|
|
|
foreach ($subCategoriesObj as $key => $thiscat) { |
|
66
|
|
|
displayCategory($thiscat, $level); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
unset($categoryObj); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param bool $showmenu |
|
74
|
|
|
* @param int $categoryid |
|
75
|
|
|
* @param int $nb_subcats |
|
76
|
|
|
* @param null $categoryObj |
|
77
|
|
|
*/ |
|
78
|
|
|
function editcat($showmenu = false, $categoryid = 0, $nb_subcats = 4, $categoryObj = null) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
global $xoopsDB, $smartPartnerCategoryHandler, $xoopsUser, $myts, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
|
|
81
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
82
|
|
|
|
|
83
|
|
|
// If there is a parameter, and the id exists, retrieve data: we're editing a category |
|
84
|
|
|
if ($categoryid != 0) { |
|
85
|
|
|
|
|
86
|
|
|
// Creating the category object for the selected category |
|
87
|
|
|
//$categoryObj = new SmartpartnerCategory($categoryid); |
|
|
|
|
|
|
88
|
|
|
$categoryObj = $smartPartnerCategoryHandler->get($categoryid); |
|
89
|
|
|
|
|
90
|
|
|
echo "<br>\n"; |
|
91
|
|
|
if ($categoryObj->notLoaded()) { |
|
92
|
|
|
redirect_header('category.php', 1, _AM_SPARTNER_NOCOLTOEDIT); |
|
93
|
|
|
} |
|
94
|
|
|
smartpartner_collapsableBar('edittable', 'edittableicon', _AM_SPARTNER_CATEGORY_EDIT, _AM_SPARTNER_CATEGORY_EDIT_INFO); |
|
95
|
|
|
} else { |
|
96
|
|
|
if (!$categoryObj) { |
|
97
|
|
|
$categoryObj = $smartPartnerCategoryHandler->create(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
//echo "<br>\n"; |
|
101
|
|
|
smartpartner_collapsableBar('createtable', 'createtableicon', _AM_SPARTNER_CATEGORY_CREATE, _AM_SPARTNER_CATEGORY_CREATE_INFO); |
|
102
|
|
|
} |
|
103
|
|
|
// Start category form |
|
104
|
|
|
$mytree = new XoopsTree($xoopsDB->prefix('smartpartner_categories'), 'categoryid', 'parentid'); |
|
105
|
|
|
$sform = new XoopsThemeForm(_AM_SPARTNER_CATEGORY, 'op', xoops_getenv('PHP_SELF')); |
|
106
|
|
|
$sform->setExtra('enctype="multipart/form-data"'); |
|
107
|
|
|
|
|
108
|
|
|
// Name |
|
109
|
|
|
$sform->addElement(new XoopsFormText(_AM_SPARTNER_CATEGORY, 'name', 50, 255, $categoryObj->name('e')), true); |
|
110
|
|
|
|
|
111
|
|
|
// Description |
|
112
|
|
|
$sform->addElement(new XoopsFormTextArea(_AM_SPARTNER_CATEGORY_DSC, 'description', $categoryObj->description('e'), 7, 60)); |
|
113
|
|
|
|
|
114
|
|
|
// IMAGE |
|
115
|
|
|
$image_array = XoopsLists:: getImgListAsArray(smartpartner_getUploadDir('category')); |
|
|
|
|
|
|
116
|
|
|
$image_select = new XoopsFormSelect('', 'image', $categoryObj->image()); |
|
117
|
|
|
$image_select->addOption('-1', '---------------'); |
|
118
|
|
|
$image_select->addOptionArray($image_array); |
|
119
|
|
|
$image_select->setExtra("onchange='showImgSelected(\"image3\", \"image\", \"" . 'uploads/smartpartner/assets/images/category/' . "\", \"\", \"" . XOOPS_URL . "\")'"); |
|
120
|
|
|
$image_tray = new XoopsFormElementTray(_AM_SPARTNER_CATEGORY_IMAGE, ' '); |
|
121
|
|
|
$image_tray->addElement($image_select); |
|
122
|
|
|
$image_tray->addElement(new XoopsFormLabel('', "<br><br><img src='" . smartpartner_getImageDir('category', false) . $categoryObj->image() . "' name='image3' id='image3' alt='' />")); |
|
123
|
|
|
$image_tray->setDescription(_AM_SPARTNER_CATEGORY_IMAGE_DSC); |
|
124
|
|
|
$sform->addElement($image_tray); |
|
125
|
|
|
|
|
126
|
|
|
// IMAGE UPLOAD |
|
127
|
|
|
$max_size = 5000000; |
|
128
|
|
|
$file_box = new XoopsFormFile(_AM_SPARTNER_CATEGORY_IMAGE_UPLOAD, 'image_file', $max_size); |
|
129
|
|
|
$file_box->setExtra("size ='45'"); |
|
130
|
|
|
$file_box->setDescription(_AM_SPARTNER_CATEGORY_IMAGE_UPLOAD_DSC); |
|
131
|
|
|
$sform->addElement($file_box); |
|
132
|
|
|
|
|
133
|
|
|
// Weight |
|
134
|
|
|
$sform->addElement(new XoopsFormText(_AM_SPARTNER_CATEGORY_WEIGHT, 'weight', 4, 4, $categoryObj->weight())); |
|
135
|
|
|
|
|
136
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
137
|
|
|
$group_list = $memberHandler->getGroupList(); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
// Parent Category |
|
142
|
|
|
ob_start(); |
|
143
|
|
|
$mytree->makeMySelBox('name', 'weight', $categoryObj->parentid(), 1, 'parentid'); |
|
144
|
|
|
//makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") |
|
|
|
|
|
|
145
|
|
|
$parent_cat_select = new XoopsFormLabel(_AM_SPARTNER_CATEGORY_PARENT, ob_get_contents()); |
|
146
|
|
|
$parent_cat_select->setDescription(_AM_SPARTNER_CATEGORY_PARENT_DSC); |
|
147
|
|
|
$sform->addElement($parent_cat_select); |
|
148
|
|
|
ob_end_clean(); |
|
149
|
|
|
|
|
150
|
|
|
// Added by fx2024 |
|
151
|
|
|
// sub Categories |
|
152
|
|
|
|
|
153
|
|
|
$cat_tray = new XoopsFormElementTray(_AM_SPARTNER_CATEGORY_SUBCATS_CREATE, '<br><br>'); |
|
154
|
|
|
$cat_tray->setDescription(_AM_SPARTNER_CATEGORY_SUBCATS_CREATE_DSC); |
|
155
|
|
|
for ($i = 0; $i < $nb_subcats; ++$i) { |
|
156
|
|
|
if ($i < (isset($_POST['scname']) ? count($_POST['scname']) : 0)) { |
|
157
|
|
|
$subname = isset($_POST['scname']) ? $_POST['scname'][$i] : ''; |
|
158
|
|
|
} else { |
|
159
|
|
|
$subname = ''; |
|
160
|
|
|
} |
|
161
|
|
|
$cat_tray->addElement(new XoopsFormText('', 'scname[' . $i . ']', 50, 255, $subname), true); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$t = new XoopsFormText('', 'nb_subcats', 3, 2); |
|
165
|
|
|
$l = new XoopsFormLabel('', sprintf(_AM_SPARTNER_ADD_OPT, $t->render())); |
|
166
|
|
|
$b = new XoopsFormButton('', 'submit', _AM_SPARTNER_ADD_OPT_SUBMIT, 'submit'); |
|
167
|
|
|
if ($categoryid == 0) { |
|
168
|
|
|
$b->setExtra('onclick="this.form.elements.op.value=\'addsubcats\'"'); |
|
169
|
|
|
} else { |
|
170
|
|
|
$b->setExtra('onclick="this.form.elements.op.value=\'mod\'"'); |
|
171
|
|
|
} |
|
172
|
|
|
$r = new XoopsFormElementTray(''); |
|
173
|
|
|
$r->addElement($l); |
|
174
|
|
|
$r->addElement($b); |
|
175
|
|
|
$cat_tray->addElement($r); |
|
176
|
|
|
|
|
177
|
|
|
$sform->addElement($cat_tray); |
|
178
|
|
|
//End of fx2024 code |
|
179
|
|
|
|
|
180
|
|
|
/*$gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
|
|
181
|
|
|
$mod_perms = $gpermHandler->getGroupIds('category_moderation', $categoryid, $module_id); |
|
182
|
|
|
|
|
183
|
|
|
$moderators_select = new XoopsFormSelect('', 'moderators', $moderators, 5, true); |
|
184
|
|
|
$moderators_tray->addElement($moderators_select); |
|
185
|
|
|
|
|
186
|
|
|
$butt_mngmods = new XoopsFormButton('', '', 'Manage mods', 'button'); |
|
187
|
|
|
$butt_mngmods->setExtra('onclick="javascript:small_window(\'pop.php\', 370, 350);"'); |
|
188
|
|
|
$moderators_tray->addElement($butt_mngmods); |
|
189
|
|
|
|
|
190
|
|
|
$butt_delmod = new XoopsFormButton('', '', 'Delete mod', 'button'); |
|
191
|
|
|
$butt_delmod->setExtra('onclick="javascript:deleteSelectedItemsFromList(this.form.elements[\'moderators[]\']);"'); |
|
192
|
|
|
$moderators_tray->addElement($butt_delmod); |
|
193
|
|
|
|
|
194
|
|
|
$sform->addElement($moderators_tray); |
|
195
|
|
|
*/ |
|
196
|
|
|
$sform->addElement(new XoopsFormHidden('categoryid', $categoryid)); |
|
197
|
|
|
|
|
198
|
|
|
//$parentid = $categoryObj->parentid('s'); |
|
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
//$sform -> addElement( new XoopsFormHidden( 'parentid', $parentid ) ); |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
$sform->addElement(new XoopsFormHidden('nb_sub_yet', $nb_subcats)); |
|
203
|
|
|
|
|
204
|
|
|
// Action buttons tray |
|
205
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
|
206
|
|
|
|
|
207
|
|
|
/*for ($i = 0, $iMax = count($moderators); $i < $iMax; ++$i) { |
|
|
|
|
|
|
208
|
|
|
$allmods[] = $moderators[$i]; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
$hiddenmods = new XoopsFormHidden('allmods', $allmods); |
|
212
|
|
|
$button_tray->addElement($hiddenmods); |
|
213
|
|
|
*/ |
|
214
|
|
|
$hidden = new XoopsFormHidden('op', 'addcategory'); |
|
215
|
|
|
$button_tray->addElement($hidden); |
|
216
|
|
|
|
|
217
|
|
|
// No ID for category -- then it's new category, button says 'Create' |
|
218
|
|
|
if (!$categoryid) { |
|
219
|
|
|
$butt_create = new XoopsFormButton('', '', _AM_SPARTNER_CREATE, 'submit'); |
|
220
|
|
|
$butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
|
221
|
|
|
$button_tray->addElement($butt_create); |
|
222
|
|
|
|
|
223
|
|
|
$butt_clear = new XoopsFormButton('', '', _AM_SPARTNER_CLEAR, 'reset'); |
|
224
|
|
|
$button_tray->addElement($butt_clear); |
|
225
|
|
|
|
|
226
|
|
|
$butt_cancel = new XoopsFormButton('', '', _AM_SPARTNER_CANCEL, 'button'); |
|
227
|
|
|
$butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
228
|
|
|
$button_tray->addElement($butt_cancel); |
|
229
|
|
|
|
|
230
|
|
|
$sform->addElement($button_tray); |
|
231
|
|
|
$sform->display(); |
|
232
|
|
|
smartpartner_close_collapsable('createtable', 'createtableicon'); |
|
233
|
|
|
} else { |
|
234
|
|
|
// button says 'Update' |
|
235
|
|
|
$butt_create = new XoopsFormButton('', '', _AM_SPARTNER_MODIFY, 'submit'); |
|
236
|
|
|
$butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"'); |
|
237
|
|
|
$button_tray->addElement($butt_create); |
|
238
|
|
|
|
|
239
|
|
|
$butt_cancel = new XoopsFormButton('', '', _AM_SPARTNER_CANCEL, 'button'); |
|
240
|
|
|
$butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
241
|
|
|
$button_tray->addElement($butt_cancel); |
|
242
|
|
|
|
|
243
|
|
|
$sform->addElement($button_tray); |
|
244
|
|
|
$sform->display(); |
|
245
|
|
|
smartpartner_close_collapsable('edittable', 'edittableicon'); |
|
246
|
|
|
} |
|
247
|
|
|
/* |
|
248
|
|
|
//Added by fx2024 |
|
249
|
|
|
if ($categoryid) { |
|
250
|
|
|
// TODO: displaysubcats comes from smartpartner and need to be adapted for smartpartner |
|
251
|
|
|
include_once XOOPS_ROOT_PATH . "/modules/smartpartner/include/displaysubcats.php"; |
|
252
|
|
|
|
|
253
|
|
|
// TODO: displayitems comes from smartpartner and need to be adapted for smartpartner |
|
254
|
|
|
//include_once XOOPS_ROOT_PATH . "/modules/smartpartner/include/displayitems.php"; |
|
255
|
|
|
} |
|
256
|
|
|
//end of fx2024 code |
|
257
|
|
|
*/ |
|
258
|
|
|
unset($hidden); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
include_once __DIR__ . '/admin_header.php'; |
|
262
|
|
|
include(XOOPS_ROOT_PATH . '/class/xoopstree.php'); |
|
263
|
|
|
|
|
264
|
|
|
global $smartPartnerCategoryHandler; |
|
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
$op = ''; |
|
267
|
|
|
|
|
268
|
|
|
if (isset($_GET['op'])) { |
|
269
|
|
|
$op = $_GET['op']; |
|
270
|
|
|
} |
|
271
|
|
|
if (isset($_POST['op'])) { |
|
272
|
|
|
$op = $_POST['op']; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
// Where do we start ? |
|
276
|
|
|
$startcategory = isset($_GET['startcategory']) ? (int)$_GET['startcategory'] : 0; |
|
277
|
|
|
|
|
278
|
|
|
switch ($op) { |
|
279
|
|
|
case 'mod': |
|
280
|
|
|
$categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0; |
|
281
|
|
|
|
|
282
|
|
|
//Added by fx2024 |
|
283
|
|
|
|
|
284
|
|
|
$nb_subcats = isset($_POST['nb_subcats']) ? (int)$_POST['nb_subcats'] : 0; |
|
285
|
|
|
$nb_subcats += (isset($_POST['nb_sub_yet']) ? (int)$_POST['nb_sub_yet'] : 4); |
|
286
|
|
|
if ($categoryid == 0) { |
|
287
|
|
|
$categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0; |
|
288
|
|
|
} |
|
289
|
|
|
//end of fx2024 code |
|
290
|
|
|
|
|
291
|
|
|
smartpartner_xoops_cp_header(); |
|
292
|
|
|
|
|
293
|
|
|
editcat(true, $categoryid, $nb_subcats); |
|
294
|
|
|
break; |
|
295
|
|
|
|
|
296
|
|
|
case 'addcategory': |
|
297
|
|
|
global $_POST, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $modify, $myts, $categoryid; |
|
|
|
|
|
|
298
|
|
|
|
|
299
|
|
|
$categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0; |
|
300
|
|
|
$parentid = isset($_POST['parentid']) ? (int)$_POST['parentid'] : 0; |
|
301
|
|
|
|
|
302
|
|
|
if ($categoryid != 0) { |
|
303
|
|
|
$categoryObj = $smartPartnerCategoryHandler->get($categoryid); |
|
304
|
|
|
} else { |
|
305
|
|
|
$categoryObj = $smartPartnerCategoryHandler->create(); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
// Uploading the image, if any |
|
309
|
|
|
// Retreive the filename to be uploaded |
|
310
|
|
|
if (isset($_FILES['image_file']['name']) && $_FILES['image_file']['name'] != '') { |
|
311
|
|
|
$filename = $_POST['xoops_upload_file'][0]; |
|
312
|
|
View Code Duplication |
if (!empty($filename) || $filename != '') { |
|
|
|
|
|
|
313
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
// TODO: implement smartpartner mimetype management |
|
316
|
|
|
|
|
317
|
|
|
$max_size = $xoopsModuleConfig['maximum_imagesize']; |
|
318
|
|
|
$max_imgwidth = $xoopsModuleConfig['img_max_width']; |
|
319
|
|
|
$max_imgheight = $xoopsModuleConfig['img_max_height']; |
|
320
|
|
|
$allowed_mimetypes = smartpartner_getAllowedImagesTypes(); |
|
321
|
|
|
|
|
322
|
|
|
include_once(XOOPS_ROOT_PATH . '/class/uploader.php'); |
|
323
|
|
|
|
|
324
|
|
|
if ($_FILES[$filename]['tmp_name'] == '' || !is_readable($_FILES[$filename]['tmp_name'])) { |
|
325
|
|
|
redirect_header('javascript:history.go(-1)', 2, _AM_SPARTNER_FILEUPLOAD_ERROR); |
|
326
|
|
|
exit; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
$uploader = new XoopsMediaUploader(smartpartner_getImageDir('category'), $allowed_mimetypes, $max_size, $max_imgwidth, $max_imgheight); |
|
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
if ($uploader->fetchMedia($filename) && $uploader->upload()) { |
|
332
|
|
|
$categoryObj->setVar('image', $uploader->getSavedFileName()); |
|
333
|
|
|
} else { |
|
334
|
|
|
redirect_header('javascript:history.go(-1)', 2, _AM_SPARTNER_FILEUPLOAD_ERROR . $uploader->getErrors()); |
|
335
|
|
|
exit; |
|
336
|
|
|
} |
|
337
|
|
|
} |
|
338
|
|
|
} else { |
|
339
|
|
|
if (isset($_POST['image'])) { |
|
340
|
|
|
$categoryObj->setVar('image', $_POST['image']); |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
$categoryObj->setVar('parentid', isset($_POST['parentid']) ? (int)$_POST['parentid'] : 0); |
|
344
|
|
|
|
|
345
|
|
|
$applyall = isset($_POST['applyall']) ? (int)$_POST['applyall'] : 0; |
|
346
|
|
|
$categoryObj->setVar('weight', isset($_POST['weight']) ? (int)$_POST['weight'] : 1); |
|
347
|
|
|
|
|
348
|
|
|
$categoryObj->setVar('name', $_POST['name']); |
|
349
|
|
|
|
|
350
|
|
|
$categoryObj->setVar('description', $_POST['description']); |
|
351
|
|
|
|
|
352
|
|
|
if ($categoryObj->isNew()) { |
|
353
|
|
|
$redirect_msg = _AM_SPARTNER_CATEGORY_CREATED; |
|
354
|
|
|
$redirect_to = 'category.php?op=mod'; |
|
355
|
|
|
} else { |
|
356
|
|
|
$redirect_msg = _AM_SPARTNER_CATEGORY_MODIFIED; |
|
357
|
|
|
$redirect_to = 'category.php'; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
View Code Duplication |
if (!$categoryObj->store()) { |
|
|
|
|
|
|
361
|
|
|
redirect_header('javascript:history.go(-1)', 3, _AM_SPARTNER_CATEGORY_SAVE_ERROR . smartpartner_formatErrors($categoryObj->getErrors())); |
|
362
|
|
|
exit; |
|
363
|
|
|
} |
|
364
|
|
|
//Added by fx2024 |
|
365
|
|
|
$parentCat = $categoryObj->categoryid(); |
|
366
|
|
|
|
|
367
|
|
|
for ($i = 0, $iMax = count($_POST['scname']); $i < $iMax; ++$i) { |
|
368
|
|
|
if ($_POST['scname'][$i] != '') { |
|
369
|
|
|
$categoryObj = $smartPartnerCategoryHandler->create(); |
|
370
|
|
|
$categoryObj->setVar('name', $_POST['scname'][$i]); |
|
371
|
|
|
$categoryObj->setVar('parentid', $parentCat); |
|
372
|
|
|
|
|
373
|
|
View Code Duplication |
if (!$categoryObj->store()) { |
|
|
|
|
|
|
374
|
|
|
redirect_header('javascript:history.go(-1)', 3, _AM_SPARTNER_CATEGORY_SUBCAT_SAVE_ERROR . smartpartner_formatErrors($categoryObj->getErrors())); |
|
375
|
|
|
exit; |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
//end of fx2024 code |
|
381
|
|
|
redirect_header($redirect_to, 2, $redirect_msg); |
|
382
|
|
|
|
|
383
|
|
|
break; |
|
384
|
|
|
|
|
385
|
|
|
//Added by fx2024 |
|
386
|
|
|
|
|
387
|
|
|
case 'addsubcats': |
|
388
|
|
|
$categoryid = 0; |
|
389
|
|
|
$nb_subcats = (int)$_POST['nb_subcats'] + $_POST['nb_sub_yet']; |
|
390
|
|
|
|
|
391
|
|
|
smartpartner_xoops_cp_header(); |
|
392
|
|
|
|
|
393
|
|
|
$categoryObj = $smartPartnerCategoryHandler->create(); |
|
394
|
|
|
$categoryObj->setVar('name', $_POST['name']); |
|
395
|
|
|
$categoryObj->setVar('description', $_POST['description']); |
|
396
|
|
|
$categoryObj->setVar('weight', $_POST['weight']); |
|
397
|
|
|
if (isset($parentCat)) { |
|
398
|
|
|
$categoryObj->setVar('parentid', $parentCat); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
editcat(true, $categoryid, $nb_subcats, $categoryObj); |
|
402
|
|
|
exit(); |
|
403
|
|
|
|
|
404
|
|
|
break; |
|
405
|
|
|
//end of fx2024 code |
|
406
|
|
|
|
|
407
|
|
View Code Duplication |
case 'del': |
|
|
|
|
|
|
408
|
|
|
global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET; |
|
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
|
411
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
412
|
|
|
|
|
413
|
|
|
$categoryid = isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0; |
|
414
|
|
|
$categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : $categoryid; |
|
415
|
|
|
|
|
416
|
|
|
//$categoryObj = new SmartpartnerCategory($categoryid); |
|
|
|
|
|
|
417
|
|
|
$categoryObj = $smartPartnerCategoryHandler->get($categoryid); |
|
418
|
|
|
|
|
419
|
|
|
$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
420
|
|
|
$name = isset($_POST['name']) ? $_POST['name'] : ''; |
|
421
|
|
|
|
|
422
|
|
|
if ($confirm) { |
|
423
|
|
|
if (!$smartPartnerCategoryHandler->delete($categoryObj)) { |
|
424
|
|
|
redirect_header('category.php', 1, _AM_SPARTNER_CATEGORY_DELETE_ERROR); |
|
425
|
|
|
exit; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
redirect_header('category.php', 1, sprintf(_AM_SPARTNER_CATEGORY_DELETED, $name)); |
|
429
|
|
|
} else { |
|
430
|
|
|
// no confirm: show deletion condition |
|
431
|
|
|
$categoryid = isset($_GET['categoryid']) ? (int)$_GET['categoryid'] : 0; |
|
432
|
|
|
xoops_cp_header(); |
|
433
|
|
|
xoops_confirm(array('op' => 'del', 'categoryid' => $categoryObj->categoryid(), 'confirm' => 1, 'name' => $categoryObj->name()), 'category.php', |
|
434
|
|
|
_AM_SPARTNER_CATEGORY_DELETE . " '" . $categoryObj->name() . "'. <br> <br>" . _AM_SPARTNER_CATEGORY_DELETE_CONFIRM, _AM_SPARTNER_DELETE); |
|
435
|
|
|
xoops_cp_footer(); |
|
436
|
|
|
} |
|
437
|
|
|
exit(); |
|
438
|
|
|
break; |
|
439
|
|
|
|
|
440
|
|
|
case 'cancel': |
|
|
|
|
|
|
441
|
|
|
redirect_header('category.php', 1, sprintf(_AM_SPARTNER_BACK2IDX, '')); |
|
442
|
|
|
|
|
443
|
|
|
case 'default': |
|
444
|
|
|
default: |
|
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
smartpartner_xoops_cp_header(); |
|
447
|
|
|
$indexAdmin = new ModuleAdmin(); |
|
448
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__)); |
|
449
|
|
|
|
|
450
|
|
|
$indexAdmin->addItemButton(_AM_SPARTNER_CATEGORY_CREATE, 'category.php?op=mod', 'add', ''); |
|
451
|
|
|
echo $indexAdmin->renderButton('left', ''); |
|
452
|
|
|
|
|
453
|
|
|
/* |
|
|
|
|
|
|
454
|
|
|
echo "<br>\n"; |
|
455
|
|
|
echo "<form><div style=\"margin-bottom: 12px;\">"; |
|
456
|
|
|
echo "<input type='button' name='button' onclick=\"location='category.php?op=mod'\" value='" . _AM_SPARTNER_CATEGORY_CREATE . "'> "; |
|
457
|
|
|
//echo "<input type='button' name='button' onclick=\"location='partner.php?op=mod'\" value='" . _AM_SPARTNER_CREATEITEM . "'> "; |
|
458
|
|
|
echo "</div></form>"; |
|
459
|
|
|
*/ |
|
460
|
|
|
// Creating the objects for top categories |
|
461
|
|
|
$categoriesObj = $smartPartnerCategoryHandler->getCategories($xoopsModuleConfig['perpage_admin'], $startcategory, 0); |
|
462
|
|
|
|
|
463
|
|
|
smartpartner_collapsableBar('createdcategories', 'createdcategoriesicon', _AM_SPARTNER_CATEGORIES_TITLE, _AM_SPARTNER_CATEGORIES_DSC); |
|
464
|
|
|
|
|
465
|
|
|
echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
|
466
|
|
|
echo '<tr>'; |
|
467
|
|
|
echo "<td class='bg3' align='left'><b>" . _AM_SPARTNER_CATEGORY . '</b></td>'; |
|
468
|
|
|
echo "<td class='bg3' width='65' align='center'><b>" . _AM_SPARTNER_WEIGHT . '</b></td>'; |
|
469
|
|
|
echo "<td width='60' class='bg3' align='center'><b>" . _AM_SPARTNER_ACTION . '</b></td>'; |
|
470
|
|
|
echo '</tr>'; |
|
471
|
|
|
$totalCategories = $smartPartnerCategoryHandler->getCategoriesCount(0); |
|
472
|
|
|
if (count($categoriesObj) > 0) { |
|
473
|
|
|
foreach ($categoriesObj as $key => $thiscat) { |
|
474
|
|
|
displayCategory($thiscat); |
|
475
|
|
|
} |
|
476
|
|
|
} else { |
|
477
|
|
|
echo '<tr>'; |
|
478
|
|
|
echo "<td class='head' align='center' colspan= '7'>" . _AM_SPARTNER_CATEGORY_NONE . '</td>'; |
|
479
|
|
|
echo '</tr>'; |
|
480
|
|
|
$categoryid = '0'; |
|
481
|
|
|
} |
|
482
|
|
|
echo "</table>\n"; |
|
483
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
484
|
|
|
$pagenav = new XoopsPageNav($totalCategories, $xoopsModuleConfig['perpage_admin'], $startcategory, 'startcategory'); |
|
485
|
|
|
echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
|
486
|
|
|
echo '<br>'; |
|
487
|
|
|
smartpartner_close_collapsable('createdcategories', 'createdcategoriesicon'); |
|
488
|
|
|
echo '<br>'; |
|
489
|
|
|
//editcat(false); |
|
490
|
|
|
break; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
//smart_modFooter(); |
|
|
|
|
|
|
494
|
|
|
//xoops_cp_footer(); |
|
495
|
|
|
include_once __DIR__ . '/admin_footer.php'; |
|
496
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.