protected function _createCategoriesTree($categories, $itemPattern, $templatePattern, $selectedPattern, $maxlevel = 0, $selectedIDs = array())
 {
     global $cms_language;
     static $level;
     $level++;
     $return = "";
     //get all level categories object
     $categoriesObjects = array();
     $subCats = array();
     foreach ($categories as $catID => $subCategories) {
         $category = CMS_moduleCategories_catalog::getByID($catID);
         $categoriesObjects[$category->getAttribute('order')] = $category;
         $subCats[$catID] = $subCategories;
     }
     //sort categories by order
     ksort($categoriesObjects);
     ///then display it
     foreach ($categoriesObjects as $category) {
         $catID = $category->getID();
         $subCategories = $subCats[$catID];
         $subcats = '';
         if (is_array($subCategories) && $subCategories && (!$maxlevel || $level < $maxlevel)) {
             //recurse on subcategories
             $subcats = $this->_createCategoriesTree($subCategories, $itemPattern, $templatePattern, $selectedPattern, $maxlevel, $selectedIDs);
         }
         $iconPathFS = $category->getIconPath(true, PATH_RELATIVETO_FILESYSTEM, true);
         if ($iconPathFS && file_exists($iconPathFS)) {
             $iconPathWR = CMS_websitesCatalog::getCurrentDomain() . $category->getIconPath(true, PATH_RELATIVETO_WEBROOT, true);
             $icon = '<img src="' . $iconPathWR . '" alt="" title="' . SensitiveIO::sanitizeHTMLString($category->getLabel($cms_language)) . '" />';
         } else {
             $icon = '';
         }
         $replace = array('{id}' => $catID, '{label}' => $category->getLabel($cms_language), '{description}' => $category->getDescription($cms_language), '{sublevel}' => $subcats, '{lvl}' => $level, '{icon}' => $icon);
         if ($selectedIDs && in_array($catID, $selectedIDs)) {
             $return .= str_replace(array_keys($replace), $replace, $selectedPattern);
         } else {
             $return .= str_replace(array_keys($replace), $replace, $itemPattern);
         }
     }
     $return = str_replace('{sublevel}', $return, $templatePattern);
     $level--;
     return $return;
 }
Beispiel #2
0
 /**
  * Get all the categories (used as root) which have a level 
  * equal to clearance given (@see CMS_profile, constants CLEARANCE_MODULE_* )
  *
  * @param integer $clearance, clearance level categories equals to (Default set to false : returns all categories)
  * @param string $module, the module codename we want root categories of
  * @param boolean $return_objects, if set to true method will return an array of CMS_moduleCategory (Default set to false)
  * @param boolean $strict, if set to true method strictly check clearance (default : true)
  * @return array(integer or CMS_moduleCategory), false if nothing found
  * @access public
  */
 function getRootCategories($clearance = false, $module = false, $return_objects = false, $strict = true)
 {
     static $rootCategories;
     $mode = 'mode_' . (string) $this->_id . '_' . ($clearance === false ? 'false' : (string) $clearance) . '_' . (string) $module . '_' . (string) $strict;
     if (!isset($rootCategories[$mode])) {
         $rootCategories[$mode] = array();
         if (SensitiveIO::isPositiveInteger($this->_id)) {
             // Take only categories from given module
             $stack_categoriesClearances = $this->_moduleCategoriesClearances->getCategoriesClearances($module);
         }
         if (isset($stack_categoriesClearances)) {
             $elements = $stack_categoriesClearances->getElements();
         }
         if (isset($elements) && is_array($elements) && $elements) {
             $items = array();
             while (list($k, $v) = each($elements)) {
                 $categoryID = $v[0];
                 $categoryClearance = $v[1];
                 if ($categoryID && ($clearance !== false && $strict && (int) $categoryClearance === (int) $clearance || $clearance !== false && !$strict && (int) $categoryClearance >= (int) $clearance || $clearance === false)) {
                     $rootCategories[$mode][] = (int) $categoryID;
                 }
             }
             $rootCategories[$mode] = @array_unique($rootCategories[$mode]);
         } else {
             $rootCategories[$mode] = false;
         }
     }
     if ($rootCategories[$mode] === false) {
         return false;
     } else {
         if ($return_objects) {
             $items = array();
             if (is_array($rootCategories[$mode]) && $rootCategories[$mode]) {
                 foreach ($rootCategories[$mode] as $categoryID) {
                     $items[] = CMS_moduleCategories_catalog::getByID($categoryID);
                 }
             }
             return $items;
         } else {
             return $rootCategories[$mode];
         }
     }
 }
