/**
  * create category
  */
 public function newcatAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     $cat = new Category();
     $cat->getDataFromInput();
     // submit button wasn't pressed -> category was chosen from dropdown
     // we now get the parent (security) category domains so we can inherit them
     if (!$this->request->request->get('category_submit', null)) {
         $newCat = $_POST['category'];
         $pcID = $newCat['parent_id'];
         $pCat = new Category();
         $parentCat = $pCat->get($pcID);
         //$newCat['security_domain'] = $parentCat['security_domain'];
         //for ($i=1; $i<=5; $i++) {
         //    $name = 'data' . $i . '_domain';
         //    $newCat[$name] = $parentCat[$name];
         //}
         $_SESSION['newCategory'] = $newCat;
         return $this->redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     if (!$cat->validate('admin')) {
         return $this->redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     $attributes = array();
     $values = $this->request->request->get('attribute_value', array());
     foreach ($this->request->request->get('attribute_name', array()) as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     if ($attributes) {
         $cat->setDataField('__ATTRIBUTES__', $attributes);
     }
     $cat->insert();
     // since the original insert can't construct the ipath (since
     // the insert id is not known yet) we update the object here.
     $cat->update();
     $msg = __f('Done! Inserted the %s category.', $cat->_objData['name']);
     LogUtil::registerStatus($msg);
     return $this->redirect(ModUtil::url('Categories', 'admin', 'view') . '#top');
 }
Example #2
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);
 }
 /**
  * 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'));
 }