Ejemplo n.º 1
0
 public function save()
 {
     $this->checkAjaxToken();
     $mode = $this->request->getPost()->get('mode', 'new');
     $accessLevel = $mode == 'edit' ? ACCESS_EDIT : ACCESS_ADD;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', $accessLevel));
     $result = array();
     $cat = new Categories_DBObject_Category();
     $cat->getDataFromInput();
     if (!$cat->validate()) {
         $args = array('cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'mode' => $mode);
         return $this->edit($args);
     }
     $attributes = array();
     $values = $this->request->getPost()->get('attribute_value');
     foreach ($this->request->getPost()->get('attribute_name') as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     $cat->setDataField('__ATTRIBUTES__', $attributes);
     if ($mode == 'edit') {
         // retrieve old category from DB
         $category = $this->request->getPost()->get('category');
         $oldCat = new Categories_DBObject_Category(DBObject::GET_FROM_DB, $category['id']);
         // update new category data
         $cat->update();
         // since a name change will change the object path, we must rebuild it here
         if ($oldCat->getDataField('name') != $cat->getDataField('name')) {
             CategoryUtil::rebuildPaths('path', 'name', $cat->getDataField('id'));
         }
     } else {
         $cat->insert();
         // update new category data
         $cat->update();
     }
     $categories = CategoryUtil::getSubCategories($cat->getDataField('id'), true, true, true, true, true);
     $options = array('nullParent' => $cat->getDataField('parent_id'), 'withWraper' => false);
     $node = CategoryUtil::getCategoryTreeJS((array) $categories, true, true, $options);
     $leafStatus = array('leaf' => array(), 'noleaf' => array());
     foreach ($categories as $c) {
         if ($c['is_leaf']) {
             $leafStatus['leaf'][] = $c['id'];
         } else {
             $leafStatus['noleaf'][] = $c['id'];
         }
     }
     $result = array('action' => $mode == 'edit' ? 'edit' : 'add', 'cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'node' => $node, 'leafstatus' => $leafStatus, 'result' => true);
     return new Zikula_Response_Ajax($result);
 }
Ejemplo n.º 2
0
    /**
     * create category
     */
    public function newcat()
    {
        $this->checkCsrfToken();

        if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
            return LogUtil::registerPermissionError();
        }

        $dr = (int)FormUtil::getPassedValue('dr', 0, 'POST');
        $url = System::serverGetVar('HTTP_REFERER');

        if (!$dr) {
            return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url);
        }

        $cat = new Categories_DBObject_Category ();
        $data = $cat->getDataFromInput();

        if (!$cat->validate()) {
            $this->redirect(ModUtil::url('Categories', 'user', 'edit', $_POST) . '#top');
        }

        $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 = $this->__f('Done! Inserted the %s category.', $data['name']);
        LogUtil::registerStatus($msg);
        $this->redirect($url);
    }
Ejemplo n.º 3
0
 /**
  * create category
  */
 public function newcat()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
         return LogUtil::registerPermissionError();
     }
     $cat = new Categories_DBObject_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 (!FormUtil::getPassedValue('category_submit', null, 'POST')) {
         $newCat = $_POST['category'];
         $pcID = $newCat['parent_id'];
         $pCat = new Categories_DBObject_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 System::redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     if (!$cat->validate('admin')) {
         return System::redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     $attributes = array();
     $values = FormUtil::getPassedValue('attribute_value', array(), 'POST');
     foreach (FormUtil::getPassedValue('attribute_name', array(), 'POST') 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);
     $this->redirect(ModUtil::url('Categories', 'admin', 'view') . '#top');
 }