commit 515615477f5f1d30b07672bd3bf35a8245a0799b
Author: Hamish Coleman <colemah3@osiris.localdomain>
Date:   Thu Jun 7 15:25:09 2007 +1000

    ensure that all forms of the interface work similarly

diff --git a/mrtg.cgi b/mrtg.cgi
index f8b1b7b..82b2e94 100755
--- a/mrtg.cgi
+++ b/mrtg.cgi
@@ -196,15 +196,8 @@ sub init_lists(@) {
 	return $l;
 }
 
-sub print_menu_table($$) {
-	my ($lists,$style) = @_;
-
-	my $target;
-	if ($style eq 'wide') {
-		$target="_self";
-	} else {
-		$target="basefrm";
-	}
+sub print_menu_table($$$$) {
+	my ($lists,$style,$target,$page) = @_;
 
 	print "\n<table border=2 cellpadding=2 cellspacing=0 style=\"margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;\">\n";
 
@@ -231,7 +224,7 @@ sub print_menu_table($$) {
 		}
 		print " <td valign=top>\n";
 		for my $j (sort keys %{$lists->{$i}}) {
-			print "  ".a({-href=>"?page=list&list=$i,$j",-target=>$target},"$j")."<br>\n";
+			print "  ".a({-href=>"?page=$page&list=$i,$j",-target=>$target},"$j")."<br>\n";
 		}
 		print " </td>\n";
 
@@ -252,6 +245,7 @@ sub print_treemenu($) {
 
 	print "USETEXTLINKS = 1\n";
 	print "STARTALLOPEN = 0\n";
+	print "HIGHLIGHT = 1\n";
 	print "ICONPATH = ''\n";
 	print 'foldersTree = gFld("<i>MRTG Tree</i>", "javascript:parent.op()")',"\n";
 	print 'foldersTree.treeID = "Frameset"',"\n";
@@ -305,40 +299,41 @@ sub print_list($$$) {
 	return 1;
 }
 
-sub print_graph_chooser($$) {
-	my ($this_graph,$selfurl) = @_;
+sub print_graph_chooser($$$$) {
+	my ($this_graph,$list,$page,$changepage) = @_;
 
-	$selfurl .= 'page=list&';
+	my $selfurl = "?page=$page&list=$list&";
 
 	if ($this_graph eq 'day') {
 		print 'Daily';
 	} else {
-		print a({-href=>$selfurl.'graph=day&',-target=>'_self'}, 'Daily');
+		print a({-href=>$selfurl.'graph=day',-target=>'_self'}, 'Daily');
 	}
 	print '&nbsp;';
 	if ($this_graph eq 'week') {
 		print 'Weekly';
 	} else {
-		print a({-href=>$selfurl.'graph=week&',-target=>'_self'}, 'Weekly')
+		print a({-href=>$selfurl.'graph=week',-target=>'_self'}, 'Weekly')
 	}
 	print '&nbsp;';
 	if ($this_graph eq 'month') {
 		print 'Monthly';
 	} else {
-		print a({-href=>$selfurl.'graph=month&',-target=>'_self'}, 'Monthly')
+		print a({-href=>$selfurl.'graph=month',-target=>'_self'}, 'Monthly')
 	}
 	print '&nbsp;';
 	if ($this_graph eq 'year') {
 		print 'Yearly';
 	} else {
-		print a({-href=>$selfurl.'graph=year&',-target=>'_self'}, 'Yearly')
+		print a({-href=>$selfurl.'graph=year',-target=>'_self'}, 'Yearly')
 	}
 	print '&nbsp;';
 
 	print '&nbsp;';
-	print a({-href=>'?'}, 'Change List'),
-		'&nbsp;',
-		'(This List is ',param('list'),")\n";
+	if (defined $changepage) {
+		print a({-href=>"?page=$changepage"}, 'Change List'), '&nbsp;';
+	}
+	print '(This List is ',param('list'),")\n";
 }
 
 my $page = param('page') || 'treeview';
@@ -351,7 +346,7 @@ if($page eq 'frame') {
 	print "<html><head><title>$this_host MRTG Index (V$VERSION)</title></head>\n";
 	print '<frameset cols="200,*">';
 	print '<frame src="?page=menu" name=treeframe>';
-	print '<frame src="?page=list&list=OTHER,OTHER" name=basefrm>';
+	print '<frame src="?page=list&list=" name=basefrm>';
 	print "</frameset>\n";
 	print "</html>\n";
 
@@ -382,15 +377,17 @@ if($page eq 'frame') {
 	$refresh = $interval if $refresh <= $guardband;
 	my $expires = gmtime (time + $interval * 2 + $guardband);
 
+	my $list = param('list');
 	my $graph = param('graph') || 'day';
-	my $selfurl ='?list='.param('list').'&';
 
 	print
 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
-	print_graph_chooser($graph,$selfurl);
-	print "<br/>";
-	print_list($lists,$graph,param('list')||'none');
+	if ($list) {
+		print_graph_chooser($graph,$list,$page,'none');
+		print "<br/>";
+		print_list($lists,$graph,$list);
+	}
 	print end_html;
 } elsif($page eq 'menu') {
 	print header,
@@ -399,7 +396,7 @@ if($page eq 'frame') {
 
 	@tests = init_tests(@config_files);
 	$lists = init_lists(@tests);
-	print_menu_table($lists,'high');
+	print_menu_table($lists,'high','basefrm','list');
 	print end_html;
 } elsif($page eq 'treemenu') {
 	print header,
@@ -420,7 +417,9 @@ if($page eq 'frame') {
 	print hr;
 	print a({-href=>"?page=none",-target=>"_top"}, "Old menu");
 	print br;
-	print a({-href=>"?page=frame",-target=>"_top"}, "Basic frame");
+	print a({-href=>"?page=noframe",-target=>"_top"}, "No frames");
+	print br;
+	print a({-href=>"?page=frame",-target=>"_top"}, "Basic frames");
 
 	print end_html;
 } elsif($page eq 'noframe') {
@@ -439,10 +438,9 @@ if($page eq 'frame') {
 	$refresh = $interval if $refresh <= $guardband;
 	my $expires = gmtime (time + $interval * 2 + $guardband);
 
+	my $list = param('list');
 	my $graph = param('graph') || 'day';
 
-	my $selfurl.='list='.param('list').'&';
-
 	print
 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
@@ -450,12 +448,14 @@ if($page eq 'frame') {
 	print "<table cellpadding=2 cellspacing=0>\n";
 
 	print "<tr><td valign=top>";
-	print_menu_table($lists,'high');
+	print_menu_table($lists,'high','_self','noframe');
 
 	print "<td valign=top>\n";
-	print_graph_chooser($graph,$selfurl);
-	print "<br/>";
-	print_list($lists,$graph,param('list'));
+	if ($list) {
+		print_graph_chooser($graph,$list,$page,'noframe');
+		print "<br/>";
+		print_list($lists,$graph,param('list'));
+	}
 
 	print "</table>\n";
 	print end_html;
@@ -471,7 +471,7 @@ if($page eq 'frame') {
 		{-width=>"100\%"},
 		TR(td("Select which list to show"))
 	);
-	print_menu_table($lists,'wide');
+	print_menu_table($lists,'wide','_self','list');
 	print "\n","Direct questions and feedback to ",
 		a({-href=>"mailto:hamish\@zot.org"}, "Hamish"),
 		" (Version $VERSION)",
@@ -479,7 +479,7 @@ if($page eq 'frame') {
 
 }
 
-if ($warnings) {
+if ($warnings && param('debug')) {
 	print "<pre>\n", "$warnings", "</pre>\n";
 }
 
