2010-03-29 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_visual_map.php,
	godmode/reporting/visual_console_builder.wizard.php,
	godmode/reporting/visual_console_builder.php,
	godmode/reporting/visual_console_builder.editor.php,
	godmode/reporting/visual_console_builder.editor.js,
	godmode/reporting/visual_console_builder.elements.php: worked about the new
	visual console builder editor, now it is finished but I will clean and
	comment the source code.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2528 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2010-03-30 17:39:32 +00:00
parent e5ccf4f757
commit 5a0b86793d
7 changed files with 359 additions and 41 deletions

View File

@ -1,4 +1,15 @@
2010-03-24 Miguel de Dios <miguel.dedios@artica.es>
2010-03-29 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_visual_map.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/reporting/visual_console_builder.editor.php,
godmode/reporting/visual_console_builder.editor.js,
godmode/reporting/visual_console_builder.elements.php: worked about the new
visual console builder editor, now it is finished but I will clean and
comment the source code.
2010-03-29 Miguel de Dios <miguel.dedios@artica.es>
* include/ajax/visual_console_builder.ajax.php,
godmode/reporting/visual_console_builder.editor.php,
@ -6,7 +17,7 @@
godmode/reporting/visual_console_builder.editor.js: worked about the new
visual console builder editor, now it is developing, don't afray.
2010-03-24 Miguel de Dios <miguel.dedios@artica.es>
2010-03-29 Miguel de Dios <miguel.dedios@artica.es>
* include/ajax/visual_console_builder.ajax.php,
godmode/reporting/visual_console_builder.editor.php,
@ -17,7 +28,7 @@
* godmode/reporting/visual_console_builder.constans.php: added the file that
it has the constans.
2010-03-24 Miguel de Dios <miguel.dedios@artica.es>
2010-03-26 Miguel de Dios <miguel.dedios@artica.es>
* include/config_process.php,
godmode/reporting/visual_console_builder.editor.php,
@ -27,7 +38,7 @@
* include/javascript/jquery.colorpicker.js: we used the old versión, and
patch with self code for z-index to upper position.
2010-03-24 Miguel de Dios <miguel.dedios@artica.es>
2010-03-25 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_visual_map.php,
include/ajax/visual_console_builder.ajax.php,

View File

@ -1,3 +1,16 @@
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
var creationItem = null;
var openPropertiesPanel = false;
var idItem = 0;

View File

@ -88,7 +88,7 @@ $intervals[4838400] = __('Last month');
$intervals[9676800] = "2 ".__('months');
$intervals[29030400] = "6 ".__('months');
//Trick for it have a traduct "any" text.
//Trick for it have a traduct text for javascript.
echo '<span id="any_text" style="display: none;">' . __('Any') . '</span>';
echo '<span id="ip_text" style="display: none;">' . __('IP') . '</span>';

View File

