Fixed sql error in statistics (oracle). Ticket #2690

This commit is contained in:
Arturo Gonzalez Diaz 2015-09-08 10:40:12 +02:00
parent ccd17545f3
commit bd432db9fd
1 changed files with 22 additions and 27 deletions

View File

@ -2814,7 +2814,7 @@ function events_get_count_events_validated ($filter, $period = null, $date = nul
global $config; global $config;
$sql_filter = ' AND 1=1 '; $sql_filter = " 1=1 ";
if (isset($filter['id_group'])) { if (isset($filter['id_group'])) {
$id_group = groups_safe_acl ($config["id_user"], $filter['id_group'], "AR"); $id_group = groups_safe_acl ($config["id_user"], $filter['id_group'], "AR");
@ -2824,32 +2824,32 @@ function events_get_count_events_validated ($filter, $period = null, $date = nul
} }
$sql_filter .= $sql_filter .=
sprintf(' AND id_grupo IN (%s) ', implode (",", $id_group)); sprintf(" AND id_grupo IN (%s) ", implode (",", $id_group));
} }
if (!empty($filter['id_agent'])) { if (!empty($filter['id_agent'])) {
$sql_filter .= $sql_filter .=
sprintf(' AND id_agente = %d ', $filter['id_agent']); sprintf(" AND id_agente = %d ", $filter['id_agent']);
} }
$date_filter = ''; $date_filter = '';
if (!empty($date) && !empty($period)) { if (!empty($date) && !empty($period)) {
$datelimit = $date - $period; $datelimit = $date - $period;
$date_filter .= sprintf (' AND utimestamp > %d AND utimestamp <= %d ', $date_filter .= sprintf (" AND utimestamp > %d AND utimestamp <= %d ",
$datelimit, $date); $datelimit, $date);
} }
else if (!empty($period)) { else if (!empty($period)) {
$date = time(); $date = time();
$datelimit = $date - $period; $datelimit = $date - $period;
$date_filter .= sprintf (' AND utimestamp > %d AND utimestamp <= %d ', $date_filter .= sprintf (" AND utimestamp > %d AND utimestamp <= %d ",
$datelimit, $date); $datelimit, $date);
} }
else if (!empty($date)) { else if (!empty($date)) {
$date_filter .= sprintf (' AND utimestamp <= %d ', $date); $date_filter .= sprintf (" AND utimestamp <= %d ", $date);
} }
$sql_where = ' AND 1=1 '; $sql_where = " AND 1=1 ";
$criticities = array(); $criticities = array();
if ($filter_event_critical) { if ($filter_event_critical) {
$criticities[] = 4; $criticities[] = 4;
@ -2858,27 +2858,22 @@ function events_get_count_events_validated ($filter, $period = null, $date = nul
$criticities[] = 3; $criticities[] = 3;
} }
if (!empty($criticities)) { if (!empty($criticities)) {
$sql_where .= ' AND criticity IN (' . implode(', ', $criticities) . ')'; $sql_where .= " AND criticity IN (" . implode(",", $criticities) . ")";
} }
if ($filter_event_validated) { if ($filter_event_validated) {
$sql_where .= ' AND estado = 1 '; $sql_where .= " AND estado = 1 ";
} }
if ($filter_event_no_validated) { if ($filter_event_no_validated) {
$sql_where .= ' AND estado = 0 '; $sql_where .= " AND estado = 0 ";
} }
if (!empty($filter_event_search)) { if (!empty($filter_event_search)) {
$sql_where .= ' AND (evento LIKE "%%'. io_safe_input($filter_event_search) . '%%"'. $sql_where .= " AND (evento LIKE '%%" . io_safe_input($filter_event_search) . "%%'" .
' OR id_evento LIKE "%%' . io_safe_input($filter_event_search) . '%%")'; " OR id_evento LIKE '%%" . io_safe_input($filter_event_search) . "%%')";
} }
$sql = sprintf ('SELECT estado, $sql = sprintf ("SELECT estado, COUNT(*) AS count FROM tevento WHERE %s " . $sql_where . " GROUP BY estado", $sql_filter);
COUNT(*) AS count
FROM tevento WHERE
%s ' . $sql_where . '
GROUP BY estado',
$sql_filter);
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);