Fixed the search to be compatible with oracle databases

This commit is contained in:
Alejandro Gallardo Escobar 2015-05-20 17:00:18 +02:00
parent 143243636c
commit 6c715cf483
6 changed files with 130 additions and 73 deletions

View File

@ -179,8 +179,7 @@ if ($searchAgents) {
break;
}
$select =
"SELECT t1.id_agente, t1.ultimo_contacto, t1.nombre, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled";
$select = "SELECT t1.id_agente, t1.ultimo_contacto, t1.nombre, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled";
if ($only_count) {
$limit = " ORDER BY " . $order['field'] . " " . $order['order'] .
" LIMIT " . $config["block_size"] . " OFFSET 0";
@ -190,7 +189,26 @@ if ($searchAgents) {
" LIMIT " . $config['block_size'] . " OFFSET " . get_parameter('offset',0);
}
$query = $select . $sql . $limit;
$query = $select . $sql;
switch ($config["dbtype"]) {
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);
if (empty($agents))

View File

@ -18,6 +18,7 @@ global $config;
include_once('include/functions_custom_graphs.php');
//Check ACL
$searchGraphs = check_acl($config["id_user"], 0, "IR");
$graphs = false;
@ -25,33 +26,24 @@ $graphs = false;
if ($searchGraphs) {
//Check ACL
$usergraphs = custom_graphs_get_user($config['id_user'], true);
$usergraphs_id = array_keys($usergraphs);
if (!$usergraphs_id) {
$graphs_condition = " AND 1<>1";
}
else {
$graphs_condition = " AND id_graph IN (".implode(',',$usergraphs_id).")";
}
if (empty($usergraphs_id))
return;
$fromwhere = "FROM tgraph
WHERE (name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%')".$graphs_condition;
$limitoffset = "LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
$filter = array();
$filter[] = "(name LIKE '%$stringSearchSQL%' OR description LIKE '%$stringSearchSQL%')";
$filter['id_graph'] = $usergraphs_id;
$sql_count = "SELECT COUNT(id_graph) AS count $fromwhere";
$columns = array('id_graph', 'name', 'description');
$count_columns = array('COUNT(id_graph) AS count');
if ($only_count) {
$totalGraphs = db_get_value_sql($sql_count);
}
else {
$sql = "SELECT id_graph, name, description $fromwhere $limitoffset";
$graphs = db_process_sql($sql);
if($graphs !== false) {
$totalGraphs = db_get_value_sql($sql_count);
}
$totalGraphs = db_get_value_filter('tgraph', $filter, $count_columns);
if (! $only_count && (int)$totalGraphs > 0) {
$filter['limit'] = $config['block_size'];
$filter['offset'] = (int) get_parameter('offset');
$graphs = db_get_all_rows_filter('tgraph', $filter, $columns);
}
}
?>

View File

@ -19,41 +19,46 @@ global $config;
$searchMaps = check_acl($config["id_user"], 0, "IR");
$maps = false;
$totalMaps = 0;
if ($searchMaps) {
$sql = "SELECT t1.id, t1.name, t1.id_group,
(SELECT COUNT(*) FROM tlayout_data t2 WHERE t2.id_layout = t1.id) AS count
FROM tlayout t1 WHERE t1.name LIKE '%" . $stringSearchSQL . "%'
LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
$user_groups = users_get_groups($config['id_user'], 'AR', false);
$id_user_groups = array_keys($user_groups);
$id_user_groups_str = implode(',', $id_user_groups);
if (empty($id_user_groups))
return;
$sql = "SELECT tl.id, tl.name, tl.id_group, COUNT(tld.id_layout) AS count
FROM tlayout tl
LEFT JOIN tlayout_data tld
ON tl.id = tld.id_layout
WHERE tl.name LIKE '%$stringSearchSQL%'
AND tl.id_group IN ($id_user_groups_str)
GROUP BY tl.id, tl.name, tl.id_group";
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql .= " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
break;
case "oracle":
$set = array();
$set['limit'] = $config['block_size'];
$set['offset'] = (int) get_parameter('offset');
$sql = oracle_recode_query ($sql, $set);
break;
}
$maps = db_process_sql($sql);
if($maps !== false) {
$maps_id = array();
foreach($maps as $key => $map) {
if (!check_acl ($config["id_user"], $map["id_group"], "AR")) {
unset($maps[$key]);
}
else {
$maps_id[] = $map['id'];
}
}
if ($maps !== false) {
$totalMaps = count($maps);
if(!$maps_id) {
$maps_condition = "";
}
else {
// Condition with the visible agents
$maps_condition = " AND id IN (\"".implode('","',$maps_id)."\")";
}
$sql = "SELECT COUNT(id) AS count FROM tlayout WHERE name LIKE '%" . $stringSearchSQL . "%'".$maps_condition;
$totalMaps = db_get_value_sql($sql);
if($only_count) {
if ($only_count) {
unset($maps);
}
}
else {
$totalMaps = 0;
}
}
?>

View File

@ -119,8 +119,8 @@ if ($searchModules) {
)
)
AND
t1.nombre COLLATE utf8_general_ci LIKE "%' . $stringSearchSQL . '%" OR
t3.nombre LIKE "%' . $stringSearchSQL . '%"';
(t1.nombre COLLATE utf8_general_ci LIKE "%' . $stringSearchSQL . '%" OR
t3.nombre LIKE "%' . $stringSearchSQL . '%")';
break;
case "postgresql":
$chunk_sql = '
@ -147,8 +147,8 @@ if ($searchModules) {
)
)
) AND
t1.nombre LIKE \'%' . $stringSearchSQL . '%\' OR
t3.nombre LIKE \'%' . $stringSearchSQL . '%\'';
(t1.nombre LIKE \'%' . $stringSearchSQL . '%\' OR
t3.nombre LIKE \'%' . $stringSearchSQL . '%\')';
break;
case "oracle":
$chunk_sql = '
@ -164,7 +164,7 @@ if ($searchModules) {
AND
' . $subquery_enterprise . ' (t2.id_grupo IN (' . implode(',', $id_userGroups) . ')
(t2.id_grupo IN (' . implode(',', $id_userGroups) . ')
OR 0 IN (
SELECT id_grupo
FROM tusuario_perfil
@ -175,21 +175,35 @@ if ($searchModules) {
)
)
) AND
UPPER(t1.nombre) LIKE UPPER(\'%' . $stringSearchSQL . '%\') OR
t3.nombre LIKE \'%' . $stringSearchSQL . '%\'';
(UPPER(t1.nombre) LIKE UPPER(\'%' . $stringSearchSQL . '%\') OR
t3.nombre LIKE \'%' . $stringSearchSQL . '%\')';
break;
}
$totalModules = db_get_value_sql("
SELECT COUNT(t1.id_agente_modulo) AS count_modules " .
$chunk_sql);
$totalModules = db_get_value_sql("SELECT COUNT(t1.id_agente_modulo) AS count_modules " . $chunk_sql);
if (!$only_count) {
$select = "SELECT *, t1.nombre AS module_name, t2.nombre AS agent_name ";
$limit = " ORDER BY " . $order['field'] . " " . $order['order'] .
" LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
$select = "SELECT t1.*, t1.nombre AS module_name, t2.nombre AS agent_name ";
$order_by = " ORDER BY " . $order['field'] . " " . $order['order'];
$limit = " LIMIT " . $config['block_size'] . " OFFSET " . (int) get_parameter ('offset');
$modules = db_get_all_rows_sql($select . $chunk_sql . $limit);
$query = $select . $chunk_sql . $order_by;
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$query .= $limit;
break;
case "oracle":
$set = array();
$set['limit'] = $config['block_size'];
$set['offset'] = (int) get_parameter('offset');
$query = oracle_recode_query ($query, $set);
break;
}
$modules = db_get_all_rows_sql($query);
}
}
?>

View File

@ -47,12 +47,26 @@ $reports = false;
if($searchReports) {
$sql = "SELECT id_report, name, description
FROM treport
WHERE (name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%')".$reports_condition.
" LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
WHERE (name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%')".$reports_condition;
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql .= " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
break;
case "oracle":
$set = array();
$set['limit'] = $config['block_size'];
$set['offset'] = (int) get_parameter('offset');
$sql = oracle_recode_query ($sql, $set);
break;
}
$sql_count = "SELECT COUNT(id_report) AS count
FROM treport
WHERE (name LIKE '%" . $stringSearchSQL . "%' OR description LIKE '%" . $stringSearchSQL . "%')".$reports_condition;
if($only_count) {
$totalReports = db_get_value_sql($sql_count);
}

View File

@ -130,8 +130,22 @@ if ($searchUsers) {
lastname LIKE '%" . $stringSearchSQL . "%' OR
middlename LIKE '%" . $stringSearchSQL . "%' OR
email LIKE '%" . $stringSearchSQL . "%'
ORDER BY " . $order['field'] . " " . $order['order'] . "
LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
ORDER BY " . $order['field'] . " " . $order['order'];
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql .= " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
break;
case "oracle":
$set = array();
$set['limit'] = $config['block_size'];
$set['offset'] = (int) get_parameter('offset');
$sql = oracle_recode_query ($sql, $set);
break;
}
$users = db_process_sql($sql);
if ($users !== false) {