/**
  * Validates input on content object level
  * @return eZInputValidator::STATE_ACCEPTED or eZInputValidator::STATE_INVALID if
  *        the values are accepted or not
  */
 function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $returnCode = eZInputValidator::STATE_ACCEPTED;
     $inputObjectName = $base . '_jcremoteid_object_' . $contentObjectAttribute->attribute('id');
     $inputNewNodeName = $base . '_jcremoteid_nn_' . $contentObjectAttribute->attribute('id');
     $inputNodeName = $base . '_jcremoteid_node_list_' . $contentObjectAttribute->attribute('id');
     $errors = array();
     //Test object Remote ID
     if (!jcRemoteID::isValidObjectRemoteID($http->postVariable($inputObjectName), $contentObjectAttribute->attribute('contentobject_id'), $errors)) {
         //Existing node
         $returnCode = eZInputValidator::STATE_INVALID;
     }
     //Test new node (for new objects) Remote ID
     if ($http->hasPostVariable($inputNewNodeName)) {
         if (!jcRemoteID::isValidNodeRemoteID($http->postVariable($inputNewNodeName), false, $errors, true)) {
             //Existing node
             $returnCode = eZInputValidator::STATE_INVALID;
         }
     }
     //Test each node remote ID value to make sure that it is not in use
     if (is_array($http->postVariable($inputNodeName))) {
         foreach ($http->postVariable($inputNodeName) as $nodeID => $remoteID) {
             if (!jcRemoteID::isValidNodeRemoteID($remoteID, $nodeID, $errors)) {
                 //Existing node
                 $returnCode = eZInputValidator::STATE_INVALID;
             }
         }
     }
     //Update errors list
     $contentObjectAttribute->setValidationError(join(', ', $errors));
     return $returnCode;
 }
Beispiel #2
0
if ($node = eZContentObjectTreeNode::fetch($NodeID)) {
    if ($Module->currentAction() == 'UpdateRemoteID') {
        // test values
        $inputObjectName = 'jcremoteid_object';
        $inputNodeListName = 'jcremoteid_node_list';
        $http = new eZHTTPTool();
        $object = $node->attribute('object');
        if ($http->hasPostVariable($inputObjectName) && jcRemoteID::isValidObjectRemoteID($http->postVariable($inputObjectName), $object->attribute('id'), $errors)) {
            $object->setAttribute('remote_id', $http->postVariable($inputObjectName));
            $object->store();
        }
        if ($http->hasPostVariable($inputNodeListName) && is_array($http->postVariable($inputNodeListName))) {
            $remoteIDNodeList = $http->postVariable($inputNodeListName);
            foreach ($object->attribute('assigned_nodes') as $node_item) {
                $node_item_id = $node_item->attribute('node_id');
                if (isset($remoteIDNodeList[$node_item_id]) && jcRemoteID::isValidNodeRemoteID($remoteIDNodeList[$node_item_id], $node_item_id, $errors)) {
                    $node_item->setAttribute('remote_id', $remoteIDNodeList[$node_item_id]);
                    $node_item->store();
                    if ($node_item_id == $NodeID) {
                        //update $node for template if errors
                        $node = $node_item;
                    }
                }
            }
        }
        // If ok -> send data
        if (empty($errors)) {
            //Clear cache of this object
            eZContentCacheManager::clearContentCache($object->attribute('id'));
            //Redirect to node
            $Module->redirectTo('content/view/full/' . $NodeID);