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 = CountMsg($email);
109 td {-class => $leftclass,
110 -align => 'center'}, "$nextseq",
111 td {-class => $dataclass,
113 (textfield {-class => 'inputfieldright',
114 -style => 'width:100%',
117 -name => "pattern$nextseq",
118 -value => $pattern}),
119 td {-class => $dataclass,
120 -align => 'center'}, '@',
121 td {-class => $dataclass},
122 (textfield {-class => 'inputfield',
123 -style => 'width:100%',
126 -name => "domain$nextseq",
128 td {-class => $dataclass},
129 (textfield {-class => 'inputfieldright',
130 -style => 'width:100%',
133 -name => "hit_count$nextseq",
134 -value => $hit_count}),
135 td {-class => $dataclass},
136 (textfield {-class => 'inputfieldright',
137 -style => 'width:100%',
140 -name => "retention$nextseq",
141 -value => $retention}),
142 td {-class => $rightclass},
143 (textfield {-class => 'inputfield',
144 -style => 'width:100%',
147 -name => "comment$nextseq",
155 my ($type, @selected) = @_;
157 # First display the last page and add the appropriate number of
158 # empty, editable entries (possibly filled in) for the user to add
160 my $selected = @selected;
161 my $nextseq = GetNextSequenceNo(
166 my $next = ($nextseq - $lines) + $selected - 1;
168 $next = 0 if $next < 0;
170 my $Type = ucfirst $type;
182 NavigationBar($userid);
184 # Now display table and new entry
187 -action => "add2${type}list.cgi",
191 print start_table {-align => 'center',
198 th {-class => 'tableleftend'}, 'Seq',
199 th {-class => 'tableheader'}, 'Username',
200 th {-class => 'tableheader'}, '@',
201 th {-class => 'tableheader'}, 'Domain',
202 th {-class => 'tableheader'}, 'Hit Count',
203 th {-class => 'tableheader'}, 'Retention',
204 th {-class => 'tablerightend'}, 'Comments',
207 my $list = ReturnList(
216 for my $record (@$list) {
220 $record->{pattern} //= ' ';
221 $record->{domain} //= ' ';
222 $record->{comment} //= ' ';
223 $record->{hit_count} //= ' ';
224 $record->{retention} //= ' ';
227 td {-class => 'tableleftdata', -align => 'center'}, $record->{sequence},
228 td {-class => 'tabledata', -align => 'right'}, $record->{pattern},
229 td {-class => 'tabledata', -align => 'center'}, '@',
230 td {-class => 'tabledata', -align => 'left'}, $record->{domain},
231 td {-class => 'tabledata', -align => 'right'}, $record->{hit_count},
232 td {-class => 'tabledata', -align => 'right'}, $record->{retention},
233 td {-class => 'tablerightdata', -align => 'left'}, $record->{comment},
237 # Now the input line(s)
238 if (@selected == 0) {
239 PrintInputLine($nextseq, undef, 'tablebottomleft', 'tablebottomdata',
243 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
244 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
245 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
247 PrintInputLine($nextseq++, $_, $leftclass, $dataclass, $rightclass);
254 submit ({-name => 'update',
256 -onClick => 'return CheckEntry (document.list);'}),
257 submit ({-name => 'Reset',
259 -onClick => 'history.back(); return false'}),
269 my @selected = ReturnSequenceNbrs;
271 my $Type = ucfirst $type;
283 NavigationBar($userid);
285 # Redisplay the page but open up the lines that are getting modified
288 -action => 'modifyentries.cgi',
292 # Print some hidden fields to pass along
293 print hidden ({-name => 'type', -default => $type}),
294 hidden ({-name => 'next', -default => $next});
296 print start_table {-align => 'center',
303 th {-class => 'tableleftend'}, 'Seq',
304 th {-class => 'tableheader'}, 'Username',
305 th {-class => 'tableheader'}, '@',
306 th {-class => 'tableheader'}, 'Domain',
307 th {-class => 'tableheader'}, 'Hit Count',
308 th {-class => 'tableheader'}, 'Retention',
309 th {-class => 'tablerightend'}, 'Comments',
312 my $list = ReturnList(
322 for my $record (@$list) {
323 my $leftclass = ($i == @$list || $record->{sequence} eq $total) ?
324 'tablebottomleft' : 'tableleftdata';
325 my $dataclass = ($i == @$list || $record->{sequence} eq $total) ?
326 'tablebottomdata' : 'tabledata';
327 my $rightclass = ($i == @$list || $record->{sequence} eq $total) ?
328 'tablebottomright' : 'tablerightdata';
333 td {-class => $leftclass,
334 -align => 'center'}, $record->{sequence};
336 if ($selected[$s] and $record->{sequence} eq $selected[$s]) {
339 $record->{pattern} //= '';
340 $record->{domain} //= '';
341 $record->{comment} //= '';
342 $record->{hit_count} //= '';
343 $record->{retention} //= '';
346 td {-class => $dataclass,
348 (textfield {-class => 'inputfieldright',
349 -style => 'width:100%',
353 -name => "pattern$record->{sequence}",
354 -value => $record->{pattern}}),
355 td {-class => $dataclass,
356 -align => 'center'}, '@',
357 td {-class => $dataclass},
358 (textfield {-class => 'inputfield',
359 -style => 'width:100%',
363 -name => "domain$record->{sequence}",
364 -value => $record->{domain}}),
365 td {-class => $dataclass},
366 (textfield {-class => 'inputfieldright',
367 -style => 'width:100%',
371 -name => "hit_count$record->{sequence}",
372 -value => $record->{hit_count}}),
373 td {-class => $dataclass},
374 (textfield {-class => 'inputfieldright',
375 -style => 'width:100%',
379 -name => "retention$record->{sequence}",
380 -value => $record->{retention}}),
381 td {-class => $rightclass},
382 (textfield {-class => 'inputfield',
383 -style => 'width:100%',
387 -name => "comment$record->{sequence}",
388 -value => $record->{comment}});
391 # Put in ' ' for undefined fields
392 $record->{pattern} //= ' ';
393 $record->{domain} //= ' ';
394 $record->{comment} //= ' ';
395 $record->{hit_count} //= ' ';
396 $record->{retention} //= ' ';
399 td {-class => $dataclass,
400 -align => 'right'}, $record->{pattern},
401 td {-class => $dataclass,
402 -align => 'center'}, '@',
403 td {-class => $dataclass,
404 -align => 'left'}, $record->{domain},
405 td {-class => $dataclass,
406 -align => 'right'}, $record->{hit_count},
407 td {-class => $dataclass,
408 -align => 'right'}, $record->{retention},
409 td {-class => $rightclass,
410 -align => 'left'}, $record->{comment};
419 submit ({-name => 'update',
421 -onClick => 'return CheckEntry (document.list);'}),
422 submit ({-name => 'Reset',
424 -onClick => 'history.back(); return false'}),
431 sub WhitelistMarked {
432 AddNewEntry('white', ReturnSequenceNbrs);
437 sub BlacklistMarked {
438 AddNewEntry('black', ReturnSequenceNbrs);
444 AddNewEntry('null', ReturnSequenceNbrs);
450 $userid ||= $ENV{USER};
454 my %options = GetUserOptions($userid);
456 $lines = $options{'Page'};
463 if ($action eq 'Add') {
465 } elsif ($action eq 'Delete') {
466 DeleteEntries($type);
467 } elsif ($action eq 'Modify') {
468 ModifyEntries($type);
469 } elsif ($action eq 'Whitelist') {
471 } elsif ($action eq 'Blacklist') {
473 } elsif ($action eq 'Nulllist') {
479 "Unknown action ($action)",
480 "Unknown action ($action)"
483 NavigationBar($userid);
484 DisplayError("Unknown action encountered ($action)");
487 Footing($table_name);