Exemplo n.º 1
0
 /**
  * edit category
  */
 public function editAction()
 {
     $cid = $this->request->get('cid', 0);
     $root_id = $this->request->get('dr', 1);
     $mode = $this->request->get('mode', 'new');
     $allCats = '';
     $editCat = '';
     $languages = ZLanguage::getInstalledLanguages();
     // indicates that we're editing
     if ($mode == 'edit') {
         if (!SecurityUtil::checkPermission('Categories::category', "::", ACCESS_ADMIN)) {
             throw new \Zikula\Framework\Exception\ForbiddenException();
         }
         if (!$cid) {
             return LogUtil::registerError($this->__('Error! Cannot determine valid \'cid\' for edit mode in \'Categories_admin_edit\'.'));
         }
         $category = new Category();
         $editCat = $category->select($cid);
         if ($editCat == false) {
             return LogUtil::registerError($this->__('Sorry! No such item found.'), 404);
         }
     } else {
         // new category creation
         if (!SecurityUtil::checkPermission('Categories::category', '::', ACCESS_ADD)) {
             throw new \Zikula\Framework\Exception\ForbiddenException();
         }
         // since we inherit the domain settings from the parent, we get
         // the inherited (and merged) object from session
         if (isset($_SESSION['newCategory']) && $_SESSION['newCategory']) {
             $editCat = $_SESSION['newCategory'];
             unset($_SESSION['newCategory']);
             $category = new Category();
             // need this for validation info
         } elseif (FormUtil::getValidationErrors()) {
             $category = new Category(DBObject::GET_FROM_VALIDATION_FAILED);
             // need this for validation info
             $editCat = $category->get();
         } else {
             $category = new Category();
             // need this for validation info
             $editCat['sort_value'] = '0';
         }
     }
     $reloadOnCatChange = $mode != 'edit';
     $allCats = CategoryUtil::getSubCategories($root_id, true, true, true, false, true);
     // now remove the categories which are below $editCat ...
     // you should not be able to set these as a parent category as it creates a circular hierarchy (see bug #4992)
     if (isset($editCat['ipath'])) {
         $cSlashEdit = StringUtil::countInstances($editCat['ipath'], '/');
         foreach ($allCats as $k => $v) {
             $cSlashCat = StringUtil::countInstances($v['ipath'], '/');
             if ($cSlashCat >= $cSlashEdit && strpos($v['ipath'], $editCat['ipath']) !== false) {
                 unset($allCats[$k]);
             }
         }
     }
     $selector = CategoryUtil::getSelector_Categories($allCats, 'id', isset($editCat['parent_id']) ? $editCat['parent_id'] : 0, 'category[parent_id]', isset($defaultValue) ? $defaultValue : null, null, $reloadOnCatChange);
     $attributes = isset($editCat['__ATTRIBUTES__']) ? $editCat['__ATTRIBUTES__'] : array();
     $this->view->assign('mode', $mode)->assign('category', $editCat)->assign('attributes', $attributes)->assign('languages', $languages)->assign('categorySelector', $selector)->assign('validation', $category->_objValidation);
     if ($mode == 'edit') {
         $this->view->assign('haveSubcategories', CategoryUtil::haveDirectSubcategories($cid))->assign('haveLeafSubcategories', CategoryUtil::haveDirectSubcategories($cid, false, true));
     }
     return $this->response($this->view->fetch('categories_admin_edit.tpl'));
 }
Exemplo n.º 2
0
 /**
  * move category
  */
 public function moveAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_EDIT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     if ($this->request->request->get('category_cancel', null)) {
         return $this->redirect(ModUtil::url('Categories', 'admin', 'view'));
     }
     $cid = $this->request->request->get('cid', null);
     $cat = new Category();
     $cat->get($cid);
     $cat->move($_POST['category']['parent_id']);
     $msg = __f('Done! Moved the %s category.', $cat->_objData['name']);
     LogUtil::registerStatus($msg);
     return $this->redirect(ModUtil::url('Categories', 'admin', 'view'));
 }
