More changes to quickstats.
[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 start_div end_div);
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_div {-id => 'highlightrow'};
45
46   print start_table ({-align       => 'center',
47                       -id          => $table_name,
48                       -border      => 0,
49                       -cellspacing => 0,
50                       -cellpadding => 2,
51                       -cols        => 9,
52                       -width       => '100%'});
53   print start_Tr {-valign => 'bottom'};
54   print th {-class => 'tableleftend'}, 'Date';
55
56   for (@Types) {
57     print th {-class => 'tableheader'}, ucfirst;
58   } # for
59
60   print th {-class => 'tablerightend'}, 'Total';
61
62   my %dates = GetStats(
63     userid => $userid,
64     days   => $nbr_days,
65     date   => $date
66   );
67   my %totals;
68
69   for my $date (sort {$b cmp $a} (keys (%dates))) {
70     print start_Tr;
71     print td {-class => 'tablerightleftdata',
72               -align => 'center'}, FormatDate $date, 1;
73
74     my $day_total = 0;
75
76     for (@Types) {
77       my $value = $dates{$date}{$_};
78       if ($value == 0) {
79         print td {-class => 'tabledata'}, ' ';
80       } else {
81         print td {-class => 'tabledata',
82                   -align => 'center'},
83               a {-href => "detail.cgi?type=$_;date=$date"},
84                  $value;
85       } # if
86       $totals{$_} += $value;
87       $day_total  += $value;
88     } # for
89
90     if ($day_total == 0) {
91       print td {-class => 'tableleftrightdata'}, ' ';
92     } else {
93       print td {-class => 'tableleftrightdata',
94                 -align => 'center'}, $day_total;
95     } # if
96
97     print end_Tr;
98   } # for
99
100   my $grand_total = 0;
101
102   print start_Tr;
103   print th {-class => 'tablebottomlefttotal'}, 'Totals';
104
105   for (@Types) {
106     if ($totals{$_} == 0) {
107       print td {-class => 'tablebottomtotal'}, ' ';
108     } else {
109       print td {-class => 'tablebottomtotal',
110                 -align => 'center'},
111             a {-href => "detail.cgi?type=$_"}, $totals{$_};
112     } # if
113
114     $grand_total += $totals{$_};
115   } # for
116
117   print td {-class => 'tablebottomrighttotal',
118             -align => 'center'}, $grand_total;
119
120   print end_Tr;
121   print end_table;
122   print end_div;
123
124   return;
125 } # Body
126
127 # Main
128 my $userid = Heading (
129   'getcookie',
130   '',
131   'Statistics',
132   'Statistics',
133   '',
134   $table_name
135 );
136
137 $userid //= $ENV{USER};
138
139 SetContext($userid);
140
141 unless ($nbr_days) {
142   my %options = GetUserOptions $userid;
143   $nbr_days = $options{Dates};
144 } # unless
145
146 NavigationBar($userid);
147
148 Body($userid);
149
150 Footing($table_name);
151
152 exit;