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.
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 # Package for reports generation
21 # Classes should inherit Torrus::ReportGenerator
23 package Torrus
::ReportGenerator
;
31 use Torrus
::SQL
::Reports
;
32 use Torrus
::SQL
::SrvExport
;
41 if( not ref( $options ) or
42 not defined( $options->{'Date'} ) or
43 not defined( $options->{'Time'} ) or
44 not defined( $options->{'Name'} ) )
46 Error
('Missing options in Torrus::Report constructor');
51 bless ($self, $class);
53 # For monthly reports, adjust date and time for the first day of the month
54 if( $self->isMonthly() )
56 $options->{'Time'} = '00:00';
57 my ($ss,$mm,$hh,$day,$month,$year,$zone) =
58 strptime
( $options->{'Date'} );
61 $self->{'StartDate'} = sprintf('%.4d-%.2d-01', $year, $month);
62 $options->{'Date'} = $self->{'StartDate'};
63 $self->{'StartUnixTime'} = str2time
( $self->{'StartDate'} );
64 $self->{'Year'} = $year;
65 $self->{'Month'} = $month;
67 # Count the number of seconds in the month and define the end date
69 my $endmonth = $month + 1;
77 my $enddate = sprintf('%.4d-%.2d-01', $endyear, $endmonth);
78 $self->{'EndDate'} = $enddate;
79 $self->{'EndUnixTime'} = str2time
( $self->{'EndDate'} );
81 $self->{'RangeSeconds'} =
82 $self->{'EndUnixTime'} - $self->{'StartUnixTime'};
85 if( $self->usesSrvExport() )
88 Torrus
::SQL
::SrvExport
->new( $options->{'SrvExportSqlSubtype'} );
89 if( not defined( $srvExp ) )
91 Error
('Cannot connect to the database');
94 $self->{'srvexport'} = $srvExp;
97 $self->{'options'} = $options;
99 my $sqlRep = Torrus
::SQL
::Reports
->new( $options->{'ReportsSqlSubtype'} );
100 if( not defined( $sqlRep ) )
102 Error
('Cannot connect to the database');
105 $self->{'backend'} = $sqlRep;
107 my $reportId = $sqlRep->reportId( $options->{'Date'},
109 $options->{'Name'} );
110 $self->{'reportId'} = $reportId;
112 if( $sqlRep->isComplete( $reportId ) )
114 Error
('Report already exists');
124 die('Virtual method called');
143 # indent-tabs-mode: nil
144 # perl-indent-level: 4