[freeside-commits] freeside/httemplate/view port_graph.html, NONE, 1.1 svc_port.cgi, NONE, 1.1
Erik Levinson
levinse at wavetail.420.am
Fri Jan 28 18:50:29 PST 2011
Update of /home/cvs/cvsroot/freeside/httemplate/view
In directory wavetail.420.am:/tmp/cvs-serv31698/httemplate/view
Added Files:
port_graph.html svc_port.cgi
Log Message:
torrus, RT10574
--- NEW FILE: svc_port.cgi ---
<% 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 '<A HREF="javascript:void(0);" onclick="preset_range(\''
.$start.'\',\''.$end.'\')">'.$label.'</A>';
}
my $html_foot = sub {
my $default_end = time;
my $default_start = $default_end-86400;
my $graph = '';
if($start && $end) {
$graph = "<BR><BR><IMG SRC=${p}/view/port_graph.html?svcnum=$svcnum;".
"start=".str2time($start).";end=".str2time($end).">";
}
return '
<script type="text/javascript">
function preset_range(start,end){
document.getElementById(\'start_text\').value = start;
document.getElementById(\'end_text\').value = end;
}
</script>
<FORM ACTION=? METHOD="GET">
<INPUT TYPE="HIDDEN" NAME="svcnum" VALUE="'.$svcnum.'">
<B>Bandwidth Graph</B><BR>
'.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)
.' <BR>
<TABLE>'
. 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,
})
. '<TR><TD colspan="2"><input type="submit" value="Display"></TR>
</TABLE>
</FORM>'.$graph;
};
</%init>
--- NEW FILE: port_graph.html ---
% 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);
</%init>
More information about the freeside-commits
mailing list