Factor out getting the list of subtypes; add MIB types which were loaded from database

This commit is contained in:
Paul Gear
2015-06-13 22:55:18 +10:00
parent da346c3a35
commit 7dbb670638
2 changed files with 41 additions and 17 deletions

View File

@@ -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')" >
<?php
foreach ($types as $avail_type)
foreach (get_graph_subtypes($type) as $avail_type)
{
echo("<option value='".generate_url($vars, array('type' => $type."_".$avail_type, 'page' => "graphs"))."'");
if ($avail_type == $subtype) { echo(" selected"); }
echo(">".nicecase($avail_type)."</option>");
if ($avail_type == $subtype) {
echo(" selected");
}
$display_type = is_mib_graph($type, $avail_type) ? $avail_type : nicecase($avail_type);
echo(">$display_type</option>");
}
?>
</select>

View File

@@ -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;
}
?>