Initial add of defaria.com
[clearscm.git] / defaria.com / bin / detail.cgi
1 #!/usr/bin/perl
2 #################################################################################
3 # File:         $RCSfile: detail.cgi,v $
4 # Revision:     $Revision: 1.1 $
5 # Description:  Displays list of email addresses based on report type.
6 # Author:       Andrew@DeFaria.com
7 # Created:      Fri Nov 29 14:17:21  2002
8 # Modified:     $Date: 2013/06/12 14:05:47 $
9 # Language:     perl
10 #
11 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
12 #
13 ################################################################################use strict;
14 use warnings;
15
16 use MIME::Words qw(:all);
17 use FindBin;
18 $0 = $FindBin::Script;
19
20 use lib $FindBin::Bin;
21
22 use MAPS;
23 use MAPSLog;
24 use MAPSUtil;
25 use MAPSWeb;
26 use CGI qw (:standard *table start_td end_td start_Tr end_Tr start_div end_div);
27 use CGI::Carp 'fatalsToBrowser';
28
29 my $type   = param ('type');
30 my $next   = param ('next');
31 my $lines  = param ('lines');
32 my $date   = param ('date');
33
34 $date ||= '';
35
36 my $userid;
37 my $current;
38 my $last;
39 my $prev;
40 my $total;
41 my $table_name = 'detail';
42
43 my %types = (
44   'blacklist'   => [
45     'Blacklist report',
46     'The following blacklisted users attempted to email you'
47   ],
48   'whitelist'   => [
49     'Delivered report',
50     'Delivered email from the following users'
51   ],
52   'nulllist'    => [
53     'Discarded report',
54     'Discarded messages from the following users'
55   ],
56   'error'       => [
57     'Error report',
58     'Errors detected'
59   ],
60   'mailloop'    => [
61     'MailLoop report',
62     'Automatically detected mail loops from the following users'
63   ],
64   'registered'  => [
65     'Registered report',
66     'The following users have recently registered'
67   ],
68   'returned'    => [
69     'Returned report',
70     'Sent Register reply to the following users'
71   ]
72 );
73
74 sub MakeButtons {
75   my $type = shift;
76
77   my $prev_button = $prev >= 0 ?
78     a ({-href => "detail.cgi?type=$type;date=$date;next=$prev"},
79       '<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>') : '';
80   my $next_button = ($next + $lines) < $total ?
81     a {-href => "detail.cgi?type=$type;date=$date;next=" . ($next + $lines)},
82       '<img src=/maps/images/next.gif border=0 alt=Next align=middle>' : '';
83
84   my $buttons = $prev_button;
85
86   if ($type eq 'whitelist') {
87     $buttons = $buttons .
88       submit ({-name    => 'action',
89                -value   => 'Blacklist Marked',
90                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
91       submit ({-name    => 'action',
92                -value   => 'Nulllist Marked',
93                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
94       submit ({-name    => 'action',
95                -value   => 'Reset Marks',
96                -onClick => 'return ClearAll (document.detail);'});
97   } elsif ($type eq 'blacklist') {
98     $buttons = $buttons .
99       submit ({-name    => 'action',
100                -value   => 'Whitelist Marked',
101                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
102       submit ({-name    => 'action',
103                -value   => 'Nulllist Marked',
104                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
105       submit ({-name    => 'action',
106                -value   => 'Reset Marks',
107                -onClick => 'return ClearAll (document.detail);'});
108   } elsif ($type eq 'nulllist') {
109     $buttons = $buttons .
110       submit ({-name    => 'action',
111                -value   => 'Whitelist Marked',
112                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
113       submit ({-name    => 'action',
114                -value   => 'Blacklist Marked',
115                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
116       submit ({-name    => 'action',
117                -value   => 'Reset Marks',
118                -onClick => 'return ClearAll (document.detail);'});
119   } else {
120     $buttons = $buttons .
121       submit ({-name    => 'action',
122                -value   => 'Whitelist Marked',
123                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
124       submit ({-name    => 'action',
125                -value   => 'Blacklist Marked',
126                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
127       submit ({-name    => 'action',
128                -value   => 'Nulllist Marked',
129                -onClick => 'return CheckAtLeast1Checked (document.detail);'}) .
130       submit ({-name    => 'action',
131                -value   => 'Reset Marks',
132                -onClick => 'return ClearAll (document.detail);'});
133   } # if
134
135   return $buttons . $next_button;
136 } # MakeButtons
137
138 sub PrintTable {
139   my ($type) = @_;
140
141   my $current = $next + 1;
142
143   print div {-align => 'center'}, b (
144     '(' . $current . '-' . $last . ' of ' . $total . ')');
145   print start_form {
146     -method => 'post',
147     -action => 'processaction.cgi',
148     -name   => 'detail'
149   };
150   print start_table ({-align        => 'center',
151                       -id           => $table_name,
152                       -border       => 0,
153                       -cellspacing  => 0,
154                       -cellpadding  => 0,
155                       -width        => '100%'}) . "\n";
156
157   my $buttons = MakeButtons $type;
158
159   print start_div {-class => 'toolbar'};
160   print
161     Tr [
162       td {-class  => 'tablebordertopleft',
163           -valign => 'middle'},
164       td {-class  => 'tablebordertopright',
165           -valign => 'middle',
166           -align  => 'center'}, $buttons,
167     ];
168   print end_div;
169
170   foreach my $sender (ReturnSenders $userid, $type, $next, $lines, $date) {
171     my @msgs = ReturnMessages $userid, $sender;
172
173     $next++;
174     print
175       start_Tr {-valign => 'middle'};
176     print
177       td {-class => 'tableborder'}, small ($next,
178         checkbox {-name  => "action$next",
179                   -label => ''}),
180           hidden ({-name     => "email$next",
181                    -default => $sender});
182     print
183       start_td {-align => 'left'};
184     print
185       start_table {-class       => 'tablerightdata',
186                    -cellpadding => 2,
187                    -callspacing => 0,
188                    -border      => 0,
189                    -width       => '100%',
190                    -bgcolor     => '#d4d0c8'};
191     print
192       td {-class => 'tablelabel',
193           -valign => 'middle',
194           -width  => '40'}, 'Sender:',
195       td {-class  => 'sender',
196           -valign => 'middle'},
197       a {-href    => "mailto:$sender"}, $sender;
198     print
199       end_table;
200
201     my $messages = 1;
202
203     foreach (@msgs) {
204       my $msg_date = pop @{$_};
205       my $subject  = pop @{$_};
206
207       if ($date eq substr ($msg_date, 0, 10)) {
208         $msg_date = b font {-color => 'green'}, SQLDatetime2UnixDatetime $msg_date;
209       } else {
210         $msg_date = SQLDatetime2UnixDatetime $msg_date;
211       } # if
212
213       $subject = $subject eq '' ? '&lt;Unspecified&gt;' : $subject;
214       $subject = decode_mimewords ($subject);
215       $subject =~ s/\>/&gt;/g;
216       $subject =~ s/\</&lt;/g;
217
218       print
219         start_table {-class       => 'tablerightdata',
220                      -cellpadding => 2,
221                      -cellspacing => 2,
222                      -border      => 0,
223                      -width       => '100%'};
224       my $msg_nbr = $messages;
225       print
226         Tr [
227           td {-class   => 'msgnbr',
228               -valign  => 'middle',
229               -rowspan => 2,
230               -width   => '2%'}, $messages++,
231           td {-class   => 'tablelabel',
232               -valign  => 'middle',
233               -width   => '45'}, 'Subject:',
234           td {-class   => 'subject',
235               -valign  => 'middle',
236               -bgcolor => '#ffffff'},
237            a {-href    => "display.cgi?sender=$sender;msg_nbr=$msg_nbr"}, $subject,
238           td {-class   => 'date',
239               -width   => '130',
240               -valign  => 'middle'}, $msg_date
241         ];
242       print end_table;
243     } # foreach
244     print end_td;
245     print end_Tr;
246   } # foreach
247
248   print start_div {-class => 'toolbar'};
249   print
250     Tr [
251       td {-class  => 'tableborderbottomleft',
252           -valign => 'middle'},
253       td {-class  => 'tableborderbottomright',
254           -valign => 'middle'},
255       $buttons
256     ];
257   print end_div;
258   print end_table;
259   print end_form;
260 } # PrintTable
261
262 # Main
263 my @scripts = ('ListActions.js');
264
265 my $heading_date =$date ne '' ? ' on ' . FormatDate ($date) : '';
266
267 $userid = Heading (
268   'getcookie',
269   '',
270   (ucfirst ($type) . ' Report'),
271   $types {$type} [0],
272   $types {$type} [1] . $heading_date,
273   $table_name,
274   @scripts
275 );
276
277 $userid ||= $ENV{USER};
278
279 SetContext $userid;
280 NavigationBar $userid;
281
282 unless ($lines) {
283   my %options = GetUserOptions $userid;
284   $lines = $options{'Page'};
285 } # unless
286
287 if ($date eq '') {
288   $condition .= "userid = '$userid' and type = '$type'";
289 } else {
290   my $sod = $date . ' 00:00:00';
291   my $eod = $date . ' 23:59:59';
292
293   $condition .= "userid = '$userid' and type = '$type' "
294               . "and timestamp > '$sod' and timestamp < '$eod' ";
295 } # if
296
297 $total = MAPSDB::count_distinct ('log', 'sender', $condition);
298
299 $next ||= 0;
300
301 $last = $next + $lines < $total ? $next + $lines : $total;
302
303 if (($next - $lines) > 0) {
304   $prev = $next - $lines;
305 } else {
306   $prev = $next eq 0 ? -1 : 0;
307 } # if
308
309 PrintTable $type;
310
311 Footing $table_name;
312
313 exit;