Exemplo n.º 1
0
 /**
  * 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');
 }
Exemplo n.º 2
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);
 }