Ejemplo n.º 1
0
 /**
  * update category
  */
 public function editAction()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_EDIT)) {
         throw new \Zikula\Framework\Exception\ForbiddenException();
     }
     $dr = (int) $this->request->request->get('dr', 0);
     $ref = System::serverGetVar('HTTP_REFERER');
     $returnfunc = strpos($ref, "useredit") !== false ? 'useredit' : 'edit';
     $url = ModUtil::url('Categories', 'user', $returnfunc, array('dr' => $dr));
     if (!$dr) {
         return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url);
     }
     $obj = new Category();
     $data = $obj->getDataFromInput();
     $oldData = $obj->get($data['id']);
     $obj->setData($data);
     if (!$oldData) {
         $msg = $this->__f('Error! Cannot retrieve category with ID %s.', $data['id']);
         return LogUtil::registerError($msg, null, $url);
     }
     if ($oldData['is_locked']) {
         //! %1$s is the id, %2$s is the name
         return LogUtil::registerError($this->__f('Notice: The administrator has locked the category \'%2$s\' (ID \'%$1s\'). You cannot edit or delete it.', array($data['id'], $oldData['name'])), null, $url);
     }
     if (!$obj->validate()) {
         $_POST['cid'] = (int) $_POST['category']['id'];
         return $this->redirect(ModUtil::url('Categories', 'user', 'edit', $_POST) . '#top');
     }
     $attributes = array();
     $values = $this->request->request->get('attribute_value');
     foreach ($this->request->request->get('attribute_name') as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     $obj->setDataField('__ATTRIBUTES__', $attributes);
     // update new category data
     $obj->update();
     // since a name change will change the object path, we must rebuild it here
     if ($oldData['name'] != $data['name']) {
         CategoryUtil::rebuildPaths('path', 'name', $data['id']);
     }
     $msg = $this->__f('Done! Saved the %s category.', $oldData['name']);
     LogUtil::registerStatus($msg);
     return $this->redirect($url);
 }
Ejemplo n.º 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);
 }