2013-05-06 Miguel de Dios <miguel.dedios@artica.es>

* operation/agentes/group_view.php, godmode/groups/group_list.php,
	include/functions_groups.php: added pagination to groups views.
	
	PENDING TASK: #346
	
	* include/functions_component_groups.php: cleaned source code style.
	
	* include/functions.php: added function "is_array_empty" for
	deepers arrays.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8107 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-05-07 12:32:30 +00:00
parent 9f176dd1fa
commit 8adceb3061
6 changed files with 170 additions and 43 deletions

View File

@ -1,3 +1,15 @@
2013-05-06 Miguel de Dios <miguel.dedios@artica.es>
* operation/agentes/group_view.php, godmode/groups/group_list.php,
include/functions_groups.php: added pagination to groups views.
PENDING TASK: #346
* include/functions_component_groups.php: cleaned source code style.
* include/functions.php: added function "is_array_empty" for
deepers arrays.
2013-05-06 Sergio Martin <sergio.martin@artica.es>
* include/help/en/help_module_interval_factor.php

View File

@ -248,6 +248,13 @@ db_clean_cache();
$groups = users_get_groups_tree ($config['id_user'], "AR", true);
$table->width = '98%';
echo '<br />';
echo '<form method="post" action="index.php?sec='.$sec.'&sec2=godmode/groups/configure_group&pure='.$pure.'">';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_submit_button (__('Create group'), 'crt', false, 'class="sub next"');
echo '</div>';
echo '</form>';
if (!empty($groups)) {
$table->head = array ();
$table->head[0] = __('Name');
@ -263,6 +270,49 @@ if (!empty($groups)) {
$iterator = 0;
$all_group = $groups[0];
$groups = array_slice($groups, 1);
//Set the content of page of groups
$offset = (int)get_parameter('offset', 0);
$count_visible_groups = 0;
$count_visible_groups_block = 0;
$stop_count_block = false;
$count = 0;
$start = 0;
$stop = 0;
//$offset = $offset - $offset / $config['block_size'];
foreach ($groups as $group) {
if (((int)$group['parent']) == 0) {
$count_visible_groups++;
if (!$stop_count_block)
$count_visible_groups_block++;
}
if (($count_visible_groups - 1) == ($offset) ) {
$stop_count_block = true;
$start = $count;
}
// -1 for in the all pages is added all group
if (($count_visible_groups - 1) == ($offset + ($config['block_size'] - 1))) {
$stop_count_block = true;
$stop = $count;
}
$count++;
}
if ($stop == 0) {
$stop = $start + $config['block_size'];
}
// 1 for to add all group
ui_pagination($count_visible_groups + 1, false, 0, $config['block_size'] - 1);
$groups = array_slice($groups, $start, ($stop - $start));
$groups = array_merge(array($all_group), $groups);
foreach ($groups as $id_group => $group) {
if ($group['deep'] == 0) {
$table->rowstyle[$iterator] = '';
@ -364,6 +414,8 @@ if (!empty($groups)) {
}
html_print_table ($table);
ui_pagination($count_visible_groups + 1, false, 0, $config['block_size'] - 1);
}
else {
echo "<div class='nf'>".__('There are no defined groups')."</div>";

View File

@ -1746,4 +1746,20 @@ function set_js_value($name, $value) {
html_print_div(array('id' => 'php_to_js_value_' . $name, 'content' => $value, 'hidden' => true));
}
function is_array_empty($InputVariable)
{
$Result = true;
if (is_array($InputVariable) && count($InputVariable) > 0) {
foreach ($InputVariable as $Value) {
$Result = $Result && is_array_empty($Value);
}
}
else {
$Result = empty($InputVariable);
}
return $Result;
}
?>

View File

@ -785,6 +785,21 @@ function groups_get_group_row_data($id_group, $group_all, $group, &$printed_grou
return $rows;
}
function groups_get_groups_with_agent($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false, $id_groups = null, $keys_field = 'id_grupo') {
$groups = users_get_groups($id_user, $privilege, $returnAllGroup, $returnAllColumns, $id_groups, $keys_field);
$return = array();
foreach ($groups as $group) {
$data = reporting_get_group_stats($group['id_grupo']);
if ($data["total_agents"] != 0) {
$return[] = $group;
}
}
return $return;
}
/**
* Print a row in the groups view (Recursive function)
*
@ -797,6 +812,9 @@ function groups_get_group_row_data($id_group, $group_all, $group, &$printed_grou
function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
global $config;
if ($id_group < 0)
return;
if (isset($printed_groups[$id_group])) {
return;
}
@ -804,9 +822,6 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
// Store printed group to not print it again
$printed_groups[$id_group] = 1;
if ($id_group < 0)
return;
// Get stats for this group
$data = reporting_get_group_stats($id_group);
@ -833,6 +848,8 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
$group_class = 'group_view_normal';
}
ob_start();
echo "<tr style='height: 35px;'>";
// Group name
@ -863,11 +880,13 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
$data["total_agents"];
if ($id_group != 0) {
$data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente
$data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente)
FROM tagente
WHERE id_grupo = $id_group AND disabled = 0");
}
else {
$data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente
$data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente)
FROM tagente
WHERE disabled = 0");
}
@ -967,10 +986,22 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
echo "</tr>";
$row[$id_group] = ob_get_clean();
foreach($group['childs'] as $child) {
groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups);
if (array_key_exists($child, $group_all)) {
$row_child = groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups);
if (!is_array_empty($row_child)) {
$row = $row + $row_child;
}
}
}
return $row;
}
/**
* Gets a group by id_group
*

View File

@ -85,28 +85,44 @@ $counter = 1;
$agents = agents_get_group_agents(array_keys($groups));
$offset = (int)get_parameter('offset', 0);
if (count($agents) > 0) {
$groups_get_groups_with_agent = groups_get_groups_with_agent($config['id_user'], "AR", true, true);
ui_pagination(count($groups_get_groups_with_agent));
echo '<table cellpadding="0" cellspacing="0" style="margin-top:10px;" class="groupsview" border="0" width="98%">';
echo "<tr>";
echo "<th width='25%' class='first opacity_cell'>".__("Group")."</th>";
echo "<th width='25%' class='first opacity_cell'>" . __("Group") . "</th>";
echo "<th style='min-width:26px;'></th>";
echo "<th width='10%' class='opacity_cell'>".__("Agents")."</th>";
echo "<th width='10%'>".__("Agent unknown")."</th>";
echo "<th width='10%' class='opacity_cell'>".__("Unknown")."</th>";
echo "<th width='10%'>".__("Not Init")."</th>";
echo "<th width='10%' class='opacity_cell'>".__("Normal")."</th>";
echo "<th width='10%'>".__("Warning")."</th>";
echo "<th width='10%' class='opacity_cell'>".__("Critical")."</th>";
echo "<th width='10%' class='last' style='min-width: 100px'>".__("Alert fired")."</th>";
echo "<th width='10%' class='opacity_cell'>" . __("Agents") . "</th>";
echo "<th width='10%'>" . __("Agent unknown") . "</th>";
echo "<th width='10%' class='opacity_cell'>" . __("Unknown") . "</th>";
echo "<th width='10%'>" . __("Not Init") . "</th>";
echo "<th width='10%' class='opacity_cell'>" . __("Normal") . "</th>";
echo "<th width='10%'>" . __("Warning") . "</th>";
echo "<th width='10%' class='opacity_cell'>" . __("Critical") . "</th>";
echo "<th width='10%' class='last' style='min-width: 100px'>" . __("Alert fired") . "</th>";
$printed_groups = array();
// For each valid group for this user, take data from agent and modules
$table_rows = array();
foreach ($groups as $id_group => $group) {
groups_get_group_row($id_group, $groups, $group, $printed_groups);
$rows = groups_get_group_row($id_group, $groups, $group, $printed_groups);
if (!is_array_empty($rows)) {
$table_rows += $rows;
}
}
$table_rows = array_slice($table_rows, $offset, $config['block_size']);
foreach($table_rows as $row) {
echo $row;
}
echo "</table>";
ui_pagination(count($groups_get_groups_with_agent));
}
else {
echo "<div class='nf'>" . __('There are no defined agents') .