Fixed the alert info retrieving for oracle databases

This commit is contained in:
Alejandro Gallardo Escobar 2015-06-16 17:53:30 +02:00
parent 1905c8a038
commit 3e2391a7c3
1 changed files with 29 additions and 21 deletions

View File

@ -662,30 +662,38 @@ function alerts_get_alert_templates ($filter = false, $fields = false) {
function alerts_get_alert_template ($id_alert_template) { function alerts_get_alert_template ($id_alert_template) {
global $config; global $config;
$alert_templates = false;
$id_alert_template = safe_int ($id_alert_template, 1); $id_alert_template = safe_int ($id_alert_template, 1);
if (empty ($id_alert_template))
return false;
if (!empty ($id_alert_template)) {
switch ($config['dbtype']) { switch ($config['dbtype']) {
case "mysql": case "mysql":
case "postgresql": case "postgresql":
return db_get_row ('talert_templates', 'id', $id_alert_template); $alert_templates = db_get_row ('talert_templates', 'id', $id_alert_template);
break; break;
case "oracle": case "oracle":
$fields_select = db_get_all_rows_sql('SELECT column_name $sql = "SELECT column_name
FROM user_tab_columns FROM user_tab_columns
WHERE table_name = \'TALERT_TEMPLATES\' WHERE table_name = 'TALERT_TEMPLATES'
AND column_name NOT IN (\'TIME_FROM\',\'TIME_TO\')'); AND column_name NOT IN ('TIME_FROM','TIME_TO')";
foreach ($fields_select as $field_select){ $fields_select = db_get_all_rows_sql($sql);
$select_field[] = $field_select['column_name'];
} $column_names = array_map(function($item) {
$select_stmt = implode(',', $select_field); return $item['column_name'];
return db_get_row_sql("SELECT $select_stmt, }, $fields_select);
$column_names_str = implode(',', $column_names);
$sql = "SELECT $column_names_str,
to_char(time_from, 'hh24:mi:ss') AS time_from, to_char(time_from, 'hh24:mi:ss') AS time_from,
to_char(time_to, 'hh24:mi:ss') AS time_to to_char(time_to, 'hh24:mi:ss') AS time_to
FROM talert_templates"); FROM talert_templates
WHERE id = $id_alert_template";
$alert_templates = db_get_row_sql($sql);
break; break;
} }
}
return $alert_templates;
} }
/** /**