2009-02-23 Esteban Sanchez <estebans@artica.es>

* godmode/reporting/map_builder.php: Use process_sql_update and
	process_sql_insert instead of generating SQL sentences. Added
	wz_jsgraphics to draw the lines. Do not draw any lines if no map is
	selected.

	* include/functions_db.php: Moved return_status_layout() to
	functions_visual_map.php (and renamed to get_layout_status()). Allow
	passing a string to get_db_all_rows_filter()
esteban@silviojose:~/work/src/pandora/pandora_console$ head -30 ChangeLog 
2009-02-23  Esteban Sanchez  <estebans@artica.es>

	* godmode/reporting/map_builder.php: Use process_sql_update and
	process_sql_insert instead of generating SQL sentences. Added
	wz_jsgraphics to draw the lines. Do not draw any lines if no map is
	selected.

	* include/functions_db.php: Moved return_status_layout() to
	functions_visual_map.php (and renamed to get_layout_status()). Allow
	passing a string to get_db_all_rows_filter()

	* include/functions_visual_map.php: Moved get_layout_status() from
	functions_db.php. Added get_user_layouts().

	* operation/visual_console/index.php: Use get_user_layouts() to fetch
	layouts.

	* operation/visual_console/render_view.php: Added wz_jsgraphics and
	changed direct config manipulation with require_javascript_file().

	* godmode/reporting/reporting_builder.php: Style correction.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1473 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2009-02-23 13:41:40 +00:00
parent a6d299dcf7
commit 7991f8af1b
7 changed files with 157 additions and 95 deletions

View File

@ -1,3 +1,25 @@
2009-02-23 Esteban Sanchez <estebans@artica.es>
* godmode/reporting/map_builder.php: Use process_sql_update and
process_sql_insert instead of generating SQL sentences. Added
wz_jsgraphics to draw the lines. Do not draw any lines if no map is
selected.
* include/functions_db.php: Moved return_status_layout() to
functions_visual_map.php (and renamed to get_layout_status()). Allow
passing a string to get_db_all_rows_filter()
* include/functions_visual_map.php: Moved get_layout_status() from
functions_db.php. Added get_user_layouts().
* operation/visual_console/index.php: Use get_user_layouts() to fetch
layouts.
* operation/visual_console/render_view.php: Added wz_jsgraphics and
changed direct config manipulation with require_javascript_file().
* godmode/reporting/reporting_builder.php: Style correction.
2009-02-23 Esteban Sanchez <estebans@artica.es>
* images/pixel_black.png: Added to

View File

