From 6877b0f1447c211f1a992487eeaf9bda787c4b71 Mon Sep 17 00:00:00 2001 From: levinse Date: Sat, 29 Jan 2011 02:50:27 +0000 Subject: torrus, RT10574 --- httemplate/view/port_graph.html | 40 ++++++++++++++++++ httemplate/view/svc_port.cgi | 91 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 httemplate/view/port_graph.html create mode 100644 httemplate/view/svc_port.cgi (limited to 'httemplate/view') diff --git a/httemplate/view/port_graph.html b/httemplate/view/port_graph.html new file mode 100644 index 000000000..fc5d0db3f --- /dev/null +++ b/httemplate/view/port_graph.html @@ -0,0 +1,40 @@ +% if ($error) { warn $error; } +% else { +<% $png %> +% } +<%init> + +# NOTE: the weird warn/die stuff here is because this file is accessed as +# IMG SRC="port_graph.html" - easier than hacking an uglier solution + +unless ( $FS::CurrentUser::CurrentUser->access_right('View customer services') ) { + warn "access denied"; + die; +} + +my $svcnum = $cgi->param('svcnum'); +unless ( $svcnum =~ /^\d+$/ ) { + warn 'invalid svcnum'; + die; +} + +my $start = $cgi->param('start'); +my $end = $cgi->param('end'); +unless ( $start =~ /^\d+$/ && $end =~ /^\d+$/ ) { + warn 'invalid start and/or end times'; + die; +} + +my $svc_port = qsearchs('svc_port', { 'svcnum' => $svcnum }); +unless($svc_port) { + warn 'invalid svc_port'; + die; +} + +my $error = ''; +my $png = $svc_port->graph_png('start' => $start, 'end' => $end); +$error = 'error from graph_png: '.$png if length($png) < 200; + +http_header('Content-Type' => 'image/png') unless($error); + + diff --git a/httemplate/view/svc_port.cgi b/httemplate/view/svc_port.cgi new file mode 100644 index 000000000..84d0e49e3 --- /dev/null +++ b/httemplate/view/svc_port.cgi @@ -0,0 +1,91 @@ +<% include('elements/svc_Common.html', + 'table' => 'svc_port', + 'fields' => \@fields, + 'labels' => \%labels, + 'html_foot' => $html_foot, + ) +%> +<%init> + +use Date::Parse 'str2time'; + +my $conf = new FS::Conf; +my $date_format = $conf->config('date_format') || '%m/%d/%Y'; + +my $fields = FS::svc_port->table_info->{'fields'}; +my %labels = map { $_ => ( ref($fields->{$_}) + ? $fields->{$_}{'label'} + : $fields->{$_} + ); + } keys %$fields; +my @fields = keys %$fields; + +my $svcnum; +if ( $cgi->param('svcnum') ) { + $cgi->param('svcnum') =~ /^(\d+)$/ or die "unparsable svcnum"; + $svcnum = $1; +} else { + my($query) = $cgi->keywords; + $query =~ /^(\d+)$/ or die "no svcnum"; + $svcnum = $1; +} + +my $start = ''; +my $end = ''; +if ( $cgi->param('start') && $cgi->param('end') ) { + $start = $cgi->param('start'); + $end = $cgi->param('end'); +} + +sub preset_range { + my($start,$end,$label,$date_format) = (shift,shift,shift,shift); + warn "$start $end $date_format"; + $start = time2str($date_format,$start); + $end = time2str($date_format,$end); + return ''.$label.''; +} + +my $html_foot = sub { + my $default_end = time; + my $default_start = $default_end-86400; + my $graph = ''; + + if($start && $end) { + $graph = "

"; + } + + return ' + +
+ + Bandwidth Graph
+  '.preset_range($default_start,$default_end,'Last Day',$date_format) + .' | '.preset_range($default_end-86400*7,$default_end,'Last Week',$date_format) + .' | '.preset_range($default_end-86400*30,$default_end,'Last Month',$date_format) + .' | '.preset_range($default_end-86400*365,$default_end,'Last Year',$date_format) + .'
+ ' + . include('/elements/tr-input-date-field.html', { + 'name' => 'start', + 'label' => 'Start Date', + 'value' => $start, + }) + . include('/elements/tr-input-date-field.html', { + 'name' => 'end', + 'label' => 'End Date', + 'noinit' => 1, + 'value' => $end, + }) + . ' +
+
'.$graph; +}; + + -- cgit v1.2.1