From a1dcb44d8173ce96de463ac1148a0593bc22236d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 3 Jul 2013 08:50:50 +0000 Subject: [PATCH] 2013-07-03 Miguel de Dios * mobile/index.php, mobile/operation/networkmaps.php, mobile/operation/networkmap.php, mobile/operation/home.php, mobile/include/ui.class.php, include/functions_networkmap.php, include/functions_ui.php: uploaded the some changes and files for to show networkmaps in the Pandora mobile. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8457 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 27 ++ .../include/functions_networkmap.php | 131 +++++++--- pandora_console/include/functions_ui.php | 9 +- pandora_console/mobile/include/ui.class.php | 2 +- pandora_console/mobile/index.php | 10 + pandora_console/mobile/operation/home.php | 5 + .../mobile/operation/networkmap.php | 232 ++++++++++++++++++ .../mobile/operation/networkmaps.php | 202 +++++++++++++++ 8 files changed, 579 insertions(+), 39 deletions(-) create mode 100755 pandora_console/mobile/operation/networkmap.php create mode 100755 pandora_console/mobile/operation/networkmaps.php diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c4ea505df7..d9d840cbc5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-07-03 Miguel de Dios + + * mobile/index.php, mobile/operation/networkmaps.php, + mobile/operation/networkmap.php, mobile/operation/home.php, + mobile/include/ui.class.php, include/functions_networkmap.php, + include/functions_ui.php: uploaded the some changes and files + for to show networkmaps in the Pandora mobile. + 2013-07-03 Sergio Martin * godmode/users/configure_user.php: improve the meta @@ -9,6 +17,25 @@ * include/functions_api.php: Changed the way of encode data configuration in create/update config form API +2013-07-02 Miguel de Dios + + * extensions/system_info.php: clean source code style. + + * mobile/include/ui.class.php: fixed the selectbox for int values. + + * mobile/operation/home.php, mobile/index.php, + mobile/operation/networkmaps.php, mobile/operation/networkmap.php: + added networkmap. + + * include/functions_ui.php: added for get only the src of module + type. + + * include/functions_networkmap.php, + operation/agentes/networkmap.topology.php: add support for + networkmaps in mobile. + + MERGED FROM THE BRANCH 4.0 + 2013-07-02 Miguel de Dios * include/functions_networkmap.php, diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 50903eff74..ec904876cc 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -14,6 +14,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + + /** * @package Include * @subpackage Network_Map @@ -45,9 +47,9 @@ function networkmap_is_descendant ($node, $ascendant, $parents) { } // Generate a dot graph definition for graphviz -function networkmap_generate_dot ($pandora_name, $group = 0, $simple = 0, - $font_size = 12, $layout = 'radial', $nooverlap = 0, $zoom = 1, - $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0, +function networkmap_generate_dot ($pandora_name, $group = 0, + $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0, + $zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0, $id_networkmap = 0, $show_snmp_modules = 0, $cut_names = true, $relative = false, $text_filter = '') { @@ -271,6 +273,7 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, $simple = 0, $groups_hiden = array(); foreach ($nodes_groups as $node_group) { + $node_count++; // Save node parent information to define edges later @@ -383,15 +386,18 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, $simple = 0, } switch ($node['type']) { case 'group': - $graph .= networkmap_create_group_node ($node , $simple, $font_size)."\n\t\t"; + $graph .= networkmap_create_group_node ($node , $simple, $font_size) . + "\n\t\t"; $stats['groups'][] = $node['id_grupo']; break; case 'agent': - $graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true)."\n\t\t"; + $graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true) . + "\n\t\t"; $stats['agents'][] = $node['id_agente']; break; case 'module': - $graph .= networkmap_create_module_node ($node , $simple, $font_size)."\n\t\t"; + $graph .= networkmap_create_module_node ($node , $simple, $font_size) . + "\n\t\t"; $stats['modules'][] = $node['id_agente_modulo']; break; } @@ -445,42 +451,55 @@ function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom // Returns a group node definition function networkmap_create_group_node ($group, $simple = 0, $font_size = 10, $metaconsole = false, $id_server = null) { + global $config; + global $hack_networkmap_mobile; + $status = groups_get_status ($group['id_grupo']); // Set node status - switch($status) { + switch ($status) { case 0: - $status_color = '#8DFF1D'; // Normal monitor + $status_color = '#8DFF1D'; // Normal monitor break; case 1: - $status_color = '#FF1D1D'; // Critical monitor + $status_color = '#FF1D1D'; // Critical monitor break; case 2: - $status_color = '#FFE308'; // Warning monitor + $status_color = '#FFE308'; // Warning monitor break; case 4: - $status_color = '#FFA300'; // Alert fired + $status_color = '#FFA300'; // Alert fired break; default: - $status_color = '#BBBBBB'; // Unknown monitor + $status_color = '#BBBBBB'; // Unknown monitor break; } + + $icon = groups_get_icon($group['id_grupo']); if ($simple == 0) { // Set node icon - if (file_exists (html_print_image("images/groups_small/" . $icon . ".png", true, false, true, true))) { + if ($hack_networkmap_mobile) { + $img_node = $config['homedir'] . "/images/groups_small/" . $icon . ".png"; + html_debug_print($img_node, true); + if (!file_exists($img_node)) { + $img_node = '-'; + } + $img_node = ''; + } + else if (file_exists (html_print_image("images/groups_small/" . $icon . ".png", true, false, true, true))) { $img_node = html_print_image("images/groups_small/" . $icon . ".png", true, false, false, true); } else { $img_node = '-'; } - if (strlen(groups_get_name($group['id_grupo'])) > 40){ + if (strlen(groups_get_name($group['id_grupo'])) > 40) { $name = substr(groups_get_name($group['id_grupo']), 0, 40) . '...'; } - else{ + else { $name = groups_get_name($group['id_grupo']); } @@ -518,7 +537,8 @@ function networkmap_create_group_node ($group, $simple = 0, $font_size = 10, $me // Returns a node definition function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cut_names = true, $relative = false, $metaconsole = false, $id_server = null) { global $config; - + global $hack_networkmap_mobile; + $status = agents_get_status_from_counts($agent); if (defined('METACONSOLE')) { @@ -564,20 +584,28 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu } if ($simple == 0) { - // Set node icon - $img_node = ui_print_os_icon ($agent['id_os'], false, true, true, true, true, $relative); - $img_node = str_replace($config['homeurl'] . '/', '', $img_node); - $img_node = str_replace($config['homeurl'], '', $img_node); - - if (defined('METACONSOLE')) { - $img_node = str_replace('../../', '', $img_node); - } - - if ($relative) { - $img_node = html_print_image($img_node, true, false, false, true); + if ($hack_networkmap_mobile) { + $img_node = ui_print_os_icon($agent['id_os'], false, true, true, true, true, true); + + $img_node = $config['homedir'] . '/' . $img_node; + $img_node = ''; } else { - $img_node = html_print_image($img_node, true, false, false, false); + // Set node icon + $img_node = ui_print_os_icon ($agent['id_os'], false, true, true, true, true, $relative); + $img_node = str_replace($config['homeurl'] . '/', '', $img_node); + $img_node = str_replace($config['homeurl'], '', $img_node); + + if (defined('METACONSOLE')) { + $img_node = str_replace('../../', '', $img_node); + } + + if ($relative) { + $img_node = html_print_image($img_node, true, false, false, true); + } + else { + $img_node = html_print_image($img_node, true, false, false, false); + } } if (defined("METACONSOLE")) { @@ -627,10 +655,13 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu } function networkmap_create_module_group_node ($module_group, $simple = 0, $font_size = 10, $metaconsole = false, $id_server = null) { + global $config; + global $hack_networkmap_mobile; + // Set node status switch ($module_group['status']) { - case 0: + case 0: $status_color = '#8DFF1D'; // Normal monitor break; case 1: @@ -666,6 +697,15 @@ function networkmap_create_module_group_node ($module_group, $simple = 0, $font_ tooltip="' . $url_tooltip . '"];'; } else { + if ($hack_networkmap_mobile) { + $img_node = ui_print_moduletype_icon($module['id_tipo_modulo'], true, true, false, true); + + $img_node = $config['homedir'] . '/' . $img_node; + $img_node = ''; + } + else { + $img_node = ui_print_moduletype_icon ($module['id_tipo_modulo'], true, true, false); + } if (defined("METACONSOLE")) { $url = ''; $url_tooltip = ''; @@ -685,8 +725,10 @@ function networkmap_create_module_group_node ($module_group, $simple = 0, $font_ // Returns a module node definition function networkmap_create_module_node ($module, $simple = 0, $font_size = 10, $metaconsole = false, $id_server = null) { + global $config; + global $hack_networkmap_mobile; - if(isset($module['status'])) { + if (isset($module['status'])) { $status = $module['status']; } else { @@ -696,7 +738,7 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10, $ // Set node status switch ($status) { - case 0: + case 0: $status_color = '#8DFF1D'; // Normal monitor break; case 1: @@ -713,6 +755,16 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10, $ break; } + if ($hack_networkmap_mobile) { + $img_node = ui_print_moduletype_icon($module['id_tipo_modulo'], true, true, false, true); + + $img_node = $config['homedir'] . '/' . $img_node; + $img_node = ''; + } + else { + $img_node = ui_print_moduletype_icon ($module['id_tipo_modulo'], true, true, false); + } + if ($simple == 0) { if (defined("METACONSOLE")) { @@ -733,7 +785,7 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10, $ '", fontsize='.$font_size.', style="filled", ' . 'fixedsize=true, width=0.30, height=0.30, ' . 'label=< + $img_node . '
' . - ui_print_moduletype_icon ($module['id_tipo_modulo'], true, true, false). '
' . io_safe_output($module['nombre']) . '
>, shape="circle", URL="' . $url . '", tooltip="' . $url_tooltip . '"];'; @@ -762,6 +814,8 @@ function networkmap_create_module_node ($module, $simple = 0, $font_size = 10, $ // Returns the definition of the central module function networkmap_create_pandora_node ($name, $font_size = 10, $simple = 0, $stats = array()) { + global $hack_networkmap_mobile; + global $config; $stats_json = base64_encode(json_encode($stats)); @@ -782,9 +836,14 @@ function networkmap_create_pandora_node ($name, $font_size = 10, $simple = 0, $s $color = "#373737"; } - $img_tag = html_print_image($img_src, true, false, false, true); - - $img = '' . $img_tag . ''; + if ($hack_networkmap_mobile) { + $img = '' . + "" . + ''; + } + else { + $img = '' . html_print_image("images/networkmap/pandora_node.png", true, false, false, true) . ''; + } $name = ''.$name.''; $label = ''.$img.$name.'
'; if ($simple == 1) { @@ -1010,7 +1069,7 @@ function networkmap_get_networkmaps ($id_user = '', $type = '', $optgrouped = tr break; } - if ($networkmaps_raw === false){ + if ($networkmaps_raw === false) { return false; } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index a8ab2252a2..1e2e3e6d97 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -499,6 +499,7 @@ function ui_print_group_icon ($id_group, $return = false, $path = "groups_small" else $icon = "world"; + $output = ''; // Don't show link in metaconsole @@ -575,7 +576,7 @@ function ui_print_os_icon ($id_os, $name = true, $return = false, $apply_skin = if ($networkmap) { $subfolter = 'networkmap'; } - + $icon = (string) db_get_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os); $os_name = get_os_name ($id_os); if (empty ($icon)) { @@ -1738,7 +1739,7 @@ function ui_debug ($var, $backtrace = true) { * * @return string An HTML string with the icon. Printed if return is false */ -function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative = false, $options = true) { +function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative = false, $options = true, $src = false) { global $config; $type = db_get_row ("ttipo_modulo", "id_tipo", (int) $id_moduletype, array ("descripcion", "icon")); @@ -1751,6 +1752,10 @@ function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative = if (! file_exists ($config['homedir'].'/'.$imagepath)) $imagepath = ENTERPRISE_DIR.'/'.$imagepath; + if ($src) { + return $imagepath; + } + if ($options) { return html_print_image ($imagepath, $return, array ("border" => 0, diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php index 6dcfba8e29..4197947434 100755 --- a/pandora_console/mobile/include/ui.class.php +++ b/pandora_console/mobile/include/ui.class.php @@ -520,7 +520,7 @@ class Ui { $selected = ''; if (isset($options['selected'])) { - if ($options['selected'] == $item_id) { + if ($options['selected'] === $item_id) { $selected = "selected = 'selected'"; } } diff --git a/pandora_console/mobile/index.php b/pandora_console/mobile/index.php index 44f8201af2..1747297d33 100644 --- a/pandora_console/mobile/index.php +++ b/pandora_console/mobile/index.php @@ -34,6 +34,8 @@ require_once('operation/agents.php'); require_once('operation/modules.php'); require_once('operation/module_graph.php'); require_once('operation/agent.php'); +require_once('operation/networkmaps.php'); +require_once('operation/networkmap.php'); $enterpriseHook = enterprise_include('mobile/include/enterprise.class.php'); $system = System::getInstance(); @@ -142,6 +144,14 @@ switch ($action) { $agent = new Agent(); $agent->show(); break; + case 'networkmaps': + $networkmaps = new Networkmaps(); + $networkmaps->show(); + break; + case 'networkmap': + $networkmap = new Networkmap(); + $networkmap->show(); + break; } break; } diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index 7cceb38be5..af7ec7c3c8 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -70,6 +70,11 @@ class Home { 'text' => __('Modules'), 'href' => 'index.php?page=modules'); $ui->contentAddHtml($ui->createButton($options)); + $options = array('icon' => 'star', + 'pos' => 'right', + 'text' => __('Networkmaps'), + 'href' => 'index.php?page=networkmaps'); + $ui->contentAddHtml($ui->createButton($options)); $ui->endContent(); $ui->showPage(); return; diff --git a/pandora_console/mobile/operation/networkmap.php b/pandora_console/mobile/operation/networkmap.php new file mode 100755 index 0000000000..ec9f86c201 --- /dev/null +++ b/pandora_console/mobile/operation/networkmap.php @@ -0,0 +1,232 @@ +checkACL($this->acl)) { + $this->correct_acl = true; + } + else { + $this->correct_acl = false; + } + } + + public function ajax($parameter2 = false) { + $system = System::getInstance(); + + if (!$this->correct_acl) { + return; + } + else { + switch ($parameter2) { + case 'xxx': + //$this->getFilters(); + //$page = $system->getRequest('page', 0); + break; + } + } + } + + private function getFilters() { + $system = System::getInstance(); + + $this->id = (int)$system->getRequest('id', 0); + } + + public function show() { + if (!$this->correct_acl) { + $this->show_fail_acl(); + } + else { + $this->getFilters(); + + $this->networkmap = db_get_row('tnetwork_map', + 'id_networkmap', $this->id); + + $this->show_networkmap(); + } + } + + private function show_fail_acl() { + $error['title_text'] = __('You don\'t have access to this page'); + $error['content_text'] = __('Access to this page is restricted to authorized users only, please contact system administrator if you need assistance.

Please know that all attempts to access this page are recorded in security logs of Pandora System Database'); + $home = new Home(); + $home->show($error); + } + + private function show_networkmap() { + $ui = Ui::getInstance(); + $system = System::getInstance(); + + $ui->createPage(); + $ui->createDefaultHeader(sprintf(__("PandoraFMS: Networkmap %s"), + $this->network_map['name'])); + $ui->showFooter(false); + $ui->beginContent(); + + //Hack for mobile + global $hack_networkmap_mobile; + $hack_networkmap_mobile = true; + + switch ($this->networkmap['type']) { + case 'groups': + $graph = networkmap_generate_dot_groups ( + __('Pandora FMS'), + $this->networkmap['id_group'], + $this->networkmap['simple'], + $this->networkmap['font_size'], + $this->networkmap['layout'], + (bool)$this->networkmap['nooverlap'], + $this->networkmap['zoom'], + $this->networkmap['distance_nodes'], + $this->networkmap['center'], 1, 0, + $this->networkmap['only_modules_with_alerts'], + $this->networkmap['id_module_group'], + $this->networkmap['hide_policy_modules'], + $this->networkmap['depth'], + $this->networkmap['id_networkmap']); + break; + case 'policies': + $enterprise = enterprise_include('/include/functions_policies.php'); + + if ($enterprise != ENTERPRISE_NOT_HOOK) { + $graph = policies_generate_dot_graph (__('Pandora FMS'), + $this->networkmap['id_group'], + $this->networkmap['simple'], + $this->networkmap['font_size'], + $this->networkmap['layout'], + (bool)$this->networkmap['nooverlap'], + $this->networkmap['zoom'], + $this->networkmap['distance_nodes'], + $this->networkmap['center'], 1, 0, + $this->networkmap['only_modules_with_alerts'], + $this->networkmap['id_module_group'], + $this->networkmap['depth'], + $this->networkmap['id_networkmap']); + } + break; + default: + case 'topology': + $graph = networkmap_generate_dot (__('Pandora FMS'), + $this->networkmap['id_group'], + $this->networkmap['simple'], + $this->networkmap['font_size'], + $this->networkmap['layout'], + (bool)$this->networkmap['nooverlap'], + $this->networkmap['zoom'], + $this->networkmap['distance_nodes'], + $this->networkmap['center'], 1, 0, + $this->networkmap['id_networkmap'], + $this->networkmap['show_snmp_modules'], true, + true); + break; + } + + + + if ($graph === false) { + $ui->contentAddHtml('

' . __('No networkmaps') . '

'); + + $ui->endContent(); + $ui->showPage(); + + return; + } + + + $filter = networkmap_get_filter($this->networkmap['layout']); + + // Generate image and map + // If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set + $filename_map = safe_url_extraclean ( + $system->getConfig('attachment_store')) . "/networkmap_" . $filter; + $filename_img = safe_url_extraclean ( + $system->getConfig('attachment_store')) . "/networkmap_" . + $filter . "_" . $this->networkmap['font_size']; + $url_img = "../attachment/networkmap_" . + $filter . "_" . $this->networkmap['font_size']; + $filename_dot = safe_url_extraclean( + $system->getConfig("attachment_store")) . "/networkmap_" . $filter; + if ($this->networkmap['simple']) { + $filename_map .= "_simple"; + $filename_img .= "_simple"; + $url_img .= "_simple"; + $filename_dot .= "_simple"; + } + if ($this->networkmap['nooverlap']) { + $filename_map .= "_nooverlap"; + $filename_img .= "_nooverlap"; + $url_img .= "_nooverlap"; + $filename_dot .= "_nooverlap"; + } + $filename_map .= "_" . $this->networkmap['id_networkmap'] . ".map"; + $filename_img .= "_" . $this->networkmap['id_networkmap'] . ".png"; + $url_img .= "_" . $this->networkmap['id_networkmap'] . ".png"; + $filename_dot .= "_" . $this->networkmap['id_networkmap'] . ".dot"; + + if ($this->networkmap['regenerate'] != 1 && file_exists($filename_img) && filemtime($filename_img) > get_system_time () - 300) { + $result = true; + } + else { + $fh = @fopen ($filename_dot, 'w'); + if ($fh === false) { + $result = false; + } + else { + fwrite ($fh, $graph); + $cmd = $filter . " -Tcmapx -o" . $filename_map." -Tpng -o".$filename_img." ".$filename_dot; + $result = system ($cmd); + html_debug_print($cmd, true); + fclose ($fh); + //unlink ($filename_dot); + } + } + + if ($result !== false) { + if (! file_exists ($filename_map)) { + $ui->contentAddHtml('

' . __('Map could not be generated') . '

'); + + $ui->endContent(); + $ui->showPage(); + + return; + } + $ui->contentAddHtml('
'); + $ui->contentAddHtml(''); + $ui->contentAddHtml('
'); + } + else { + $ui->contentAddHtml('

' . __('Map could not be generated') . '

'); + + $ui->endContent(); + $ui->showPage(); + + return; + } + + $ui->endContent(); + $ui->showPage(); + } +} +?> \ No newline at end of file diff --git a/pandora_console/mobile/operation/networkmaps.php b/pandora_console/mobile/operation/networkmaps.php new file mode 100755 index 0000000000..4d7b54f779 --- /dev/null +++ b/pandora_console/mobile/operation/networkmaps.php @@ -0,0 +1,202 @@ +checkACL($this->acl)) { + $this->correct_acl = true; + } + else { + $this->correct_acl = false; + } + } + + public function ajax($parameter2 = false) { + $system = System::getInstance(); + + if (!$this->correct_acl) { + return; + } + else { + switch ($parameter2) { + case 'xxx': + //$this->getFilters(); + //$page = $system->getRequest('page', 0); + break; + } + } + } + + private function getFilters() { + $system = System::getInstance(); + $user = User::getInstance(); + + $this->group = (int)$system->getRequest('group', __("Group")); + if (!$user->isInGroup($this->acl, $this->group)) { + $this->group = 0; + } + if (($this->group === __("Group")) || ($this->group == 0)) { + $this->group = 0; + } + else { + $this->default = false; + } + + $this->type = $system->getRequest('type', __("Type")); + if (($this->type === __("Type")) || ($this->type == 0)) { + $this->type = 0; + } + else { + $this->default = false; + } + } + + public function show() { + if (!$this->correct_acl) { + $this->show_fail_acl(); + } + else { + $this->getFilters(); + $this->show_networkmaps(); + } + } + + private function show_fail_acl() { + $error['title_text'] = __('You don\'t have access to this page'); + $error['content_text'] = __('Access to this page is restricted to authorized users only, please contact system administrator if you need assistance.

Please know that all attempts to access this page are recorded in security logs of Pandora System Database'); + $home = new Home(); + $home->show($error); + } + + private function show_networkmaps() { + $ui = Ui::getInstance(); + + $ui->createPage(); + $ui->createDefaultHeader(__("PandoraFMS: Networkmaps")); + $ui->showFooter(false); + $ui->beginContent(); + $filter_title = sprintf(__('Filter Networkmaps by %s'), + $this->filterNetworkmapsGetString()); + $ui->contentBeginCollapsible($filter_title); + $ui->beginForm("index.php?page=networkmaps"); + $system = System::getInstance(); + $groups = users_get_groups_for_select( + $system->getConfig('id_user'), "AR", true, true, false, 'id_grupo'); + $options = array( + 'name' => 'group', + 'title' => __('Group'), + 'label' => __('Group'), + 'items' => $groups, + 'selected' => $this->group + ); + $ui->formAddSelectBox($options); + + $networkmap_types = networkmap_get_filter_types(); + $networkmap_types[0] = __('All'); + $options = array( + 'name' => 'type', + 'title' => __('Type'), + 'label' => __('Type'), + 'items' => $networkmap_types, + 'selected' => $this->type + ); + $ui->formAddSelectBox($options); + + $options = array( + 'icon' => 'refresh', + 'icon_pos' => 'right', + 'text' => __('Apply Filter') + ); + $ui->formAddSubmitButton($options); + $html = $ui->getEndForm(); + $ui->contentCollapsibleAddItem($html); + $ui->contentEndCollapsible(); + $this->listNetworkmapsHtml(); + $ui->endContent(); + $ui->showPage(); + } + + private function listNetworkmapsHtml() { + $system = System::getInstance(); + $ui = Ui::getInstance(); + + // Create filter + $where = array(); + // Order by type field + $where['order'] = 'type'; + + if ($this->group != '0') + $where['id_group'] = $this->group; + + if ($this->type != '0') + $where['type'] = $this->type; + + $network_maps = db_get_all_rows_filter('tnetwork_map', + $where); + if (empty($network_maps)) { + $network_maps = array(); + } + $list = array(); + foreach ($network_maps as $networkmap) { + $row = array(); + $row[__('Name')] = '' . io_safe_output($networkmap['name']) . ''; + $row[__('Type')] = $networkmap['type']; + $row[__('Group')] = ui_print_group_icon($networkmap["id_group"], true); + $list[] = $row; + } + + if (count($network_maps) == 0) { + $ui->contentAddHtml('

' . __('No networkmaps') . '

'); + } + else { + $table = new Table(); + $table->id = 'list_networkmaps'; + $table->importFromHash($list); + $ui->contentAddHtml($table->getHTML()); + } + } + + private function filterNetworkmapsGetString() { + if ($this->default) { + return __("(Default)"); + } + else { + $networkmap_types = networkmap_get_filter_types(); + $networkmap_types[0] = __('All'); + $type = $networkmap_types[$this->type]; + $group = groups_get_name($this->group, true); + + + $string = sprintf( + __("(Type: %s - Group: %s)"), + $type, $group); + + return $string; + } + } +} +?> \ No newline at end of file