3 use vars qw($dsn $username $password $dbh $query);
4 use vars qw($my_mon $my_year);
6 use vars qw($min_time $max_time $min_mon $max_mon $min_year $max_year );
8 use CGI::Carp qw(fatalsToBrowser);
12 require "/etc/icelog.conf";
15 ($query) = $cgi->keywords;
17 $dbh = DBI->connect($dsn, $username, $password)
18 or die "Can't connect to $dsn: ". $DBI::errstr;
20 if ( $cgi->param('customer') ) {
21 @customers = ( $cgi->param('customer') );
23 my $sth = $dbh->prepare('select distinct customer from icelog')
25 $sth->execute or die $sth->errstr;
26 @customers = map { $_->[0] } @{$sth->fetchall_arrayref};
29 ($my_mon,$my_year) = ($cgi->param('mon'), $cgi->param('year'));
31 my $sth = $dbh->prepare('select min(start), max(start) from icelog')
33 $sth->execute or die $sth->errstr;
34 ( $min_time, $max_time ) = @{$sth->fetchrow_arrayref};
36 ( $min_mon, $min_year ) = (localtime($min_time))[4,5];
37 $min_mon++; $min_year+=1900;
38 ( $max_mon, $max_year ) = (localtime($max_time))[4,5];
39 $max_mon++; $max_year+=1900;
41 my $title = 'icecast log';
42 if ( $my_mon && $my_year ) {
43 $title .= " $my_mon/$my_year";
48 print $cgi->header, <<END;
51 <title>icecast log</title>
53 <body bgcolor="#e8e8e8">
57 for ( my($mon,$year) = ($min_mon, $min_year);
58 $year < $max_year || ( $year == $max_year && $mon <= $max_mon);
59 do { $mon++; if ( $mon == 13 ) { $year++; $mon-=12; } }
61 $cgi->param('year', $year);
62 $cgi->param('mon', $mon);
63 print '<a href="'. $cgi->self_url. qq(">$mon/$year</a> | );
65 $cgi->param('year', '');
66 $cgi->param('mon', '');
67 print '<a href="'. $cgi->self_url. qq(">all</a>);
68 $cgi->param('year', $my_year);
69 $cgi->param('mon', $my_mon);
74 <tr><th>Cust#</th><th>Minutes (live)</th><th>Minutes (archived)</th><th>Minutes (total)</th></tr>
77 foreach my $customer ( @customers ) {
79 my $liveminutes = &getminutes($customer, 'Y', $my_mon, $my_year);
80 my $archminutes = &getminutes($customer, 'N', $my_mon, $my_year);
81 my $totminutes = $liveminutes + $archminutes;
83 $cgi->param('customer', $customer);
84 my $self_url = $cgi->self_url;
86 print qq(<tr><td><a href="$self_url">$customer</a></td><td>$liveminutes</td><td>$archminutes</td><td>$totminutes</td></tr>);
95 my($customer, $liveflag, $mon, $year) = @_;
97 'select sum(seconds) from icelog where customer = ? and liveflag = ?';
98 if ( $mon && $year ) {
99 my $start = timelocal(0,0,0,1,$mon-1,$year-1900);
100 $mon++; if ( $mon == 13 ) { $year++; $mon-=12; }
101 my $end = timelocal(0,0,0,1,$mon-1,$year-1900) - 1;
102 $statement .= " and start >= $start and start <= $end";
105 my $sth = $dbh->prepare($statement) or die $dbh->errstr;
106 $sth->execute($customer, $liveflag) or die $sth->errstr;
107 my $seconds = $sth->fetchrow_arrayref->[0];
109 sprintf("%.3f", $seconds / 60);