@ -24,6 +24,7 @@ if (! give_acl ($config['id_user'], 0, "IW")) {
exit;
}
require_once('godmode/reporting/visual_console_builder.constans.php');
require_once ('include/functions_visual_map.php');
//Arrays for select box.
@ -42,6 +43,9 @@ foreach ($all_images as $image_file) {
$image_file = substr ($image_file, 0, strlen ($image_file) - 4);
$images_list[$image_file] = $image_file;
}
$layoutDataTypes = get_layout_data_types();
/* Layout_data editor form */
$intervals = array ();
$intervals[3600] = "1 ".__('hour');
@ -61,7 +65,7 @@ $table->width = '100%';
$table->head = array ();
$table->head[0] = __('Label') . ' / ' . __('Type') . ' / ' . __('Parent');
$table->head[1] = __('Image') . ' / ' . __('Agent') . ' / ' . __('Map linked');
$table->head[2] = __('Height') . ' / ' . __('Module') . ' / ' . __('Label color');
$table->head[2] = __('Height / Max value') . ' / ' . __('Module') . ' / ' . __('Label color');
$table->head[3] = __('Width') . ' / ' . __('Period');
$table->head[4] = __('Left');
$table->head[5] = __('Top');
@ -77,6 +81,7 @@ $table->data[0][3] = print_input_text('height', $visualConsole['height'], '', 3,
$table->data[0][4] = '';
$table->data[0][5] = '';
$table->data[0][6] = '';
$table->data[1][0] = __('Background');
$table->data[1][1] = '';
$table->data[1][2] = '';
@ -84,6 +89,7 @@ $table->data[1][3] = '';
$table->data[1][4] = '';
$table->data[1][5] = '';
$table->data[1][6] = '';
$table->data[2][0] = '';
$table->data[2][1] = '';
$table->data[2][2] = '';
@ -102,8 +108,8 @@ foreach ($layoutDatas as $layoutData) {
$idLayoutData = $layoutData['id'];
$table->data[$i][0] = print_input_text ('label_' . $idLayoutData, $layoutData['label'], '', 20, 200, true);
if ($layoutData['type'] == 0) {
$table->data[$i][1] = print_select ($images_list, 'image', $layoutData['image'], '', 'None', '', true);
if ($layoutData['type'] == STATIC_GRAPH) {
$table->data[$i][1] = print_select ($images_list, 'image_' . $idLayoutData, $layoutData['image'], '', 'None', '', true);
}
else {
$table->data[$i][1] = '';
@ -112,18 +118,27 @@ foreach ($layoutDatas as $layoutData) {
$table->data[$i][3] = print_input_text('height_' . $idLayoutData, $layoutData['height'], '', 3, 5, true);
$table->data[$i][4] = print_input_text('left_' . $idLayoutData, $layoutData['pos_x'], '', 3, 5, true);
$table->data[$i][5] = print_input_text('top_' . $idLayoutData, $layoutData['pos_y'], '', 3, 5, true);
$table->data[$i][6] = '<a href=""><img src="images/cross.png" /></a>';
$table->data[$i + 1][0] = print_select (get_layout_data_types(), 'type_' . $idLayoutData, $layoutData['type'], '', '', 0, true, false, false);
$table->data[$i + 1][1] = print_input_text_extended ('agent_' . $idLayoutData, get_agent_name($layoutData['id_agent']), 'text-agent', '', 25, 100, false, '',
array('style' => 'background: #ffffff url(images/lightning.png) no-repeat right;'), true);
$table->data[$i][6] = '<a href="index.php?sec=gmap&sec2=godmode/reporting/visual_console_builder&tab=' .
$activeTab . '&action=delete&id_visual_console=' . $visualConsole["id"] . '&id_element=' . $idLayoutData . '" ' .
'onclick="javascript: if (!confirm(\'' . __('Are you sure?') . '\')) return false;"><img src="images/cross.png" /></a>';
$table->data[$i + 1][0] = $layoutDataTypes[$layoutData['type']];
$table->data[$i + 1][1] = print_input_text_extended ('agent_' . $idLayoutData, get_agent_name($layoutData['id_agent']), 'text-agent_' . $idLayoutData, '', 25, 100, false, '',
array('class' => 'text-agent', 'style' => 'background: #ffffff url(images/lightning.png) no-repeat right;'), true);
$table->data[$i + 1][2] = print_select_from_sql('SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE id_agente = ' . $layoutData['id_agent'],
'module_' . $idLayoutData, $layoutData['id_agente_modulo'], '', '---', 0, true);
if ($layoutData['type'] == MODULE_GRAPH) {
$table->data[$i + 1][3] = print_select ($intervals, 'period_' . $idLayoutData, $layoutData['period'], '', '--', 0, true);
}
else {
$table->data[$i + 1][3] = '';
}
$table->data[$i + 1][4] = '';
$table->data[$i + 1][5] = '';
$table->data[$i + 1][6] = '';
$table->data[$i + 2][0] = print_select_from_sql ('SELECT id, label FROM tlayout_data WHERE id_layout = '. $idVisualConsole,
'parent_' . $idLayoutData, $layoutData['parent_item'], '', 'None', '', true);
$table->data[$i + 2][0] = print_select_from_sql ('SELECT id, label FROM tlayout_data WHERE id_layout = '. $idVisualConsole . ' AND id !=' . $idLayoutData,
'parent_' . $idLayoutData, $layoutData['parent_item'], '', 'None', 0, true);
$table->data[$i + 2][1] = print_select_from_sql ('SELECT id, name FROM tlayout WHERE id != ' . $idVisualConsole,
'map_linked_' . $idLayoutData, $layoutData['id_layout_linked'], '', 'None', '', true);
//$table->data[$i + 2][2] = print_input_text ('label_color_' . $idLayoutData, '#000000', $layoutData['label_color'], 7, 7, true);
@ -146,13 +161,26 @@ foreach ($layoutDatas as $layoutData) {
}
$alternativeStyle = !$alternativeStyle;
//$table->data[5][1] = print_input_text_extended ('agent', '', 'text-agent', '', 30, 100, false, '',
$i = $i + 3;
}
echo '<form method="post" action="index.php?sec=gmap&sec2=godmode/reporting/visual_console_builder&tab=' . $activeTab . '&id_visual_console=' . $visualConsole["id"] . '">';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_input_hidden ('action', 'update');
print_input_hidden ('id_visual_console', $visualConsole["id"]);
print_submit_button (__('Update'), 'go', false, 'class="sub next"');
echo '</div>';
print_table($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_submit_button (__('Update'), 'go', false, 'class="sub next"');
echo '</div>';
echo '</form>';
//Trick for it have a traduct text for javascript.
echo '<span id="ip_text" style="display: none;">' . __('IP') . '</span>';
require_css_file ('color-picker');
require_jquery_file ('ui.core');
@ -170,4 +198,64 @@ require_jquery_file('autocomplete');
$(document).ready (function () {
$(".label_color").attachColorPicker();
});
var idText = $("#ip_text").html();
$(".text-agent").autocomplete(
"ajax.php",
{
minChars: 2,
scroll:true,
extraParams: {
page: "operation/agentes/exportdata",
search_agents: 1,
id_group: function() { return $("#group").val(); }
},
formatItem: function (data, i, total) {
if (total == 0)
$(".text-agent").css ('background-color', '#cc0000');
else
$(".text-agent").css ('background-color', '');
if (data == "")
return false;
return data[0]+'<br><span class="ac_extra_field">' + idText + ': '+data[1]+'</span>';
},
delay: 200
}
);
$(".text-agent").result (
function (event, data, formatted) {
var id = $(this).attr('id').replace('text-agent_', '');
selectAgent = true;
var agent_name = this.value;
$('#module_' + id).fadeOut ('normal', function () {
$('#module_' + id).empty ();
var inputs = [];
inputs.push ("filter=disabled = 0");
inputs.push ("agent_name=" + agent_name);
inputs.push ("get_agent_modules_json=1");
inputs.push ("page=operation/agentes/ver_agente");
jQuery.ajax ({
data: inputs.join ("&"),
type: 'GET',
url: action="ajax.php",
timeout: 10000,
dataType: 'json',
success: function (data) {
$('#module_' + id).append ($('<option></option>').attr ('value', 0).text ("--"));
jQuery.each (data, function (i, val) {
s = js_html_entity_decode (val['nombre']);
$('#module_' + id).append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s));
});
$('#module_' + id).fadeIn ('normal');
}
});
});
}
);
</script>

View File

@ -1,5 +1,4 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
@ -27,7 +26,7 @@ if (! give_acl ($config['id_user'], 0, "IW")) {
require_once ('include/functions_visual_map.php');
$action = get_parameterBetweenListValues('action', array('new', 'save', 'edit', 'update'), 'new');
$action = get_parameterBetweenListValues('action', array('new', 'save', 'edit', 'update', 'delete'), 'new');
$activeTab = get_parameterBetweenListValues('tab', array('data', 'list_elements', 'wizard', 'editor', 'preview'), 'data');
$idVisualConsole = get_parameter('id_visual_console', 0);
@ -81,34 +80,77 @@ switch ($activeTab) {
break;
case 'list_elements':
switch ($action) {
case 'edit':
case 'update':
//Update background
//debugPrint(get_db_row_filter('tlayout', array('id' => $idVisualConsole)));
$background = get_parameter('background');
$width = get_parameter('width');
$height = get_parameter('height');
process_sql_update('tlayout', array('background' => $background,
'width' => $width, 'height' => $height), array('id' => $idVisualConsole));
//debugPrint(get_db_row_filter('tlayout', array('id' => $idVisualConsole)));
//Update elements in visual map
$idsElements = get_db_all_rows_filter('tlayout_data', array('id_layout' => $idVisualConsole), array('id'));
foreach ($idsElements as $idElement) {
$id = $idElement['id'];
$values = array();
$values['label'] = get_parameter('label_' . $id, '');
$values['image'] = get_parameter('image_' . $id, '');
$values['width'] = get_parameter('width_' . $id, 0);
$values['height'] = get_parameter('height_' . $id, 0);
$values['pos_x'] = get_parameter('left_' . $id, 0);
$values['pos_y'] = get_parameter('top_' . $id, 0);
$agentName = get_parameter('agent_' . $id, '');
$values['id_agent'] = get_agent_id($agentName);
$values['id_agente_modulo'] = get_parameter('module_' . $id, 0);
$values['parent_item'] = get_parameter('parent_' . $id, 0);
$values['id_layout_linked'] = get_parameter('map_linked_' . $id, 0);
$values['label_color'] = get_parameter('label_color_' . $id, '#000000');
process_sql_update('tlayout_data', $values, array('id' => $id));
}
break;
case 'delete':
$id_element = get_parameter('id_element');
$result = process_sql_delete('tlayout_data', array('id' => $id_element));
if ($result !== false) {
$statusProcessInDB = array('flag' => true, 'message' => '<h3 class="suc">'.__('Successfully delete.').'</h3>');
}
break;
}
$visualConsole = get_db_row_filter('tlayout', array('id' => $idVisualConsole));
$visualConsoleName = $visualConsole['name'];
$action = 'edit';
break;
case 'wizard':
$visualConsole = get_db_row_filter('tlayout', array('id' => $idVisualConsole));
$visualConsoleName = $visualConsole['name'];
switch ($action) {
case 'update':
$id_agents = get_parameter ('id_agents', array ());
$id_modules = get_parameter ('module', array ());
$image = get_parameter ('image');
$range = (int) get_parameter ("range", 50);
$width = (int) get_parameter ("width", 0);
$height = (int) get_parameter ("height", 0);
$message = '';
$message = process_wizard_add ($id_agents, $image, $layout["id"], $range, $width, $height);
if (!empty ($id_modules)) {
$message .= process_wizard_add_modules ($id_modules, $image, $layout["id"], $range, $width, $height);
}
$statusProcessInDB = array('flag' => true, 'message' => $message);
$action = 'edit';
break;
}
break;
case 'editor':
switch ($action) {
case 'update':
case 'edit':
$visualConsole = get_db_row_filter('tlayout', array('id' => $idVisualConsole));
$visualConsoleName = $visualConsole['name'];
break;
case 'update':
$values = array('background' => get_parameter('background_image'),
'height' => get_parameter('height_background'),
'width' => get_parameter('width_background'));
$result = process_sql_update('tlayout', $values, array('id' => $idVisualConsole));
if ($result !== false) {
$action = 'edit';
$statusProcessInDB = array('flag' => true, 'message' => '<h3 class="suc">'.__('Successfully update.').'</h3>');
}
else {
$statusProcessInDB = array('flag' => false, 'message' => '<h3 class="error">'.__('Could not be update.').'</h3>');
}
$visualConsole = get_db_row_filter('tlayout', array('id' => $idVisualConsole));
$visualConsoleName = $visualConsole['name'];
break;
}
break;
@ -137,7 +179,7 @@ $buttons = array(
if ($action == 'new') $buttons = array('data' => $buttons['data']); //Show only the data tab
$buttons[$activeTab]['active'] = true;
print_page_header(__('Visual console builder') . "&nbsp;" . $visualConsoleName, "", false, "visual_console_editor_" . $activeTab . "_tab", false, $buttons);
print_page_header(__('Visual console builder') . "&nbsp;" . $visualConsoleName, "", false, "visual_console_editor_" . $activeTab . "_tab", true, $buttons);
//The source code for PAINT THE PAGE
if ($statusProcessInDB !== null) {
@ -145,6 +187,9 @@ if ($statusProcessInDB !== null) {
}
switch ($activeTab) {
case 'wizard':
require_once('godmode/reporting/visual_console_builder.wizard.php');
break;
case 'data':
require_once('godmode/reporting/visual_console_builder.data.php');
break;

View File

@ -0,0 +1,83 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Login check
global $config;
check_login ();
if (! give_acl ($config['id_user'], 0, "IW")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access report builder");
require ("general/noaccess.php");
exit;
}
require_once('godmode/reporting/visual_console_builder.constans.php');
require_once ('include/functions_visual_map.php');
$table->id = 'wizard_table';
$table->width = '65%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->data = array ();
$images_list = array ();
$all_images = list_files ('images/console/icons/', "png", 1, 0);
foreach ($all_images as $image_file) {
if (strpos ($image_file, "_bad"))
continue;
if (strpos ($image_file, "_ok"))
continue;
if (strpos ($image_file, "_warning"))
continue;
$image_file = substr ($image_file, 0, strlen ($image_file) - 4);
$images_list[$image_file] = $image_file;
}
$table->data[0][0] = __('Image');
$table->data[0][1] = print_select ($images_list, 'image', '', '', '', '', true);
$table->data[1][0] = __('Image range (px)');
$table->data[1][1] = print_input_text ('range', 50, '', 5, 5, true);
$table->data[2][0] = __('Image size (px)');
$table->data[2][1] = __('Width').': '.print_input_text ('width', 0, '', 5, 5, true);
$table->data[2][1] .= '<br />'.__('Height').': '.print_input_text ('height', 0, '', 5, 5, true);
$table->data[3][0] = __('Agents');
$table->data[3][1] = print_select (get_group_agents ($visualConsole['id_group'], false, "none"),
'id_agents[]', 0, false, '', '', true, true);
$table->data[4][0] = __('Modules');
$table->data[4][1] = print_select (array (), 'module[]', 0, false, '', '', true, true);
echo '<form method="post" action="index.php?sec=gmap&sec2=godmode/reporting/visual_console_builder&tab=' . $activeTab . '&id_visual_console=' . $visualConsole["id"] . '" onsubmit="if (! confirm(\''.__('Are you sure to add many elements\nin visual map?').'\')) return false;">';
print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_input_hidden ('action', 'update');
print_input_hidden ('id_visual_console', $visualConsole["id"]);
print_submit_button (__('Add'), 'go', false, 'class="sub wizard wand"');
echo '</div>';
echo '</form>';
?>
<script language="javascript" type="text/javascript">
$(document).ready (function () {
$("#id_agents").change (agent_changed);
});
</script>

View File

@ -19,6 +19,84 @@
* @subpackage Reporting
*/
function process_wizard_add ($id_agents, $image, $id_layout, $range, $width = 0, $height = 0) {
if (empty ($id_agents)) {
print_error_message (__('No agents selected'));
return false;
}
$id_agents = (array) $id_agents;
$error = false;
$pos_y = 10;
$pos_x = 10;
foreach ($id_agents as $id_agent) {
if ($pos_x > 600) {
$pos_x = 10;
$pos_y = $pos_y + $range;
}
process_sql_insert ('tlayout_data',
array ('id_layout' => $id_layout,
'pos_x' => $pos_x,
'pos_y' => $pos_y,
'label' => get_agent_name ($id_agent),
'image' => $image,
'id_agent' => $id_agent,
'width' => $width,
'height' => $height,
'label_color' => '#000000')
);
$pos_x = $pos_x + $range;
}
$return = print_success_message (__('Agent successfully added to layout'), '', true);
return $return;
}
function process_wizard_add_modules ($id_modules, $image, $id_layout, $range, $width = 0, $height = 0) {
if (empty ($id_modules)) {
print_error_message (__('No modules selected'));
return false;
}
$id_modules = (array) $id_modules;
$error = false;
$pos_y = 10;
$pos_x = 10;
foreach ($id_modules as $id_module) {
if ($pos_x > 600) {
$pos_x = 10;
$pos_y = $pos_y + $range;
}
$id_agent = get_agentmodule_agent ($id_module);
process_sql_insert ('tlayout_data',
array ('id_layout' => $id_layout,
'pos_x' => $pos_x,
'pos_y' => $pos_y,
'label' => get_agentmodule_name ($id_module),
'image' => $image,
'id_agent' => $id_agent,
'id_agente_modulo' => $id_module,
'width' => $width,
'height' => $height,
'label_color' => '#000000')
);
$pos_x = $pos_x + $range;
}
$return = print_success_message (__('Modules successfully added to layout'), '', true);
return $return;
}
function getColorLineStatus($layoutData) {
switch (getStatusElement($layoutData)) {
case 3: