1 # Copyright (C) 2005 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: ReportOutput.pm,v 1.1 2010-12-27 00:03:40 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 # Package for generating report output to HTML, PDF, whatever
21 # Media-specific classes should inherit from this package
24 package Torrus::ReportOutput;
29 use Torrus::SQL::Reports;
30 use Torrus::ServiceID;
39 bless ($self, $class);
41 $self->{'options'} = $options;
42 defined( $self->{'options'}->{'Tree'} ) or die;
44 my $sqlRep = Torrus::SQL::Reports->new( $options->{'ReportsSqlSubtype'} );
45 if( not defined( $sqlRep ) )
47 Error('Cannot connect to the database');
50 $self->{'backend'} = $sqlRep;
52 my $outdir = $Torrus::Global::reportsDir . '/' .
53 $self->{'options'}->{'Tree'};
54 $self->{'outdir'} = $outdir;
58 if( not mkdir( $outdir ) )
60 Error('Cannot create directory ' . $outdir . ': ' . $!);
68 # initialize the subclasses' internals
83 my %monthlyReportNames;
86 if( not $self->{'options'}->{'All_Service_IDs'} )
88 my $srvId = new Torrus::ServiceID;
89 $srvIdList = $srvId->getAllForTree( $self->{'options'}->{'Tree'} );
92 my $allReports = $self->{'backend'}->getAllReports( $srvIdList );
94 # frontpage, title, list of years, etc.
95 $self->genIntroduction( $allReports );
97 while( my( $year, $yearRef ) = each %{$allReports} )
99 my $monthlyReportFields = {};
100 my $srvidMonthlyFields = {};
102 while( my( $month, $monthRef ) = each %{$yearRef} )
104 my $dailyReportFields = {};
106 while( my( $day, $dayRef ) = each %{$monthRef} )
108 while( my( $reportName, $fieldsRef ) = each %{$dayRef} )
110 # Check if the report is monthly
111 if( not defined( $monthlyReportNames{$reportName} ) )
114 $Torrus::ReportGenerator::modules{$reportName};
115 eval( 'require ' . $class );
118 $monthlyReportNames{$reportName} =
119 $class->isMonthly() ? 1:0;
122 # This report is monthly -- do not include it in daily
124 if( $monthlyReportNames{$reportName} )
126 $monthlyReportFields->{$month}{$reportName} =
128 while( my( $serviceid, $fref ) = each %{$fieldsRef} )
130 $srvidMonthlyFields->{$serviceid}{$reportName}->{
136 $dailyReportFields->{$day} = $dayRef;
141 $ok = $self->genDailyOutput( $year, $month, $dailyReportFields )?
145 $ok = $self->genSrvIdOutput( $year, $srvidMonthlyFields ) ? $ok:0;
146 $ok = $self->genMonthlyOutput( $year, $monthlyReportFields ) ? $ok:0;;
153 # Print the head page and years reference
157 my $allReports = shift;
163 # Print monthly report for a given service ID
164 # The fields argument is a hash of hashes:
165 # serviceid => reportname => month => fieldname => {value, units}
177 # day => reportname => serviceid => fieldname => {value, units}
188 # Print monthly report
190 # month => reportname => serviceid => fieldname => {value, units}
208 # indent-tabs-mode: nil
209 # perl-indent-level: 4