Added use lib for clearscm
[clearscm.git] / maps / bin / stats.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: stats.cgi,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  This script produces a table of statistics of mail processed for
7 #               the user.
8 # Author:       Andrew@DeFaria.com
9 # Created:      Fri Nov 29 14:17:21  2002
10 # Modified:     $Date: 2013/06/12 14:05:47 $
11 # Language:     perl
12 #
13 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
14 #
15 ################################################################################
16 use strict;
17 use warnings;
18
19 use FindBin;
20
21 local $0 = $FindBin::Script;
22
23 use lib "$FindBin::Bin/../lib";
24 use lib "$FindBin::Bin/../../lib";
25
26 use MAPS;
27 use MAPSLog;
28 use MAPSWeb;
29 use DateUtils;
30
31 use CGI qw (:standard *table start_Tr end_Tr);
32 use CGI::Carp 'fatalsToBrowser';
33
34 my $nbr_days = param('nbr_days');
35 my $date     = param('date');
36
37 my $table_name = 'stats';
38
39 $date = defined $date ? $date : Today2SQLDatetime;
40
41 sub Body($) {
42   my ($userid) = @_;
43
44   print start_table ({-align       => 'center',
45                       -id          => $table_name,
46                       -border      => 0,
47                       -cellspacing => 0,
48                       -cellpadding => 2,
49                       -cols        => 9,
50                       -width       => '100%'});
51   print start_Tr {-valign => 'bottom'};
52   print th {-class => 'tableleftend'}, 'Date';
53
54   for (@Types) {
55     print th {-class => 'tableheader'}, ucfirst;
56   } # for
57
58   print th {-class => 'tablerightend'}, 'Total';
59
60   my %dates = GetStats(
61     userid => $userid,
62     days   => $nbr_days,
63     date   => $date
64   );
65   my %totals;
66
67   for my $date (sort {$b cmp $a} (keys (%dates))) {
68     print start_Tr;
69     print td {-class => 'tablerightleftdata',
70               -align => 'center'}, FormatDate $date, 1;
71
72     my $day_total = 0;
73
74     for (@Types) {
75       my $value = $dates{$date}{$_};
76       if ($value == 0) {
77         print td {-class => 'tabledata'}, ' ';
78       } else {
79         print td {-class => 'tabledata',
80                   -align => 'center'},
81               a {-href => "detail.cgi?type=$_;date=$date"},
82                  $value;
83       } # if
84       $totals{$_} += $value;
85       $day_total  += $value;
86     } # for
87
88     if ($day_total == 0) {
89       print td {-class => 'tableleftrightdata'}, ' ';
90     } else {
91       print td {-class => 'tableleftrightdata',
92                 -align => 'center'}, $day_total;
93     } # if
94
95     print end_Tr;
96   } # for
97
98   my $grand_total = 0;
99
100   print start_Tr;
101   print th {-class => 'tablebottomlefttotal'}, 'Totals';
102
103   for (@Types) {
104     if ($totals{$_} == 0) {
105       print td {-class => 'tablebottomtotal'}, ' ';
106     } else {
107       print td {-class => 'tablebottomtotal',
108                 -align => 'center'},
109             a {-href => "detail.cgi?type=$_"}, $totals{$_};
110     } # if
111
112     $grand_total += $totals{$_};
113   } # for
114
115   print td {-class => 'tablebottomrighttotal',
116             -align => 'center'}, $grand_total;
117
118   print end_Tr;
119   print end_table;
120
121   return;
122 } # Body
123
124 # Main
125 my $userid = Heading (
126   'getcookie',
127   '',
128   'Statistics',
129   'Statistics',
130   '',
131   $table_name
132 );
133
134 $userid //= $ENV{USER};
135
136 SetContext($userid);
137
138 unless ($nbr_days) {
139   my %options = GetUserOptions $userid;
140   $nbr_days = $options{Dates};
141 } # unless
142
143 NavigationBar($userid);
144
145 Body($userid);
146
147 Footing($table_name);
148
149 exit;