|
| 1 | +<?php |
| 2 | +/* |
| 3 | + You may not change or alter any portion of this comment or credits of |
| 4 | + supporting developers from this source code or any supporting source code |
| 5 | + which is considered copyrighted (c) material of the original comment or credit |
| 6 | + authors. |
| 7 | +
|
| 8 | + This program is distributed in the hope that it will be useful, but |
| 9 | + WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | + */ |
| 12 | +/** |
| 13 | + * Category Admin file |
| 14 | + * |
| 15 | + * @package module\xoopsfaq\admin |
| 16 | + * @author John Neill |
| 17 | + * @author XOOPS Module Development Team |
| 18 | + * @copyright Copyright (c) 2001-2017 {@link http://xoops.org XOOPS Project} |
| 19 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
| 20 | + * @since:: 1.23 |
| 21 | + * |
| 22 | + * @see Xmf\Request |
| 23 | + * @see Xmf\Module\Helper\Permission |
| 24 | + */ |
| 25 | +use Xmf\Request; |
| 26 | + |
| 27 | +require_once __DIR__ . '/admin_header.php'; |
| 28 | +xoops_cp_header(); |
| 29 | + |
| 30 | +$xfCatHandler = $xfHelper->getHandler('category'); |
| 31 | + |
| 32 | +$op = Request::getCmd('op', 'default'); |
| 33 | +switch ($op) { |
| 34 | + case 'edit': |
| 35 | + $adminObject->displayNavigation('category.php'); |
| 36 | + $catId = Request::getInt('category_id', null); |
| 37 | + $obj = $xfCatHandler->get($catId); |
| 38 | + if ($obj instanceof XoopsfaqCategory) { |
| 39 | + $obj->displayForm(); |
| 40 | + } else { |
| 41 | + $xfCatHandler->displayError(_AM_XOOPSFAQ_ERROR_COULD_NOT_EDIT_CAT); |
| 42 | + } |
| 43 | + break; |
| 44 | + |
| 45 | + case 'delete': |
| 46 | + $ok = Request::getInt('ok', XoopsfaqConstants::CONFIRM_NOT_OK); |
| 47 | + $catId = Request::getInt('category_id', XoopsfaqConstants::DEFAULT_CATEGORY); |
| 48 | + if (XoopsfaqConstants::CONFIRM_OK === (int)$ok) { |
| 49 | + // check to make sure this passes form submission security |
| 50 | + if ($GLOBALS['xoopsSecurity'] instanceof XoopsSecurity) { |
| 51 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
| 52 | + // failed xoops security check |
| 53 | + $xfHelper->redirect('admin/index.php', XoopsfaqConstants::REDIRECT_DELAY_MEDIUM, $GLOBALS['xoopsSecurity']->getErrors(true)); |
| 54 | + } |
| 55 | + } else { |
| 56 | + $xfHelper->redirect('admin/index.php', XoopsfaqConstants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSFAQ_INVALID_SECURITY_TOKEN); |
| 57 | + } |
| 58 | + |
| 59 | + $obj = $xfCatHandler->get($catId); |
| 60 | + if ($obj instanceof XoopsfaqCategory && !$obj->isNew()) { |
| 61 | + // Delete all FAQs in this category |
| 62 | + $xfFaqHandler = $xfHelper->getHandler('contents'); |
| 63 | + $criteria = new Criteria('contents_cid', $catId); |
| 64 | + $success = $xfFaqHandler->deleteAll($criteria); |
| 65 | + // Delete the category |
| 66 | + if (true === $xfCatHandler->delete($obj)) { |
| 67 | + // Delete comments |
| 68 | + xoops_comment_delete($xfHelper->getModule()->getVar('mid'), $catId); |
| 69 | + $xfHelper->redirect('admin/category.php', XoopsfaqConstants::REDIRECT_DELAY_MEDIUM, _AM_XOOPSFAQ_DBSUCCESS); |
| 70 | + // Delete permissions |
| 71 | + $permHelper = new Xmf\Module\Helper\Permission(); |
| 72 | + $permHelper->deletePermissionForItem('viewcat', $catId); |
| 73 | + } |
| 74 | + } |
| 75 | + $xfCatHandler->displayError(_AM_XOOPSFAQ_ERROR_COULD_NOT_DEL_CAT); |
| 76 | + } else { |
| 77 | + $adminObject->displayNavigation('category.php'); |
| 78 | + xoops_confirm(array('op' => 'delete', 'category_id' => $catId, 'ok' => XoopsfaqConstants::CONFIRM_OK), 'category.php', _AM_XOOPSFAQ_RUSURE_CAT); |
| 79 | + } |
| 80 | + break; |
| 81 | + |
| 82 | + case 'save': |
| 83 | + if ( ($GLOBALS['xoopsSecurity'] instanceof XoopsSecurity) ) { |
| 84 | + if ( !$GLOBALS['xoopsSecurity']->check() ) { |
| 85 | + // failed xoops security check |
| 86 | + $xfHelper->redirect('admin/index.php', 3, $GLOBALS['xoopsSecurity']->getErrors(true)); |
| 87 | + } |
| 88 | + } else { |
| 89 | + $xfHelper->redirect('admin/index.php', XoopsfaqConstants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSFAQ_INVALID_SECURITY_TOKEN); |
| 90 | + } |
| 91 | + |
| 92 | + $catId = Request::getInt('category_id', XoopsfaqConstants::DEFAULT_CATEGORY, 'POST'); |
| 93 | + $obj = $xfCatHandler->get($catId); // creates category if catId = 0, else gets requested category |
| 94 | + if ($obj instanceof XoopsfaqCategory) { |
| 95 | + $obj->setVar('category_title', Request::getString('category_title', '')); |
| 96 | + $obj->setVar('category_order', Request::getInt('category_order', XoopsfaqConstants::DEFAULT_ORDER)); |
| 97 | + if ($savedId = $xfCatHandler->insert($obj)) { |
| 98 | + // Save group permissions |
| 99 | + $permHelper = new Xmf\Module\Helper\Permission(); |
| 100 | + $name = $permHelper->defaultFieldName('viewcat', $catId); |
| 101 | + $groups = Xmf\Request::getArray($name, array(), 'POST'); |
| 102 | + $permHelper->savePermissionForItem('viewcat', $savedId, $groups); |
| 103 | + $xfHelper->redirect('admin/category.php', XoopsfaqConstants::REDIRECT_DELAY_MEDIUM, _AM_XOOPSFAQ_DBSUCCESS); |
| 104 | + } |
| 105 | + } |
| 106 | + $xfCatHandler->displayError(_AM_XOOPSFAQ_ERROR_COULD_NOT_ADD_CAT); |
| 107 | + break; |
| 108 | + |
| 109 | + case 'default': |
| 110 | + default: |
| 111 | + $adminObject->displayNavigation('category.php'); |
| 112 | + $adminObject->addItemButton(_XO_XOOPSFAQ_ADDCAT, 'category.php?op=edit', 'add' , ''); |
| 113 | + $adminObject->displayButton('left'); |
| 114 | + $xfCatHandler->displayAdminListing('order'); |
| 115 | + break; |
| 116 | +} |
| 117 | +include_once __DIR__ . '/admin_footer.php'; |
0 commit comments