<%doc>
############################################################################
###    (C)opyright 2003 - 2008 RIPE NCC
###    This file is part of DNSMon
###
###    DNSMon is free software: you can redistribute it and/or modify
###    it under the terms of the GNU General Public License as published by
###    the Free Software Foundation, either version 3 of the License, or
###    (at your option) any later version.
###
###    DNSMon is distributed in the hope that it will be useful,
###    but WITHOUT ANY WARRANTY; without even the implied warranty of
###    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
###    GNU General Public License for more details.
###
###    You should have received a copy of the GNU General Public License
###    along with DNSMon.  If not, see <http://www.gnu.org/licenses/>.
############################################################################
</%doc>
<%args>
	$day => '';
	$month => '';
	$year => '';
	$hour => '';
	$period => '24h';
	$domain => 'all';
	$shift =>'0h';
	$af =>'ipv4';
</%args>

<%perl>
	if ($day) {	# escape to a manual plot
		$m->comp('plot', %ARGS);
		return;
	}

	$ARGS{af} = $af;
	$ARGS{domain} = $domain;
	$ARGS{domain} = 'root' if $domain eq 'all';

	my $t2 = $m->comp('/lib/rrdplots:last_val', srv=>'k.root-servers.net');
	my $t = $t2 - $DAY;
</%perl>

<&| /lib/fillform, subs => \%ARGS &>
	<div id="select_domain">
		<form name="Servers" action="/dns-servmon/domain/summary" method="get">
			<& /lib/rrdplots:select_domain, af=>$af &>
			<input type="hidden" name="af" value="<% $ARGS{af} %>" />
			<input type="submit" value="SHOW" name="show" />
			&nbsp;&nbsp;&nbsp;&nbsp; Select domain and click SHOW for individual overview or <a href="<& /lib/url, path => $r->uri, query => {map { $_ => $ARGS{$_}} grep {/^(af)$/} keys %ARGS} &>">view all domains</a>
		</form>
	</div>
</&>
<div id="domain_overview_head">

% if ($domain ne 'all') {
	Domain Overview for <b><% $domain %>.</b> (<% $af %>)
        &nbsp;&nbsp;Click on a plot to show it full size.
% } else {
	<b>Overview of last 24 hours for all monitored domains.</b>  (<% $af %>)
        &nbsp;&nbsp;Click on a plot to show it full size.
% }

</div>

<table id="domain_overview_plots" summary="Overview of domain plots" >
% if ($domain ne 'all') {
% if ($m->comp('/lib/rrdplots:known_domain', domain => $domain, af=>$af)) {
	<tr>
		<td>
			Last 24 Hours<br />
			<& /lib/rrdplots:plot_domain, fuzzy=>1, domain=>$domain, start=>$t, stop=>$t2-1, scale=>'475', af=>$af &>
		</td>
% $m->flush_buffer;
		<td>
			Last 48 Hours<br />
			<& /lib/rrdplots:plot_domain, fuzzy=>1, domain=>$domain, start=>$t - $DAY, stop=>$t2-1, scale=>'475', af=>$af &>
		</td>
	</tr><tr>
% $m->flush_buffer;
		<td>
			Previous 7 days<br />
			<& /lib/rrdplots:plot_domain, fuzzy=>1, domain=>$domain, start=>$t-$DAY*6-($t->epoch%$DAY), stop=>$t2-($t2->epoch%$DAY)-1, scale=>'475', af=> $af &>
		</td>
		<td>
			Previous 14 days<br />
			<& /lib/rrdplots:plot_domain, fuzzy=>1, domain=>$domain, start=>$t-$DAY*13-($t->epoch%$DAY), stop=>$t2-($t2->epoch%$DAY)-1, scale=>'475', af=> $af &>
		</td>
	</tr>
% } else{
	<tr>
		<td>
			<p><strong>This domain has no <% $af %> coverage by DNSMon</strong></p>
		</td>
	</tr>
% }
% $m->flush_buffer;
% } else {
%	my $n = 0;
%	my $afn = $af eq "ipv6" ? &AF_INET6 : &AF_INET;
%	foreach my $d (RIPE::DNSMon::RRD::all_domains($afn)) {
% 		if ($n % 2 == 0) {
%			if ($n) {
	</tr>
%			}
	<tr>
%		}
		<td>
			<% $d %><br />
			<& /lib/rrdplots:plot_domain, fuzzy=>1, domain=>$d, start=>$t, stop=>$t2-1, xscale=>'475', yscale=>'318', af=>$af  &>
		</td>
% $m->flush_buffer;
%	$n++;
%	}
%	if ($n) {
	</tr>
%	}
%}
</table>

<%once>
	use Time::Piece;
	my $DAY = Time::Piece->ONE_DAY;
	my $WEEK = Time::Piece->ONE_WEEK;
</%once>
