From 9bdd1af4884ca748048f7a2c64b35a516007cbf4 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 29 Nov 2018 13:24:12 +0100 Subject: [PATCH] fixed errors in visual console --- .../visual_console_builder.editor.js | 134 +++++------------- pandora_console/include/functions_graph.php | 7 +- .../include/functions_reporting.php | 5 +- .../include/functions_visual_map.php | 62 ++++---- pandora_console/include/graphs/fgraph.php | 24 +++- 5 files changed, 99 insertions(+), 133 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 055762abc8..d7cf3687e9 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -220,12 +220,11 @@ function update_button_palette_callback() { // TODO VALIDATE DATA switch (selectedItem) { case 'background': - if(values['width'] < 1024 || values['height'] < 768){ - alert('Min allowed size is 1024x768'); - return false; + alert('Min allowed size is 1024x768'); + return false; } - + if(values['width'] == 0 && values['height'] == 0) { values['width'] = $("#hidden-background_original_width").val(); @@ -235,7 +234,6 @@ function update_button_palette_callback() { $("#background").css('width', values['width']); $("#background").css('height', values['height']); - //$("#background").css('background', 'url(images/console/background/' + values['background'] + ')'); var image = values['background']; $("#background_img").attr('src', "images/spinner.gif"); set_image("background", null, image); @@ -243,7 +241,6 @@ function update_button_palette_callback() { idElement = 0; break; case 'box_item': - if($('input[name=width_box]').val() == ''){ alert('Undefined width'); return false; @@ -252,11 +249,11 @@ function update_button_palette_callback() { alert('Undefined height'); return false; } - + $("#" + idItem + " div").css('background-color', values['fill_color']); $("#" + idItem + " div").css('border-color', values['border_color']); $("#" + idItem + " div").css('border-width', values['border_width'] + "px"); - + if(values['height_box']==0 || values['width_box']==0){ $("#" + idItem + " div").css('width', "300px"); $("#" + idItem + " div").css('height', "180px"); @@ -271,54 +268,43 @@ function update_button_palette_callback() { alert('Undefined image'); return false; } - + $("#text_" + idItem).html(values['label']); - + if(values['show_statistics'] == 1){ - if (!$('#image_'+idItem).length) { - if(values['label_position'] == 'left'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:right;'); - } else if(values['label_position'] == 'right'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:left;'); - } else{ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png"); - } - - + $('#'+idItem).append($image); - } - + if ((values['width'] == 0) || (values['height'] == 0)) { - $("#image_" + idItem).removeAttr('width'); - $("#image_" + idItem).removeAttr('height'); - $("#image_" + idItem).attr('width', 520); - $("#image_" + idItem).attr('height', 80); - $("#image_" + idItem).css('width', '520px'); - $("#image_" + idItem).css('height', '80px'); - $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); - + $("#image_" + idItem).removeAttr('width'); + $("#image_" + idItem).removeAttr('height'); + $("#image_" + idItem).attr('width', 520); + $("#image_" + idItem).attr('height', 80); + $("#image_" + idItem).css('width', '520px'); + $("#image_" + idItem).css('height', '80px'); + $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); } else { $("#image_" + idItem).removeAttr('width'); @@ -328,49 +314,36 @@ function update_button_palette_callback() { $("#image_" + idItem).css('width', values['width'] + 'px'); $("#image_" + idItem).css('height', values['height'] + 'px'); $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); - } - + } } else{ - if ((values['width'] == 0) || (values['height'] == 0)) { - if(values['image'] != '' && values['image'] != 'none'){ - if (!$('#image_'+idItem).length) { - if(values['label_position'] == 'left'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:right;'); - } else if(values['label_position'] == 'right'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:left;'); - } else{ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png"); - } - - + $('#'+idItem).append($image); - } - + if($('#preview > img').prop('naturalWidth') == null || $('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){ $("#image_" + idItem).removeAttr('width'); $("#image_" + idItem).removeAttr('height'); @@ -382,15 +355,11 @@ function update_button_palette_callback() { else{ $("#image_" + idItem).removeAttr('width'); $("#image_" + idItem).removeAttr('height'); - $("#image_" + idItem).attr('width', $('#preview > img')[0].naturalHeight); $("#image_" + idItem).attr('height', $('#preview > img')[0].naturalHeight); $("#image_" + idItem).css('width', $('#preview > img')[0].naturalHeight+'px'); - $("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px'); - - + $("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px'); } - } else{ $("#image_" + idItem).removeAttr('width'); @@ -401,7 +370,6 @@ function update_button_palette_callback() { $("#image_" + idItem).css('height', '70px'); $("#image_" + idItem).remove(); } - } else { $("#image_" + idItem).removeAttr('width'); @@ -411,14 +379,9 @@ function update_button_palette_callback() { $("#image_" + idItem).css('width', values['width'] + 'px'); $("#image_" + idItem).css('height', values['height'] + 'px'); } - } - - - break; case 'static_graph': - if($('input[name=width]').val() == ''){ alert('Undefined width'); return false; @@ -433,10 +396,8 @@ function update_button_palette_callback() { } $("#text_" + idItem).html(values['label']); - + if(values['show_statistics'] == 1){ - - if ((values['width'] == 0) || (values['height'] == 0)) { $("#image_" + idItem).removeAttr('width'); $("#image_" + idItem).removeAttr('height'); @@ -445,7 +406,6 @@ function update_button_palette_callback() { $("#image_" + idItem).css('width', '520px'); $("#image_" + idItem).css('height', '80px'); $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); - } else { $("#image_" + idItem).removeAttr('width'); @@ -455,50 +415,35 @@ function update_button_palette_callback() { $("#image_" + idItem).css('width', values['width'] + 'px'); $("#image_" + idItem).css('height', values['height'] + 'px'); $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); - } - + } } else{ - if ((values['width'] == 0) || (values['height'] == 0)) { - if(values['image'] != '' && values['image'] != 'none'){ - if (!$('#image_'+idItem).length) { - if(values['label_position'] == 'left'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:right;'); - } else if(values['label_position'] == 'right'){ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png") .attr('style','float:left;'); - } else{ - var $image = $('') .attr('id', 'image_' + idItem) .attr('class', 'image') .attr('src', 'images/console/icons/'+values["image"]+".png"); - } - - $('#'+idItem).append($image); - } - - + if($('#preview > img').prop('naturalWidth') == null || $('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){ $("#image_" + idItem).removeAttr('width'); $("#image_" + idItem).removeAttr('height'); @@ -510,15 +455,11 @@ function update_button_palette_callback() { else{ $("#image_" + idItem).removeAttr('width'); $("#image_" + idItem).removeAttr('height'); - $("#image_" + idItem).attr('width', $('#preview > img')[0].naturalHeight); $("#image_" + idItem).attr('height', $('#preview > img')[0].naturalHeight); $("#image_" + idItem).css('width', $('#preview > img')[0].naturalHeight+'px'); - $("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px'); - - + $("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px'); } - } else{ $("#image_" + idItem).removeAttr('width'); @@ -529,7 +470,6 @@ function update_button_palette_callback() { $("#image_" + idItem).css('height', '70px'); $("#image_" + idItem).remove(); } - } else { $("#image_" + idItem).removeAttr('width'); @@ -539,9 +479,7 @@ function update_button_palette_callback() { $("#image_" + idItem).css('width', values['width'] + 'px'); $("#image_" + idItem).css('height', values['height'] + 'px'); } - } - break; case 'percentile_bar': case 'percentile_item': @@ -549,13 +487,15 @@ function update_button_palette_callback() { alert('Undefined width'); return false; } + if($('input[name=height_percentile]').val() == ''){ alert('Undefined height'); return false; } - + $("#text_" + idItem).html(values['label']); $("#image_" + idItem).attr("src", "images/spinner.gif"); + if (values['type_percentile'] == 'bubble') { setPercentileBubble(idItem, values); } @@ -568,7 +508,7 @@ function update_button_palette_callback() { else { setPercentileBar(idItem, values); } - + break; case 'module_graph': if($('#dir_items').html() == 'horizontal'){ @@ -2479,7 +2419,6 @@ function setPercentileCircular (id_data, values) { width_percentile = values['width_percentile']; var parameter = Array(); - parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"}); parameter.push ({name: "action", value: "get_module_value"}); parameter.push ({name: "id_element", value: id_data}); @@ -2514,7 +2453,7 @@ function setPercentileCircular (id_data, values) { else { value_text = module_value + " " + unit_text; } - + $("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/circular-progress-bar.png'); if($('#text-width_percentile').val() == 0){ $("#" + id_data + " img").css('width', '130px'); @@ -2524,12 +2463,12 @@ function setPercentileCircular (id_data, values) { $("#" + id_data + " img").css('width', $('#text-width_percentile').val()+'px'); $("#" + id_data + " img").css('height', $('#text-width_percentile').val()+'px'); } - + if($('#'+id_data+' table').css('float') == 'right' || $('#'+id_data+ ' table').css('float') == 'left'){ - $('#'+id_data+ ' img').css('margin-top', parseInt($('#'+id_data).css('height'))/2 - parseInt($('#'+id_data+ ' img').css('height'))/2); + $('#'+id_data+ ' img').css('margin-top', parseInt($('#'+id_data).css('height'))/2 - parseInt($('#'+id_data+ ' img').css('height'))/2); } else{ - $('#'+id_data+ ' img').css('margin-left',parseInt($('#'+id_data).css('width'))/2 - parseInt($('#'+id_data+ ' img').css('width'))/2); + $('#'+id_data+ ' img').css('margin-left',parseInt($('#'+id_data).css('width'))/2 - parseInt($('#'+id_data+ ' img').css('width'))/2); } } }); @@ -3835,14 +3774,12 @@ function updateDB_visual(type, idElement , values, event, top, left) { case 'clock': case 'auto_sla_graph': case 'donut_graph': - - if ((typeof(values['mov_left']) != 'undefined') && - (typeof(values['mov_top']) != 'undefined')) { + if ((typeof(values['absolute_left']) != 'undefined') && + (typeof(values['absolute_top']) != 'undefined')) { $("#" + idElement).css('top', '0px').css('top', top + 'px'); $("#" + idElement).css('left', '0px').css('left', left + 'px'); } - else if ((typeof(values['absolute_left']) != 'undefined') && - (typeof(values['absolute_top']) != 'undefined')) { + else{ $("#" + idElement).css('top', '0px').css('top', top + 'px'); $("#" + idElement).css('left', '0px').css('left', left + 'px'); } @@ -3952,7 +3889,6 @@ function updateDB(type, idElement , values, event) { parameter.push({name: key, value: val}); }); - switch (type) { // -- line_item -- case 'handler_start': diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 2953b6843d..cf039842be 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -3282,13 +3282,10 @@ function graph_graphic_moduleevents ($id_agent, $id_module, $width, $height, $pe $data = array (); - //$resolution = $config['graph_res'] * ($period * 2 / $width); // Number of "slices" we want in graph - $resolution = 5 * ($period * 2 / $width); // Number of "slices" we want in graph - $interval = (int) ($period / $resolution); - $date = get_system_time (); + $interval = 24; + $date = get_system_time(); $datelimit = $date - $period; $periodtime = floor ($period / $interval); - $time = array (); $data = array (); $legend = array(); $full_legend = array(); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f691a1bf0e..1d2558f147 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -218,11 +218,11 @@ function reporting_make_reporting_data($report = null, $id_report, } } - if(sizeof($content['id_agent']) != 1){ + if(is_array($content['id_agent']) && sizeof($content['id_agent']) != 1){ $content['style']['name_label'] = str_replace("_agent_",sizeof($content['id_agent']).__(' agents'),$content['style']['name_label']); } - if(sizeof($content['id_agent_module']) != 1){ + if(is_array($content['id_agent_module']) && sizeof($content['id_agent_module']) != 1){ $content['style']['name_label'] = str_replace("_module_",sizeof($content['id_agent_module']).__(' modules'),$content['style']['name_label']); } @@ -6063,6 +6063,7 @@ function reporting_general($report, $content) { $i = 0; $index = 0; $is_string = array(); + foreach ($generals as $row) { //Metaconsole connection $server_name = $row ['server_name']; diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 1451cb80d3..082415c63c 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -1205,7 +1205,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. hbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']) . '
'; } @@ -1213,7 +1213,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. vbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']) . '
'; } @@ -1223,7 +1223,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. hbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']) . '
'; } @@ -1231,7 +1231,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. vbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']) . '
'; } @@ -1240,14 +1240,14 @@ function visual_map_print_item($mode = "read", $layoutData, if ($layoutData['type_graph'] == 'horizontal') { $img = hbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']); } else { $img = vbar_graph($module_data, 400, 400, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']); } @@ -1259,7 +1259,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. hbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']) . '
'; } @@ -1267,7 +1267,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. vbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']) . '
'; } @@ -1277,7 +1277,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. hbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']) . '
'; } @@ -1285,7 +1285,7 @@ function visual_map_print_item($mode = "read", $layoutData, $img = '
'. vbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']) . '
'; } @@ -1294,14 +1294,14 @@ function visual_map_print_item($mode = "read", $layoutData, if ($layoutData['type_graph'] == 'horizontal') { $img = hbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], $layoutData['border_color']); } else { $img = vbar_graph($module_data, $width, $height, $color, array(), array(), - ui_get_full_url("images/image_problem.opaque.png", false, false, false), + ui_get_full_url("images/image_problem_area.png", false, false, false), "", "", $water_mark, $config['fontpath'], 6, "", 0, $config['homeurl'], $layoutData['image'], true, false, $layoutData['border_color']); } @@ -2282,11 +2282,9 @@ function visual_map_print_item($mode = "read", $layoutData, if ($layoutData['parent_item'] != 0) { $parent = db_get_row_filter('tlayout_data', array('id' => $layoutData['parent_item'])); - + echo ''; } } @@ -2306,19 +2304,35 @@ function get_if_module_is_image ($id_module) { } function get_bars_module_data ($id_module) { - $mod_values = db_get_value_filter('datos', 'tagente_estado', array('id_agente_modulo' => $id_module)); + //This charts is only serialize graphs. + //In other string show image no data to show. - if (preg_match("/\r\n/", $mod_values)) { - $values = explode("\r\n", $mod_values); - } - elseif (preg_match("/\n/", $mod_values)) { - $values = explode("\n", $mod_values); + $mod_values = db_get_value_filter( + 'datos', + 'tagente_estado', + array( + 'id_agente_modulo' => $id_module + ) + ); + + $values = false; + //avoid showing the image type modules. WUX + if(strpos($mod_values, 'data:image/png;base64') !== 0){ + if (preg_match("/\r\n/", $mod_values)) { + $values = explode("\r\n", $mod_values); + } + elseif (preg_match("/\n/", $mod_values)) { + $values = explode("\n", $mod_values); + } } $values_to_return = array(); $index = 0; $color_index = 0; $total = 0; + + if(!$values) return false; + foreach ($values as $val) { $data = explode(",", $val); $values_to_return[$data[0]] = array('g' =>$data[1]); @@ -3323,9 +3337,7 @@ function visual_map_print_user_lines($layout_data, $proportion = null) { } echo ''; } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 4c623c90da..e5c6d2f77a 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -141,7 +141,17 @@ function vbar_graph( setup_watermark($water_mark, $water_mark_file, $water_mark_url); if (empty($chart_data)) { - return ''; + return html_print_image ( + $no_data_image, + true, + array( + 'width' => $width, + 'height' => $height, + 'title' => __('No data to show') + ), + false, + true + ); } if($ttl == 2){ @@ -271,7 +281,17 @@ function hbar_graph($chart_data, $width, $height, setup_watermark($water_mark, $water_mark_file, $water_mark_url); if (empty($chart_data)) { - return ''; + return html_print_image ( + $no_data_image, + true, + array( + 'width' => $width, + 'height' => $height, + 'title' => __('No data to show') + ), + false, + true + ); } if($ttl == 2){