@ -57,10 +57,14 @@ if ($create_layout) {
$width = $bg_info[0];
$height = $bg_info[1];
}
$sql = sprintf ('INSERT INTO tlayout (name, id_group, background, height, width)
VALUES ("%s", %d, "%s", %d, %d)',
$name, $id_group, $background, $height, $width);
$id_layout = process_sql ($sql, 'insert_id');
$values = array ();
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['background'] = $background;
$values['height'] = $height;
$values['width'] = $width;
$id_layout = process_sql_insert ('tlayout', $values);
if ($id_layout !== false) {
echo '<h3 class="suc">'.__('Created successfully').'</h3>';
} else {
@ -72,10 +76,8 @@ if ($create_layout) {
}
if ($delete_layout) {
$sql = sprintf ('DELETE FROM tlayout_data WHERE id_layout = %d', $id_layout);
process_sql ($sql);
$sql = sprintf ('DELETE FROM tlayout WHERE id = %d', $id_layout);
$result = process_sql ($sql);
process_sql_delete ('tlayout_data', array ('id_layout', $id_layout));
$result = process_sql_delete ('tlayout', array ('id', $id_layout));
if ($result) {
echo '<h3 class="suc">'.__('Deleted successfully').'</h3>';
} else {
@ -98,11 +100,11 @@ if ($update_layout) {
$width = $bg_info[0];
if (! $height)
$height = $bg_info[1];
$sql = sprintf ('UPDATE tlayout SET name = "%s", background = "%s",
height = %d, width = %d
WHERE id = %d',
$name, $background, $height, $width, $id_layout);
$result = mysql_query ($sql);
$result = process_sql_update ('tlayout',
array ('name' => $name, 'background' => $background,
'height' => $height, 'width' => $width),
array ('id' => $id));
if ($result) {
echo '<h3 class="suc">'.__('Update layout successful').'</h3>';
} else {
@ -185,7 +187,9 @@ if ($update_layout_data_coords) {
pos_x = %d, pos_y = %d
WHERE id = %d',
$layout_data_x, $layout_data_y, $id_layout_data);
process_sql ($sql);
process_sql_update ('tlayout_data',
array ('pos_x' => $layout_data_x, 'pos_y' => $layout_data_y),
array ('id' => $id_layout_data));
if (defined ('AJAX')) {
exit;
@ -196,12 +200,11 @@ if ($delete_layout_data) {
$ids_layout_data = (array) get_parameter ('ids_layout_data');
foreach ($ids_layout_data as $id_layout_data) {
$sql = sprintf ('UPDATE tlayout_data SET parent_item = 0 WHERE parent_item = %d',
$id_layout_data);
process_sql ($sql);
process_sql_update ('tlayout_data', array ('parent_item' => 0),
array ('parent_item' => $id_layout_data));
$sql = sprintf ('DELETE FROM tlayout_data WHERE id = %d',
$id_layout_data);
process_sql ($sql);
process_sql_delete ('tlayout_data', array ('id' => $id_layout_data));
}
if (defined ('AJAX')) {
@ -223,25 +226,19 @@ if ($update_layout_data) {
$layout_data_width = (int) get_parameter ("width");
$layout_data_height = (int) get_parameter ("height");
$sql = sprintf ('UPDATE tlayout_data SET
image = "%s", label = "%s",
label_color = "%s",
id_agent = %d,
id_agente_modulo = %d,
type = %d, parent_item = %d,
period = %d, id_layout_linked = %d,
width = %d, height = %d
WHERE id = %d',
$layout_data_image, $layout_data_label,
$layout_data_label_color,
$layout_data_id_agent,
$layout_data_id_agent_module,
$layout_data_type, $layout_data_parent_item,
$layout_data_period * 3600,
$layout_data_map_linked,
$layout_data_width, $layout_data_height,
$id_layout_data);
$result = process_sql ($sql);
$values = array ();
$values['image'] = $layout_data_image;
$values['label'] = $layout_data_label;
$values['label_color'] = $layout_data_label_color;
$values['id_agent'] = $layout_data_id_agent;
$values['id_agente_modulo'] = $layout_data_id_agent_module;
$values['type'] = $layout_data_type;
$values['parent_item'] = $layout_data_parent_item;
$values['period'] = $layout_data_period;
$values['id_layout_linked'] = $layout_data_map_linked;
$values['height'] = $height;
$values['width'] = $width;
$result = process_sql_update ('tlayout_data', $values, array ('id' => $id_layout_data));
if ($result !== false) {
echo '<h3 class="suc">'.__('Updated successfully').'</h3>';
@ -439,6 +436,7 @@ require_jquery_file ('ui.core');
require_jquery_file ('ui.draggable');
require_jquery_file ('ui.droppable');
require_jquery_file ('colorpicker');
require_javascript_file ('wz_jsgraphics');
require_javascript_file ('pandora_visual_console');
?>
<script language="javascript" type="text/javascript">
@ -470,8 +468,10 @@ function agent_changed (event, id_agent, selected) {
}
$(document).ready (function () {
<?php if ($id_layout): ?>
if (lines)
draw_lines (lines, 'layout_map');
<?php endif; ?>
$('#background').change (function () {
background = this.value;
if (background == '')

View File

@ -119,7 +119,7 @@ if ($delete_report) {
$sql2 = sprintf ('DELETE FROM treport WHERE id_report = %d', $id_report);
$res = process_sql ($sql);
$res2 = process_sql ($sql2);
if ($res AND $res2)
if ($res && $res2)
echo "<h3 class=suc>".__('Reporting successfully deleted')."</h3>";
else
echo "<h3 class=error>".__('There was a problem deleting reporting')."</h3>";

View File

@ -1587,8 +1587,11 @@ function get_db_all_rows_filter ($table, $filter, $fields = false) {
return false;
}
if (is_array ($filter))
$filter = format_array_to_where_clause_sql ($filter);
$sql = sprintf ('SELECT %s FROM %s WHERE %s',
$fields, $table, format_array_to_where_clause_sql ($filter));
$fields, $table, $filter);
return get_db_all_rows_sql ($sql);
}
@ -1885,50 +1888,6 @@ function return_status_agent ($id_agent = 0) {
return $status;
}
/**
* Get the status of a layout.
*
* It gets all the data of the contained elements (including nested
* layouts), and makes an AND operation to be sure that all the items
* are OK. If any of them is down, then result is down (0)
*
* @param int Id of the layout
*
* @return bool The status of the given layout.
*/
function return_status_layout ($id_layout = 0) {
$temp_status = 0;
$temp_total = 0;
$sql = sprintf ('SELECT id_agente_modulo, parent_item, id_layout_linked, id_agent FROM `tlayout_data` WHERE `id_layout` = %d', $id_layout);
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return 0;
foreach ($result as $rownum => $data) {
// Other Layout (Recursive!)
if (($data["id_layout_linked"] != 0) && ($data["id_agente_modulo"] == 0)) {
$temp_status = return_status_layout ($data["id_layout_linked"]);
if ($temp_status > $temp_total){
$temp_total = $temp_status;
}
// Module
} elseif ($data["id_agente_modulo"] != 0) {
$temp_status = return_status_agent_module ($data["id_agente_modulo"]);
if ($temp_status > $temp_total)
$temp_total = $temp_status;
// Agent
} else {
$temp_status = return_status_agent ($data["id_agent"]);
if ($temp_status > $temp_total)
$temp_total = $temp_status;
}
}
return $temp_total;
}
/**
* Get the current value of an agent module.
*

View File

@ -37,7 +37,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines =
foreach ($layout_datas as $layout_data) {
// Linked to other layout ?? - Only if not module defined
if ($layout_data['id_layout_linked'] != 0) {
$status = return_status_layout ($layout_data['id_layout_linked']);
$status = get_layout_status ($layout_data['id_layout_linked']);
$status_parent = 3;
} else {
@ -208,9 +208,94 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines =
* @return array Layout data types
*/
function get_layout_data_types () {
$types = array (0 => __('Static graph'),
1 => __('Module graph'));
$types = array ();
$types[0] = __('Static graph');
$types[1] = __('Module graph');
return $types;
}
/**
* Get a list with the layouts for a user.
*
* @param int User id.
* @param bool Wheter to return all the fields or only the name (to use in
* print_select() directly)
* @param array Additional filters to filter the layouts.
*
* @return array A list of layouts the user can see.
*/
function get_user_layouts ($id_user = 0, $only_names = false, $filter = false) {
if (! is_array ($filter))
$filter = array ();
$where = format_array_to_where_clause_sql ($filter);
if ($where != '') {
$where .= ' AND ';
}
$groups = get_user_groups ($id_user);
$where .= sprintf ('id_group IN (%s)', implode (",", array_keys ($groups)));
$layouts = get_db_all_rows_filter ('tlayout', $where);
if ($layouts == false)
return array ();
$retval = array ();
foreach ($layouts as $layout) {
if ($only_names)
$retval[$layout['id']] = $layout['name'];
else
$retval[$layout['id']] = $layout;
}
return $retval;
}
/**
* Get the status of a layout.
*
* It gets all the data of the contained elements (including nested
* layouts), and makes an AND operation to be sure that all the items
* are OK. If any of them is down, then result is down (0)
*
* @param int Id of the layout
*
* @return bool The status of the given layout. True if it's OK, false if not.
*/
function get_layout_status ($id_layout = 0) {
$temp_status = 0;
$temp_total = 0;
$sql = sprintf ('SELECT id_agente_modulo, parent_item, id_layout_linked, id_agent
FROM `tlayout_data` WHERE `id_layout` = %d', $id_layout);
$result = get_db_all_rows_filter ('tlayout_data', array ('id' => $id_layout),
array ('id_agente_modulo', 'parent_item', 'id_layout_linked', 'id_agent'));
if ($result === false)
return 0;
foreach ($result as $rownum => $data) {
// Other Layout (Recursive!)
if (($data["id_layout_linked"] != 0) && ($data["id_agente_modulo"] == 0)) {
$temp_status = get_layout_status ($data["id_layout_linked"]);
if ($temp_status > $temp_total) {
$temp_total = $temp_status;
}
// Module
} elseif ($data["id_agente_modulo"] != 0) {
$temp_status = return_status_agent_module ($data["id_agente_modulo"]);
if ($temp_status > $temp_total)
$temp_total = $temp_status;
// Agent
} else {
$temp_status = return_status_agent ($data["id_agent"]);
if ($temp_status > $temp_total)
$temp_total = $temp_status;
}
}
return $temp_total;
}
?>

View File

@ -16,18 +16,13 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Login check
check_login ();
echo "<h2>".__('Visual console')." &gt; ".__('Summary')."</h2>";
$layouts = get_db_all_rows_in_table ('tlayout','name');
if ($layouts === false)
$layouts = array ();
require_once ('include/functions_visual_map.php');
$layouts = get_user_layouts ();
$table->width = 500;
$table->data = array ();

View File

@ -103,7 +103,8 @@ if ($config["pure"] && $config["refr"] != 0) {
require_jquery_file ('countdown');
require_css_file ('countdown');
}
$config['js'][] = 'pandora_visual_console';
require_javascript_file ('wz_jsgraphics');
require_javascript_file ('pandora_visual_console');
?>
<script language="javascript" type="text/javascript">
/* <![CDATA[ */