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