function customObjectAttributeHTTPAction($http, $action, $contentObjectAttribute, $parameters)
 {
     $contentobjectID = false;
     if (eZDataType::fetchActionValue($action, 'new_class', $classID) or $action == 'new_class') {
         if ($action == 'new_class') {
             $base = $parameters['base_name'];
             $classVariableName = $base . '_new_class';
             if ($http->hasPostVariable($classVariableName)) {
                 $classVariable = $http->postVariable($classVariableName);
                 $classID = $classVariable[$contentObjectAttribute->attribute('id')];
                 $class = eZContentClass::fetch($classID);
             } else {
                 return false;
             }
         } else {
             $class = eZContentClass::fetch($classID);
         }
         if ($class) {
             $classAttribute = $contentObjectAttribute->attribute('contentclass_attribute');
             $class_content = $classAttribute->content();
             $content = $contentObjectAttribute->content();
             $priority = 0;
             for ($i = 0; $i < count($content['relation_list']); ++$i) {
                 if ($content['relation_list'][$i]['priority'] > $priority) {
                     $priority = $content['relation_list'][$i]['priority'];
                 }
             }
             $base = $parameters['base_name'];
             $nodePlacement = false;
             $nodePlacementName = $base . '_object_initial_node_placement';
             if ($http->hasPostVariable($nodePlacementName)) {
                 $nodePlacementMap = $http->postVariable($nodePlacementName);
                 if (isset($nodePlacementMap[$contentObjectAttribute->attribute('id')])) {
                     $nodePlacement = $nodePlacementMap[$contentObjectAttribute->attribute('id')];
                 }
             }
             $relationItem = $this->createInstance($class, $priority + 1, $contentObjectAttribute, $nodePlacement);
             if ($class_content['default_placement']) {
                 $relationItem['parent_node_id'] = $class_content['default_placement']['node_id'];
             }
             $content['relation_list'][] = $relationItem;
             $hasAttributeInput = false;
             $attributeInputVariable = $base . '_has_attribute_input';
             if ($http->hasPostVariable($attributeInputVariable)) {
                 $attributeInputMap = $http->postVariable($attributeInputVariable);
                 if (isset($attributeInputMap[$contentObjectAttribute->attribute('id')])) {
                     $hasAttributeInput = $attributeInputMap[$contentObjectAttribute->attribute('id')];
                 }
             }
             if ($hasAttributeInput) {
                 $object = $relationItem['object'];
                 $attributes = $object->contentObjectAttributes();
                 foreach ($attributes as $attribute) {
                     $attributeBase = $base . '_ezorl_init_class_' . $object->attribute('contentclass_id') . '_attr_' . $attribute->attribute('contentclassattribute_id');
                     $oldAttributeID = $attribute->attribute('id');
                     $attribute->setAttribute('id', false);
                     if ($attribute->fetchInput($http, $attributeBase)) {
                         $attribute->setAttribute('id', $oldAttributeID);
                         $attribute->store();
                     }
                 }
             }
             $contentObjectAttribute->setContent($content);
             $contentObjectAttribute->store();
         } else {
             eZDebug::writeError("Unknown class ID {$classID}, cannot instantiate object", __METHOD__);
         }
     } else {
         if (eZDataType::fetchActionValue($action, 'edit_objects', $contentobjectID) or $action == 'edit_objects' or $action == 'remove_objects') {
             $base = $parameters['base_name'];
             $selectionBase = $base . '_selection';
             $selections = array();
             $http = eZHTTPTool::instance();
             if ($http->hasPostVariable($selectionBase)) {
                 $selectionMap = $http->postVariable($selectionBase);
                 $selections = $selectionMap[$contentObjectAttribute->attribute('id')];
             }
             if ($contentobjectID !== false) {
                 $selections[] = $contentobjectID;
             }
             if ($action == 'edit_objects' or eZDataType::fetchActionValue($action, 'edit_objects', $contentobjectID)) {
                 $content = $contentObjectAttribute->content();
                 foreach ($content['relation_list'] as $key => $relationItem) {
                     if (!$relationItem['is_modified'] and in_array($relationItem['contentobject_id'], $selections)) {
                         $object = eZContentObject::fetch($relationItem['contentobject_id']);
                         if ($object->attribute('can_edit')) {
                             $content['relation_list'][$key]['is_modified'] = true;
                             $translationSourceBase = $base . '_translation_source_' . $contentObjectAttribute->attribute('id') . '_' . $relationItem['contentobject_id'];
                             $languageFrom = false;
                             if ($http->hasPostVariable($translationSourceBase) && $http->postVariable($translationSourceBase) !== '') {
                                 $languageFrom = $http->postVariable($translationSourceBase);
                             }
                             $version = $object->createNewVersionIn($contentObjectAttribute->attribute('language_code'), $languageFrom);
                             $content['relation_list'][$key]['contentobject_version'] = $version->attribute('version');
                         }
                     }
                 }
                 $contentObjectAttribute->setContent($content);
                 $contentObjectAttribute->store();
             } else {
                 if ($action == 'remove_objects') {
                     $content = $contentObjectAttribute->content();
                     $relationList = $content['relation_list'];
                     $newRelationList = array();
                     foreach ($relationList as $relationItem) {
                         if (in_array($relationItem['contentobject_id'], $selections)) {
                             $this->removeRelationObject($contentObjectAttribute, $relationItem);
                         } else {
                             $newRelationList[] = $relationItem;
                         }
                     }
                     $content['relation_list'] = $newRelationList;
                     $contentObjectAttribute->setContent($content);
                     $contentObjectAttribute->store();
                 }
             }
         } else {
             if ($action == 'browse_objects') {
                 $module = $parameters['module'];
                 $redirectionURI = $parameters['current-redirection-uri'];
                 $ini = eZINI::instance('content.ini');
                 $browseType = 'AddRelatedObjectListToDataType';
                 $browseTypeINIVariable = $ini->variable('ObjectRelationDataTypeSettings', 'ClassAttributeStartNode');
                 foreach ($browseTypeINIVariable as $value) {
                     list($classAttributeID, $type) = explode(';', $value);
                     if (is_numeric($classAttributeID) and $classAttributeID == $contentObjectAttribute->attribute('contentclassattribute_id') and strlen($type) > 0) {
                         $browseType = $type;
                         break;
                     }
                 }
                 // Fetch the list of "allowed" classes .
                 // A user can select objects of only those allowed classes when browsing.
                 $classAttribute = $contentObjectAttribute->attribute('contentclass_attribute');
                 $classContent = $classAttribute->content();
                 if (isset($classContent['class_constraint_list'])) {
                     $classConstraintList = $classContent['class_constraint_list'];
                 } else {
                     $classConstraintList = array();
                 }
                 $browseParameters = array('action_name' => 'AddRelatedObject_' . $contentObjectAttribute->attribute('id'), 'type' => $browseType, 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_set_object_relation_list]', 'value' => $contentObjectAttribute->attribute('id')), 'persistent_data' => array('HasObjectInput' => 0), 'from_page' => $redirectionURI);
                 $base = $parameters['base_name'];
                 $nodePlacementName = $base . '_browse_for_object_start_node';
                 if ($http->hasPostVariable($nodePlacementName)) {
                     $nodePlacement = $http->postVariable($nodePlacementName);
                     if (isset($nodePlacement[$contentObjectAttribute->attribute('id')])) {
                         $browseParameters['start_node'] = eZContentBrowse::nodeAliasID($nodePlacement[$contentObjectAttribute->attribute('id')]);
                     }
                 }
                 if (count($classConstraintList) > 0) {
                     $browseParameters['class_array'] = $classConstraintList;
                 }
                 eZContentBrowse::browse($browseParameters, $module);
             } else {
                 if ($action == 'set_object_relation_list') {
                     if (!$http->hasPostVariable('BrowseCancelButton')) {
                         $selectedObjectIDArray = $http->postVariable("SelectedObjectIDArray");
                         $content = $contentObjectAttribute->content();
                         $priority = 0;
                         for ($i = 0; $i < count($content['relation_list']); ++$i) {
                             if ($content['relation_list'][$i]['priority'] > $priority) {
                                 $priority = $content['relation_list'][$i]['priority'];
                             }
                         }
                         if ($selectedObjectIDArray !== null) {
                             foreach ($selectedObjectIDArray as $objectID) {
                                 // Check if the given object ID has a numeric value, if not go to the next object.
                                 if (!is_numeric($objectID)) {
                                     eZDebug::writeError("Related object ID (objectID): '{$objectID}', is not a numeric value.", __METHOD__);
                                     continue;
                                 }
                                 /* Here we check if current object is already in the related objects list.
                                  * If so, we don't add it again.
                                  * FIXME: Stupid linear search. Maybe there's some better way?
                                  */
                                 $found = false;
                                 foreach ($content['relation_list'] as $i) {
                                     if ($i['contentobject_id'] == $objectID) {
                                         $found = true;
                                         break;
                                     }
                                 }
                                 if ($found) {
                                     continue;
                                 }
                                 ++$priority;
                                 $content['relation_list'][] = $this->appendObject($objectID, $priority, $contentObjectAttribute);
                                 $contentObjectAttribute->setContent($content);
                                 $contentObjectAttribute->store();
                             }
                         }
                     }
                 } else {
                     eZDebug::writeError("Unknown custom HTTP action: " . $action, 'eZObjectRelationListType');
                 }
             }
         }
     }
 }
 static function browse($parameters = array(), &$module)
 {
     $ini = eZINI::instance('browse.ini');
     if (!isset($parameters['action_name'])) {
         $parameters['action_name'] = $ini->variable('BrowseSettings', 'DefaultActionName');
     }
     if (!isset($parameters['type'])) {
         $parameters['type'] = $parameters['action_name'];
     }
     //$ini->variable( $parameters['action_name'], 'BrowseType' );
     if (!isset($parameters['selection'])) {
         if ($ini->hasVariable($parameters['type'], 'SelectionType')) {
             $parameters['selection'] = $ini->variable($parameters['type'], 'SelectionType');
         } else {
             $parameters['selection'] = $ini->variable('BrowseSettings', 'DefaultSelectionType');
         }
     }
     if (!isset($parameters['return_type'])) {
         if ($ini->hasVariable($parameters['type'], 'ReturnType')) {
             $parameters['return_type'] = $ini->variable($parameters['type'], 'ReturnType');
         } else {
             $parameters['return_type'] = $ini->variable('BrowseSettings', 'DefaultReturnType');
         }
     }
     if (!isset($parameters['browse_custom_action'])) {
         $parameters['browse_custom_action'] = false;
     }
     if (!isset($parameters['custom_action_data'])) {
         $parameters['custom_action_data'] = false;
     }
     if (!isset($parameters['description_template'])) {
         $parameters['description_template'] = false;
     }
     if (!isset($parameters['start_node'])) {
         $parameters['start_node'] = $ini->variable($parameters['type'], 'StartNode');
     }
     if (!isset($parameters['ignore_nodes_select'])) {
         $parameters['ignore_nodes_select'] = array();
     }
     if (!isset($parameters['ignore_nodes_select_subtree'])) {
         $parameters['ignore_nodes_select_subtree'] = array();
     }
     if (!isset($parameters['ignore_nodes_click'])) {
         $parameters['ignore_nodes_click'] = array();
     }
     if (!isset($parameters['class_array'])) {
         if ($ini->hasVariable($parameters['type'], 'Class')) {
             $parameters['class_array'] = $ini->variable($parameters['type'], 'Class');
         } else {
             $parameters['class_array'] = false;
         }
     }
     if (isset($parameters['keys'])) {
         $overrideStartNode = false;
         foreach ($parameters['keys'] as $key => $keyValue) {
             $variableName = 'StartNode_' . $key;
             if (!$ini->hasVariable($parameters['type'], $variableName)) {
                 continue;
             }
             $keyData = $ini->variable($parameters['type'], $variableName);
             if (is_array($keyValue)) {
                 foreach ($keyValue as $keySubValue) {
                     if (isset($keyData[$keySubValue])) {
                         $overrideStartNode = $keyData[$keySubValue];
                     }
                 }
             } else {
                 if (isset($keyData[$keyValue])) {
                     $overrideStartNode = $keyData[$keyValue];
                 }
             }
             if ($overrideStartNode) {
                 break;
             }
         }
         if ($overrideStartNode) {
             $parameters['start_node'] = $overrideStartNode;
         }
     }
     if (!isset($parameters['persistent_data'])) {
         $parameters['persistent_data'] = false;
     }
     if (!isset($parameters['permission'])) {
         $parameters['permission'] = false;
     }
     if (!isset($parameters['top_level_nodes'])) {
         $parameters['top_level_nodes'] = $ini->variable('BrowseSettings', 'DefaultTopLevelNodes');
         if ($ini->hasVariable($parameters['type'], 'TopLevelNodes')) {
             $parameters['top_level_nodes'] = $ini->variable($parameters['type'], 'TopLevelNodes');
         }
     }
     if (!is_numeric($parameters['start_node'])) {
         $parameters['start_node'] = eZContentBrowse::nodeAliasID($parameters['start_node']);
     }
     for ($i = 0; $i < count($parameters['top_level_nodes']); $i++) {
         if (!is_numeric($parameters['top_level_nodes'][$i])) {
             $parameters['top_level_nodes'][$i] = eZContentBrowse::nodeAliasID($parameters['top_level_nodes'][$i]);
         }
     }
     if (!isset($parameters['cancel_page'])) {
         $parameters['cancel_page'] = false;
     }
     if (!isset($parameters['from_page'])) {
         eZDebug::writeError($parameters, 'eZContentBrowse::browse() $parameters[\'from_page\'] is not set');
     }
     $http = eZHTTPTool::instance();
     $http->setSessionVariable('BrowseParameters', $parameters);
     if ($module === null) {
         return "/content/browse/";
     } else {
         $module->redirectTo("/content/browse/");
         return "/content/browse/";
     }
 }
 function customObjectAttributeHTTPAction($http, $action, $contentObjectAttribute, $parameters)
 {
     switch ($action) {
         case "set_object_relation":
             if ($http->hasPostVariable('BrowseActionName') and $http->postVariable('BrowseActionName') == 'AddRelatedObject_' . $contentObjectAttribute->attribute('id') and $http->hasPostVariable("SelectedObjectIDArray")) {
                 if (!$http->hasPostVariable('BrowseCancelButton')) {
                     $selectedObjectArray = $http->hasPostVariable("SelectedObjectIDArray");
                     $selectedObjectIDArray = $http->postVariable("SelectedObjectIDArray");
                     // Delete the old version from ezcontentobject_link if count of translations > 1
                     $this->removeContentObjectRelation($contentObjectAttribute);
                     $objectID = $selectedObjectIDArray[0];
                     $contentObjectAttribute->setAttribute('data_int', $objectID);
                     $contentObjectAttribute->store();
                 }
             }
             break;
         case "browse_object":
             $module = $parameters['module'];
             $redirectionURI = $parameters['current-redirection-uri'];
             $ini = eZINI::instance('content.ini');
             $browseParameters = array('action_name' => 'AddRelatedObject_' . $contentObjectAttribute->attribute('id'), 'type' => 'AddRelatedObjectToDataType', 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_set_object_relation]', 'value' => $contentObjectAttribute->attribute('id')), 'persistent_data' => array('HasObjectInput' => 0), 'from_page' => $redirectionURI);
             $browseTypeINIVariable = $ini->variable('ObjectRelationDataTypeSettings', 'ClassAttributeStartNode');
             foreach ($browseTypeINIVariable as $value) {
                 list($classAttributeID, $type) = explode(';', $value);
                 if ($classAttributeID == $contentObjectAttribute->attribute('contentclassattribute_id') && strlen($type) > 0) {
                     $browseParameters['type'] = $type;
                     break;
                 }
             }
             $nodePlacementName = $parameters['base_name'] . '_browse_for_object_start_node';
             if ($http->hasPostVariable($nodePlacementName)) {
                 $nodePlacement = $http->postVariable($nodePlacementName);
                 if (isset($nodePlacement[$contentObjectAttribute->attribute('id')])) {
                     $browseParameters['start_node'] = eZContentBrowse::nodeAliasID($nodePlacement[$contentObjectAttribute->attribute('id')]);
                 }
             }
             // Fetch the list of "allowed" classes .
             // A user can select objects of only those allowed classes when browsing.
             $classAttribute = $contentObjectAttribute->attribute('contentclass_attribute');
             $classContent = $classAttribute->content();
             if (isset($classContent['class_constraint_list'])) {
                 $classConstraintList = $classContent['class_constraint_list'];
             } else {
                 $classConstraintList = array();
             }
             if (count($classConstraintList) > 0) {
                 $browseParameters['class_array'] = $classConstraintList;
             }
             eZContentBrowse::browse($browseParameters, $module);
             break;
         case "remove_object":
             // Delete the old version from ezcontentobject_link if count of translations > 1
             $this->removeContentObjectRelation($contentObjectAttribute);
             $contentObjectAttribute->setAttribute('data_int', 0);
             $contentObjectAttribute->store();
             break;
         default:
             eZDebug::writeError("Unknown custom HTTP action: " . $action, "eZObjectRelationType");
             break;
     }
 }