Fixed problems with search data in general search. Gitlab: #508
This commit is contained in:
parent
7605de5794
commit
ed83c756e2
|
@ -115,113 +115,57 @@ if ($searchAgents) {
|
||||||
$userGroups = users_get_groups($config['id_user'], 'AR', false);
|
$userGroups = users_get_groups($config['id_user'], 'AR', false);
|
||||||
$id_userGroups = array_keys($userGroups);
|
$id_userGroups = array_keys($userGroups);
|
||||||
|
|
||||||
switch ($config["dbtype"]) {
|
$sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
|
||||||
case "mysql":
|
|
||||||
$sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
|
|
||||||
INNER JOIN taddress_agent ON
|
INNER JOIN taddress_agent ON
|
||||||
taddress.id_a = taddress_agent.id_a
|
taddress.id_a = taddress_agent.id_a
|
||||||
WHERE taddress.ip LIKE '%$stringSearchSQL%'";
|
WHERE taddress.ip LIKE '%$stringSearchSQL%'";
|
||||||
|
|
||||||
$id = db_get_all_rows_sql($sql);
|
$id = db_get_all_rows_sql($sql);
|
||||||
if($id != ''){
|
if ($id != '') {
|
||||||
$aux = $id[0]['id_agent'];
|
$aux = $id[0]['id_agent'];
|
||||||
$search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
$search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%cd " . $stringSearchSQL . "%%' OR
|
||||||
t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
||||||
t1.id_agente = $aux";
|
t1.id_agente = $aux";
|
||||||
|
|
||||||
if(count($id)>=2){
|
if (count($id) >= 2) {
|
||||||
for ($i = 1; $i < count($id); $i++){
|
for ($i = 1; $i < count($id); $i++) {
|
||||||
$aux = $id[$i]['id_agent'];
|
$aux = $id[$i]['id_agent'];
|
||||||
$search_sql .= " OR t1.id_agente = $aux";
|
$search_sql .= " OR t1.id_agente = $aux";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
$search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
|
||||||
t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
|
||||||
t1.direccion COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
|
||||||
t1.alias COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%'";
|
|
||||||
}
|
}
|
||||||
$sql = "
|
|
||||||
FROM tagente t1
|
|
||||||
INNER JOIN tgrupo t2
|
|
||||||
ON t2.id_grupo = t1.id_grupo
|
|
||||||
WHERE (
|
|
||||||
1 = (
|
|
||||||
SELECT is_admin
|
|
||||||
FROM tusuario
|
|
||||||
WHERE id_user = '" . $config['id_user'] . "'
|
|
||||||
)
|
|
||||||
OR t1.id_grupo IN (
|
|
||||||
" . implode(',', $id_userGroups) . "
|
|
||||||
) OR 0 IN (
|
|
||||||
SELECT id_grupo
|
|
||||||
FROM tusuario_perfil
|
|
||||||
WHERE id_usuario = '" . $config['id_user'] . "'
|
|
||||||
AND id_perfil IN (
|
|
||||||
SELECT id_perfil
|
|
||||||
FROM tperfil WHERE agent_view = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
AND (
|
|
||||||
".$search_sql."
|
|
||||||
)
|
|
||||||
";
|
|
||||||
break;
|
|
||||||
case "postgresql":
|
|
||||||
case "oracle":
|
|
||||||
$sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
|
|
||||||
INNER JOIN taddress_agent ON
|
|
||||||
taddress.id_a = taddress_agent.id_a
|
|
||||||
WHERE taddress.ip LIKE '%$stringSearchSQL%'";
|
|
||||||
|
|
||||||
$id = db_get_all_rows_sql($sql);
|
|
||||||
if($id != ''){
|
|
||||||
$aux = $id[0]['id_agent'];
|
|
||||||
$search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%" . strtolower($stringSearchSQL) . "%%' OR
|
|
||||||
t2.nombre COLLATE utf8_general_ci LIKE '%%" . strtolower($stringSearchSQL) . "%%' OR
|
|
||||||
t1.id_agente = $aux";
|
|
||||||
|
|
||||||
if(count($id)>=2){
|
|
||||||
for ($i = 1; $i < count($id); $i++){
|
|
||||||
$aux = $id[$i]['id_agent'];
|
|
||||||
$search_sql .= " OR t1.id_agente = $aux";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$search_sql = " lower(t1.nombre) LIKE '%%" . strtolower($stringSearchSQL) . "%%' OR
|
|
||||||
lower(t2.nombre) LIKE '%%" . strtolower($stringSearchSQL) . "%%' OR
|
|
||||||
lower(t1.direccion) LIKE '%%" . strtolower($stringSearchSQL) . "%%' OR
|
|
||||||
lower(t1.alias) LIKE '%%" . strtolower($stringSearchSQL) . "%%'";
|
|
||||||
}
|
|
||||||
$sql = "
|
|
||||||
FROM tagente t1
|
|
||||||
INNER JOIN tgrupo t2
|
|
||||||
ON t2.id_grupo = t1.id_grupo
|
|
||||||
WHERE (
|
|
||||||
1 = (
|
|
||||||
SELECT is_admin
|
|
||||||
FROM tusuario
|
|
||||||
WHERE id_user = '" . $config['id_user'] . "'
|
|
||||||
)
|
|
||||||
OR t1.id_grupo IN (
|
|
||||||
" . implode(',', $id_userGroups) . "
|
|
||||||
) OR 0 IN (
|
|
||||||
SELECT id_grupo
|
|
||||||
FROM tusuario_perfil
|
|
||||||
WHERE id_usuario = '" . $config['id_user'] . "'
|
|
||||||
AND id_perfil IN (
|
|
||||||
SELECT id_perfil
|
|
||||||
FROM tperfil WHERE agent_view = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
AND (
|
|
||||||
".$search_sql."
|
|
||||||
)
|
|
||||||
";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
||||||
|
t2.nombre COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
||||||
|
t1.direccion COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%' OR
|
||||||
|
t1.alias COLLATE utf8_general_ci LIKE '%%" . $stringSearchSQL . "%%'";
|
||||||
|
}
|
||||||
|
$sql = "
|
||||||
|
FROM tagente t1
|
||||||
|
INNER JOIN tgrupo t2
|
||||||
|
ON t2.id_grupo = t1.id_grupo
|
||||||
|
WHERE (
|
||||||
|
1 = (
|
||||||
|
SELECT is_admin
|
||||||
|
FROM tusuario
|
||||||
|
WHERE id_user = '" . $config['id_user'] . "'
|
||||||
|
)
|
||||||
|
OR t1.id_grupo IN (
|
||||||
|
" . implode(',', $id_userGroups) . "
|
||||||
|
) OR 0 IN (
|
||||||
|
SELECT id_grupo
|
||||||
|
FROM tusuario_perfil
|
||||||
|
WHERE id_usuario = '" . $config['id_user'] . "'
|
||||||
|
AND id_perfil IN (
|
||||||
|
SELECT id_perfil
|
||||||
|
FROM tperfil WHERE agent_view = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
AND (
|
||||||
|
".$search_sql."
|
||||||
|
)
|
||||||
|
";
|
||||||
|
|
||||||
$select = "SELECT t1.id_agente, t1.ultimo_contacto, t1.nombre, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled, t1.alias";
|
$select = "SELECT t1.id_agente, t1.ultimo_contacto, t1.nombre, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled, t1.alias";
|
||||||
if ($only_count) {
|
if ($only_count) {
|
||||||
|
@ -235,25 +179,8 @@ if ($searchAgents) {
|
||||||
|
|
||||||
$query = $select . $sql;
|
$query = $select . $sql;
|
||||||
|
|
||||||
switch ($config["dbtype"]) {
|
$query .= $limit;
|
||||||
case "mysql":
|
|
||||||
case "postgresql":
|
|
||||||
$query .= $limit;
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
$set = array();
|
|
||||||
$set['limit'] = $config['block_size'];
|
|
||||||
|
|
||||||
if ($only_count)
|
|
||||||
$set['offset'] = 0;
|
|
||||||
else
|
|
||||||
$set['offset'] = (int) get_parameter('offset');
|
|
||||||
|
|
||||||
$query .= " ORDER BY " . $order['field'] . " " . $order['order'];
|
|
||||||
$query = oracle_recode_query ($query, $set);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agents = db_process_sql($query);
|
$agents = db_process_sql($query);
|
||||||
if (empty($agents))
|
if (empty($agents))
|
||||||
$agents = array();
|
$agents = array();
|
||||||
|
|
|
@ -34,6 +34,7 @@ foreach ($arrayKeywords as $keyword) {
|
||||||
array_push($temp, "%" . $keyword . "%");
|
array_push($temp, "%" . $keyword . "%");
|
||||||
}
|
}
|
||||||
$stringSearchSQL = implode(" ", $temp);
|
$stringSearchSQL = implode(" ", $temp);
|
||||||
|
$stringSearchSQL = str_replace('_', '\_', $stringSearchSQL);
|
||||||
|
|
||||||
if ($config['search_category'] == "all")
|
if ($config['search_category'] == "all")
|
||||||
$searchTab = "main";
|
$searchTab = "main";
|
||||||
|
|
Loading…
Reference in New Issue