top.window.location = '../../index.php'"; exit; } require_once __DIR__ . "/" . "../../includes/include_basics_only.php"; require_once __DIR__ . "/" . "../../includes/classes/ConnectPDO.php"; $auth = new AuthNew($_SESSION['s_logado'], $_SESSION['s_nivel'], 2, 2); use includes\classes\ConnectPDO; $conn = ConnectPDO::getInstance(); $post = $_POST; // var_dump($post); $terms = ""; $criteria = array(); $criterText = ""; $badgeClass = "badge badge-info p-2 mb-1"; $badgeClassDirectAttributes = "badge badge-success p-2 mb-1"; $badgeClassAggregatedAttributes = "badge badge-oc-olive p-2 mb-1"; $badgeClassCustomFields = "badge badge-oc-teal p-2 mb-1"; $badgeClassEmptySearch = "badge badge-danger p-2 mb-1"; $imgsPath = "../../includes/imgs/"; $config = getConfig($conn); $render_custom_fields = (isset($post['render_custom_fields']) ? $post['render_custom_fields']: 1); $possibleOperations = ['<', '>', '<=', '>=', '==', '===', '!=', 'IN']; $hasLimitationByAllowedClients = false; $hasLimitationByAllowedUnits = false; /* Cliente */ $field_label = TRANS('CLIENT'); $post_field_sufix = "client"; $field_table = "clients"; $field_id = "id"; $field_name = "nickname"; if (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $fieldIn = ""; $unitIn = ""; $treatedPostField = array_map('noHtml', $post[$post_field_sufix]); foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $sql = "SELECT inst_cod FROM instituicao WHERE inst_client IN ({$fieldIn}) "; $res = $conn->query($sql); if ($res->rowCount()) { foreach ($res->fetchAll() as $rowUnit) { if (strlen((string)$unitIn)) $unitIn .= ","; $unitIn .= $rowUnit['inst_cod']; } $terms .= " AND inst.inst_cod IN ({$unitIn}) "; } $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } else { /* Não houve seleção de cliente - é necessário checar se há limite de visualização para a área primária do usuário */ if (!empty($_SESSION['s_allowed_units'])) { $hasLimitationByAllowedClients = true; $terms .= " AND inst.inst_cod IN ({$_SESSION['s_allowed_units']}) "; } } /* Unidade */ $field_label = TRANS('COL_UNIT'); $post_field_sufix = "unidade"; $sql_column = "inst.inst_cod"; $field_table = "instituicao"; $field_id = "inst_cod"; $field_name = "inst_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('noHtml', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } else { /* Não houve seleção de unidade - é necessário checar se há limite de visualização para a área primária do usuário */ if (!empty($_SESSION['s_allowed_units'])) { $hasLimitationByAllowedUnits = true; $terms .= " AND inst.inst_cod IN ({$_SESSION['s_allowed_units']}) "; } } /* Usuário do ativo */ /* Exibição dos critérios relacionados aos usuários dos ativos */ if (isset($post['no_empty_asset_user']) && !empty($post['no_empty_asset_user'])) { $criterText = TRANS('SMART_ASSETS_HAVING_USERS') . "
"; $criteria[] = "{$criterText}"; $terms .= " "; } elseif (isset($post['no_asset_user']) && !empty($post['no_asset_user'])) { $criterText = TRANS('SMART_ASSETS_NOT_HAVING_USERS') . "
"; $criteria[] = "{$criterText}"; $terms .= " "; } elseif (isset($post['asset_user']) && !empty($post['asset_user'])) { $criterText = ""; $treatedPostField = array_map('intval', $post['asset_user']); $usersNames = getArrayOfUsersNamesByIds($conn, $treatedPostField); $criterText = implode(", ", $usersNames); $criterText = TRANS('FIELD_USER') . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; $terms .= " "; } /* Etiqueta */ $field_label = TRANS('ASSET_TAG'); $post_field_sufix = "etiqueta"; $sql_column = "c.comp_inv"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '' ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $tmp = explode(',', (string)$post[$post_field_sufix]); // $treatValues = array_map('intval', $tmp); $treatValues = array_map('noHtml', $tmp); $tagIN = ""; foreach ($treatValues as $tag) { if (strlen((string)$tagIN)) $tagIN .= ", "; $tag = trim($tag); $tagIN .= "'{$tag}'"; } $terms .= " AND {$sql_column} IN ({$tagIN}) "; $criterText = $field_label . ": {$tagIN}
"; $criteria[] = "{$criterText}"; } /* Tipo de ativo */ $field_label = TRANS('COL_TYPE'); $post_field_sufix = "equip_type"; $sql_column = "c.comp_tipo_equip"; $field_table = "tipo_equip"; $field_id = "tipo_cod"; $field_name = "tipo_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $fieldIn = ""; if (is_array($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } } else { /* Se não for array, indica que a requisição não está vindo do filtro avancado */ $fieldIn = (int)$post[$post_field_sufix]; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* asset_or_resource : Filtra se é busca sobre todos os ativos ou apenas recursos */ $field_label = TRANS('CONSIDERS'); // $queryForTypes = [ // 1 => "", // 2 => "AND cat.cat_is_product = 0", // 3 => "AND cat.cat_is_product = 1" // ]; $queryForTypes = [ 1 => "", 2 => "AND (c.is_product IS NULL OR c.is_product = 0) ", 3 => "AND c.is_product = 1" ]; $optionsForTypes = [ 1 => TRANS('ALL_TYPES'), 2 => TRANS('ONLY_ASSETS'), 3 => TRANS('ONLY_RESOURCES') ]; if (isset($post['asset_or_resource']) && !empty($post['asset_or_resource'])) { $treatedPostField = (int)$post['asset_or_resource']; $terms .= $queryForTypes[$treatedPostField]; $criterText = $field_label . ": " . $optionsForTypes[$treatedPostField] ."
"; $criteria[] = "{$criterText}"; } /* Categoria do tipo de ativo */ $field_label = TRANS('ASSET_CATEGORY'); $post_field_sufix = "asset_category"; $sql_column = "equip.tipo_categoria"; $field_table = "assets_categories"; $field_id = "id"; $field_name = "cat_name"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $fieldIn = ""; if (is_array($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } } else { /* Se não for array, indica que a requisição não está vindo do filtro avancado */ $fieldIn = (int)$post[$post_field_sufix]; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Fabricante */ $field_label = TRANS('COL_MANUFACTURER'); $post_field_sufix = "manufacturer"; $sql_column = "fab.fab_cod"; $field_table = "fabricantes"; $field_id = "fab_cod"; $field_name = "fab_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Modelo */ $field_label = TRANS('COL_MODEL'); $post_field_sufix = "model"; $sql_column = "model.marc_cod"; $field_table = "marcas_comp"; $field_id = "marc_cod"; $field_name = "marc_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $fieldIn = ""; if (is_array($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } } else { $fieldIn = (int)$post[$post_field_sufix]; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Serial number */ $field_label = TRANS('SERIAL_NUMBER'); $post_field_sufix = "serial_number"; $sql_column = "c.comp_sn"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '' ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $tmp = explode(',', (string)$post[$post_field_sufix]); // $treatValues = array_map('intval', $tmp); $treatValues = array_map('noHtml', $tmp); $tagIN = ""; foreach ($treatValues as $tag) { if (strlen((string)$tagIN)) $tagIN .= ", "; $tag = trim($tag); $tagIN .= "'{$tag}'"; } $terms .= " AND {$sql_column} IN ({$tagIN}) "; $criterText = $field_label . ": {$tagIN}
"; $criteria[] = "{$criterText}"; } /* Part-number */ $field_label = TRANS('COL_PARTNUMBER'); $post_field_sufix = "part_number"; $sql_column = "c.comp_part_number"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '' ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $tmp = explode(',', (string)$post[$post_field_sufix]); // $treatValues = array_map('intval', $tmp); $treatValues = array_map('noHtml', $tmp); $tagIN = ""; foreach ($treatValues as $tag) { if (strlen((string)$tagIN)) $tagIN .= ", "; $tag = trim($tag); $tagIN .= "'{$tag}'"; } $terms .= " AND {$sql_column} IN ({$tagIN}) "; $criterText = $field_label . ": {$tagIN}
"; $criteria[] = "{$criterText}"; } /* Departamento */ $field_label = TRANS('DEPARTMENT'); $post_field_sufix = "departamento"; $sql_column = "c.comp_local"; $field_table = "localizacao"; $field_id = "loc_id"; $field_name = "local"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $fieldIn = ""; if (is_array($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } } else { /* Se não for array, indica que a requisição não está vindo do filtro avancado */ $fieldIn = (int)$post[$post_field_sufix]; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Situação */ $field_label = TRANS('STATE'); $post_field_sufix = "condition"; $sql_column = "c.comp_situac"; $field_table = "situacao"; $field_id = "situac_cod"; $field_name = "situac_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Fornecedores */ $field_label = TRANS('COL_VENDOR'); $post_field_sufix = "supplier"; $sql_column = "c.comp_fornecedor"; $field_table = "fornecedores"; $field_id = "forn_cod"; $field_name = "forn_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Centro de Custo */ $field_label = TRANS('COST_CENTER'); $post_field_sufix = "cost_center"; $sql_column = "c.comp_ccusto"; $db_name = DB_CCUSTO; $field_table = TB_CCUSTO; $field_id = CCUSTO_ID; $field_name = CCUSTO_DESC; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$db_name}.{$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Nota Fiscal */ $field_label = TRANS('INVOICE_NUMBER'); $post_field_sufix = "invoice_number"; $sql_column = "c.comp_nf"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '' ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $tmp = explode(',', (string)$post[$post_field_sufix]); // $treatValues = array_map('intval', $tmp); $treatValues = array_map('noHtml', $tmp); $tagIN = ""; foreach ($treatValues as $tag) { if (strlen((string)$tagIN)) $tagIN .= ", "; $tag = trim($tag); $tagIN .= "'{$tag}'"; } $terms .= " AND {$sql_column} IN ({$tagIN}) "; $criterText = $field_label . ": {$tagIN}
"; $criteria[] = "{$criterText}"; } /* Assistência */ $field_label = TRANS('ASSISTENCE'); $post_field_sufix = "assistance"; $sql_column = "c.comp_assist"; $field_table = "assistencia"; $field_id = "assist_cod"; $field_name = "assist_desc"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Tipo de garantia */ $field_label = TRANS('FIELD_TYPE_WARRANTY'); $post_field_sufix = "warranty_type"; $sql_column = "c.comp_tipo_garant"; $field_table = "tipo_garantia"; $field_id = "tipo_garant_cod"; $field_name = "tipo_garant_nome"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} != '-1' AND {$sql_column} != '0' AND {$sql_column} IS NOT NULL AND {$sql_column} != '') "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} = '-1' OR {$sql_column} = '0' OR {$sql_column} IS NULL OR {$sql_column} = '' ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = array_map('intval', $post[$post_field_sufix]); $fieldIn = ""; foreach ($treatedPostField as $field) { if (strlen((string)$fieldIn)) $fieldIn .= ","; $fieldIn .= (int)$field; } $terms .= " AND {$sql_column} IN ({$fieldIn}) "; $criterText = ""; $sqlCriter = "SELECT {$field_name} FROM {$field_table} WHERE {$field_id} in ({$fieldIn}) ORDER BY {$field_name}"; $resCriter = $conn->query($sqlCriter); foreach ($resCriter->fetchAll() as $rowCriter) { if (strlen((string)$criterText)) $criterText .= ", "; $criterText .= $rowCriter[$field_name]; } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Garantia */ $field_label = TRANS('WARRANTY_STATUS'); $post_field_sufix = "warranty_status"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND (c.comp_data_compra IS NOT NULL AND c.comp_garant_meses IS NOT NULL) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND (c.comp_data_compra IS NULL OR c.comp_garant_meses IS NULL) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $criterText = ""; if ((int)$post[$post_field_sufix] == 1) { $terms .= " AND (date_add(c.comp_data_compra, INTERVAL tmp.tempo_meses month) >= now()) "; $criterText .= TRANS('UNDER_WARRANTY'); } elseif ((int)$post[$post_field_sufix] == 2) { $terms .= " AND (date_add(c.comp_data_compra, INTERVAL tmp.tempo_meses month) < now()) "; $criterText .= TRANS('SEL_GUARANTEE_EXPIRED'); } $criterText = $field_label . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } /* Data mínima de aquisição */ $field_label = TRANS('SMART_MIN_PURCHASE_DATE'); $post_field_sufix = "purchase_date_from"; $sql_column = "c.comp_data_compra"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} IS NOT NULL ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} IS NULL ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = noHtml($post[$post_field_sufix]); if (!isValidDate($treatedPostField, 'd/m/Y')) { $errorFieldMessage = TRANS('MSG_ERROR_WRONG_FORMATTED') . ": " . $field_label; echo message('warning', '', $errorFieldMessage, '', '' , 1); exit; } $date_from = ""; $date_from = $treatedPostField . " 00:00:00"; $date_from = dateDB($date_from); $terms .= " AND ( {$sql_column} >= '{$date_from}' ) "; $criterText = $field_label . ": " . $treatedPostField . "
"; $criteria[] = "{$criterText}"; } /* Data máxima de aquisição */ $field_label = TRANS('SMART_MAX_PURCHASE_DATE'); $post_field_sufix = "purchase_date_to"; $sql_column = "c.comp_data_compra"; if (isset($post['no_empty_' . $post_field_sufix]) && $post['no_empty_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} IS NOT NULL ) "; $criterText = $field_label . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_' . $post_field_sufix]) && $post['no_' . $post_field_sufix] == 1) { $terms .= " AND ( {$sql_column} IS NULL ) "; $criterText = $field_label . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$post_field_sufix]) && !empty($post[$post_field_sufix])) { $treatedPostField = noHtml($post[$post_field_sufix]); if (!isValidDate($treatedPostField, 'd/m/Y')) { $errorFieldMessage = TRANS('MSG_ERROR_WRONG_FORMATTED') . ": " . $field_label; echo message('warning', '', $errorFieldMessage, '', '' , 1); exit; } $date_from = ""; $date_from = $treatedPostField . " 23:59:59"; $date_from = dateDB($date_from); $terms .= " AND ( {$sql_column} <= '{$date_from}' ) "; $criterText = $field_label . ": " . $treatedPostField . "
"; $criteria[] = "{$criterText}"; } // if (empty($terms)) { // $criterText = TRANS('SMART_WITHOUT_SEARCH_CRITERIA') . "
"; // $criteria[] = "{$criterText}"; // } // echo $terms; $sql = $QRY["full_detail_ini"]; $sql .= $terms; $sql .= " ORDER BY instituicao, etiqueta"; // /* Controle para evitar consultas sem critérios relevantes */ // if (empty(trim($terms))) { // $criterText = TRANS('SMART_WITHOUT_SEARCH_CRITERIA') . "
"; // $criteria[] = "{$criterText}"; // /* Não permito a busca de ativos sem ao menos um critério dentro dos campos oficiais */ // echo message('warning', '', TRANS('CHOOSE_AT_LEAST_ONE_CRITERIA_ASSETS'), '', '' , 1); // exit; // } $sqlResult = $conn->query($sql); $totalFiltered = $sqlResult->rowCount(); /* Exibição dos critérios sobre os atributos diretos do ativo pesquisado */ if (!empty($post['measure_type'])) { $i = 0; foreach ($post['measure_type'] as $measure) { if (!empty($post['measure_value'][$i]) && !empty($post['operation'][$i]) && !empty($post['measure_unit'][$i])) { if (!in_array($post['operation'][$i], $possibleOperations)) { $errorFieldMessage = TRANS('MSG_INVALID_OPERATION'); echo message('warning', '', $errorFieldMessage, '', '' , 1); exit; } $measure_type_name = getMeasureTypes($conn, (int)$post['measure_type'][$i])['mt_name']; $measure_unit_name = getMeasureUnits($conn, (int)$post['measure_unit'][$i])['unit_abbrev']; $criterText = $measure_type_name . ' ' . $post['operation'][$i] . ' ' . noHtml($post['measure_value'][$i]) . $measure_unit_name . "
"; $criteria[] = "{$criterText}"; } $i++; } } /* Exibição dos critérios sobre os atributos agregados ao ativo pesquisado */ if (!empty($post['asset_type_aggregated'])) { $i = 0; foreach ($post['asset_type_aggregated'] as $type_aggregated) { if (!empty($post['asset_type_aggregated']) && !empty($post['measure_type_aggregated']) && !empty($post['measure_value_aggregated'][$i]) && !empty($post['measure_unit_aggregated'][$i])) { $asset_type_name = getAssetsTypes($conn, (int)$post['asset_type_aggregated'][$i])['tipo_nome']; $measure_type_name = getMeasureTypes($conn, (int)$post['measure_type_aggregated'][$i])['mt_name']; $measure_unit_name = getMeasureUnits($conn, (int)$post['measure_unit_aggregated'][$i])['unit_abbrev']; $criterText = $asset_type_name . ' ' . TRANS('WITH') . ' ' . $measure_type_name . ' ' . noHtml($post['operation_aggregated'][$i]) . ' ' . noHtml($post['measure_value_aggregated'][$i]) . $measure_unit_name . "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_empty_']) && count($post['no_empty_']) && array_key_exists($post['asset_type_aggregated'][$i], $post['no_empty_'])) { $asset_type_name = getAssetsTypes($conn, $post['asset_type_aggregated'][$i])['tipo_nome']; $criterText = $asset_type_name . ': ' . TRANS('OCO_SEL_ANY'). "
"; $criteria[] = "{$criterText}"; } elseif (isset($post['no_']) && count($post['no_']) && array_key_exists($post['asset_type_aggregated'][$i], $post['no_'])) { $asset_type_name = getAssetsTypes($conn, (int)$post['asset_type_aggregated'][$i])['tipo_nome']; $criterText = $asset_type_name . ': ' . TRANS('SEL_NONE'); $criteria[] = "{$criterText}"; } $i++; } } /** * Campos personalizados * Tipos de campos possíveis: * ["date", "datetime", "select", "select_multi", "number", "text", "textarea", "checkbox"] * * Até o momento esses são os campos permitidos e tratados: * ["date", "datetime", "select", "select_multi", "number", "text", "textarea", "checkbox"] */ $custom_fields = []; $custom_fields_full = []; if ($render_custom_fields) { $types = ["date", "datetime", "select", "select_multi", "number", "text", "textarea", "checkbox"]; $custom_fields = getCustomFields($conn, null, 'equipamentos', $types); /* Apenas campos customizados ativos e que podem ser pesquisados */ $custom_fields_full = getCustomFields($conn, null, 'equipamentos'); /* Para montar a tabela de exibição, todos os campos ativos sao utilizados */ } /* Montagem dos Critérios dos campos personalizados preenchidos */ $emptyPrefix = "no_"; $notEmptyPrefix = "no_empty_"; $minDatePrefix = "min_"; $maxDatePrefix = "max_"; $minNumberPrefix = "minNum_"; $maxNumberPrefix = "maxNum_"; $noRenderPrefix = "norender_"; $dontRender = []; /** Armazenarei aqui os valores a serem checados por cada chamado */ $customTerms = []; foreach ($custom_fields as $cfield) { $criterText = ""; /* Ver os campos que não devem ser renderizados */ if (isset($post[$noRenderPrefix . $cfield['field_name']]) && $post[$noRenderPrefix . $cfield['field_name']] == 1) { $dontRender[] = $cfield['id']; } if (isset($post[$notEmptyPrefix . $cfield['field_name']]) && $post[$notEmptyPrefix . $cfield['field_name']] == 1) { /* Qualquer valor não vazio */ $criterText = $cfield['field_label'] . ": " . TRANS('SMART_NOT_EMPTY') . "
"; $criteria[] = "{$criterText}"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['!='][] = ''; } elseif (isset($post[$emptyPrefix . $cfield['field_name']]) && $post[$emptyPrefix . $cfield['field_name']] == 1) { /* Valor obrigatiamente vazio */ $criterText = $cfield['field_label'] . ": " . TRANS('SMART_EMPTY') . "
"; $criteria[] = "{$criterText}"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['=='][] = ''; } elseif (isset($post[$cfield['field_name']]) && !empty($post[$cfield['field_name']])) { /* Valor informado */ if ($cfield['field_type'] == 'select' || $cfield['field_type'] == 'select_multi') { $treatedPostField = array_map('noHtml', $post[$cfield['field_name']]); $fieldIN = []; foreach ($treatedPostField as $fieldValue) { $fieldIN[] = getCustomFieldValue($conn, $fieldValue); /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['IN'][] = $fieldValue; } } else { /* Ver tratamento para cada tipo de campo - Datas não entram nesse laço */ $fieldIN = noHtml($post[$cfield['field_name']]); /* id - operador - valor de comparacao */ // $customTerms[$cfield['id']]['=='][] = $fieldIN; /* Operador de comparação direta '===' */ $customTerms[$cfield['id']]['==='][] = $fieldIN; } $criterText = (is_array($fieldIN) ? implode(", ", $fieldIN) : $fieldIN); $criterText = $cfield['field_label'] . ": " . $criterText ."
"; $criteria[] = "{$criterText}"; } elseif (isset($post[$minDatePrefix . $cfield['field_name']]) && !empty($post[$minDatePrefix . $cfield['field_name']])) { /* Se tiver data mínima selecionada - Campos do tipo date ou datetime' */ $criterText = noHtml($post[$minDatePrefix . $cfield['field_name']]); $criterText = $cfield['field_label'] . " (" . TRANS('MIN_DATE') . "): " . $criterText ."
"; $criterText2 = ""; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['<='][] = noHtml($post[$minDatePrefix . $cfield['field_name']]); /* Tem data final? */ if (isset($post[$maxDatePrefix . $cfield['field_name']]) && !empty($post[$maxDatePrefix . $cfield['field_name']])) { $criterText2 = noHtml($post[$maxDatePrefix . $cfield['field_name']]); $criterText2 = $cfield['field_label'] . " (" . TRANS('MAX_DATE') . "): " . $criterText2 ."
"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['>='][] = noHtml($post[$maxDatePrefix . $cfield['field_name']]); } $criteria[] = "{$criterText}"; $criteria[] = "{$criterText2}"; } elseif (isset($post[$maxDatePrefix . $cfield['field_name']]) && !empty($post[$maxDatePrefix . $cfield['field_name']])) { /* Se tiver data máxima selecionada mas não tiver data mínima */ $criterText = noHtml($post[$maxDatePrefix . $cfield['field_name']]); $criterText = $cfield['field_label'] . " (" . TRANS('MAX_DATE') . "): " . $criterText ."
"; $criterText2 = ""; $criteria[] = "{$criterText}"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['>='][] = noHtml($post[$maxDatePrefix . $cfield['field_name']]); } elseif (isset($post[$minNumberPrefix . $cfield['field_name']]) && !empty($post[$minNumberPrefix . $cfield['field_name']])) { /* Se tiver data mínima selecionada - Campos do tipo date ou datetime' */ $criterText = noHtml($post[$minNumberPrefix . $cfield['field_name']]); $criterText = $cfield['field_label'] . " (" . TRANS('MIN_VALUE') . "): " . $criterText ."
"; $criterText2 = ""; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['<='][] = noHtml($post[$minNumberPrefix . $cfield['field_name']]); /* Tem limite final? */ if (isset($post[$maxNumberPrefix . $cfield['field_name']]) && !empty($post[$maxNumberPrefix . $cfield['field_name']])) { $criterText2 = noHtml($post[$maxNumberPrefix . $cfield['field_name']]); $criterText2 = $cfield['field_label'] . " (" . TRANS('MAX_VALUE') . "): " . $criterText2 ."
"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['>='][] = noHtml($post[$maxNumberPrefix . $cfield['field_name']]); } $criteria[] = "{$criterText}"; $criteria[] = "{$criterText2}"; } elseif (isset($post[$maxNumberPrefix . $cfield['field_name']]) && !empty($post[$maxNumberPrefix . $cfield['field_name']])) { /* Se tiver data máxima selecionada mas não tiver data mínima */ $criterText = noHtml($post[$maxNumberPrefix . $cfield['field_name']]); $criterText = $cfield['field_label'] . " (" . TRANS('MAX_VALUE') . "): " . $criterText ."
"; $criterText2 = ""; $criteria[] = "{$criterText}"; /* id - operador - valor de comparacao */ $customTerms[$cfield['id']]['>='][] = noHtml($post[$maxNumberPrefix . $cfield['field_name']]); } } /* Final da montagem dos critérios sobre os campos personalizados preenchidos */ if (empty($criteria)) { $criterText = TRANS('SMART_WITHOUT_SEARCH_CRITERIA') . "
"; $criteria[] = "{$criterText}"; } $criterios = ""; ?>
fetchAll() as $row){ $nestedData = array(); $showRecord = true; if ($showRecord) { /* Usuários dos ativos */ if (isset($post['no_empty_asset_user']) && !empty($post['no_empty_asset_user'])) { $showRecord = getUserFromAssetId($conn, $row['comp_cod']); } if (isset($post['no_asset_user']) && !empty($post['no_asset_user'])) { $showRecord = !getUserFromAssetId($conn, $row['comp_cod']); } if (isset($post['asset_user']) && !empty($post['asset_user'])) { $showRecord = false; $treatedPostField = array_map('intval', $post['asset_user']); $possibleAssets = getAssetsFromArrayOfUsers($conn, $treatedPostField); if (in_array($row['comp_cod'], $possibleAssets)) { $showRecord = true; } } } $userInfo = []; $allocated_to_user_id = getUserFromAssetId($conn, $row['comp_cod']); if (!empty($allocated_to_user_id)) { $userInfo = getUserById($conn, $allocated_to_user_id['user_id']); } $allocated_to = (!empty($userInfo) ? $userInfo['nome'] : '-'); /* Retona array com as especificações físicas agregadas ao ativo */ $aggregated_specs = getAssetSpecs($conn, $row['comp_cod']); /* Retona array com as especificações físicas agregadas ao ativo */ $hard_aggregated_specs = getAssetSpecs($conn, $row['comp_cod'], null, false); /* Retona array com as especificações de software agregadas ao ativo */ $soft_aggregated_specs = getAssetSpecs($conn, $row['comp_cod'], null, true); /* Atributos diretos do modelo do ativo */ if ($showRecord) { if (!empty($post['measure_type'])) { $i = 0; foreach ($post['measure_type'] as $measure) { if (!empty($post['measure_value'][$i]) && !empty($post['operation'][$i]) && !empty($post['measure_unit'][$i])) { if (!in_array($post['operation'][$i], $possibleOperations)) { $errorFieldMessage = TRANS('MSG_INVALID_OPERATION'); echo message('warning', '', $errorFieldMessage, '', '' , 1); exit; } if (!modelHasAttribute($conn, $row['modelo_cod'], noHtml($post['measure_unit'][$i]), $post['operation'][$i], $post['measure_value'][$i])) { $showRecord = false; break; } } $i++; } } } /* Atributos agregados ao ativo */ if ($showRecord) { if (!empty($post['asset_type_aggregated'])) { $matchesSpecs = []; $matchesNotEmpty = []; $matchesEmpty = []; /* Inicializo false, se atender a algum critério volta a ser true */ $showRecord = false; $countCriteria = 0; $i = 0; foreach ($post['asset_type_aggregated'] as $type_aggregated) { if (!empty($post['asset_type_aggregated'][$i]) && !empty($post['measure_type_aggregated'][$i]) && !empty($post['measure_value_aggregated'][$i]) && !empty($post['measure_unit_aggregated'][$i])) { $countCriteria++; foreach ($aggregated_specs as $asset_spec) { if ($post['asset_type_aggregated'][$i] == $asset_spec['marc_tipo'] && modelHasAttribute($conn, $asset_spec['marc_cod'], $post['measure_unit_aggregated'][$i], $post['operation_aggregated'][$i], $post['measure_value_aggregated'][$i])) { // $matchesSpecs[$asset_spec['marc_tipo'].'-'.$post['measure_type_aggregated'][$i].'-'.$post['measure_unit_aggregated'][$i].'-'.$post['measure_value_aggregated'][$i]] = $post['measure_unit_aggregated'][$i]; $matchesSpecs[] = noHtml($post['measure_unit_aggregated'][$i]); break; } } } elseif (isset($post['no_empty_']) && count($post['no_empty_']) && array_key_exists($post['asset_type_aggregated'][$i], $post['no_empty_'])) { $countCriteria++; /* Pesquisa por 'qualquer' */ foreach ($aggregated_specs as $asset_spec) { if ($post['asset_type_aggregated'][$i] == $asset_spec['marc_tipo']) { $matchesNotEmpty[] = noHtml($asset_spec['marc_tipo']); break; } } } elseif (isset($post['no_']) && count($post['no_']) && array_key_exists($post['asset_type_aggregated'][$i], $post['no_'])) { /* Pesquisa por 'nenhum' */ $countCriteria++; $showRecord = true; foreach ($aggregated_specs as $asset_spec) { foreach ($post['no_'] as $none => $value) { if ($none == $asset_spec['marc_tipo'] && $none == $post['asset_type_aggregated'][$i]) { $showRecord = false; break; } } if (!$showRecord) { break; } } if ($showRecord) { $matchesEmpty[] = noHtml($post['asset_type_aggregated'][$i]); } } $i++; } if ((count($matchesSpecs) + count($matchesNotEmpty) + count($matchesEmpty) == $countCriteria) ) { $showRecord = true; } else { $showRecord = false; } // var_dump([ // 'Etiqueta do Ativo' => $row['etiqueta'], // 'countCriteria' => $countCriteria, // 'matchesSpecs' => $matchesSpecs, // 'matchesNotEmpty' => $matchesNotEmpty, // 'matchesEmpty' => $matchesEmpty // ]); } } /** * Processamento para consulta sobre os campos personalizados */ if ($showRecord && count($customTerms)) { foreach ($customTerms as $id => $op) { $isNumber = false; $isDate = false; $assetFieldValues = getAssetCustomFields($conn, $row['comp_cod'], $id); if ($assetFieldValues['field_type'] == 'date') { /* campo de data */ $isDate = true; } elseif ($assetFieldValues['field_type'] == 'number') { /* campo numérico */ $isNumber = true; } $ticketFieldValue = $assetFieldValues['field_value_idx']; foreach ($op as $operation => $values) { if ($showRecord) { $foundOne = false; foreach ($values as $value) { if ($operation == "!=" && $showRecord) { /* não vazio */ $showRecord = (!empty($ticketFieldValue)); } elseif ($operation == "==" && $showRecord) { /* vazio */ $showRecord = (empty($ticketFieldValue)); } elseif ($operation == "===" && $showRecord) { /* Campos de comparação direta do valor - Tipo texto*/ $showRecord = ($ticketFieldValue == $value); } elseif ($operation == "IN") { /* valor do post */ $expMultiValues = (!empty($ticketFieldValue) ? explode(',', (string)$ticketFieldValue) : []); foreach ($expMultiValues as $SepValue) { if ($SepValue == $value) { $foundOne = true; } } $showRecord = $foundOne; } elseif ($operation == "<=" && $showRecord) { /* A data pesquisada tem que ser menor ou igual à data gravada */ if ($isNumber) { if (!empty($ticketFieldValue)) { $baseValue = ""; if (filter_var($value, FILTER_VALIDATE_INT)) { $baseValue = $value; } else { $showRecord = false; } if (!($baseValue <= $ticketFieldValue)) { $showRecord = false; } } else { $showRecord = false; } } elseif ($isDate) { if (!empty($ticketFieldValue)) { $baseDate = ""; if (isValidDate($value, "d/m/Y")) { $baseDate = dateDB($value); } else { $showRecord = false; } if (!(strtotime($baseDate) <= strtotime($ticketFieldValue))) { $showRecord = false; } } else { $showRecord = false; } } else { /* datetime */ if (!empty($ticketFieldValue)) { $baseDate = ""; if (isValidDate($value, "d/m/Y H:i")) { $baseDate = dateDB($value); } else { $showRecord = false; } if (!(strtotime($baseDate) <= strtotime($ticketFieldValue))) { $showRecord = false; } } else { $showRecord = false; } } } elseif ($operation == ">=" && $showRecord) { if ($isNumber) { if (!empty($ticketFieldValue)) { $baseValue = ""; if (filter_var($value, FILTER_VALIDATE_INT)) { $baseValue = $value; } else { $showRecord = false; } if (!($baseValue >= $ticketFieldValue)) { $showRecord = false; } } else { $showRecord = false; } } /* A data pesquisada tem que ser maior ou igual à data gravada */ elseif ($isDate) { if (!empty($ticketFieldValue)) { $baseDate = ""; if (isValidDate($value, "d/m/Y")) { $baseDate = dateDB($value . " 23:59:59"); } else { $showRecord = false; } if (!(strtotime($baseDate) >= strtotime($ticketFieldValue))) { $showRecord = false; } } else { $showRecord = false; } } else { /* Datetime */ if (!empty($ticketFieldValue)) { $baseDate = ""; if (isValidDate($value, "d/m/Y H:i")) { $baseDate = dateDB($value); } else { $showRecord = false; } if (!(strtotime($baseDate) >= strtotime($ticketFieldValue))) { $showRecord = false; } } else { $showRecord = false; } } } } } } } } /** Final do processamento sobre consulta por campos personalizados */ if ($showRecord) { $cost_center = ""; if (!empty($row['ccusto'])) { $ccusto_array = getCostCenters($conn, $row['ccusto']); $cost_center = (!empty($ccusto_array) ? $ccusto_array['ccusto_name'] . " - " . $ccusto_array['ccusto_cod'] : ""); } /* Atributos diretos */ $modelDetails = getModelSpecs($conn, $row['modelo_cod']); $directAttributes = ''; foreach ($modelDetails as $detail) { $directAttributes .= '
  • ' . $detail['mt_name'] . ': ' . $detail['spec_value'] . '' . $detail['unit_abbrev'] . '
  • '; } /* Atributos agregados */ $aggregatedAttributes = ''; if (!empty($hard_aggregated_specs)) { foreach ($hard_aggregated_specs as $spec) { $aggregatedAttributes .= '
  • ' . $spec['tipo_nome'] . ': ' . $spec['marc_nome'] . '
  • '; } } /* Atributos de software agregados */ $softAggregatedAttributes = ''; if (!empty($soft_aggregated_specs)) { foreach ($soft_aggregated_specs as $spec) { $softAggregatedAttributes .= '
  • ' . $spec['tipo_nome'] . ': ' . $spec['marc_nome'] . '
  • '; } } $mbArray = getPeripheralInfo($conn, $row['tipo_mb']); $procArray = getPeripheralInfo($conn, $row['tipo_proc']); $memoArray = getPeripheralInfo($conn, $row['tipo_memo']); $hddArray = getPeripheralInfo($conn, $row['tipo_hd']); $networkArray = getPeripheralInfo($conn, $row['tipo_rede']); $modemArray = getPeripheralInfo($conn, $row['tipo_modem']); $videoArray = getPeripheralInfo($conn, $row['tipo_video']); $soundArray = getPeripheralInfo($conn, $row['tipo_som']); $cdromArray = getPeripheralInfo($conn, $row['tipo_cdrom']); $dvdromArray = getPeripheralInfo($conn, $row['tipo_dvd']); $recorderArray = getPeripheralInfo($conn, $row['tipo_grav']); $motherboard = $mbArray['mdit_fabricante']. " " . $mbArray['mdit_desc'] . " " . $mbArray['mdit_desc_capacidade'] . " " . $mbArray['mdit_sufixo']; $processor = $procArray['mdit_fabricante']. " " . $procArray['mdit_desc'] . " " . $procArray['mdit_desc_capacidade'] . " " . $procArray['mdit_sufixo']; $memory = $memoArray['mdit_fabricante']. " " . $memoArray['mdit_desc'] . " " . $memoArray['mdit_desc_capacidade'] . " " . $memoArray['mdit_sufixo']; $hdd = $hddArray['mdit_fabricante']. " " . $hddArray['mdit_desc'] . " " . $hddArray['mdit_desc_capacidade'] . " " . $hddArray['mdit_sufixo']; $network = $networkArray['mdit_fabricante']. " " . $networkArray['mdit_desc'] . " " . $networkArray['mdit_desc_capacidade'] . " " . $networkArray['mdit_sufixo']; $modem = $modemArray['mdit_fabricante']. " " . $modemArray['mdit_desc'] . " " . $modemArray['mdit_desc_capacidade'] . " " . $modemArray['mdit_sufixo']; $video = $videoArray['mdit_fabricante']. " " . $videoArray['mdit_desc'] . " " . $videoArray['mdit_desc_capacidade'] . " " . $videoArray['mdit_sufixo']; $sound = $soundArray['mdit_fabricante']. " " . $soundArray['mdit_desc'] . " " . $soundArray['mdit_desc_capacidade'] . " " . $soundArray['mdit_sufixo']; $cdrom = $cdromArray['mdit_fabricante']. " " . $cdromArray['mdit_desc'] . " " . $cdromArray['mdit_desc_capacidade'] . " " . $cdromArray['mdit_sufixo']; $recorder = $recorderArray['mdit_fabricante']. " " . $recorderArray['mdit_desc'] . " " . $recorderArray['mdit_desc_capacidade'] . " " . $recorderArray['mdit_sufixo']; $dvdrom = $dvdromArray['mdit_fabricante']. " " . $dvdromArray['mdit_desc'] . " " . $dvdromArray['mdit_desc_capacidade'] . " " . $dvdromArray['mdit_sufixo']; $deprecatedAttributes = ''; if (!empty(trim($motherboard))) { $deprecatedAttributes .= '
  • ' . TRANS('MOTHERBOARD') . ' ' . $mbArray['mdit_fabricante'] . ' ' . $mbArray['mdit_desc'] . ' ' . $mbArray['mdit_desc_capacidade'] . ' ' . $mbArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($processor))) { $deprecatedAttributes .= '
  • ' . TRANS('PROCESSOR') . ' ' . $procArray['mdit_fabricante'] . ' ' . $procArray['mdit_desc'] . ' ' . $procArray['mdit_desc_capacidade'] . ' ' . $procArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($memory))) { $deprecatedAttributes .= '
  • ' . TRANS('CARD_MEMORY') . ' ' . $memoArray['mdit_fabricante'] . ' ' . $memoArray['mdit_desc'] . ' ' . $memoArray['mdit_desc_capacidade'] . ' ' . $memoArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($hdd))) { $deprecatedAttributes .= '
  • ' . TRANS('MNL_HD') . ' ' . $hddArray['mdit_fabricante'] . ' ' . $hddArray['mdit_desc'] . ' ' . $hddArray['mdit_desc_capacidade'] . ' ' . $hddArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($network))) { $deprecatedAttributes .= '
  • ' . TRANS('CARD_NETWORK') . ' ' . $networkArray['mdit_fabricante'] . ' ' . $networkArray['mdit_desc'] . ' ' . $networkArray['mdit_desc_capacidade'] . ' ' . $networkArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($modem))) { $deprecatedAttributes .= '
  • ' . TRANS('CARD_MODEN') . ' ' . $modemArray['mdit_fabricante'] . ' ' . $modemArray['mdit_desc'] . ' ' . $modemArray['mdit_desc_capacidade'] . ' ' . $modemArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($video))) { $deprecatedAttributes .= '
  • ' . TRANS('CARD_VIDEO') . ' ' . $videoArray['mdit_fabricante'] . ' ' . $videoArray['mdit_desc'] . ' ' . $videoArray['mdit_desc_capacidade'] . ' ' . $videoArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($sound))) { $deprecatedAttributes .= '
  • ' . TRANS('CARD_SOUND') . ' ' . $soundArray['mdit_fabricante'] . ' ' . $soundArray['mdit_desc'] . ' ' . $soundArray['mdit_desc_capacidade'] . ' ' . $soundArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($cdrom))) { $deprecatedAttributes .= '
  • ' . TRANS('FIELD_CDROM') . ' ' . $cdromArray['mdit_fabricante'] . ' ' . $cdromArray['mdit_desc'] . ' ' . $cdromArray['mdit_desc_capacidade'] . ' ' . $cdromArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($recorder))) { $deprecatedAttributes .= '
  • ' . TRANS('MNL_GRAV') . ' ' . $recorderArray['mdit_fabricante'] . ' ' . $recorderArray['mdit_desc'] . ' ' . $recorderArray['mdit_desc_capacidade'] . ' ' . $recorderArray['mdit_sufixo'] . '
  • '; } if (!empty(trim($dvdrom))) { $deprecatedAttributes .= '
  • ' . TRANS('DVD') . ' ' . $dvdromArray['mdit_fabricante'] . ' ' . $dvdromArray['mdit_desc'] . ' ' . $dvdromArray['mdit_desc_capacidade'] . ' ' . $dvdromArray['mdit_sufixo'] . '
  • '; } $category = (isset($row['categoria_cod']) && !empty($row['categoria_cod']) ? getAssetsCategories($conn, (int)$row['categoria_cod'])['cat_name'] : ''); /* Se for uma situação operacional marcada para destaque */ if ($row['situac_destaque'] == '1') { $classHighlight = 'destaque'; } else { $classHighlight = ''; } $result_ids[] = $row['comp_cod']; ?> (". TRANS('RESULT_LIMITED_BY_PERMISSIONS').")"; } ?>
    " . $row['etiqueta'] . ""; ?>
    :