Beispiel #3
0
 if (!$cms_message) {
     //check inputs tags (sometimes, IE remove type="text" ...)
     //then save source
     $item->setAttribute('source', $item->checkInputs($_POST["source_" . $item->getID()]));
 }
 // Categories
 // Write item relations with categories
 $ids = $_POST["ids"] ? @array_unique(@explode(';', $_POST["ids"])) : array();
 if (!$cms_message && $item->writeToPersistence()) {
     $item_relations = new CMS_forms_formularCategories($item);
     if (sizeof($ids) <= 0) {
         $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_ERROR_CATEGORIES_EMPTY, false, MOD_CMS_FORMS_CODENAME) . "\n";
     } else {
         $item_relations->init();
         foreach ($ids as $id) {
             $cat = CMS_moduleCategories_catalog::getByID($id);
             if ($cat->hasError() || !$item_relations->categoryExists($cat) && !$item_relations->addCategory($cat)) {
                 $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_ERROR_ADD_CATEGORY, array($cat->getLabel($cms_language)), MOD_CMS_FORMS_CODENAME) . "\n";
             }
         }
         if (!$item_relations->writeToPersistence()) {
             $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_ERROR_ADD_CATEGORIES, false, MOD_CMS_FORMS_CODENAME) . "\n";
         }
     }
 }
 // Save data
 if (!$cms_message && $item->writeToPersistence()) {
     header("Location: items.php?cms_message_id=" . MESSAGE_ACTION_OPERATION_DONE . "&" . session_name() . "=" . session_id());
     exit;
 }
 break;
 /**
  * Import module from given array datas
  *
  * @param array $data The module datas to import
  * @param array $params The import parameters.
  *		array(
  *				module	=> false|true : the module to create categories (required)
  *				create	=> false|true : create missing objects (default : true)
  *				update	=> false|true : update existing objects (default : true)
  *				files	=> false|true : use files from PATH_TMP_FS (default : true)
  *			)
  * @param CMS_language $cms_language The CMS_langage to use
  * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids
  * @param string $infos : Reference : The import infos returned
  * @return boolean : true on success, false on failure
  * @access public
  */
 static function fromArray($data, $params, $cms_language, &$idsRelation, &$infos)
 {
     if (!isset($params['module'])) {
         $infos .= 'Error : missing module codename for categories importation ...' . "\n";
         return false;
     }
     $module = CMS_modulesCatalog::getByCodename($params['module']);
     if ($module->hasError()) {
         $infos .= 'Error : invalid module for categories importation : ' . $params['module'] . "\n";
         return false;
     }
     $return = true;
     foreach ($data as $categoryDatas) {
         $importType = '';
         if (isset($categoryDatas['uuid']) && ($id = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['uuid']))) {
             //category already exist : load it if we can update it
             if (!isset($params['update']) || $params['update'] == true) {
                 $category = CMS_moduleCategories_catalog::getByID($id);
                 $importType = ' (Update)';
             }
         } else {
             //create new category if we can
             if (!isset($params['create']) || $params['create'] == true) {
                 //if category to create has parent, try to get it
                 if (isset($categoryDatas['parent']) && $categoryDatas['parent']) {
                     //check for uuid translation
                     if (isset($idsRelation['categories-uuid'][$categoryDatas['parent']])) {
                         $categoryDatas['parent'] = $idsRelation['categories-uuid'][$categoryDatas['parent']];
                     }
                     //parent already exist : load it
                     $parentId = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['parent']);
                 }
                 if (isset($categoryDatas['root']) && $categoryDatas['root']) {
                     //check for uuid translation
                     if (isset($idsRelation['categories-uuid'][$categoryDatas['root']])) {
                         $categoryDatas['root'] = $idsRelation['categories-uuid'][$categoryDatas['root']];
                     }
                     //root already exist : load it
                     $rootId = CMS_moduleCategories_catalog::categoryExists($params['module'], $categoryDatas['root']);
                 }
                 //create category
                 $category = new CMS_moduleCategory(0, $cms_language);
                 $importType = ' (Creation)';
                 //set module
                 $category->setAttribute('moduleCodename', $params['module']);
                 if (isset($rootId)) {
                     $category->setAttribute('rootID', $rootId);
                 }
                 if (isset($parentId)) {
                     $category->setAttribute('parentID', $parentId);
                 }
             }
         }
         if (isset($category)) {
             if ($category->fromArray($categoryDatas, $params, $cms_language, $idsRelation, $infos)) {
                 $return &= true;
                 $infos .= 'Category "' . $category->getLabel($cms_language) . '" successfully imported' . $importType . "\n";
             } else {
                 $return = false;
                 $infos .= 'Error during import of category ' . $categoryDatas['id'] . $importType . "\n";
             }
         }
     }
     return $return;
 }
