top.window.location = '../../index.php'"; exit; } require_once __DIR__ . "/" . "../../includes/include_geral_new.inc.php"; require_once __DIR__ . "/" . "../../includes/classes/ConnectPDO.php"; use includes\classes\ConnectPDO; $conn = ConnectPDO::getInstance(); $auth = new AuthNew($_SESSION['s_logado'], $_SESSION['s_nivel'], 2, 1); $config = getConfig($conn); $status_done = $config['conf_status_done']; $closured_status = ($status_done <> 4 ? '4,' . $status_done : 4); $filter_areas = ""; if (isAreasIsolated($conn) && $_SESSION['s_nivel'] != 1) { /* Visibilidade isolada entre áreas para usuários não admin */ $u_areas = $_SESSION['s_uareas']; $filter_areas = " ar.sis_id IN ({$u_areas}) AND "; } $post = $_POST; $exception = ""; $data = []; $raw_data = []; $clean_data = []; $fulltext_search = true; $array_not_having = []; if (empty($post['problema']) || strlen(trim($post['problema'])) < 5 ) { echo message('warning','', TRANS('FILL_AT_LEAST_5_CHARS'), ''); exit; } $chars = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜüÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿRr'; $words = array_unique(str_word_count($post['problema'], 1, $chars)); /* Descarta palavras com menos de 5 caracteres */ $words = array_values( array_filter( $words, function ($value) { return strlen((string)$value) >= 5; } ) ); $words_not_having = (isset($post['not_having']) && !empty($post['not_having'])? $post['not_having'] : ''); if (!empty($words_not_having)) { $array_not_having = array_unique(str_word_count($post['not_having'], 1, $chars)); } /* Descarta palavras com menos de 5 caracteres */ $array_not_having = array_values( array_filter( $array_not_having, function ($value) { return strlen((string)$value) >= 5; } ) ); /* Adiciona o prefixo para a pesquisa de exclusão: '-' */ $array_not_having = array_map(function ($value) { return '-' . $value; }, $array_not_having); $words_not_having = (!empty($array_not_having) ? implode(' ', $array_not_having) : ''); // var_dump([ // 'words' => $words, // 'array_not_having' => $array_not_having, // 'words_not_having' => $words_not_having // ]); exit; /* Ver se utilizarei na montagem do sql */ $html_words = array_map('htmlentities', $words); $highlight_words = implode("|", $words); // var_dump([ // 'words' => $words, // 'html_words' => $html_words, // ]); $data['start_date'] = (isset($post['data_inicial']) && !empty($post['data_inicial']) ? dateDB($post['data_inicial']) : ''); $data['end_date'] = (isset($post['data_final']) && !empty($post['data_final']) ? dateDB($post['data_final']) : ''); $data['search_in_comments'] = (isset($post['search_in_comments']) && $post['search_in_comments'] == 'on' ? 1 : 0); $data['search_in_progress_tickets'] = (isset($post['search_in_progress_tickets']) && $post['search_in_progress_tickets'] == 'on' ? 1 : 0); $data['any_word'] = (isset($post['anyword']) && $post['anyword'] == 'on' ? 1 : 0); $data['with_attachments'] = (isset($post['onlyImgs']) && $post['onlyImgs'] == 'on' ? 1 : 0); $data['operator'] = (isset($post['operador']) && $post['operador'] != '-1' ? $post['operador'] : ''); $words_operation = ($data['any_word'] ? ' OR ' : ' AND '); $with_attachments_from = ($data['with_attachments'] ? ', imagens i ' : ''); $with_attachments_where = ($data['with_attachments'] ? ' AND o.numero = i.img_oco ' : ''); $with_operator_where = ($data['operator'] ? ' AND u.user_id = '. $data['operator'] : ''); $date_from_sql = (!empty($data['start_date']) ? " o.data_fechamento >= '{$data['start_date']}' AND " : ''); $date_to_sql = (!empty($data['end_date']) ? " o.data_fechamento <= '{$data['end_date']}' AND " : ''); /** Se for buscar na base de assentmentos */ $words_entries_select = ' a.assentamento AS assentamento, '; $words_entries_from = ', assentamentos a '; $words_entries_where = 's.numero = a.ocorrencia AND '; $statusTerm = " o.status IN ({$closured_status}) AND "; if ($data['search_in_progress_tickets']) { $statusTerm = ""; } /** Pesquina nas tabelas ocorrencias e solucoes */ $words_search_sql = ""; /** Pesquina na tabela de assentamentos */ $words_entries_sql = ""; if (!$fulltext_search) { foreach ($words as $word) { if (strlen((string)$words_search_sql)) $words_search_sql .= $words_operation; $words_search_sql .= " ((o.descricao) LIKE ('%{$word}%') OR"; $words_search_sql .= " (s.problema) LIKE ('%{$word}%') OR"; $words_search_sql .= " (s.solucao) LIKE ('%{$word}%'))"; if (strlen((string)$words_entries_sql)) $words_entries_sql .= $words_operation; $words_entries_sql .= " (a.assentamento) LIKE ('%{$word}%')"; } $words_entries_sql = ' OR ' . $words_entries_sql; } else { if (!$data['any_word']) { $words = array_map(function ($value) { return '+' . $value; }, $words); } $words_in_terms = implode(' ', $words) . ' ' . $words_not_having; $words_search_sql = "MATCH (o.descricao) AGAINST ('{$words_in_terms}' IN BOOLEAN MODE) OR "; $words_search_sql .= "MATCH (s.problema, s.solucao) AGAINST ('{$words_in_terms}' IN BOOLEAN MODE)"; if ($data['search_in_comments']) { $words_search_sql .= " OR MATCH (a.assentamento) AGAINST ('{$words_in_terms}' IN BOOLEAN MODE)"; } } if (!$data['search_in_comments']) { $words_entries_select = ''; $words_entries_from = ''; $words_entries_where = ''; $words_entries_sql = ''; } if ($data['search_in_progress_tickets']) { $sqlBase = "SELECT o.numero AS numero, o.descricao AS descricao, COALESCE(s.problema, '-') AS problema, -- s.problema AS problema, COALESCE(s.solucao, '-') AS solucao, -- s.solucao AS solucao, s.data AS data_fechamento, u.nome AS responsavel, {$words_entries_select} ar.sistema AS area FROM ocorrencias o LEFT JOIN solucoes s ON o.numero = s.numero, sistemas ar, usuarios u {$with_attachments_from} {$words_entries_from} WHERE {$date_from_sql} {$date_to_sql} o.sistema = ar.sis_id AND {$filter_areas} {$words_entries_where} -- s.responsavel = u.user_id u.user_id = o.operador {$with_operator_where} {$with_attachments_where} AND ( {$words_search_sql} {$words_entries_sql} ) ORDER BY o.numero LIMIT 1000 "; } else { $sqlBase = "SELECT o.numero AS numero, o.descricao AS descricao, s.problema AS problema, s.solucao AS solucao, s.data AS data_fechamento, u.nome AS responsavel, {$words_entries_select} ar.sistema AS area FROM ocorrencias o, sistemas ar, solucoes s, usuarios u {$with_attachments_from} {$words_entries_from} WHERE {$date_from_sql} {$date_to_sql} o.status IN ({$closured_status}) AND o.sistema = ar.sis_id AND {$filter_areas} o.numero = s.numero AND {$words_entries_where} s.responsavel = u.user_id {$with_operator_where} {$with_attachments_where} AND ( {$words_search_sql} ) ORDER BY o.numero LIMIT 1000 "; } try { $res = $conn->query($sqlBase); foreach ($res->fetchAll() as $row) { $raw_data[] = $row; } } catch (Exception $e) { $exception .= "
| = TRANS('NUMBER_ABBREVIATE'); ?> | = TRANS('AREA'); ?> | = TRANS('DESCRIPTION'); ?> | = TRANS('TXT_DESC_TEC_PROB'); ?> | = TRANS('SOLUTION'); ?> | = TRANS('OCO_RESP'); ?> | = TRANS('DONE_DATE'); ?> |
|---|---|---|---|---|---|---|
| = "" . $row['numero'] . ""; ?> | = $row['area']; ?> | = destaca($highlight_words, $row['descricao']); ?> | = destaca($highlight_words, $row['problema']); ?> | = destaca($highlight_words, $row['solucao']); ?> | = $row['responsavel']; ?> | = dateScreen($row['data_fechamento']); ?> |