2 #################################################################################
4 # File: $RCSfile: processaction.cgi,v $
5 # Revision: $Revision: 1.1 $
6 # Description: Process the action
7 # Author: Andrew@DeFaria.com
8 # Created: Mon Jan 16 20:25:32 PST 2006
9 # Modified: $Date: 2013/06/12 14:05:47 $
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
20 use lib "$FindBin::Bin/../lib";
21 use lib "$FindBin::Bin/../../lib";
26 use CGI qw (:standard *table start_Tr end_Tr);
27 use CGI::Carp 'fatalsToBrowser';
29 my $type = param 'type';
30 my $action = param 'action';
31 my $next = param 'next';
32 my $userid = cookie 'MAPSUser';
35 my $table_name = 'list';
37 my @scripts = ('ListActions.js');
39 sub ReturnSequenceNbrs {
45 push @sequence_nbrs, $1;
49 return @sequence_nbrs;
50 } # ReturnSequenceNbrs
55 my @sequence_nbrs = ReturnSequenceNbrs;
59 for (@sequence_nbrs) {
60 my ($err, $msg) = DeleteList(
66 # How to best handle error?
67 croak $msg if $err < 0;
73 DisplayError('Nothing to delete!');
81 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted entry");
83 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted $count entries");
90 sub PrintInputLine ($$$$$) {
91 my ($nextseq, $email_nbr, $leftclass, $dataclass, $rightclass) = @_;
99 if (defined $email_nbr && $email_nbr ne '') {
100 $email = param "email$email_nbr";
101 if ($email && $email ne '') {
102 ($pattern, $domain) = split /\@/, $email;
105 $hit_count = CountEmail(
107 additional => "sender like '%$email%'",
112 td {-class => $leftclass,
113 -align => 'center'}, "$nextseq",
114 td {-class => $dataclass,
116 (textfield {-class => 'inputfieldright',
117 -style => 'width:100%',
120 -name => "pattern$nextseq",
121 -value => $pattern}),
122 td {-class => $dataclass,
123 -align => 'center'}, '@',
124 td {-class => $dataclass},
125 (textfield {-class => 'inputfield',
126 -style => 'width:100%',
129 -name => "domain$nextseq",
131 td {-class => $dataclass},
132 (textfield {-class => 'inputfieldright',
133 -style => 'width:100%',
136 -name => "hit_count$nextseq",
137 -value => $hit_count}),
138 td {-class => $dataclass},
139 (textfield {-class => 'inputfieldright',
140 -style => 'width:100%',
143 -name => "retention$nextseq",
144 -value => $retention}),
145 td {-class => $rightclass},
146 (textfield {-class => 'inputfield',
147 -style => 'width:100%',
150 -name => "comment$nextseq",
158 my ($type, @selected) = @_;
160 # First display the last page and add the appropriate number of
161 # empty, editable entries (possibly filled in) for the user to add
163 my $selected = @selected;
164 my $nextseq = GetNextSequenceNo(
169 my $next = ($nextseq - $lines) + $selected - 1;
171 $next = 0 if $next < 0;
173 my $Type = ucfirst $type;
185 NavigationBar($userid);
187 # Now display table and new entry
190 -action => "add2${type}list.cgi",
194 print start_table {-align => 'center',
201 th {-class => 'tableleftend'}, 'Seq',
202 th {-class => 'tableheader'}, 'Username',
203 th {-class => 'tableheader'}, '@',
204 th {-class => 'tableheader'}, 'Domain',
205 th {-class => 'tableheader'}, 'Hit Count',
206 th {-class => 'tableheader'}, 'Retention',
207 th {-class => 'tablerightend'}, 'Comments',
210 my $list = ReturnList(
219 for my $record (@$list) {
223 $record->{pattern} //= ' ';
224 $record->{domain} //= ' ';
225 $record->{comment} //= ' ';
226 $record->{hit_count} //= ' ';
227 $record->{retention} //= ' ';
230 td {-class => 'tableleftdata', -align => 'center'}, $record->{sequence},
231 td {-class => 'tabledata', -align => 'right'}, $record->{pattern},
232 td {-class => 'tabledata', -align => 'center'}, '@',
233 td {-class => 'tabledata', -align => 'left'}, $record->{domain},
234 td {-class => 'tabledata', -align => 'right'}, $record->{hit_count},
235 td {-class => 'tabledata', -align => 'right'}, $record->{retention},
236 td {-class => 'tablerightdata', -align => 'left'}, $record->{comment},
240 # Now the input line(s)
241 if (@selected == 0) {
242 PrintInputLine($nextseq, undef, 'tablebottomleft', 'tablebottomdata',
246 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
247 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
248 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
250 PrintInputLine($nextseq++, $_, $leftclass, $dataclass, $rightclass);
257 submit ({-name => 'update',
259 -onClick => 'return CheckEntry (document.list);'}),
260 submit ({-name => 'Reset',
262 -onClick => 'history.back(); return false'}),
272 my @selected = ReturnSequenceNbrs;
274 my $Type = ucfirst $type;
286 NavigationBar($userid);
288 # Redisplay the page but open up the lines that are getting modified
291 -action => 'modifyentries.cgi',
295 # Print some hidden fields to pass along
296 print hidden ({-name => 'type', -default => $type}),
297 hidden ({-name => 'next', -default => $next});
299 print start_table {-align => 'center',
306 th {-class => 'tableleftend'}, 'Seq',
307 th {-class => 'tableheader'}, 'Username',
308 th {-class => 'tableheader'}, '@',
309 th {-class => 'tableheader'}, 'Domain',
310 th {-class => 'tableheader'}, 'Hit Count',
311 th {-class => 'tableheader'}, 'Retention',
312 th {-class => 'tablerightend'}, 'Comments',
315 my $list = ReturnList(
325 for my $record (@$list) {
326 my $leftclass = ($i == @$list || $record->{sequence} eq $total) ?
327 'tablebottomleft' : 'tableleftdata';
328 my $dataclass = ($i == @$list || $record->{sequence} eq $total) ?
329 'tablebottomdata' : 'tabledata';
330 my $rightclass = ($i == @$list || $record->{sequence} eq $total) ?
331 'tablebottomright' : 'tablerightdata';
336 td {-class => $leftclass,
337 -align => 'center'}, $record->{sequence};
339 if ($selected[$s] and $record->{sequence} eq $selected[$s]) {
342 $record->{pattern} //= '';
343 $record->{domain} //= '';
344 $record->{comment} //= '';
345 $record->{hit_count} //= '';
346 $record->{retention} //= '';
349 td {-class => $dataclass,
351 (textfield {-class => 'inputfieldright',
352 -style => 'width:100%',
356 -name => "pattern$record->{sequence}",
357 -value => $record->{pattern}}),
358 td {-class => $dataclass,
359 -align => 'center'}, '@',
360 td {-class => $dataclass},
361 (textfield {-class => 'inputfield',
362 -style => 'width:100%',
366 -name => "domain$record->{sequence}",
367 -value => $record->{domain}}),
368 td {-class => $dataclass},
369 (textfield {-class => 'inputfieldright',
370 -style => 'width:100%',
374 -name => "hit_count$record->{sequence}",
375 -value => $record->{hit_count}}),
376 td {-class => $dataclass},
377 (textfield {-class => 'inputfieldright',
378 -style => 'width:100%',
382 -name => "retention$record->{sequence}",
383 -value => $record->{retention}}),
384 td {-class => $rightclass},
385 (textfield {-class => 'inputfield',
386 -style => 'width:100%',
390 -name => "comment$record->{sequence}",
391 -value => $record->{comment}});
394 # Put in ' ' for undefined fields
395 $record->{pattern} //= ' ';
396 $record->{domain} //= ' ';
397 $record->{comment} //= ' ';
398 $record->{hit_count} //= ' ';
399 $record->{retention} //= ' ';
402 td {-class => $dataclass,
403 -align => 'right'}, $record->{pattern},
404 td {-class => $dataclass,
405 -align => 'center'}, '@',
406 td {-class => $dataclass,
407 -align => 'left'}, $record->{domain},
408 td {-class => $dataclass,
409 -align => 'right'}, $record->{hit_count},
410 td {-class => $dataclass,
411 -align => 'right'}, $record->{retention},
412 td {-class => $rightclass,
413 -align => 'left'}, $record->{comment};
422 submit ({-name => 'update',
424 -onClick => 'return CheckEntry (document.list);'}),
425 submit ({-name => 'Reset',
427 -onClick => 'history.back(); return false'}),
434 sub WhitelistMarked {
435 AddNewEntry('white', ReturnSequenceNbrs);
440 sub BlacklistMarked {
441 AddNewEntry('black', ReturnSequenceNbrs);
447 AddNewEntry('null', ReturnSequenceNbrs);
453 $userid ||= $ENV{USER};
457 my %options = GetUserOptions($userid);
459 $lines = $options{'Page'};
466 if ($action eq 'Add') {
468 } elsif ($action eq 'Delete') {
469 DeleteEntries($type);
470 } elsif ($action eq 'Modify') {
471 ModifyEntries($type);
472 } elsif ($action eq 'Whitelist') {
474 } elsif ($action eq 'Blacklist') {
476 } elsif ($action eq 'Nulllist') {
482 "Unknown action ($action)",
483 "Unknown action ($action)"
486 NavigationBar($userid);
487 DisplayError("Unknown action encountered ($action)");
490 Footing($table_name);