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 ################################################################################
19 $0 = $FindBin::Script;
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 foreach (@sequence_nbrs) {
60 $count += DeleteList($type, $_);
64 DisplayError('Nothing to delete!');
66 ResequenceList($userid, $type);
69 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted entry");
71 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted $count entries");
78 sub PrintInputLine ($$$$$) {
79 my ($nextseq, $email_nbr, $leftclass, $dataclass, $rightclass) = @_;
86 if (defined $email_nbr && $email_nbr ne '') {
87 $email = param "email$email_nbr";
88 if ($email && $email ne '') {
89 ($pattern, $domain) = split /\@/, $email;
92 $hit_count = CountMsg($email);
96 td {-class => $leftclass,
97 -align => 'center'}, "$nextseq",
98 td {-class => $dataclass,
100 (textfield {-class => 'inputfield',
101 -style => 'width:100%',
105 -name => "pattern$nextseq",
106 -value => $pattern}),
107 td {-class => $dataclass,
108 -align => 'center'}, '@',
109 td {-class => $dataclass},
110 (textfield {-class => 'inputfield',
111 -style => 'width:100%',
115 -name => "domain$nextseq",
117 td {-class => $dataclass},
118 (textfield {-class => 'inputfield',
119 -style => 'width:100%',
123 -name => "comment$nextseq",
125 td {-class => $rightclass},
126 (textfield {-class => 'inputfield',
127 -style => 'width:100%',
131 -name => "hit_count$nextseq",
132 -value => $hit_count}),
139 my ($type, @selected) = @_;
141 # First display the last page and add the appropriate number of
142 # empty, editable entries (possibly filled in) for the user to add
144 my $selected = @selected;
145 my $nextseq = GetNextSequenceNo($userid, $type);
146 my $next = ($nextseq - $lines) + $selected - 1;
151 my $Type = ucfirst $type;
163 NavigationBar($userid);
165 # Now display table and new entry
168 -action => 'add2' . $type . 'list.cgi',
172 print start_table {-align => 'center',
179 th {-class => 'tableleftend'}, 'Seq',
180 th {-class => 'tableheader'}, 'Username',
181 th {-class => 'tableheader'}, '@',
182 th {-class => 'tableheader'}, 'Domain',
183 th {-class => 'tableheader'}, 'Comments',
184 th {-class => 'tablerightend'}, 'Hit Count'
187 my @list = ReturnList($type, $next, $lines);
197 my $sequence = $record{sequence};
198 my $pattern = $record{pattern} ? $record{pattern} : ' ';
199 my $domain = $record{domain} ? $record{domain} : ' ';
200 my $comment = $record{comment} ? $record{comment} : ' ';
201 my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
204 td {-class => 'tableleftdata',
205 -align => 'center'}, $sequence,
206 td {-class => 'tabledata',
207 -align => 'right'}, $pattern,
208 td {-class => 'tabledata',
209 -align => 'center'}, '@',
210 td {-class => 'tabledata',
211 -align => 'left'}, $domain,
212 td {-class => 'tabledata',
213 -align => 'left'}, $comment,
214 td {-class => 'tablerightdata',
215 -align => 'right'}, $hit_count,
219 # Now the input line(s)
220 if (@selected == 0) {
221 PrintInputLine($nextseq, undef, 'tablebottomleft', 'tablebottomdata',
225 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
226 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
227 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
229 PrintInputLine($nextseq++, $_, $leftclass, $dataclass, $rightclass);
236 submit ({-name => 'update',
238 -onClick => 'return CheckEntry (document.list);'}),
239 submit ({-name => 'Reset',
241 -onClick => 'history.back(); return false'}),
251 my @selected = ReturnSequenceNbrs;
253 my $Type = ucfirst $type;
265 NavigationBar($userid);
267 # Redisplay the page but open up the lines that are getting modified
270 -action => 'modifyentries.cgi',
274 # Print some hidden fields to pass along
276 hidden ({-name => 'type',
278 hidden ({-name => 'next',
281 print start_table {-align => 'center',
288 th {-class => 'tableleftend'}, 'Seq',
289 th {-class => 'tableheader'}, 'Username',
290 th {-class => 'tableheader'}, '@',
291 th {-class => 'tableheader'}, 'Domain',
292 th {-class => 'tableheader'}, 'Comments',
293 th {-class => 'tablerightend'}, 'Hit Count',
296 # Corner case: If on the first page (i.e. $next=0) then being zero based, we
297 # will actually get 21 entries in @list (i.e. $next=0, $lines=20 - 21 $entries
298 # are retrieved). So in that case, and that case only, we will change $lines
300 --$lines if $next == 0;
302 my @list = ReturnList($type, $next, $lines);
310 my $sequence = $record{sequence};
311 my $leftclass = ($i == @list || $sequence eq $total) ?
312 'tablebottomleft' : 'tableleftdata';
313 my $dataclass = ($i == @list || $sequence eq $total) ?
314 'tablebottomdata' : 'tabledata';
315 my $rightclass = ($i == @list || $sequence eq $total) ?
316 'tablebottomright' : 'tablerightdata';
321 td {-class => $leftclass,
322 -align => 'center'}, $record{sequence};
324 if ($record{sequence} eq $selected[$s]) {
327 my $pattern = $record{pattern} ? $record{pattern} : '';
328 my $domain = $record{domain} ? $record{domain} : '';
329 my $comment = $record{comment} ? $record{comment} : '';
330 my $hit_count = $record{hit_count} ? $record{hit_count} : '';
333 td {-class => $dataclass,
335 (textfield {-class => 'inputfield',
336 -style => 'width:100%',
340 -name => "pattern$sequence",
341 -value => $pattern}),
342 td {-class => $dataclass,
343 -align => 'center'}, '@',
344 td {-class => $dataclass},
345 (textfield {-class => 'inputfield',
346 -style => 'width:100%',
350 -name => "domain$sequence",
352 td {-class => $dataclass},
353 (textfield {-class => 'inputfield',
354 -style => 'width:100%',
358 -name => "comment$sequence",
359 -value => $comment}),
360 td {-class => $rightclass},
361 (textfield {-class => 'inputfield',
362 -style => 'width:100%',
366 -name => "hit_count$sequence",
367 -value => $hit_count});
369 # Put in ' ' for undefined fields
370 my $pattern = $record{pattern} ? $record{pattern} : ' ';
371 my $domain = $record{domain} ? $record{domain} : ' ';
372 my $comment = $record{comment} ? $record{comment} : ' ';
373 my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
376 td {-class => $dataclass,
377 -align => 'right'}, $pattern,
378 td {-class => $dataclass,
379 -align => 'center'}, '@',
380 td {-class => $dataclass,
381 -align => 'left'}, $domain,
382 td {-class => $dataclass,
383 -align => 'left'}, $comment,
384 td {-class => $rightclass,
385 -align => 'left'}, $hit_count;
394 submit ({-name => 'update',
396 -onClick => 'return CheckEntry (document.list);'}),
397 submit ({-name => 'Reset',
399 -onClick => 'history.back(); return false'}),
406 sub WhitelistMarked {
407 AddNewEntry('white', ReturnSequenceNbrs);
410 sub BlacklistMarked {
411 AddNewEntry('black', ReturnSequenceNbrs);
415 AddNewEntry('null', ReturnSequenceNbrs);
419 $userid ||= $ENV{USER};
423 my %options = GetUserOptions($userid);
425 $lines = $options{'Page'};
427 $total = count('list', "userid = \"$userid\" and type = \"$type\"") if $type;
429 if ($action eq 'Add') {
431 } elsif ($action eq 'Delete') {
432 DeleteEntries($type);
433 } elsif ($action eq 'Modify') {
434 ModifyEntries($type);
435 } elsif ($action eq 'Whitelist') {
437 } elsif ($action eq 'Blacklist') {
439 } elsif ($action eq 'Nulllist') {
445 "Unknown action ($action)",
446 "Unknown action ($action)"
449 NavigationBar($userid);
450 DisplayError("Unknown action encountered ($action)");
453 Footing($table_name);