function endItem()
 {
     if ($this->_is_item_finished !== TRUE) {
         if ($this->_item_obj != NULL) {
             // instance was not closed, close it now!
             if ($this->_is_item_instance) {
                 $this->_is_item_instance = FALSE;
             }
             // if not item instance, create one
             if (is_empty_array($this->_instance_item_obj_rs)) {
                 $this->startItemInstance();
                 $this->endItemInstance();
             }
             // The item is finished, no more additions are allowed, until the
             // startItem method is called again.
             $this->_is_item_finished = TRUE;
             $item_vars = $this->__getItemHTTPVars($this->_item_obj);
             $item_vars['trial_run'] = $this->_cfg_is_trial_run ? 'true' : 'false';
             $item_vars['confirmed'] = $this->_cfg_ignore_duplicate_title ? 'true' : 'false';
             $item_r = array(s_item_type => $this->_item_obj->getItemType(), owner_id => $this->getOwner(), title => $this->_item_obj->getTitle());
             $instance_valid = FALSE;
             $errors = array();
             $return_val = handle_item_insert($item_r, $item_vars, $errors);
             if ($return_val === TRUE) {
                 // store item id for later use
                 if ($this->_cfg_is_trial_run !== TRUE && is_numeric($item_r['item_id'])) {
                     $this->_item_id_list_r[] = $item_r['item_id'];
                 }
                 for ($i = 0; $i < count($this->_instance_item_obj_rs); $i++) {
                     $instanceObj = $this->_instance_item_obj_rs[$i];
                     // if status type is to be overriden, do it here!
                     if ($this->_cfg_override_status_type) {
                         $status_type_r = $this->_cfg_default_status_type_r;
                     } else {
                         $status_type_r = fetch_status_type_r($instanceObj->getStatusType());
                         // if illegal type, then override by default.
                         if ($status_type_r['closed_ind'] == 'Y') {
                             $status_type_r = $this->_cfg_default_status_type_r;
                         }
                     }
                     $item_r['owner_id'] = $instanceObj->getOwnerID();
                     $item_r['s_status_type'] = $status_type_r['s_status_type'];
                     $instance_vars = $this->__getItemHTTPVars($instanceObj);
                     // we are missing instance attributes if already set in item
                     $instance_vars = array_merge($instance_vars, $item_vars);
                     $return_val = handle_item_instance_insert($item_r, $status_type_r, $item_vars, $errors);
                     if ($return_val !== FALSE) {
                         $item_r['instance_no'] = $this->_cfg_is_trial_run ? $i + 1 : $item_r['instance_no'];
                         //$instanceObj->setInstanceNo($this->_cfg_is_trial_run?$i+1:$item_r['instance_no']);
                         $this->__listing_item_import_result_row($item_r, $status_type_r, $instance_vars, NULL);
                         // indicates at least one instance inserted.
                         $instance_valid = TRUE;
                     } else {
                         $item_r['instance_no'] = $this->_cfg_is_trial_run ? $i + 1 : $item_r['instance_no'];
                         //$instanceObj->setInstanceNo($this->_cfg_is_trial_run?$i+1:$item_r['instance_no']);
                         $this->__listing_item_import_result_row($item_r, $status_type_r, $instance_vars, $errors);
                     }
                 }
             } else {
                 $this->__listing_item_import_result_row($item_r, NULL, $item_vars, $errors);
             }
             $this->_item_obj = NULL;
             // end of parent item.
             return TRUE;
         } else {
             $this->_item_obj = NULL;
             $this->addError('endItem', get_opendb_lang_var('undefined_error'));
             return FALSE;
         }
     } else {
         // if($this->_is_item_finished !== TRUE)
         return FALSE;
     }
 }
Beispiel #2
0
function perform_update_process(&$item_r, &$status_type_r, &$HTTP_VARS, &$footer_links_r)
{
    global $PHP_SELF;
    do_op_title($item_r, $status_type_r, $HTTP_VARS['start-op'] == 'newinstance' ? 'newinstance' : 'update');
    $errors = NULL;
    $return_val = FALSE;
    if ($HTTP_VARS['start-op'] == 'newinstance') {
        $item_r['instance_no'] = NULL;
        $return_val = handle_item_instance_insert($item_r, $status_type_r, $HTTP_VARS, $errors);
    } else {
        $return_val = handle_item_instance_update($item_r, $status_type_r, $HTTP_VARS, $errors);
    }
    if ($return_val === TRUE) {
        $return_val = handle_item_update($item_r, $HTTP_VARS, $errors);
        if (get_opendb_config_var('item_input', 'related_item_support') !== FALSE) {
            if (!empty($HTTP_VARS['parent_item'])) {
                $parent_item_r = get_item_id_and_instance_no($HTTP_VARS['parent_item']);
                if (is_exists_item_instance($parent_item_r['item_id'], $parent_item_r['instance_no']) && !is_exists_related_item_instance_relationship($item_r['item_id'], $item_r['instance_no'], $parent_item_r['item_id'], $parent_item_r['instance_no'])) {
                    insert_item_instance_relationship($parent_item_r['item_id'], $parent_item_r['instance_no'], $item_r['item_id'], $item_r['instance_no']);
                }
            }
        }
    }
    if ($return_val === "__INVALID_DATA__") {
        echo format_error_block($errors);
        $HTTP_VARS['op'] = 'edit';
        $formContents = handle_edit_or_refresh($HTTP_VARS['op'], $item_r, $status_type_r, $HTTP_VARS, $errors);
        if ($formContents !== FALSE) {
            echo $formContents;
        } else {
            echo format_error_block($errors);
        }
    } else {
        if ($return_val === TRUE) {
            if ($HTTP_VARS['start-op'] == 'newinstance') {
                echo "<p class=\"success\">" . get_opendb_lang_var('item_instance_added') . "</p>";
            } else {
                echo "<p class=\"success\">" . get_opendb_lang_var('item_updated') . "</p>";
            }
            echo format_error_block($errors, 'warning');
            $footer_links_r[] = array(url => "item_display.php?item_id=" . $item_r['item_id'] . "&instance_no=" . $item_r['instance_no'], text => get_opendb_lang_var('back_to_item'));
        } else {
            echo format_error_block($errors);
        }
    }
}