%#
%# NAVBAR
%#
<FORM ACTION="<%$r->uri%>" METHOD="GET"><DIV class="navbar">
<SELECT class="navbutton" NAME="t" SIZE=1>
% foreach my $tt (@types_on) { 
    <OPTION VALUE="<%$tt%>" <% $tt eq $arg_t ? 'SELECTED' : ''%>><%$tt%>
% }
</SELECT>
% if ($arg_t eq 'svg') {
<SELECT class="navbutton" NAME="w" SIZE=1>
% foreach my $ww (@w_opts) { 
    <OPTION VALUE="<%$ww%>" <% $ww eq $arg_w ? 'SELECTED' : ''%>><%$ww%>
% }
</SELECT>
<SELECT class="navbutton" NAME="a" SIZE=1>
% foreach my $aa (@a_opts) { 
    <OPTION VALUE="<%$aa|h%>" <% $aa eq $arg_a ? 'SELECTED' : ''%>><%$aa|h%>
% }
</SELECT>
% }
<input class="navbutton" type="submit" value="Update">
<A class="navbutton" HREF="<%$r->uri%>">Reset</A>
<A class="navbutton" HREF="javascript:tlgo('key_view')">Toggle Key</A>
</div></FORM>
%#
%# MAP
%#
%if ($arg_t eq 'svg' and $enabled{svg}) {
%   $m->comp("SELF:netmap_svg", f => $exists{svg});
%} elsif ($enabled{$arg_t}) {
%   $m->comp("SELF:netmap_img", f => $netdisco::CONFIG{"graph_$arg_t"});
%} else {
<h1>Network Map not enabled</h1>
Please edit <tt>netdisco.conf</tt> and run <tt>netdisco -g</tt>.
%}
%#
%# KEY
%#
<div id="key_view" class="hidden">
<TABLE class="netmap-key">
<TR><TH COLSPAN=4>Key</TH></TR>
% for(my $i = 0; $i <= $#{$left_key} || $i <= $#{$right_key}; $i++) {
<tr>
%  if (defined($left_key->[$i])) {
    <td class="mapkey"><%$left_key->[$i]->[0]%></td>
    <td><%$left_key->[$i]->[1]%></td>
%  } else {
    <td colspan="2">&nbsp;</td>
%  }
%  if (defined($right_key->[$i])) {
    <td class="mapkey"><%$right_key->[$i]->[0]%></td>
    <td><%$right_key->[$i]->[1]%></td>
%  } else {
    <td colspan="2">&nbsp;</td>
%  }
</tr>
% }
</TABLE>
</div>
<%args>
$w => 1024
$a => '16:9' # laptop
$t => ''
</%args>
<%shared>
my ($arg_w,$arg_a,$arg_t,$arg_h);
my @types = qw/map png gif svg jpg jpeg/;
my @types_on = ();
my %enabled = ();
my %exists  = ();
my $dir;
</%shared>
<%init>
$arg_w = $w; $arg_a = $a; $arg_t = $t;
$dir = $m->current_comp->source_dir;

# Width / Height handling (SVG only)
my @w_opts = qw/400 600 800 1024 1200 1400/;
my @a_opts = qw/4:3 3:2 16:9/;
$arg_h = (9/16)*$arg_w;
if ($arg_a =~ /^(\d+):(\d+)$/) {
    $arg_h = ($2/$1)*$arg_w;
}

# Hack for default graph
my $default = $netdisco::CONFIG{graph};
my $def_ext;
if (defined $default) {
    $def_ext = $default;
    $def_ext =~ s/^.*\.([^\.]+)$/$1/;
    $netdisco::CONFIG{"graph_$def_ext"} = $netdisco::CONFIG{graph};
}

#
# Check for each type being enabled and created
#
foreach my $type (@types) {
    my $file = $netdisco::CONFIG{"graph_$type"};
    $file =~ s,^.*/,,g; # strip path
    $enabled{$type} = defined $file;
    push(@types_on,$type) if $enabled{$type} and $type ne 'map';
    next unless $enabled{$type};
    my $path = "$dir/$file";
    $exists{$type} = -r $path ? $file : 0;
}

# Select one as default if we haven't selected one
if ($t eq '' or !grep(/^\Q$t\E$/,@types_on)) {
    $t = $netdisco::CONFIG{graph_default} || $def_ext || $types_on[0] || 'svg';
    $arg_t = $t;
}

# Key creation
my $right_key = [
 [ '<span style="color:green;">--------</span>', 'WAN' ],
 [ '<span style="color:#f5deb3;">-------</span>', '10Mbps' ],
 [ '<span style="color:#f5deb3;">=======</span>', '100Mbps' ],
 [ '<span style="color:cyan;">=======</span>', '1.0 Gbps' ] ];

my $left_key = [];
foreach my $map (@{$netdisco::CONFIG{node_map}}) {
        my ($var,$regex,$attr,$val,$name,$label) = split(':',$map);
        next unless $name && $label;
        my ($textcolor) = $netdisco::CONFIG{node_fontcolor} || 'white';
        my ($bracketcolor) = $netdisco::CONFIG{graph_color} || 'white';

        if ($attr eq 'fillcolor') {
                $textcolor = $bracketcolor = $val;
        } elsif ($attr eq 'color') {
                $bracketcolor = $val;
        }
        my($txt) = '<span style="color:' . $bracketcolor . ';">[';
        if ($textcolor ne $bracketcolor) {
                $txt .= '</span><span style="color:' . $textcolor . ';">';
        }
        $txt .= $name;
        if ($textcolor ne $bracketcolor) {
                $txt .= '</span><span style="color:' . $bracketcolor . ';">';
        }
        $txt .= ']</span>';
        push(@{$left_key}, [ $txt, $label ]);
}
my $problem = $netdisco::CONFIG{node_problem} || 'red';
my $colorname = $problem; $colorname =~ s/^./\U$&/;
push(@{$left_key}, [ '<span style="color:' . $problem . ';">[bad-dev]</span>', 'Device Unaccessable' ]);

