Exemplo n.º 1
0
 /**
  * update category
  */
 public function edit()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_EDIT)) {
         return LogUtil::registerPermissionError();
     }
     $dr = (int) FormUtil::getPassedValue('dr', 0, 'POST');
     $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 Categories_DBObject_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'];
         $this->redirect(ModUtil::url('Categories', 'user', 'edit', $_POST) . '#top');
     }
     $attributes = array();
     $values = FormUtil::getPassedValue('attribute_value', 'POST');
     foreach (FormUtil::getPassedValue('attribute_name', 'POST') 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);
     $this->redirect($url);
 }
Exemplo n.º 2
0
 private function _createdefaultcategory($regpath = '/__SYSTEM__/Modules/Global')
 {
     // get the language
     $lang = ZLanguage::getLanguageCode();
     // get the category path for which we're going to insert our place holder category
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
     $qCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Ephemerides');
     if (!$qCat) {
         // create placeholder for all our migrated categories
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'Ephemerides');
         $cat->setDataField('display_name', array($lang => $this->__('Ephemerides')));
         $cat->setDataField('display_desc', array($lang => $this->__('Ephemerides')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // get the category path for which we're going to insert our upgraded categories
     $rootcat = CategoryUtil::getCategoryByPath($regpath);
     if ($rootcat) {
         // create an entry in the categories registry
         $registry = new Categories_DBObject_Registry();
         $registry->setDataField('modname', 'Ephemerides');
         $registry->setDataField('table', 'ephem');
         $registry->setDataField('property', 'Main');
         $registry->setDataField('category_id', $rootcat['id']);
         $registry->insert();
     } else {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * migrate old local categories to the categories module
  */
 private function _migratecategories()
 {
     // get the language file
     $lang = ZLanguage::getLanguageCode();
     $catPath = '/__SYSTEM__/Modules/Quotes';
     // create root category and entry in the categories registry
     $this->_createdefaultcategory($catPath);
     // get the category path for which we're going to insert our upgraded categories
     $rootcat = CategoryUtil::getCategoryByPath($catPath);
     // create placeholder for all our migrated quotes
     $cat = new Categories_DBObject_Category();
     $cat->setDataField('parent_id', $rootcat['id']);
     $cat->setDataField('name', 'Imported');
     $cat->setDataField('display_name', array($lang => $this->__('Imported quotes')));
     $cat->setDataField('display_desc', array($lang => $this->__('Quotes imported from .7x version')));
     if (!$cat->validate('admin')) {
         return false;
     }
     $cat->insert();
     $cat->update();
     $catid = $cat->getDataField('id');
     unset($cat);
     // migrate page category assignments
     $prefix = System::getVar('prefix');
     $sql = "SELECT pn_qid FROM {$prefix}_quotes";
     $result = DBUtil::executeSQL($sql);
     $quotes = array();
     for (; !$result->EOF; $result->MoveNext()) {
         $quotes[] = array('qid' => $result->fields[0], '__CATEGORIES__' => array('Main' => $catid), '__META__' => array('module' => 'Quotes'));
     }
     foreach ($quotes as $quote) {
         if (!DBUtil::updateObject($quote, 'quotes', '', 'qid')) {
             return LogUtil::registerError($this->__('Error! Update attempt failed.'));
         }
     }
     return true;
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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');
 }
Exemplo n.º 6
0
    /**
     * create placeholder for categories
     */
    private function _feeds_createdefaultcategory($regpath = '/__SYSTEM__/Modules/Global')
    {
        // load necessary classes
        Loader::loadClass('CategoryUtil');
        Loader::loadClassFromModule('Categories', 'Category');
        Loader::loadClassFromModule('Categories', 'CategoryRegistry');

        // get the language code
        $lang = ZLanguage::getLanguageCode();
        $dom  = ZLanguage::getModuleDomain('Feeds');

        // get the category path for which we're going to insert our place holder category
        $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
        $fCat    = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Feeds');

        if (!$fCat) {
            // create placeholder for all the module categories
            $cat = new Categories_DBObject_Category();
            $cat->setDataField('parent_id', $rootcat['id']);
            $cat->setDataField('name', 'Feeds');
            $cat->setDataField('display_name', array($lang => __('Feeds', $dom)));
            $cat->setDataField('display_desc', array($lang => __('Feed Reader.', $dom)));
            if (!$cat->validate('admin')) {
                return false;
            }
            $cat->insert();
            $cat->update();
        }

        // get the category path for which the feeds will be classified
        $rootcat = CategoryUtil::getCategoryByPath($regpath);
        if ($rootcat) {
            // create an entry in the categories registry
            $registry = new Categories_DBObject_Registry();
            $registry->setDataField('modname', 'Feeds');
            $registry->setDataField('table', 'feeds');
            $registry->setDataField('property', 'Main');
            $registry->setDataField('category_id', $rootcat['id']);
            $registry->insert();
        } else {
            return false;
        }

        return true;
    }
Exemplo n.º 7
0
 function _addressbook_createdefaultcategory()
 {
     $dom = ZLanguage::getModuleDomain('AddressBook');
     // get the language file
     $lang = ZLanguage::getLanguageCode();
     // get the category path for which we're going to insert our place holder category
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
     $adrCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook');
     if (!$adrCat) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'AddressBook');
         $cat->setDataField('display_name', array($lang => $this->__('AddressBook')));
         $cat->setDataField('display_desc', array($lang => $this->__('Adress administration.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // create the first 2 categories
     $adrCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook');
     $adrCat1 = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook/Business');
     if (!$adrCat1) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $adrCat['id']);
         $cat->setDataField('name', 'Business');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Business')));
         $cat->setDataField('display_desc', array($lang => $this->__('Business')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     $adrCat2 = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook/Personal');
     if (!$adrCat2) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $adrCat['id']);
         $cat->setDataField('name', 'Personal');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Personal')));
         $cat->setDataField('display_desc', array($lang => $this->__('Personal')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     if ($adrCat) {
         // place category registry entry for products (key == Products)
         $registry = new Categories_DBObject_Registry();
         $registry->setDataField('modname', 'AddressBook');
         $registry->setDataField('table', 'addressbook_address');
         $registry->setDataField('property', 'AddressBook');
         $registry->setDataField('category_id', $adrCat['id']);
         $registry->insert();
     }
     // now the old prefix field
     // get the category path for which we're going to insert our place holder form of address
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General');
     $foaCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address');
     if (!$foaCat) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'Form of address');
         $cat->setDataField('display_name', array($lang => $this->__('Form of address')));
         $cat->setDataField('display_desc', array($lang => $this->__('Form of address')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // create the first 2 categories
     $foaCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address');
     $foaCat1 = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address/Mr');
     if (!$foaCat1) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $foaCat['id']);
         $cat->setDataField('name', 'Mr');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Mr.')));
         $cat->setDataField('display_desc', array($lang => $this->__('Mr.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     $foaCat2 = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address/Mrs');
     if (!$foaCat2) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $foaCat['id']);
         $cat->setDataField('name', 'Mrs');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Mrs.')));
         $cat->setDataField('display_desc', array($lang => $this->__('Mrs.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     return true;
 }
Exemplo n.º 8
0
    /**
     * create the Topics category tree
     */
    private function _createtopicscategory($regpath = '/__SYSTEM__/Modules/Topics')
    {
        // get the language file
        $lang = ZLanguage::getLanguageCode();

        // get the category path for which we're going to insert our place holder category
        $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');

        // create placeholder for all the migrated topics
        $tCat    = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Topics');

        if (!$tCat) {
            // create placeholder for all our migrated categories
            $cat = new Categories_DBObject_Category();
            $cat->setDataField('parent_id', $rootcat['id']);
            $cat->setDataField('name', 'Topics');
            // pnModLangLoad doesn't handle type 1 modules
            //pnModLangLoad('Topics', 'version');
            $cat->setDataField('display_name', array($lang => $this->__('Topics')));
            $cat->setDataField('display_desc', array($lang => $this->__('Display and manage topics')));
            if (!$cat->validate('admin')) {
                return false;
            }
            $cat->insert();
            $cat->update();
        }

        // get the category path for which we're going to insert our upgraded News categories
        $rootcat = CategoryUtil::getCategoryByPath($regpath);
        if ($rootcat) {
            // create an entry in the categories registry to the Topic property
            $registry = new Categories_DBObject_Registry();
            $registry->setDataField('modname', 'News');
            $registry->setDataField('table', 'stories');
            $registry->setDataField('property', 'Topic');
            $registry->setDataField('category_id', $rootcat['id']);
            $registry->insert();
        } else {
            return false;
        }

        return true;
    }