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";
25 use CGI qw (:standard *table start_Tr end_Tr);
26 use CGI::Carp 'fatalsToBrowser';
28 my $type = param 'type';
29 my $action = param 'action';
30 my $next = param 'next';
31 my $userid = cookie 'MAPSUser';
34 my $table_name = 'list';
36 my @scripts = ('ListActions.js');
38 sub ReturnSequenceNbrs {
44 push @sequence_nbrs, $1;
48 return @sequence_nbrs;
49 } # ReturnSequenceNbrs
54 my @sequence_nbrs = ReturnSequenceNbrs;
58 for (@sequence_nbrs) {
59 my ($err, $msg) = DeleteList(
65 # How to best handle error?
66 croak $msg if $err < 0;
72 DisplayError('Nothing to delete!');
80 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted entry");
82 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted $count entries");
89 sub PrintInputLine ($$$$$) {
90 my ($nextseq, $email_nbr, $leftclass, $dataclass, $rightclass) = @_;
98 if (defined $email_nbr && $email_nbr ne '') {
99 $email = param "email$email_nbr";
100 if ($email && $email ne '') {
101 ($pattern, $domain) = split /\@/, $email;
104 $hit_count = CountMsg($email);
108 td {-class => $leftclass,
109 -align => 'center'}, "$nextseq",
110 td {-class => $dataclass,
112 (textfield {-class => 'inputfieldright',
113 -style => 'width:100%',
116 -name => "pattern$nextseq",
117 -value => $pattern}),
118 td {-class => $dataclass,
119 -align => 'center'}, '@',
120 td {-class => $dataclass},
121 (textfield {-class => 'inputfield',
122 -style => 'width:100%',
125 -name => "domain$nextseq",
127 td {-class => $dataclass},
128 (textfield {-class => 'inputfieldright',
129 -style => 'width:100%',
132 -name => "hit_count$nextseq",
133 -value => $hit_count}),
134 td {-class => $dataclass},
135 (textfield {-class => 'inputfieldright',
136 -style => 'width:100%',
139 -name => "retention$nextseq",
140 -value => $retention}),
141 td {-class => $rightclass},
142 (textfield {-class => 'inputfield',
143 -style => 'width:100%',
146 -name => "comment$nextseq",
154 my ($type, @selected) = @_;
156 # First display the last page and add the appropriate number of
157 # empty, editable entries (possibly filled in) for the user to add
159 my $selected = @selected;
160 my $nextseq = GetNextSequenceNo(
165 my $next = ($nextseq - $lines) + $selected - 1;
167 $next = 0 if $next < 0;
169 my $Type = ucfirst $type;
181 NavigationBar($userid);
183 # Now display table and new entry
186 -action => "add2${type}list.cgi",
190 print start_table {-align => 'center',
197 th {-class => 'tableleftend'}, 'Seq',
198 th {-class => 'tableheader'}, 'Username',
199 th {-class => 'tableheader'}, '@',
200 th {-class => 'tableheader'}, 'Domain',
201 th {-class => 'tableheader'}, 'Hit Count',
202 th {-class => 'tableheader'}, 'Retention',
203 th {-class => 'tablerightend'}, 'Comments',
206 my $list = ReturnList(
215 for my $record (@$list) {
219 $record->{pattern} //= ' ';
220 $record->{domain} //= ' ';
221 $record->{comment} //= ' ';
222 $record->{hit_count} //= ' ';
223 $record->{retention} //= ' ';
226 td {-class => 'tableleftdata', -align => 'center'}, $record->{sequence},
227 td {-class => 'tabledata', -align => 'right'}, $record->{pattern},
228 td {-class => 'tabledata', -align => 'center'}, '@',
229 td {-class => 'tabledata', -align => 'left'}, $record->{domain},
230 td {-class => 'tabledata', -align => 'right'}, $record->{hit_count},
231 td {-class => 'tabledata', -align => 'right'}, $record->{retention},
232 td {-class => 'tablerightdata', -align => 'left'}, $record->{comment},
236 # Now the input line(s)
237 if (@selected == 0) {
238 PrintInputLine($nextseq, undef, 'tablebottomleft', 'tablebottomdata',
242 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
243 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
244 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
246 PrintInputLine($nextseq++, $_, $leftclass, $dataclass, $rightclass);
253 submit ({-name => 'update',
255 -onClick => 'return CheckEntry (document.list);'}),
256 submit ({-name => 'Reset',
258 -onClick => 'history.back(); return false'}),
268 my @selected = ReturnSequenceNbrs;
270 my $Type = ucfirst $type;
282 NavigationBar($userid);
284 # Redisplay the page but open up the lines that are getting modified
287 -action => 'modifyentries.cgi',
291 # Print some hidden fields to pass along
292 print hidden ({-name => 'type', -default => $type}),
293 hidden ({-name => 'next', -default => $next});
295 print start_table {-align => 'center',
302 th {-class => 'tableleftend'}, 'Seq',
303 th {-class => 'tableheader'}, 'Username',
304 th {-class => 'tableheader'}, '@',
305 th {-class => 'tableheader'}, 'Domain',
306 th {-class => 'tableheader'}, 'Hit Count',
307 th {-class => 'tableheader'}, 'Retention',
308 th {-class => 'tablerightend'}, 'Comments',
311 my $list = ReturnList(
321 for my $record (@$list) {
322 my $leftclass = ($i == @$list || $record->{sequence} eq $total) ?
323 'tablebottomleft' : 'tableleftdata';
324 my $dataclass = ($i == @$list || $record->{sequence} eq $total) ?
325 'tablebottomdata' : 'tabledata';
326 my $rightclass = ($i == @$list || $record->{sequence} eq $total) ?
327 'tablebottomright' : 'tablerightdata';
332 td {-class => $leftclass,
333 -align => 'center'}, $record->{sequence};
335 if ($selected[$s] and $record->{sequence} eq $selected[$s]) {
338 $record->{pattern} //= '';
339 $record->{domain} //= '';
340 $record->{comment} //= '';
341 $record->{hit_count} //= '';
342 $record->{retention} //= '';
345 td {-class => $dataclass,
347 (textfield {-class => 'inputfieldright',
348 -style => 'width:100%',
352 -name => "pattern$record->{sequence}",
353 -value => $record->{pattern}}),
354 td {-class => $dataclass,
355 -align => 'center'}, '@',
356 td {-class => $dataclass},
357 (textfield {-class => 'inputfield',
358 -style => 'width:100%',
362 -name => "domain$record->{sequence}",
363 -value => $record->{domain}}),
364 td {-class => $dataclass},
365 (textfield {-class => 'inputfieldright',
366 -style => 'width:100%',
370 -name => "hit_count$record->{sequence}",
371 -value => $record->{hit_count}}),
372 td {-class => $dataclass},
373 (textfield {-class => 'inputfieldright',
374 -style => 'width:100%',
378 -name => "retention$record->{sequence}",
379 -value => $record->{retention}}),
380 td {-class => $rightclass},
381 (textfield {-class => 'inputfield',
382 -style => 'width:100%',
386 -name => "comment$record->{sequence}",
387 -value => $record->{comment}});
390 # Put in ' ' for undefined fields
391 $record->{pattern} //= ' ';
392 $record->{domain} //= ' ';
393 $record->{comment} //= ' ';
394 $record->{hit_count} //= ' ';
395 $record->{retention} //= ' ';
398 td {-class => $dataclass,
399 -align => 'right'}, $record->{pattern},
400 td {-class => $dataclass,
401 -align => 'center'}, '@',
402 td {-class => $dataclass,
403 -align => 'left'}, $record->{domain},
404 td {-class => $dataclass,
405 -align => 'right'}, $record->{hit_count},
406 td {-class => $dataclass,
407 -align => 'right'}, $record->{retention},
408 td {-class => $rightclass,
409 -align => 'left'}, $record->{comment};
418 submit ({-name => 'update',
420 -onClick => 'return CheckEntry (document.list);'}),
421 submit ({-name => 'Reset',
423 -onClick => 'history.back(); return false'}),
430 sub WhitelistMarked {
431 AddNewEntry('white', ReturnSequenceNbrs);
436 sub BlacklistMarked {
437 AddNewEntry('black', ReturnSequenceNbrs);
443 AddNewEntry('null', ReturnSequenceNbrs);
449 $userid ||= $ENV{USER};
453 my %options = GetUserOptions($userid);
455 $lines = $options{'Page'};
462 if ($action eq 'Add') {
464 } elsif ($action eq 'Delete') {
465 DeleteEntries($type);
466 } elsif ($action eq 'Modify') {
467 ModifyEntries($type);
468 } elsif ($action eq 'Whitelist') {
470 } elsif ($action eq 'Blacklist') {
472 } elsif ($action eq 'Nulllist') {
478 "Unknown action ($action)",
479 "Unknown action ($action)"
482 NavigationBar($userid);
483 DisplayError("Unknown action encountered ($action)");
486 Footing($table_name);