diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b3f8d9600c..429ef7d973 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2010-04-27 Miguel de Dios + + * include/functions_reporting.php: added render html for "text" and "sql" + item. + + * include/ajax/reporting.ajax.php: added request for the custom SQL. + + * include/functions_db.php: in function "get_db_value_filter" fixed the + field when the field is escape string. + + * godmode/reporting/reporting_builder.item_editor.php: added the preview of + custom SQL. + 2010-04-27 Sergio Martin * godmode/servers/manage_recontask_form.php: Avoided diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index fcf5c8db75..ceb9ad7545 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -288,7 +288,11 @@ echo '
'; - + + + + + @@ -405,8 +409,37 @@ $(document).ready (function () { agent_module_autocomplete('#text-agent', '#hidden-id_agent', '#id_agent_module'); agent_module_autocomplete('#text-agent_sla', '#hidden-id_agent_sla', '#id_agent_module_sla'); chooseType(); + chooseSQLquery(); }); +function chooseSQLquery() { + var idCustom = $("#id_custom").val(); + + if (idCustom == 0) { + $("#sql_example").html(''); + } + else { + $("#sql_example").html(''); + + var params = []; + params.push("get_custom_sql=1"); + params.push("id=" + idCustom); + params.push("page=include/ajax/reporting.ajax"); + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action="ajax.php", + timeout: 10000, + dataType: 'json', + success: function (data) { + if (data['correct']) { + $("#sql_example").html(data['sql']); + } + } + }); + } +} + function deleteSLARow(id_row) { //ajax to delete var params = []; @@ -501,6 +534,7 @@ function chooseType() { $("#row_field_separator").css('display', 'none'); $("#row_line_separator").css('display', 'none'); $("#sla_list").css('display', 'none'); + $("#row_custom_example").css('display', 'none'); switch (type) { case 'simple_graph': @@ -569,6 +603,7 @@ function chooseType() { $("#row_query").css('display', ''); $("#row_header").css('display', ''); $("#row_custom").css('display', ''); + $("#row_custom_example").css('display', ''); break; case 'url': $("#row_description").css('display', ''); diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index f1940bcd66..dad62d75aa 100644 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -27,6 +27,7 @@ if (! give_acl ($config['id_user'], 0, "IW")) { } $delete_sla_item = get_parameter('delete_sla_item', 0); +$get_custom_sql = get_parameter('get_custom_sql', 0); $add_sla = get_parameter('add_sla', 0); $id = get_parameter('id', 0); @@ -66,4 +67,19 @@ if ($add_sla) { echo json_encode($data); return; } + +if ($get_custom_sql) { + $sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $id)); + + if ($result === false) { + $data['correct'] = 0; + } + else { + $data['correct'] = 1; + $data['sql'] = $sql; + } + + echo json_encode($data); + return; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 4365dcff44..b26879aa1b 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1677,7 +1677,9 @@ function get_db_value_filter ($field, $table, $filter, $where_join = 'AND') { if ($result === false) return false; - return $result[0][$field]; + $fieldClean = str_replace('`', '', $field); + + return $result[0][$fieldClean]; } /** diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 9b0492e142..94a09bd1ec 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1576,6 +1576,72 @@ function render_report_html_item ($content, $table, $report) { $data[0] = get_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $report["datetime"]); array_push ($table->data, $data); break; + case 'text': + $data = array(); + $data[0] = "

" . __('Text') . "

"; + array_push ($table->data, $data); + $table->colspan[0][0] = 2; + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[0][0] = 2; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + $data[0] = html_entity_decode($content['text']); + array_push($table->data, $data); + $table->colspan[2][0] = 2; + break; + case 'sql': + $data = array(); + $data[0] = "

" . __('SQL') . "

"; + array_push ($table->data, $data); + $table->colspan[0][0] = 2; + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[0][0] = 2; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $table2->class = 'databox'; + $table2->width = '100%'; + + //Create the head + $table2->head = array(); + if ($content['header_definition'] != '') { + $table2->head = explode('|', $content['header_definition']); + } + + if ($content['treport_custom_sql_id'] != 0) { + $sql = get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); + } + else { + $sql = $content['external_source']; + } + + $result = get_db_all_rows_sql($sql); + if ($result === false) { + $result = array(); + } + + if (isset($result[0])) { + if (count($result[0]) > count($table2->head)) { + $table2->head = array_pad($table2->head, count($result[0]), ' '); + } + } + + $table2->data = array(); + foreach ($result as $row) { + array_push($table2->data, $row); + } + + $cellContent = print_table($table2, true); + array_push($table->data, array($cellContent)); + break; } }