</%init>
%#
%# netmap_map()
%#
<%method netmap_map>
<%perl>
return unless $enabled{'map'};
unless ($exists{'map'}) {
    $m->comp("SELF:no_file", f => $netdisco::CONFIG{graph_map});
    return;
}
my (@map, $map_age, $secs_per_day, $map_days);
open (MAP, "< $exists{'map'}");
@map = (<MAP>);
close (MAP);
</%perl>
<MAP NAME="netmap">
% foreach my $line (@map){
    <%$line%>
% }
</MAP>
</%method>
%#
%# netmap_img()
%#
<%method netmap_img>
<& SELF:netmap_map &>
% my $file = $exists{$arg_t};
% unless ($file) {
%   $m->comp('SELF:no_file', f=>$netdisco::CONFIG{"graph_$arg_t"});
%   return;  
% }
<IMG SRC="<% $file %>" ISMAP USEMAP="#netmap" style="border: none;" alt="Network Map">
<BR><%$file%> is <&SELF:file_age_days, f=>"$dir/$file"&> days old.
</%method>
%#
%# netmap_svg()
%#
<%method netmap_svg>
<%args>
$f => ''
</%args>
<%perl>
unless ($exists{'svg'}) {
    $m->comp("SELF:no_file", f => $netdisco::CONFIG{graph_svg});
    return;
}
</%perl>
<applet code="net.claribole.zgrviewer.ZGRApplet.class" archive="svg/zvtm-0.9.8.jar,svg/zgrviewer-0.8.2.jar" 
    width="<%$arg_w|h%>" height="<%$arg_h|h%>">
    <param name="type" value="application/x-java-applet;version=1.4" />  
    <param name="width" value="<%$arg_w|h%>" />  
    <param name="height" value="<%$arg_h|h%>" />  
    <param name="svgURL" value="<%$f|h%>" />
    <param name="title" value="Interactive Network Map" />
    <param name="showNavControls" value="true" />
%#  <param name="centerOnLabel" value="main_router">
    <param name="appletBackgroundColor" value="#8b7E66" />
    <param name="graphBackgroundColor" value="#000" />
    <param name="cursorColor" value="#FFF">
    <param name="highlightColor" value="red">
    <param name="antialiased" value="true">
</applet>
<TABLE class="netmap-svgkey">
<TR>
    <TH>Function</TH>
    <TH>Mouse</TH>
    <TH>Keyboard</TH>
</TR>
<TR>
    <TD>Zoom</TD>
    <TD>Mouse Wheel / Shift+Click+Vertical Drag</TD>
    <TD>+ / -<BR>PageUp / PageDown</TD>
</TR>
<TR>
    <TD>Pan</TD>
    <TD>Click+Drag</TD>
    <TD>Arrow Keys</TD>
</TR>
<TR>
    <TD>Open Device</TD>
    <TD COLSPAN=2>Double-Click / Middle Click</TD>
</TR>
<TR>
    <TD>Tool Pallet</TD>
    <TD COLSPAN=2>Move to Top-Left corner</TD>
</TR>
</TABLE>
<UL>
</UL>
</%method>
%#
%# no_file( f=>file )
%#
<%method no_file>
<%args>
$f => ''
</%args>
<h1>Error</h1>
File <%$f|h%> is not accessable.  Please run <tt>netdisco -g</tt>
or use the <a href="admin.html">Admin Panel</A>.
</%method>
%#
%# file_age_days(f => file)
%#
<%method file_age_days>
<%args>
$f => undef
</%args>
<%perl>
return -1 unless -r $f;
my $secs_per_day = 60*60*24;
my $age = (stat($f))[9];
$age = time - $age;
my $days = sprintf("%-2.2f", $age/$secs_per_day);
</%perl>
<%$days|h%>\
</%method>
%#
%# Add javascript routines to header
%#      tl(layer) - Toggles Layer visibility
%#     tlgo(layer,[anchor]) - Toggles layer and goes to anchor,
%#                            default anchor is same as layer
%#
<%method html_head>
<script type="text/javascript">
function tl ( whichLayer ) {
    var elem, vis;
    if ( document.getElementById ) elem = document.getElementById( whichLayer );
    else if ( document.all )       elem = document.all[whichLayer];
    else if ( document.layers )    elem = document.layers[whichLayer];

    vis = elem.style;

    // safari bug -- if hidden doesn't have any properties, so we know it's hidden.
    if (vis == undefined) {
        elem.setStyle('display', 'block');
        return;
    }

    if (vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function tlgo ( whichLayer, anchor ) {
    if (anchor == undefined) anchor = whichLayer;
    tl(whichLayer);
    location.href="#"+anchor;
}
</script>
</%method>
<%method title>
- Network Map \
</%method>
%# $Id: netmap.html,v 1.13 2009/06/10 23:04:32 maxbaker Exp $
%# vim:syntax=mason
