Fixed the generation filter by tag the networkmap.

This commit is contained in:
mdtrooper 2016-04-12 14:40:50 +02:00
parent 5c0620e426
commit bff44de236
3 changed files with 41 additions and 8 deletions

View File

@ -257,6 +257,8 @@ class Networkmap extends Map {
$return['dont_show_subgroups'] = false;
$return['old_mode'] = false;
$return['filter'] = $this->filter['text'];
$return['id_tag'] = $this->filter['id_tag'];
return $return;
}
@ -292,7 +294,8 @@ class Networkmap extends Map {
$parameters['dont_show_subgroups'],
false,
null,
$parameters['old_mode']);
$parameters['old_mode'],
$parameters['id_tag']);

View File

@ -231,7 +231,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$id_networkmap = 0, $show_snmp_modules = 0, $cut_names = true,
$relative = false, $text_filter = '', $l2_network_or_mixed = false,
$ip_mask = null, $dont_show_subgroups = false, $strict_user = false,
$size_canvas = null, $old_mode = false) {
$size_canvas = null, $old_mode = false, $id_tag = 0) {
global $config;
@ -351,6 +351,15 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
//return false;
$agents = array();
// Filter by tags
if (!empty($id_tag)) {
foreach ($agents as $index => $agent) {
if (!tags_agent_has_tag($agent['id_agente'], $id_tag)) {
unset($agents[$index]);
}
}
}
// Open Graph
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, $size_canvas);

View File

@ -534,6 +534,23 @@ function tags_get_tags ($ids) {
return $tags;
}
function tags_agent_has_tag($id_agent, $id_tag) {
$exists = db_get_value_sql("
SELECT COUNT(*)
FROM ttag_module
WHERE id_agente_modulo IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente = " . $id_agent . ")
AND id_tag = " . $id_tag);
if (empty($exists)) {
return false;
}
return (bool)$exists;
}
function tags_get_agents($id_tag, $id_policy_module = 0) {
$agents = db_get_all_rows_sql("
@ -2461,13 +2478,16 @@ function tags_get_user_module_and_tags ($id_user = false, $access = 'AR', $stric
*
* @return mixed Returns count of agents with this tag or false if they aren't.
*/
function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_and_tags = array(), $filter = false, $fields = false, $meta = true, $strict_user = true, $return_all_fields = false) {
function tags_get_all_user_agents ($id_tag = false, $id_user = false,
$groups_and_tags = array(), $filter = false, $fields = false,
$meta = true, $strict_user = true, $return_all_fields = false) {
global $config;
if (empty($id_tag)) {
$tag_filter = '';
} else {
}
else {
$tag_filter = " AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag = $id_tag) ";
}
if (empty($id_user)) {
@ -2481,13 +2501,14 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
}
$select_fields = implode(',',$fields);
$groups_clause = "";
if ($strict_user) {
if (!empty($groups_and_tags)) {
$groups_clause = " AND ".tags_get_acl_tags_module_condition($groups_and_tags, "tagente_modulo");
}
} else {
}
else {
$groups_clause = " AND tagente.id_grupo IN (".implode(',', array_keys($groups_and_tags)).")";
}
@ -2498,7 +2519,7 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
$groups_str = $filter['id_group'];
$groups_clause .= " AND tagente.id_grupo IN ($groups_str)";
}
$status_sql = '';
if (isset($filter['status'])) {
switch ($filter['status']) {