Beispiel #5
0
 /**
  * Builds lineage of categories from lineage stack
  *
  * @access public
  * @return array(CMS_moduleCategory)
  */
 function getLineage()
 {
     $lineage = array();
     $stack = $this->getLineageStack();
     while (list($k, $id) = @each($stack)) {
         $obj = CMS_moduleCategories_catalog::getByID($id);
         if (!$obj->hasError()) {
             $lineage[$k] = $obj;
         }
     }
     return $lineage;
 }
Beispiel #6
0
 /**
  * Gets all categories this resource belongs to
  * 
  * @access public
  * @param boolean $public
  * @return array(CMS_categories_medias)
  */
 function getCategories($public = false)
 {
     if ($public) {
         $this->_public = true;
     }
     if (!is_a($this->_form, 'CMS_forms_formular')) {
         $this->raiseError("Not a valid CMS_forms_formular given");
         return $this->_categories;
     }
     if (sizeof($this->_categories) <= 0 && $this->_form->getID() > 0) {
         $this->_categories = array();
         // Fill with values from DB
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tcategory_fca as id\n\t\t\t\tfrom\n\t\t\t\t\tmod_cms_forms_categories\n\t\t\t\twhere\n\t\t\t\t\tform_fca='" . SensitiveIO::sanitizeSQLString($this->_form->getID()) . "'\n\t\t\t\tgroup by\n\t\t\t\t\tcategory_fca\n\t\t\t";
         $q = new CMS_query($sql);
         while ($id = (int) $q->getValue('id')) {
             $obj = CMS_moduleCategories_catalog::getByID($id);
             if (!$obj->hasError()) {
                 $this->_categories[$id] = $obj;
             }
         }
     }
     return $this->_categories;
 }
            $i_current_clearance = (int) $stack_clearances->getElementValueFromKey($aRoot->getID());
            // Show all sub categories
            $content .= build_items_tree($aRoot, 0, $i_current_clearance);
        }
        $content .= '
			</ul>
			<input type="hidden" id="type-' . $hash . '" value="' . ($isUser ? 'user' : 'group') . '" />
			<input type="hidden" id="catIds-' . $hash . '" value="' . implode(',', $items_ids) . '" />
			<input type="hidden" id="profile-' . $hash . '" value="' . ($isUser ? $userId : $groupId) . '" />
			<input type="hidden" id="module-' . $hash . '" value="' . $moduleCodename . '" />
		</div>';
    }
} else {
    //get siblings
    if ($moduleCodename != MOD_STANDARD_CODENAME) {
        $item = CMS_moduleCategories_catalog::getByID($item);
        $attrs = array("module" => $moduleCodename, "language" => $cms_language, "level" => $item->getID(), "root" => false, "attrs" => false, "cms_user" => &$cms_user);
        $siblings = CMS_module::getModuleCategories($attrs);
    } else {
        $item = CMS_tree::getPageByID($item);
        $siblings = CMS_tree::getSiblings($item);
    }
    $clearances = array_reverse($modules_clearances, true);
    // Current item clearance
    $i_current_clearance = false;
    foreach ($clearances as $clearance) {
        if ($i_current_clearance === false) {
            if ($moduleCodename != MOD_STANDARD_CODENAME) {
                if ($profile->hasModuleCategoryClearance($item->getID(), $clearance, $moduleCodename)) {
                    $i_current_clearance = $clearance;
                }