Exemplo n.º 3
0
 /**
  * edit categories for the currently logged in user
  */
 public function edituserAction()
 {
     if (!SecurityUtil::checkPermission('Categories::category', '::', ACCESS_EDIT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     if (!UserUtil::isLoggedIn()) {
         return LogUtil::registerError($this->__('Error! Editing mode for user-owned categories is only available to users who have logged-in.'));
     }
     $allowUserEdit = $this->getVar('allowusercatedit', 0);
     if (!$allowUserEdit) {
         return LogUtil::registerError($this->__('Error! User-owned category editing has not been enabled. This feature can be enabled by the site administrator.'));
     }
     $userRoot = $this->getVar('userrootcat', 0);
     if (!$userRoot) {
         return LogUtil::registerError($this->__('Error! Could not determine the user root node.'));
     }
     $userRootCat = CategoryUtil::getCategoryByPath($userRoot);
     if (!$userRoot) {
         return LogUtil::registerError($this->__f('Error! The user root node seems to point towards an invalid category: %s.', $userRoot));
     }
     if ($userRootCat == 1) {
         return LogUtil::registerError($this->__("Error! The root directory cannot be modified in 'user' mode"));
     }
     $userCatName = $this->getusercategoryname();
     if (!$userCatName) {
         return LogUtil::registerError($this->__('Error! Cannot determine user category root node name.'));
     }
     $thisUserRootCatPath = $userRoot . '/' . $userCatName;
     $thisUserRootCat = CategoryUtil::getCategoryByPath($thisUserRootCatPath);
     $dr = null;
     if (!$thisUserRootCat) {
         $autoCreate = $this->getVar('autocreateusercat', 0);
         if (!$autoCreate) {
             return LogUtil::registerError($this->__("Error! The user root category node for this user does not exist, and the automatic creation flag (autocreate) has not been set."));
         }
         $installer = new Installer($this->getContainer);
         $cat = array('id' => '', 'parent_id' => $userRootCat['id'], 'name' => $userCatName, 'display_name' => unserialize($installer->makeDisplayName($userCatName)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'security_domain' => 'Categories::', 'path' => $thisUserRootCatPath, 'status' => 'A');
         $obj = new Category();
         $obj->setData($cat);
         $obj->insert();
         // since the original insert can't construct the ipath (since
         // the insert id is not known yet) we update the object here
         $obj->update();
         $dr = $obj->getID();
         $autoCreateDefaultUserCat = $this->getVar('autocreateuserdefaultcat', 0);
         if ($autoCreateDefaultUserCat) {
             $userdefaultcatname = $this->getVar('userdefaultcatname', $this->__('Default'));
             $cat = array('id' => '', 'parent_id' => $dr, 'name' => $userdefaultcatname, 'display_name' => unserialize($installer->makeDisplayName($userdefaultcatname)), 'display_desc' => unserialize($installer->makeDisplayDesc()), 'security_domain' => 'Categories::', 'path' => $thisUserRootCatPath . '/' . $userdefaultcatname, 'status' => 'A');
             $obj->setData($cat);
             $obj->insert();
             // since the original insert can't construct the ipath (since
             // the insert id is not known yet) we update the object here
             $obj->update();
         }
     } else {
         $dr = $thisUserRootCat['id'];
     }
     $url = ModUtil::url('Categories', 'user', 'edit', array('dr' => $dr));
     return $this->redirect($url);
 }
Exemplo n.º 4
0
 /**
  * resequence categories
  */
 public function resequenceAction()
 {
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_EDIT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     $dr = (int) $this->request->query->get('dr', 0);
     $url = System::serverGetVar('HTTP_REFERER');
     if (!$dr) {
         return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url);
     }
     $cats = CategoryUtil::getSubCategories($dr, false, false, false, false);
     $cats = CategoryUtil::resequence($cats, 10);
     $ak = array_keys($cats);
     foreach ($ak as $k) {
         $obj = new Category($cats[$k]);
         $obj->update();
     }
     return $this->redirect(System::serverGetVar('HTTP_REFERER'));
 }