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