1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Request;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23:
24: include_once __DIR__ . '/admin_header.php';
25:
26: $xoops = Xoops::getInstance();
27: $op = Request::getCmd('op');
28:
29: $op = isset($_POST['editor']) ? 'mod' : $op;
30: if (isset($_POST['addcategory'])) {
31: $op = 'addcategory';
32: }
33:
34:
35: $startcategory = Request::getInt('startcategory');
36: $categoryid = Request::getInt('categoryid');
37:
38: switch ($op) {
39:
40: case "del":
41:
42: $categoryObj = $publisher->getCategoryHandler()->get($categoryid);
43: $confirm = (isset($_POST['confirm'])) ? $_POST['confirm'] : 0;
44: $name = (isset($_POST['name'])) ? $_POST['name'] : '';
45: if ($confirm) {
46: if (!$publisher->getCategoryHandler()->delete($categoryObj)) {
47: $xoops->redirect("category.php", 1, _AM_PUBLISHER_DELETE_CAT_ERROR);
48: }
49: $xoops->redirect("category.php", 1, sprintf(_AM_PUBLISHER_COLISDELETED, $name));
50: } else {
51: $xoops->header();
52: echo $xoops->confirm(array('op' => 'del', 'categoryid' => $categoryObj->getVar('categoryid'), 'confirm' => 1, 'name' => $categoryObj->getVar('name')), 'category.php', _AM_PUBLISHER_DELETECOL . " '" . $categoryObj->getVar('name') . "'. <br /> <br />" . _AM_PUBLISHER_DELETE_CAT_CONFIRM, _AM_PUBLISHER_DELETE);
53: $xoops->footer();
54: }
55: break;
56:
57: case "mod":
58:
59: $nb_subcats = isset($_POST['nb_subcats']) ? (int)($_POST['nb_subcats']) : 0;
60: $nb_subcats = $nb_subcats + (isset($_POST['nb_sub_yet']) ? (int)($_POST['nb_sub_yet']) : 4);
61:
62:
63: PublisherUtils::cpHeader();
64: publisher_editCat(true, $categoryid, $nb_subcats);
65: break;
66:
67: case "addcategory":
68: global $modify;
69:
70: $parentid = Request::getInt('parentid');
71:
72: if ($categoryid != 0) {
73: $categoryObj = $publisher->getCategoryHandler()->get($categoryid);
74: } else {
75: $categoryObj = $publisher->getCategoryHandler()->create();
76: }
77:
78:
79:
80: if (isset($_FILES['image_file']['name']) && $_FILES['image_file']['name'] != "") {
81: $filename = $_POST["xoops_upload_file"][0];
82: if (!empty($filename) || $filename != "") {
83:
84: $max_size = $publisher->getConfig('maximum_filesize');
85: $max_imgwidth = $publisher->getConfig('maximum_image_width');
86: $max_imgheight = $publisher->getConfig('maximum_image_height');
87: $allowed_mimetypes = PublisherUtils::getAllowedImagesTypes();
88:
89: if ($_FILES[$filename]['tmp_name'] == "" || !is_readable($_FILES[$filename]['tmp_name'])) {
90: $xoops->redirect('javascript:history.go(-1)', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR);
91: }
92:
93: $uploader = new XoopsMediaUploader(PublisherUtils::getImageDir('category'), $allowed_mimetypes, $max_size, $max_imgwidth, $max_imgheight);
94: if ($uploader->fetchMedia($filename) && $uploader->upload()) {
95: $categoryObj->setVar('image', $uploader->getSavedFileName());
96: } else {
97: $xoops->redirect('javascript:history.go(-1)', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR . $uploader->getErrors());
98: }
99: }
100: } else {
101: if (isset($_POST['image'])) {
102: $categoryObj->setVar('image', $_POST['image']);
103: }
104: }
105: $categoryObj->setVar('parentid', (isset($_POST['parentid'])) ? (int)($_POST['parentid']) : 0);
106:
107: $applyall = isset($_POST['applyall']) ? (int)($_POST['applyall']) : 0;
108: $categoryObj->setVar('weight', isset($_POST['weight']) ? (int)($_POST['weight']) : 1);
109:
110:
111: $grpread = isset($_POST['groups_read']) ? $_POST['groups_read'] : array();
112: $grpsubmit = isset($_POST['groups_submit']) ? $_POST['groups_submit'] : array();
113: $grpmoderation = isset($_POST['groups_moderation']) ? $_POST['groups_moderation'] : array();
114:
115:
116: $categoryObj->setVar('name', $_POST['name']);
117:
118:
119: if (isset($_POST['template'])) {
120: $categoryObj->setVar('template', $_POST['template']);
121: }
122:
123: if (isset($_POST['meta_description'])) {
124: $categoryObj->setVar('meta_description', $_POST['meta_description']);
125: }
126: if (isset($_POST['meta_keywords'])) {
127: $categoryObj->setVar('meta_keywords', $_POST['meta_keywords']);
128: }
129: if (isset($_POST['short_url'])) {
130: $categoryObj->setVar('short_url', $_POST['short_url']);
131: }
132: $categoryObj->setVar('moderator', (int)($_POST['moderator']));
133: $categoryObj->setVar('description', $_POST['description']);
134:
135: if (isset($_POST['header'])) {
136: $categoryObj->setVar('header', $_POST['header']);
137: }
138:
139: if ($categoryObj->isNew()) {
140: $redirect_msg = _AM_PUBLISHER_CATCREATED;
141: $redirect_to = 'category.php?op=mod';
142: } else {
143: $redirect_msg = _AM_PUBLISHER_COLMODIFIED;
144: $redirect_to = 'category.php';
145: }
146:
147: if (!$categoryObj->store()) {
148: $xoops->redirect("javascript:history.go(-1)", 3, _AM_PUBLISHER_CATEGORY_SAVE_ERROR . PublisherUtils::formatErrors($categoryObj->getErrors()));
149: }
150:
151: PublisherUtils::saveCategoryPermissions($grpread, $categoryObj->getVar('categoryid'), 'category_read');
152: PublisherUtils::saveCategoryPermissions($grpsubmit, $categoryObj->getVar('categoryid'), 'item_submit');
153: PublisherUtils::saveCategoryPermissions($grpmoderation, $categoryObj->getVar('categoryid'), 'category_moderation');
154:
155:
156:
157: $parentCat = $categoryObj->getVar('categoryid');
158: $sizeof = sizeof($_POST['scname']);
159: for ($i = 0; $i < $sizeof; ++$i) {
160: if ($_POST['scname'][$i] != '') {
161: $categoryObj = $publisher->getCategoryHandler()->create();
162: $categoryObj->setVar('name', $_POST['scname'][$i]);
163: $categoryObj->setVar('parentid', $parentCat);
164:
165: if (!$categoryObj->store()) {
166: $xoops->redirect("javascript:history.go(-1)", 3, _AM_PUBLISHER_SUBCATEGORY_SAVE_ERROR . PublisherUtils::formatErrors($categoryObj->getErrors()));
167: }
168:
169: PublisherUtils::saveCategoryPermissions($grpread, $categoryObj->getVar('categoryid'), 'category_read');
170: PublisherUtils::saveCategoryPermissions($grpsubmit, $categoryObj->getVar('categoryid'), 'item_submit');
171: PublisherUtils::saveCategoryPermissions($grpmoderation, $categoryObj->getVar('categoryid'), 'category_moderation');
172: }
173: }
174:
175: $xoops->redirect($redirect_to, 2, $redirect_msg);
176: break;
177:
178:
179:
180: case "addsubcats":
181: $categoryid = 0;
182: $nb_subcats = (int)($_POST['nb_subcats']) + $_POST['nb_sub_yet'];
183:
184: $categoryObj = $publisher->getCategoryHandler()->create();
185: $categoryObj->setVar('name', $_POST['name']);
186: $categoryObj->setVar('description', $_POST['description']);
187: $categoryObj->setVar('weight', $_POST['weight']);
188: if (isset($parentCat)) {
189: $categoryObj->setVar('parentid', $parentCat);
190: }
191:
192: PublisherUtils::cpHeader();
193: publisher_editCat(true, $categoryid, $nb_subcats, $categoryObj);
194: exit();
195:
196: break;
197:
198:
199: case "cancel":
200: $xoops->redirect("category.php", 1, sprintf(_AM_PUBLISHER_BACK2IDX, ''));
201: break;
202: case "default":
203: default:
204: PublisherUtils::cpHeader();
205:
206:
207: echo "<br />\n";
208: echo "<form><div style=\"margin-bottom: 12px;\">";
209: echo "<input type='button' name='button' onclick=\"location='category.php?op=mod'\" value='" . _AM_PUBLISHER_CATEGORY_CREATE . "'> ";
210:
211: echo "</div></form>";
212:
213:
214: $categoriesObj = $publisher->getCategoryHandler()->getCategories($publisher->getConfig('idxcat_perpage'), $startcategory, 0);
215:
216: PublisherUtils::openCollapsableBar('createdcategories', 'createdcategoriesicon', _AM_PUBLISHER_CATEGORIES_TITLE, _AM_PUBLISHER_CATEGORIES_DSC);
217:
218: echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
219: echo "<tr>";
220: echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCATEGORYNAME . "</strong></td>";
221: echo "<td width='60' class='bg3' width='65' align='center'><strong>" . _CO_PUBLISHER_WEIGHT . "</strong></td>";
222: echo "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
223: echo "</tr>";
224: $totalCategories = $publisher->getCategoryHandler()->getCategoriesCount(0);
225: if (count($categoriesObj) > 0) {
226: foreach ($categoriesObj as $key => $thiscat) {
227: publisher_displayCategory($thiscat);
228: }
229: } else {
230: echo "<tr>";
231: echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOCAT . "</td>";
232: echo "</tr>";
233: $categoryid = '0';
234: }
235: echo "</table>\n";
236: $pagenav = new XoopsPageNav($totalCategories, $publisher->getConfig('idxcat_perpage'), $startcategory, 'startcategory');
237: echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
238: echo "<br />";
239: PublisherUtils::closeCollapsableBar('createdcategories', 'createdcategoriesicon');
240: echo "<br>";
241:
242: break;
243: }
244:
245: $xoops->footer();
246:
247: function publisher_displayCategory(PublisherCategory $categoryObj, $level = 0)
248: {
249: $publisher = Publisher::getInstance();
250:
251: $description = $categoryObj->getVar('description');
252: if (!XoopsLocale::isMultiByte()) {
253: if (strlen($description) >= 100) {
254: $description = substr($description, 0, (100 - 1)) . "...";
255: }
256: }
257: $modify = "<a href='category.php?op=mod&categoryid=" . $categoryObj->getVar('categoryid') . "&parentid=" . $categoryObj->getVar('parentid') . "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITCOL . "' alt='" . _AM_PUBLISHER_EDITCOL . "' /></a>";
258: $delete = "<a href='category.php?op=del&categoryid=" . $categoryObj->getVar('categoryid') . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETECOL . "' alt='" . _AM_PUBLISHER_DELETECOL . "' /></a>";
259:
260: $spaces = '';
261: for ($j = 0; $j < $level; ++$j) {
262: $spaces .= ' ';
263: }
264:
265: echo "<tr>";
266: echo "<td class='even' align='left'>" . $spaces . "<a href='" . PUBLISHER_URL . "/category.php?categoryid=" . $categoryObj->getVar('categoryid') . "'><img src='" . PUBLISHER_URL . "/images/links/subcat.gif' alt='' /> " . $categoryObj->getVar('name') . "</a></td>";
267: echo "<td class='even' align='center'>" . $categoryObj->getVar('weight') . "</td>";
268: echo "<td class='even' align='center'> $modify $delete </td>";
269: echo "</tr>";
270: $subCategoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $categoryObj->getVar('categoryid'));
271: if (count($subCategoriesObj) > 0) {
272: ++$level;
273: foreach ($subCategoriesObj as $thiscat) {
274: publisher_displayCategory($thiscat, $level);
275: }
276: }
277: unset($categoryObj);
278: }
279:
280: function publisher_editCat($showmenu = false, $categoryid = 0, $nb_subcats = 4, $categoryObj = null)
281: {
282: $xoops = Xoops::getInstance();
283: $publisher = Publisher::getInstance();
284:
285:
286:
287: if ($categoryid != 0) {
288:
289: $categoryObj = $publisher->getCategoryHandler()->get($categoryid);
290: if ($categoryObj->notLoaded()) {
291: $xoops->redirect("category.php", 1, _AM_PUBLISHER_NOCOLTOEDIT);
292: }
293: } else {
294: if (!$categoryObj) {
295: $categoryObj = $publisher->getCategoryHandler()->create();
296: }
297: }
298:
299: if ($categoryid != 0) {
300: if ($showmenu) {
301:
302: }
303: echo "<br />\n";
304: PublisherUtils::openCollapsableBar('edittable', 'edittableicon', _AM_PUBLISHER_EDITCOL, _AM_PUBLISHER_CATEGORY_EDIT_INFO);
305: } else {
306: if ($showmenu) {
307:
308: }
309: PublisherUtils::openCollapsableBar('createtable', 'createtableicon', _AM_PUBLISHER_CATEGORY_CREATE, _AM_PUBLISHER_CATEGORY_CREATE_INFO);
310: }
311:
312:
313: $sform = $publisher->getForm($categoryObj, 'category');
314: $sform->setSubCatsCount($nb_subcats);
315: $sform->display();
316:
317: if (!$categoryid) {
318: PublisherUtils::closeCollapsableBar('createtable', 'createtableicon');
319: } else {
320: PublisherUtils::closeCollapsableBar('edittable', 'edittableicon');
321: }
322:
323:
324: if ($categoryid) {
325: $sel_cat = $categoryid;
326:
327: PublisherUtils::openCollapsableBar('subcatstable', 'subcatsicon', _AM_PUBLISHER_SUBCAT_CAT, _AM_PUBLISHER_SUBCAT_CAT_DSC);
328:
329: $categoriesObj = $publisher->getCategoryHandler()->get($sel_cat);
330: $totalsubs = $publisher->getCategoryHandler()->getCategoriesCount($sel_cat);
331:
332: $subcatsObj = $publisher->getCategoryHandler()->getCategories(0, 0, $categoriesObj->getVar('categoryid'));
333:
334: echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
335: echo "<tr>";
336: echo "<td width='60' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATID . "</strong></td>";
337: echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATCOLNAME . "</strong></td>";
338: echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_SUBDESCRIPT . "</strong></td>";
339: echo "<td width='60' class='bg3' align='right'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
340: echo "</tr>";
341: if ($totalsubs > 0) {
342:
343: foreach ($subcatsObj as $subcat) {
344: $modify = "<a href='category.php?op=mod&categoryid=" . $subcat->getVar('categoryid') . "'><img src='" . \XoopsBaseConfig::get('url') . "/modules/" . $publisher->getModule()->dirname() . "/images/links/edit.gif' title='" . _AM_PUBLISHER_MODIFY . "' alt='" . _AM_PUBLISHER_MODIFY . "' /></a>";
345: $delete = "<a href='category.php?op=del&categoryid=" . $subcat->getVar('categoryid') . "'><img src='" . \XoopsBaseConfig::get('url') . "/modules/" . $publisher->getModule()->dirname() . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETE . "' alt='" . _AM_PUBLISHER_DELETE . "' /></a>";
346: echo "<tr>";
347: echo "<td class='head' align='left'>" . $subcat->getVar('categoryid') . "</td>";
348: echo "<td class='even' align='left'><a href='" . \XoopsBaseConfig::get('url') . "/modules/" . $publisher->getModule()->dirname() . "/category.php?categoryid=" . $subcat->getVar('categoryid') . "&parentid=" . $subcat->getVar('parentid'). "'>" . $subcat->getVar('name') . "</a></td>";
349: echo "<td class='even' align='left'>" . $subcat->getVar('description') . "</td>";
350: echo "<td class='even' align='right'> {$modify} {$delete} </td>";
351: echo "</tr>";
352: }
353: } else {
354: echo "<tr>";
355: echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOSUBCAT . "</td>";
356: echo "</tr>";
357: }
358: echo "</table>\n";
359: echo "<br />\n";
360: PublisherUtils::closeCollapsableBar('subcatstable', 'subcatsicon');
361:
362: PublisherUtils::openCollapsableBar('bottomtable', 'bottomtableicon', _AM_PUBLISHER_CAT_ITEMS, _AM_PUBLISHER_CAT_ITEMS_DSC);
363: $startitem = Request::getInt('startitem');
364:
365: $totalitems = $publisher->getItemHandler()->getItemsCount($sel_cat, array(_PUBLISHER_STATUS_PUBLISHED));
366:
367: $itemsObj = $publisher->getItemHandler()->getAllPublished($publisher->getConfig('idxcat_perpage'), $startitem, $sel_cat);
368: $totalitemsOnPage = count($itemsObj);
369: $allcats = $publisher->getCategoryHandler()->getObjects(null, true);
370: echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
371: echo "<tr>";
372: echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . "</strong></td>";
373: echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCOLNAME . "</strong></td>";
374: echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMDESC . "</strong></td>";
375: echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . "</strong></td>";
376: echo "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
377: echo "</tr>";
378: if ($totalitems > 0) {
379: for ($i = 0; $i < $totalitemsOnPage; ++$i) {
380: $categoryObj = $allcats[$itemsObj[$i]->getVar('categoryid')];
381: $modify = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->getVar('itemid'). "'><img src='" . \XoopsBaseConfig::get('url') . "/modules/" . $publisher->getModule()->dirname() . "/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>";
382: $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->getVar('itemid'). "'><img src='" . \XoopsBaseConfig::get('url') . "/modules/" . $publisher->getModule()->dirname() . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>";
383: echo "<tr>";
384: echo "<td class='head' align='center'>" . $itemsObj[$i]->getVar('itemid'). "</td>";
385: echo "<td class='even' align='left'>" . $categoryObj->getVar('name') . "</td>";
386: echo "<td class='even' align='left'>" . $itemsObj[$i]->getitemLink() . "</td>";
387: echo "<td class='even' align='center'>" . $itemsObj[$i]->datesub('s') . "</td>";
388: echo "<td class='even' align='center'> $modify $delete </td>";
389: echo "</tr>";
390: }
391: } else {
392: echo "<tr>";
393: echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS . "</td>";
394: echo "</tr>";
395: }
396: echo "</table>\n";
397: echo "<br />\n";
398: $parentid = Request::getInt('parentid');
399: $pagenav_extra_args = "op=mod&categoryid=$sel_cat&parentid=$parentid";
400: $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $startitem, 'startitem', $pagenav_extra_args);
401: echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
402: echo "<input type='button' name='button' onclick=\"location='item.php?op=mod&categoryid=" . $sel_cat . "'\" value='" . _AM_PUBLISHER_CREATEITEM . "'> ";
403: echo "</div>";
404: }
405:
406: }
407: