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; } }
function perform_insert_process(&$item_r, &$status_type_r, &$HTTP_VARS, &$footer_links_r) { global $PHP_SELF; $errors = NULL; $return_val = TRUE; $op = NULL; $return_val = handle_item_insert($item_r, $HTTP_VARS, $errors); if ($return_val === TRUE) { $return_val = handle_item_instance_insert($item_r, $status_type_r, $HTTP_VARS, $errors); if ($return_val !== FALSE) { if (get_opendb_config_var('item_input', 'related_item_support') !== FALSE) { if (is_numeric($HTTP_VARS['parent_item_id']) && is_numeric($HTTP_VARS['parent_instance_no']) && is_exists_item_instance($HTTP_VARS['parent_item_id'], $HTTP_VARS['parent_instance_no'])) { // fixme, this creates a relationship for all item instances, is that what we want? insert_item_instance_relationships($HTTP_VARS['parent_item_id'], $item_r['item_id'], $item_r['instance_no']); } elseif (!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'])) { insert_item_instance_relationship($parent_item_r['item_id'], $parent_item_r['instance_no'], $item_r['item_id'], $item_r['instance_no']); } } } } } // this will only occur for new item insert if ($return_val === "__CONFIRM_EXISTS_TITLE__" || $return_val === "__CONFIRM_EXISTS_OWNER_TITLE__") { if ($return_val === "__CONFIRM_EXISTS_OWNER_TITLE__") { $message_lang_var = 'confirm_title_same_type_and_owner_insert'; $footer_links_r[] = array(url => "listings.php?search_list=y&inc_menu=N&owner_id=" . $item_r['owner_id'] . "&title=" . urlencode($item_r['title']) . "&title_match=exact&s_item_type=" . $item_r['s_item_type'], target => '_new', text => get_opendb_lang_var('list_duplicate_title(s)')); } else { if ($return_val === "__CONFIRM_EXISTS_TITLE__") { $message_lang_var = 'confirm_title_same_type_insert'; $footer_links_r[] = array(url => "listings.php?search_list=y&inc_menu=N&title=" . urlencode($item_r['title']) . "&title_match=exact&s_item_type=" . $item_r['s_item_type'], target => '_new', text => get_opendb_lang_var('list_duplicate_title(s)')); } } do_op_title($item_r, $status_type_r, $HTTP_VARS['start-op'] == 'clone_item' ? 'clone_item' : 'insert'); echo get_op_confirm_form($PHP_SELF, get_opendb_lang_var($message_lang_var, array('title' => $item_r['title'], 's_item_type' => $item_r['s_item_type'])), $HTTP_VARS); } else { if ($return_val === "__INVALID_DATA__") { do_op_title($item_r, $status_type_r, $HTTP_VARS['start-op'] == 'clone_item' ? 'clone_item' : 'insert'); echo format_error_block($errors); $HTTP_VARS['op'] = 'new'; $formContents = handle_new_or_site($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 === "__ABORTED__") { if ($HTTP_VARS['start-op'] == 'clone_item') { do_op_title($item_r, $status_type_r, 'clone_item'); echo "<p class=\"success\">" . get_opendb_lang_var('item_not_cloned') . "</p>"; } else { do_op_title($item_r, $status_type_r, 'insert'); echo "<p class=\"success\">" . get_opendb_lang_var('item_not_added') . "</p>"; } } else { if ($return_val === TRUE) { if ($HTTP_VARS['start-op'] == 'clone_item') { do_op_title($item_r, $status_type_r, 'clone_item'); echo "<p class=\"success\">" . get_opendb_lang_var('item_cloned') . "</p>"; } else { do_op_title($item_r, $status_type_r, 'insert'); echo "<p class=\"success\">" . get_opendb_lang_var('item_added') . "</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')); $footer_links_r[] = array(url => "item_input.php?op=site-add&owner_id=" . $item_r['owner_id'], text => get_opendb_lang_var('add_new_item')); } else { do_op_title($item_r, $status_type_r, $HTTP_VARS['start-op'] == 'clone_item' ? 'clone_item' : 'insert'); echo format_error_block($errors); } } } } }