function inventories_show_list($sql_search, $sql_count, $params = '', $last_update = 0, $modal = 0) { global $config; $is_enterprise = false; if (file_exists("enterprise/include/functions_inventory.php")) { require_once "enterprise/include/functions_inventory.php"; $is_enterprise = true; } $write_permission = enterprise_hook('inventory_check_acl', array($config['id_user'], $id, true)); $params['mode'] = 'list'; if (!$sql_search) { $sql_search = "SELECT * FROM tinventory"; } $pure = get_parameter("pure"); if ($pure) { $block_limit = 5000; } else { $block_limit = $config["block_size"]; } $sql_search .= " LIMIT " . $block_limit; $offset = get_parameter("offset", 0); $sql_search .= " OFFSET {$offset}"; $inventories_aux = get_db_all_rows_sql($sql_search); $count_inv = get_db_value_sql($sql_count); if ($is_enterprise) { $inventories = inventory_get_user_inventories($config['id_user'], $inventories_aux); } else { $inventories = $inventories_aux; } if ($inventories === false) { echo ui_print_error_message(__("Empty inventory"), '', true, 'h3', true); } else { $result_check = inventories_check_same_object_type_list($inventories); $table->id = 'inventory_list'; $table->class = 'listing'; $table->width = '100%'; $table->data = array(); $table->head = array(); $table->colspan = array(); $table->head[0] = __('Id'); $table->head[1] = __('Name'); $table->head[2] = __('Owner'); $table->head[3] = __("Parent object"); $table->head[4] = __('Object type'); $table->head[5] = __('Manufacturer'); $table->head[6] = __('Contract'); $table->head[7] = __('Status'); $table->head[8] = __('Receipt date'); if ($result_check) { $res_object_fields = inventories_get_all_type_field($result_check, false, true); $i = 9; foreach ($res_object_fields as $key => $object_field) { if (isset($object_field["label"])) { $table->head[$i] = $object_field['label']; $i++; } } if (!$pure) { if (!$modal) { $table->head[$i] = __('Actions'); if ($write_permission) { $i = $i + 1; $table->head[$i] = print_checkbox('inventorycb-all', "", false, true); } } } } else { if (!$pure) { if (!$modal) { $table->head[9] = __('Actions'); if ($write_permission) { $table->head[10] = print_checkbox('inventorycb-all', "", false, true); } } } } $count = $count_inv; $params = json_encode($params); $params = base64_encode($params); $url_pag = "index.php?sec=inventory&sec2=operation/inventories/inventory¶ms=" . $params; $offset = get_parameter("offset"); if (!$pure) { pagination($count, $url_pag, $offset, false, '', 0, true); } $idx = 0; foreach ($inventories as $key => $inventory) { $data = array(); if ($modal) { $url = "javascript:loadInventory(" . $inventory['id'] . ");"; } else { $url = 'index.php?sec=inventory&sec2=operation/inventories/inventory_detail&id=' . $inventory['id']; } $data[0] = "<a href=" . $url . ">" . $inventory['id'] . "</a>"; $data[1] = "<a href=" . $url . ">" . $inventory['name'] . '</a>'; if ($inventory['owner'] != '') { $name_owner = get_db_value('nombre_real', 'tusuario', 'id_usuario', $inventory['owner']); } else { $name_owner = '--'; } $data[2] = "<a href=" . 'index.php?sec=users&sec2=operation/users/user_edit&id=' . $inventory['owner'] . ">" . $name_owner . '</a>'; if ($inventory["id_parent"] != 0) { $name_parent = get_db_value('name', 'tinventory', 'id', $inventory['id_parent']); $data[3] = "<a href=" . 'index.php?sec=inventory&sec2=operation/inventories/inventory_detail&id=' . $inventory['id_parent'] . ">" . $name_parent . '</a>'; } else { $name_parent = '--'; $data[3] = $name_parent; } if ($inventory['id_object_type'] != 0) { $name_object = get_db_value('name', 'tobject_type', 'id', $inventory['id_object_type']); $data[4] = "<a href=" . 'index.php?sec=inventory&sec2=operation/inventories/manage_objects&id=' . $inventory['id_object_type'] . ">" . $name_object . '</a>'; } else { $name_object = '--'; $data[4] = $name_object; } if ($inventory['id_manufacturer'] != 0) { $name_manufacturer = get_db_value('name', 'tmanufacturer', 'id', $inventory['id_manufacturer']); $data[5] = "<a href=" . 'index.php?sec=inventory&sec2=operation/manufacturers/manufacturer_detail&id=' . $inventory['id_manufacturer'] . ">" . $name_manufacturer . '</a>'; } else { $name_manufacturer = '--'; $data[5] = $name_manufacturer; } if ($inventory['id_contract'] != 0) { $name_contract = get_db_value('name', 'tcontract', 'id', $inventory['id_contract']); $data[6] = "<a href=" . 'index.php?sec=customers&sec2=operation/contracts/contract_detail&id_contract=' . $inventory['id_contract'] . ">" . $name_contract . '</a>'; } else { $name_contract = '--'; $data[6] = $name_contract; } if ($inventory['status'] != "") { $data[7] = __($inventory['status']); } else { $status_none = '--'; $data[7] = $status_none; } if ($inventory['receipt_date'] != "") { $data[8] = $inventory['receipt_date']; } else { $receipt_date = '--'; $data[8] = $receipt_date; } if ($result_check) { $result_object_fields = inventories_get_all_type_field($result_check, $inventory['id'], true); $i = 9; foreach ($result_object_fields as $k => $ob_field) { if (isset($ob_field["label"])) { $data[$i] = $ob_field['data']; $i++; } } if (!$pure) { if (!$modal) { if ($write_permission) { $data[$i] .= '<a href="index.php?sec=inventory&sec2=operation/inventories/inventory&quick_delete=' . $inventory["id"] . '¶ms=' . $params . '" onClick="if (!confirm(\'' . __('Are you sure?') . '\')) return false;"><img src="images/cross.png"></a>'; } } } if (!$pure) { if (!$modal) { if ($write_permission) { $i = $i + 1; $data[$i] = print_checkbox_extended('inventorycb-' . $inventory['id'], $inventory['id'], false, '', '', 'class="cb_inventory"', true); } } } } else { if (!$pure) { if (!$modal) { if ($write_permission) { $data[9] .= '<a href="index.php?sec=inventory&sec2=operation/inventories/inventory&quick_delete=' . $inventory["id"] . '" onClick="if (!confirm(\'' . __('Are you sure?') . '\')) return false;"><img src="images/cross.png"></a>'; } } } if (!$pure) { if (!$modal) { if ($write_permission) { $data[10] = print_checkbox_extended('inventorycb-' . $inventory['id'], $inventory['id'], false, '', '', 'class="cb_inventory"', true); } } } } $table->rowclass[$idx] = 'inventory_info_' . $inventory["id"]; $idx++; array_push($table->data, $data); } echo '<div id= "inventory_only_table">'; print_table($table); echo '</div>'; if (!$pure) { pagination($count, $url_pag, $offset, true, '', 0, true); if (!$modal) { if ($write_permission) { echo '<div class="button-form">'; echo print_button(__('Delete All'), '', false, 'javascript: delete_massive_inventory()', 'class="sub"', true); echo '</div>'; } } } } }
function inventories_show_list($sql_search, $sql_count, $params = '', $last_update = 0) { global $config; $is_enterprise = false; if (file_exists("enterprise/include/functions_inventory.php")) { require_once "enterprise/include/functions_inventory.php"; $is_enterprise = true; } $write_permission = enterprise_hook('inventory_check_acl', array($config['id_user'], $id, true)); $params .= "&mode=list"; if (!$sql_search) { $sql_search = "SELECT * FROM tinventory"; } if ($last_update) { $sql_search .= " ORDER BY last_update DESC"; } else { $sql_search .= " ORDER BY name ASC"; } $clean_output = get_parameter("clean_output"); if ($clean_output) { $block_limit = 5000; } else { $block_limit = $config["block_size"]; } $sql_search .= " LIMIT " . $block_limit; $offset = get_parameter("offset", 0); $sql_search .= " OFFSET {$offset}"; $inventories_aux = get_db_all_rows_sql($sql_search); $count_inv = get_db_value_sql($sql_count); if ($is_enterprise) { $inventories = inventory_get_user_inventories($config['id_user'], $inventories_aux); } else { $inventories = $inventories_aux; } if ($inventories === false) { echo "<h3 class='error'>" . __("Empty inventory") . "</h3>"; } else { $result_check = inventories_check_same_object_type_list($inventories); $table->id = 'inventory_list'; $table->class = 'listing'; $table->width = '100%'; $table->data = array(); $table->head = array(); $table->colspan = array(); $table->head[0] = __('Id'); $table->head[1] = __('Name'); $table->head[2] = __('Owner'); $table->head[3] = __("Parent object"); $table->head[4] = __('Object type'); $table->head[5] = __('Manufacturer'); $table->head[6] = __('Contract'); if ($result_check) { $res_object_fields = inventories_get_all_type_field($result_check, false, true); $i = 6; foreach ($res_object_fields as $key => $object_field) { if (isset($object_field["label"])) { $table->head[$i] = $object_field['label']; $i++; } } $table->head[$i] = __('Actions'); if ($write_permission) { $table->head[$i] = print_checkbox('inventorycb-all', "", false, true); } } else { if (!$clean_output) { $table->head[7] = __('Actions'); } if ($write_permission) { $table->head[8] = print_checkbox('inventorycb-all', "", false, true); } } $count = $count_inv; $url_pag = "index.php?sec=inventory&sec2=operation/inventories/inventory" . $params; $offset = get_parameter("offset"); if (!$clean_output) { pagination($count, $url_pag, $offset); } $idx = 0; foreach ($inventories as $key => $inventory) { $data = array(); if (defined('AJAX')) { $url = "javascript:loadInventory(" . $inventory['id'] . ");"; } else { $url = 'index.php?sec=inventory&sec2=operation/inventories/inventory_detail&id=' . $inventory['id']; } $data[0] = "<a href=" . $url . ">" . $inventory['id'] . "</a>"; $data[1] = "<a href=" . $url . ">" . $inventory['name'] . '</a>'; if ($inventory['owner'] != '') { $name_owner = get_db_value('nombre_real', 'tusuario', 'id_usuario', $inventory['owner']); } else { $name_owner = '--'; } $data[2] = "<a href=" . 'index.php?sec=inventory&sec2=users&sec2=operation/users/user_edit&id=' . $inventory['owner'] . ">" . $name_owner . '</a>'; if ($inventory["id_parent"] != 0) { $name_parent = get_db_value('name', 'tinventory', 'id', $inventory['id_parent']); $data[3] = "<a href=" . 'index.php?sec=inventory&sec2=operation/inventories/inventory_detail&id=' . $inventory['id_parent'] . ">" . $name_parent . '</a>'; } else { $name_parent = '--'; $data[3] = $name_parent; } if ($inventory['id_object_type'] != 0) { $name_object = get_db_value('name', 'tobject_type', 'id', $inventory['id_object_type']); $data[4] = "<a href=" . 'index.php?sec=inventory&sec2=operation/inventories/manage_objects&id=' . $inventory['id_object_type'] . ">" . $name_object . '</a>'; } else { $name_object = '--'; $data[4] = $name_object; } if ($inventory['id_manufacturer'] != 0) { $name_manufacturer = get_db_value('name', 'tmanufacturer', 'id', $inventory['id_manufacturer']); $data[5] = "<a href=" . 'index.php?sec=inventory&sec2=operation/manufacturers/manufacturer_detail&id=' . $inventory['id_manufacturer'] . ">" . $name_manufacturer . '</a>'; } else { $name_manufacturer = '--'; $data[5] = $name_manufacturer; } if ($inventory['id_contract'] != 0) { $name_contract = get_db_value('name', 'tcontract', 'id', $inventory['id_contract']); $data[6] = "<a href=" . 'index.php?sec=inventory&sec2=customers&sec2=operation/contracts/contract_detail&id_contract=' . $inventory['id_contract'] . ">" . $name_contract . '</a>'; } else { $name_contract = '--'; $data[6] = $name_contract; } if ($result_check) { $result_object_fields = inventories_get_all_type_field($result_check, $inventory['id'], true); $i = 6; foreach ($result_object_fields as $k => $ob_field) { if (isset($ob_field["label"])) { $data[$i] = $ob_field['data']; $i++; } } if (!$clean_output) { $data[$i] = '<a href="javascript: toggleInventoryInfo(' . $inventory['id'] . ')" id="show_info-' . $inventory["id"] . '">'; $data[$i] .= print_image("images/information.png", true, array("title" => __('Show object type fields'))); $data[$i] .= '</a> '; if ($write_permission) { $data[$i] .= '<a href="index.php?sec=inventory&sec2=operation/inventories/inventory&quick_delete=' . $inventory["id"] . '" onClick="if (!confirm(\'' . __('Are you sure?') . '\')) return false;"><img src="images/cross.png"></a>'; } } if ($write_permission) { $data[$i] = print_checkbox_extended('inventorycb-' . $inventory['id'], $inventory['id'], false, '', '', 'class="cb_inventory"', true); } } else { if (!$clean_output) { $data[7] = '<a href="javascript: toggleInventoryInfo(' . $inventory['id'] . ')" id="show_info-' . $inventory["id"] . '">'; $data[7] .= print_image("images/information.png", true, array("title" => __('Show object type fields'))); $data[7] .= '</a> '; if ($write_permission) { $data[7] .= '<a href="index.php?sec=inventory&sec2=operation/inventories/inventory&quick_delete=' . $inventory["id"] . '" onClick="if (!confirm(\'' . __('Are you sure?') . '\')) return false;"><img src="images/cross.png"></a>'; } } if ($write_permission) { $data[8] = print_checkbox_extended('inventorycb-' . $inventory['id'], $inventory['id'], false, '', '', 'class="cb_inventory"', true); } } $table->rowclass[$idx] = 'inventory_info_' . $inventory["id"]; $idx++; array_push($table->data, $data); if (!$clean_output) { $data_info = array(); $table_info->width = '98%'; $table_info->class = 'databox_color_without_line'; $table_info->size = array(); $table_info->style = array(); $table_info->data = array(); $res_obj_fields = inventories_get_all_type_field($inventory['id_object_type'], $inventory['id'], false); if (empty($res_obj_fields)) { $table_info->data[0][0] = '<b>' . __('No data to show') . '</b>'; } else { $j = 0; foreach ($res_obj_fields as $k => $ob_field) { if (isset($ob_field['label']) && $ob_field['label'] != "") { if ($ob_field['type'] == 'external') { $table_info->align[$j] = 'left;'; $table_info->data[$j][$j] = '<b>' . $ob_field['label']; $table_info->data[$j][$j] .= ' : ' . '</b>'; $table_info->data[$j][$j] .= $ob_field['data']; $j++; if (isset($ob_field['external_label']) && $ob_field['external_label'] != '') { $label_value = get_db_value_sql("SELECT " . $ob_field['external_label'] . " FROM " . $ob_field['external_table_name'] . " WHERE " . $ob_field['external_reference_field'] . " = " . $ob_field['data']); $table_info->align[$j] = 'left;'; $table_info->data[$j][$j] = '<b>' . $ob_field['external_label']; $table_info->data[$j][$j] .= ' : ' . '</b>'; $table_info->data[$j][$j] .= $label_value; $j++; } } else { $table_info->align[$j] = 'left;'; $table_info->data[$j][$j] = '<b>' . $ob_field['label']; $table_info->data[$j][$j] .= ' : ' . '</b>'; $table_info->data[$j][$j] .= $ob_field['data']; $j++; } } } } $data_info['row_info'] = print_table($table_info, true); $table_info->colspan[0][0] = 6; $table->rowclass[$idx] = 'inventory_more_info_' . $inventory["id"]; $table->rowstyle[$idx] = 'display: none;'; if ($write_permission) { $table->colspan[$idx]["row_info"] = 8; } else { $table->colspan[$idx]["row_info"] = 7; } array_push($table->data, $data_info); $idx++; } } print_table($table); if (!$clean_output) { pagination($count, $url_pag, $offset, true); } } }
$values['id_inventory'] = $id; $data = get_db_value_filter('data', 'tobject_field_data', array('id_inventory' => $id_parent, 'id_object_type_field' => $field['id'])); $values['data'] = $data; process_sql_insert('tobject_field_data', $values); } } } else if ($old_parent != false) { // Parent set to none $aditional_data = array(); $aditional_data['old'] = $old_parent; $aditional_data['new'] = ''; inventory_tracking($id,INVENTORY_PARENT_UPDATED, $aditional_data); } $inventory_companies = get_parameter("inventory_companies"); inventory_get_user_inventories(get_parameter ('companies', $inventory_companies), true); //if ($result_hook !== ENTERPRISE_NOT_HOOK) { // Update users in inventory $users = get_parameter ('users'); $users = explode(", ", safe_output($users)); inventory_update_users ($id, $users, true); //} //if ($result_hook !== ENTERPRISE_NOT_HOOK) { $companies = get_parameter ('companies'); $companies = explode(", ", safe_output($companies)); inventory_update_companies($id, $companies, true); //} } if ($result !== false) {