$read_permission = inventory_check_acl($config['id_user'], $id);

	$write_permission = inventory_check_acl($config['id_user'], $id, true);

	
	if (!$read_permission) {
		include ("general/noaccess.php");
		exit;
	}
}

//**********************************************************************
// Tabs
//**********************************************************************

print_inventory_tabs('relationships', $id, $inventory_name);

$delete_link = get_parameter ('delete_link', 0);
$add_link = get_parameter ('add_link', 0);
$ids_str = '';

if ($delete_link) {
	$id_src = get_parameter('id_src');
	$id_dst = get_parameter('id_dst');

	$result = process_sql_delete ('tinventory_relationship', array ('id_object_src' => $id_src, 'id_object_dst' => $id_dst));
	
	if ($result) {
		echo ui_print_success_message (__("Inventory relationship deleted"), '', true, 'h3', true);
	} else {
		echo ui_print_error_message (__("Error deleting inventory relationship"), '', true, 'h3', true);
		exit;
	}
}

require_once ('include/functions_inventories.php');

$inventory = get_db_row ('tinventory', 'id', $id);


//**********************************************************************
// Tabs
//**********************************************************************
if(!isset($inventory_name)){
	$inventory_name = '';
}
print_inventory_tabs('contacts', $id, $inventory_name);
$table = new stdClass;
$table->width = '99%';
$table->class = 'listing';
$table->head = array ();
$table->size = array ();

$table->head[0] = __('Company');
$table->head[1] = __('Contact');
$table->head[2] = __('Position');
$table->head[3] = __('Details');

if ($write_permission) {
	$table->head[4] = __('Edit');
	$table->size[4] = '40px';
	$table->align[4] = 'center';
if (check_login() != 0) {
    audit_db("Noauth", $config["REMOTE_ADDR"], "No authenticated access", "Trying to access event viewer");
    require "general/noaccess.php";
    exit;
}
$id = (int) get_parameter('id');
if (!give_acl($config['id_user'], get_inventory_group($id), 'IR')) {
    // Doesn't have access to this page
    audit_db($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation", "Trying to access to inventory " . $id);
    include "general/noaccess.php";
    exit;
}
//**********************************************************************
// Tabs
//**********************************************************************
print_inventory_tabs('incidents', $id, $inventory_name);
$table->width = '99%';
$table->class = 'listing';
$table->data = array();
$table->head = array();
$table->head[0] = __('Title');
$table->head[1] = __('Date');
$table->head[2] = __('Priority');
$table->head[3] = __('Status');
$table->head[4] = __('Assigned user');
$table->head[5] = __('View');
$incidents = get_incidents_on_inventory($id, false);
foreach ($incidents as $incident) {
    $data = array();
    if (!give_acl($config['id_user'], $incident['id_grupo'], 'IR')) {
        continue;
if (file_exists("enterprise/include/functions_inventory.php")) {
    require_once "enterprise/include/functions_inventory.php";
    $is_enterprise = true;
}
if ($is_enterprise) {
    $read_permission = inventory_check_acl($config['id_user'], $id);
    if (!$read_permission) {
        audit_db($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation", "Trying to access to inventory " . $id);
        include "general/error_perms.php";
        exit;
    }
}
//**********************************************************************
// Tabs
//**********************************************************************
print_inventory_tabs('tracking', $id, $inventory_name);
if (!$id) {
    require "general/noaccess.php";
    exit;
}
$trackings = get_db_all_rows_field_filter('tinventory_track', 'id_inventory', $id, 'timestamp DESC');
if ($trackings !== false) {
    $table->width = "99%";
    $table->class = 'listing';
    $table->data = array();
    $table->head = array();
    $table->head[1] = __('Description');
    $table->head[2] = __('User');
    $table->head[3] = __('Date');
    foreach ($trackings as $tracking) {
        $data = array();
    if (!$read_permission && $id) {
        include "general/noaccess.php";
        exit;
    }
}
$inventory_name = get_db_value('name', 'tinventory', 'id', $id);
if (!defined('AJAX')) {
    if (!$id) {
        echo "<h1>" . __('Create inventory object') . "</h1>";
    } else {
        if ($inventory_name) {
            //**********************************************************************
            // Tabs
            //**********************************************************************
            /* Tabs list */
            print_inventory_tabs('details', $id, $inventory_name);
            if ($id) {
                $inventory = get_inventory($id);
                if ($manage_permission) {
                    echo "<div id='button-bar-title' style='margin-right: 12px; padding-bottom: 3px;'>";
                    echo "<ul>";
                    echo "<li style='padding: 3px;'>";
                    echo '<form id="delete_inventory_form" name="delete_inventory_form" class="delete action" method="post" action="index.php?sec=inventory&sec2=operation/inventories/inventory_detail">';
                    print_input_hidden('quick_delete', $id);
                    echo "<a href='#' id='detele_inventory_submit_form'>" . print_image("images/cross.png", true, array("title" => __("Delete inventory object"))) . "</a>";
                    echo '</form>';
                    echo "</li>";
                    echo "</div>";
                }
            }
        }
$inventory_name = get_db_value('name', 'tinventory', 'id', $id);

if (!defined ('AJAX')) {
	if (!$id) {
		echo "<h2>".__('Create')."</h2>";
		echo "<h4>".__('Inventory object');
		echo integria_help ("inventory_detail", true);
		echo "</h4>";
	} 
	elseif ($inventory_name) {
		//**********************************************************************
		// Tabs
		//**********************************************************************
		/* Tabs list */
		print_inventory_tabs('details', $id, $inventory_name,$manage_permission);
	
		if ($id) {
			$inventory = get_inventory ($id);
		}
	}
}

$result_msg = '';

$update = (bool) get_parameter ('update_inventory');
$create = (bool) get_parameter ('create_inventory');
$name = (string) get_parameter ('name');
$description = (string) get_parameter ('description');
$id_contract = (int) get_parameter ('id_contract');
$id_parent = (int) get_parameter ('id_parent');