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;
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 = MAPSDB::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',
224 foreach (@selected) {
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 my @list = ReturnList $type, $next, $lines;
304 my $sequence = $record{sequence};
305 my $leftclass = ($i eq $lines || $sequence eq $total) ?
306 'tablebottomleft' : 'tableleftdata';
307 my $dataclass = ($i eq $lines || $sequence eq $total) ?
308 'tablebottomdata' : 'tabledata';
309 my $rightclass = ($i eq $lines || $sequence eq $total) ?
310 'tablebottomright' : 'tablerightdata';
315 td {-class => $leftclass,
316 -align => 'center'}, $record{sequence};
318 if ($record{sequence} eq $selected[$s]) {
321 my $pattern = $record{pattern} ? $record{pattern} : '';
322 my $domain = $record{domain} ? $record{domain} : '';
323 my $comment = $record{comment} ? $record{comment} : '';
324 my $hit_count = $record{hit_count} ? $record{hit_count} : '';
327 td {-class => $dataclass,
329 (textfield {-class => 'inputfield',
330 -style => 'width:100%',
334 -name => "pattern$sequence",
335 -value => $pattern}),
336 td {-class => $dataclass,
337 -align => 'center'}, '@',
338 td {-class => $dataclass},
339 (textfield {-class => 'inputfield',
340 -style => 'width:100%',
344 -name => "domain$sequence",
346 td {-class => $dataclass},
347 (textfield {-class => 'inputfield',
348 -style => 'width:100%',
352 -name => "comment$sequence",
353 -value => $comment}),
354 td {-class => $rightclass},
355 (textfield {-class => 'inputfield',
356 -style => 'width:100%',
360 -name => "hit_count$sequence",
361 -value => $hit_count});
363 # Put in ' ' for undefined fields
364 my $pattern = $record{pattern} ? $record{pattern} : ' ';
365 my $domain = $record{domain} ? $record{domain} : ' ';
366 my $comment = $record{comment} ? $record{comment} : ' ';
367 my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
370 td {-class => $dataclass,
371 -align => 'right'}, $pattern,
372 td {-class => $dataclass,
373 -align => 'center'}, '@',
374 td {-class => $dataclass,
375 -align => 'left'}, $domain,
376 td {-class => $dataclass,
377 -align => 'left'}, $comment,
378 td {-class => $rightclass,
379 -align => 'left'}, $hit_count;
388 submit ({-name => 'update',
390 -onClick => 'return CheckEntry (document.list);'}),
391 submit ({-name => 'Reset',
393 -onClick => 'history.back(); return false'}),
400 sub WhitelistMarked {
401 AddNewEntry 'white', ReturnSequenceNbrs;
404 sub BlacklistMarked {
405 AddNewEntry 'black', ReturnSequenceNbrs;
409 AddNewEntry 'null', ReturnSequenceNbrs;
413 $userid ||= $ENV{USER};
417 my %options = GetUserOptions $userid;
419 $lines = $options{'Page'};
421 $total = MAPSDB::count 'list', "userid = \"$userid\" and type = \"$type\""
424 if ($action eq 'Add New Entry') {
426 } elsif ($action eq 'Delete Marked') {
428 } elsif ($action eq 'Modify Marked') {
430 } elsif ($action eq 'Whitelist Marked') {
432 } elsif ($action eq 'Blacklist Marked') {
434 } elsif ($action eq 'Nulllist Marked') {
440 "Unknown action ($action)",
441 "Unknown action ($action)"
444 NavigationBar $userid;
445 DisplayError "Unknown action encountered ($action)";