<input type="hidden" id="cms_action" name="cms_action" value="validate" /> <input type="hidden" name="moduleCodename" value="' . $moduleCodename . '" /> <input type="hidden" name="object" value="' . $object->getID() . '" /> <input type="hidden" name="field" value="' . $field->getID() . '" /> <tr> <td class="admin" align="right" valign="top"><span class="admin_text_alert">*</span> ' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_TYPE) . '</td> <td class="admin">'; if (!$field->getID() || !$field->getValue("type")) { $content .= ' <select name="type" class="admin_input_text" onchange="document.getElementById(\'cms_action\').value=\'newtype\';document.frm.submit();"> <option value="">' . $cms_language->getMessage(MESSAGE_PAGE_CHOOSE) . '</option>'; //objects if (sizeof($object_types)) { $content .= '<optgroup label="' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_STANDARD_OBJECTS) . '">'; foreach ($object_types as $anObjectTypeName => $anObjectType) { if (!$object->getValue("multilanguage") || $object->getValue("multilanguage") && $anObjectTypeName != 'CMS_object_language') { $selected = $field->getValue("type") == $anObjectTypeName ? ' selected="selected"' : ''; $content .= '<option value="' . $anObjectTypeName . '"' . $selected . ' title="' . htmlspecialchars($anObjectType->getDescription($cms_language)) . '">' . $anObjectType->getObjectLabel($cms_language) . '</option>'; } } $content .= '</optgroup>'; } //poly objects if (sizeof($poly_types) > 1) { $content .= '<optgroup label="' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_POLY_OBJECTS) . '">'; foreach ($poly_types as $anObjectType) { //a poly object can't use itself or can't use an object who already use itself (infinite loop) if ($object->getID() != $anObjectType->getID() && !in_array($anObjectType->getID(), $objectUseage)) { //load fields objects for object $objectFields = CMS_poly_object_catalog::getFieldsDefinition($anObjectType->getID()); $objectModule = CMS_modulesCatalog::getByCodename(CMS_poly_object_catalog::getModuleCodenameForObjectType($anObjectType->getID()));
/** * Proceed to search and returns the array of results, null if none * found. All search options had been set yet. * * @access public * @param $return, the returned values in : * self::POLYMOD_SEARCH_RETURN_IDS for array of ids sorted * self::POLYMOD_SEARCH_RETURN_DATAS for db datas * self::POLYMOD_SEARCH_RETURN_OBJECTS for objetcs (default) * self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT for light objects (without subobjects datas) * self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT_EDITED for edited light objects. /!\ This method must not be used for objects which should be saved (used by getListOfNamesForObject only) /!\ * self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS use this method to get individual results with method getNextResult * @param boolean $loadSubObjects : all the found objects can load theirs own sub objects (default false) * /!\ CAUTION : Pass this option to true can generate a lot of subqueries /!\ * @return mixed array(CMS_poly_object) or boolean (for POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) */ function search($return = self::POLYMOD_SEARCH_RETURN_OBJECTS, $loadSubObjects = false) { global $cms_user; if ($return == self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT && !$this->_public) { $this->raiseError('Return type can\'t be self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT in a non-public search.'); $return = self::POLYMOD_SEARCH_RETURN_OBJECTS; } //this is a hack to allow light search in edited userspace. /!\ Objects must not be saved after /!\ if ($return == self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT_EDITED) { $return = self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT; } $items = array(); if ($return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) { //reset result stack if needed reset($this->_sortedResultsIds); } $this->_searchMode = $return; // Check module rights : to get any results, user should has at least CLEARANCE_MODULE_VIEW if ((!$this->_public || $this->_public && APPLICATION_ENFORCES_ACCESS_CONTROL) && (!is_object($cms_user) || !$cms_user->hasModuleClearance($this->_object->getValue('module'), CLEARANCE_MODULE_VIEW))) { if (!is_object($cms_user)) { $this->_raiseError(__CLASS__ . ' : ' . __FUNCTION__ . ' : cms_user not loaded when trying to get objects subject to rights ...'); } return $return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS ? false : $items; } //get all ids and numrows for search $this->_resultsIds = $this->_getIds(); //if results if (is_array($this->_resultsIds) && $this->_resultsIds) { //sort and limit ids to order and limit clause and to existant objects $this->_sortedResultsIds = $this->_sortIds(); //if return anything than ids if ($return != self::POLYMOD_SEARCH_RETURN_IDS && is_array($this->_sortedResultsIds) && $this->_sortedResultsIds) { //get subobjects ids if ($return != self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT) { $this->_resultsSubObjectsIds = $this->_getSubObjectsIds(); } //then load all values for objects and subobjects (if needed) $this->_values = $this->_getObjectValues(); } //clean tmp table $this->_updateTmpList(); } else { //clean tmp table $this->_updateTmpList(); return $return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS ? true : array(); } //return datas if ($return == self::POLYMOD_SEARCH_RETURN_DATAS) { return $this->_values; } //return individuals objects with method getNextResult if ($return == self::POLYMOD_SEARCH_RETURN_INDIVIDUALS_OBJECTS) { return true; } //return ids if ($return == self::POLYMOD_SEARCH_RETURN_IDS) { return $this->_sortedResultsIds; } //return objects $count = 0; if ($this->_values && $this->_sortedResultsIds) { //1- create objects values : all subObjects found for searched objects $subObjectValues = array(); foreach ($this->_resultsSubObjectsIds as $subObjectId) { $subObjectValues[$subObjectId] =& $this->_values[$subObjectId]; } //load sub objects values $loadSubObjectsValues = $return != self::POLYMOD_SEARCH_RETURN_OBJECTSLIGHT; //create objects foreach ($this->_sortedResultsIds as $aResultID) { //2- add object values to objects values $objectValues = $subObjectValues; $objectValues[$aResultID] =& $this->_values[$aResultID]; //instanciate object $obj = new CMS_poly_object($this->_object->getID(), $aResultID, $objectValues, $this->_public, $loadSubObjects, $loadSubObjectsValues); if (!$obj->hasError()) { $items[$aResultID] = $obj; $count++; } } } return $items; }
/** * Get object field as an array structure used for export * * @param array $params The export parameters. Not used here * @param array $files The reference to the found files used by object * @return array : the object array structure * @access public */ public function asArray($params = array(), &$files) { $aField = array('id' => $this->_fieldID, 'uuid' => $this->_objectFieldValues['uuid'], 'labels' => CMS_object_i18nm::getValues($this->_objectFieldValues['labelID']), 'descriptions' => CMS_object_i18nm::getValues($this->_objectFieldValues['descriptionID']), 'objectID' => $this->_objectFieldValues['objectID'], 'type' => null, 'multi' => null, 'params' => array('order' => $this->_objectFieldValues['order'], 'required' => $this->_objectFieldValues['required'], 'indexable' => $this->_objectFieldValues['indexable'], 'searchlist' => $this->_objectFieldValues['searchlist'], 'searchable' => $this->_objectFieldValues['searchable'])); $linkedObjectId = null; if (io::strpos($this->_objectFieldValues['type'], 'multi|') !== false) { $aField['multi'] = 1; $type = explode('|', $this->_objectFieldValues['type']); $aField['type'] = $type[1]; $linkedObjectId = $type[1]; } else { $aField['multi'] = 0; $aField['type'] = $this->_objectFieldValues['type']; if (io::isPositiveInteger($aField['type'])) { $linkedObjectId = $this->_objectFieldValues['type']; } } if ($linkedObjectId) { $objectDefition = new CMS_poly_object_definition($linkedObjectId); if ($objectDefition) { $aField['params']['linkedObjectUuid'] = $objectDefition->getValue('uuid'); } } if (!io::isPositiveInteger($aField['type'])) { if (class_exists($aField['type'])) { $oType = new $aField['type'](array(), $this, false); $aField['params']['params'] = $oType->asArray(); } } elseif ($aField['multi']) { $oType = new CMS_multi_poly_object($aField['type'], array(), $this, false); $aField['params']['params'] = $oType->asArray(); } return $aField; }
/** * Import module objects 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 objects importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for objects importation : ' . $params['module'] . "\n"; return false; } $return = true; //first create missing objects to get relation ids foreach ($data as $objectDatas) { if (!isset($objectDatas['uuid']) || !CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) { //create new object if we can if (!isset($params['create']) || $params['create'] == true) { //create object $object = new CMS_poly_object_definition(); //set module $object->setValue('module', $params['module']); //set uuid $object->setUuid($objectDatas['uuid']); //write object to persistence to get relations ids $object->writeToPersistence(); //set id translation if (isset($objectDatas['id']) && $objectDatas['id']) { // && $object->getID() != $objectDatas['id']) { // Fix for bug #3157 : in some cases the imported object will have the same id has the newly created, // we still need the relation table otherwise it will fail to link to the new object $idsRelation['objects'][$objectDatas['id']] = $object->getID(); } //set uuid translation if (isset($objectDatas['uuid']) && $objectDatas['uuid'] && $object->getValue('uuid') != $objectDatas['uuid']) { $idsRelation['objects-uuid'][$objectDatas['uuid']] = $object->getValue('uuid'); } } } elseif (isset($objectDatas['uuid']) && isset($objectDatas['id'])) { //get relation between imported object id and local id $id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']); if (io::isPositiveInteger($id)) { $idsRelation['objects'][$objectDatas['id']] = $id; } } } //then import objects datas foreach ($data as $objectDatas) { $importType = ''; if (isset($objectDatas['uuid']) && ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']))) { //object already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $object = CMS_poly_object_catalog::getObjectDefinition($id); $importType = ' (Update)'; //set id translation $idsRelation['objects'][$objectDatas['id']] = $id; } } else { //check for translated id if (isset($objectDatas['id']) && isset($idsRelation['objects'][$objectDatas['id']])) { //object exists with a translated id $objectDatas['id'] = $idsRelation['objects'][$objectDatas['id']]; //load translated object $object = CMS_poly_object_catalog::getObjectDefinition($objectDatas['id']); $importType = ' (Creation)'; } //check for translated uuid if (isset($objectDatas['uuid']) && isset($idsRelation['objects-uuid'][$objectDatas['uuid']])) { //object exists with a translated uuid $objectDatas['uuid'] = $idsRelation['objects-uuid'][$objectDatas['uuid']]; //load translated object if ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) { $object = CMS_poly_object_catalog::getObjectDefinition($id); $importType = ' (Creation)'; } } } if (isset($object)) { if ($object->fromArray($objectDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Object "' . $object->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of object ' . $objectDatas['id'] . $importType . "\n"; } } } return $return; }
define("MESSAGE_PAGE_OBJECT_MULTILANGUAGE", 634); define("MESSAGE_PAGE_OBJECT_INDEXATION", 326); define("MESSAGE_PAGE_OBJECT_INDEXABLE_EXPLANATION", 327); define("MESSAGE_PAGE_OBJECT_INDEXATION_LINK_TO", 328); define("MESSAGE_PAGE_OBJECT_INDEXATION_LINK_TO_EXPLANATION", 329); define("MESSAGE_PAGE_FIELD_SEARCH_RESULTS_DISPLAY", 420); define("MESSAGE_PAGE_FIELD_SEARCH_RESULTS_DISPLAY_LEGEND", 421); define("MESSAGE_PAGE_FIELD_OBJECT_SYNTAX", 421); //checks if (!$cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) { header("Location: " . PATH_ADMIN_SPECIAL_ENTRY_WR . "?cms_message_id=" . MESSAGE_PAGE_CLEARANCE_ERROR . "&" . session_name() . "=" . session_id()); exit; } $moduleCodename = $_REQUEST["moduleCodename"]; $object = new CMS_poly_object_definition($_REQUEST["object"]); $label = new CMS_object_i18nm($object->getValue("labelID")); $description = new CMS_object_i18nm($object->getValue("descriptionID")); $availableLanguagesCodes = CMS_object_i18nm::getAvailableLanguages(); if ($moduleCodename) { $polymod = CMS_modulesCatalog::getByCodename($moduleCodename); } // **************************************************************** // ** ACTIONS MANAGEMENT ** // **************************************************************** switch ($_POST["cms_action"]) { case "validate": case "switchexplanation": //checks and assignments $cms_message = ""; $object->setDebug(false); if (!$_POST["label" . $availableLanguagesCodes[0]] || !$_POST["description" . $availableLanguagesCodes[0]]) {
} $resourceStatus = array(0 => MESSAGE_PAGE_FIELD_RESOURCE_NONE, 1 => MESSAGE_PAGE_FIELD_RESOURCE_PRIMARY, 2 => MESSAGE_PAGE_FIELD_RESOURCE_SECONDARY); $adminEditableStatus = array(0 => MESSAGE_PAGE_FIELD_YES, 1 => MESSAGE_PAGE_FIELD_NO, 2 => MESSAGE_PAGE_FIELD_ONLY_FOR_ADMIN); $objectUseage = CMS_poly_object_catalog::getObjectUsage($object->getID(), true); if (!sizeof($objectUseage)) { $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_NO) . '<br />'; } else { $objectUseageLabel = $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USED) . ' : <ul>'; foreach ($objectUseage as $anObjectWhichUse) { $objectUseageLabel .= '<li>' . $anObjectWhichUse->getLabel() . '</li>'; } $objectUseageLabel .= '</ul>'; } $content = ' <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_DESCRIPTION) . ' :</strong> ' . $object->getDescription($cms_language) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_RESOURCE) . ' :</strong> ' . $cms_language->getMessage($resourceStatus[$object->getValue("resourceUsage")]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_EDITABLE) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("admineditable")]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_COMPOSED_LABEL) . ' :</strong> ' . $cms_language->getMessage($adminEditableStatus[$object->getValue("composedLabel") ? 0 : 1]) . '<br /> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_USEAGE) . ' :</strong> ' . $objectUseageLabel . ' <br /> <dialog-title type="admin_h2">' . $cms_language->getMessage(MESSAGE_PAGE_TITLE, array($object->getLabel($cms_language))) . ' :</dialog-title> <strong>' . $cms_language->getMessage(MESSAGE_PAGE_FIELD_OBJECT_GRAYED_INFOS) . '</strong>'; $content .= createHTMLStructure($object->getID(), $objectsStructure); // **************************************************************** // ** CONTENT FUNCTIONS ** // **************************************************************** function createHTMLStructure($objectID, $objectsStructure) { global $cms_language; static $level; $level++;