From 7dbb6706388cd956ba0c670b56b388f8c5b2f8c2 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 13 Jun 2015 22:55:18 +1000 Subject: [PATCH] Factor out getting the list of subtypes; add MIB types which were loaded from database --- html/pages/graphs.inc.php | 23 ++++++----------------- includes/common.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index 89c47aeec..8e438489d 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -45,20 +45,6 @@ if (!$auth) $title .= " :: ".ucfirst($subtype); } - # Load our list of available graphtypes for this object - // FIXME not all of these are going to be valid - if ($handle = opendir($config['install_dir'] . "/html/includes/graphs/".$type."/")) - { - while (false !== ($file = readdir($handle))) - { - if ($file != "." && $file != ".." && $file != "auth.inc.php" &&strstr($file, ".inc.php")) - { - $types[] = str_replace(".inc.php", "", $file); - } - } - closedir($handle); - } - $graph_array = $vars; $graph_array['height'] = "60"; $graph_array['width'] = $thumb_width; @@ -75,11 +61,14 @@ if (!$auth) onchange="window.open(this.options[this.selectedIndex].value,'_top')" > $type."_".$avail_type, 'page' => "graphs"))."'"); - if ($avail_type == $subtype) { echo(" selected"); } - echo(">".nicecase($avail_type).""); + if ($avail_type == $subtype) { + echo(" selected"); + } + $display_type = is_mib_graph($type, $avail_type) ? $avail_type : nicecase($avail_type); + echo(">$display_type"); } ?> diff --git a/includes/common.php b/includes/common.php index 43c24d97f..18abd43d1 100644 --- a/includes/common.php +++ b/includes/common.php @@ -695,4 +695,39 @@ function is_client_authorized($clientip) return false; } +/* + * @return an array of all graph subtypes for the given type + * FIXME not all of these are going to be valid + */ +function get_graph_subtypes($type) +{ + global $config; + + $types = array(); + + // find the subtypes defined in files + if ($handle = opendir($config['install_dir'] . "/html/includes/graphs/$type/")) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != ".." && $file != "auth.inc.php" && strstr($file, ".inc.php")) { + $types[] = str_replace(".inc.php", "", $file); + } + } + closedir($handle); + } + + // find the MIB subtypes + foreach ($config['graph_types'] as $type => $unused1) { + print_r($type); + foreach ($config['graph_types'][$type] as $subtype => $unused2) { + print_r($subtype); + if (is_mib_graph($type, $subtype)) { + $types[] = $subtype; + } + } + } + + sort($types); + return $types; +} + ?>