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 {
43 Debug "Entered ReturnSequenceNbrs";
47 push @sequence_nbrs, $1;
51 Debug "Returning sequence nbrs " . join ' ', @sequence_nbrs;
53 return @sequence_nbrs;
54 } # ReturnSequenceNbrs
59 my @sequence_nbrs = ReturnSequenceNbrs;
63 foreach (@sequence_nbrs) {
64 $count += DeleteList $type, $_;
68 DisplayError 'Nothing to delete!';
70 ResequenceList $userid, $type;
73 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted entry");
75 print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted $count entries");
82 sub PrintInputLine ($$$$$) {
83 my ($nextseq, $email_nbr, $leftclass, $dataclass, $rightclass) = @_;
90 if (defined $email_nbr && $email_nbr ne '') {
91 $email = param "email$email_nbr";
92 if ($email && $email ne '') {
93 ($pattern, $domain) = split /\@/, $email;
96 $hit_count = CountMsg $email;
100 td {-class => $leftclass,
101 -align => 'center'}, "$nextseq",
102 td {-class => $dataclass,
104 (textfield {-class => 'inputfield',
105 -style => 'width:100%',
109 -name => "pattern$nextseq",
110 -value => $pattern}),
111 td {-class => $dataclass,
112 -align => 'center'}, '@',
113 td {-class => $dataclass},
114 (textfield {-class => 'inputfield',
115 -style => 'width:100%',
119 -name => "domain$nextseq",
121 td {-class => $dataclass},
122 (textfield {-class => 'inputfield',
123 -style => 'width:100%',
127 -name => "comment$nextseq",
129 td {-class => $rightclass},
130 (textfield {-class => 'inputfield',
131 -style => 'width:100%',
135 -name => "hit_count$nextseq",
136 -value => $hit_count}),
143 my ($type, @selected) = @_;
145 # First display the last page and add the appropriate number of
146 # empty, editable entries (possibly filled in) for the user to add
148 my $selected = @selected;
149 my $nextseq = MAPSDB::GetNextSequenceNo $userid, $type;
150 my $next = ($nextseq - $lines) + $selected - 1;
155 my $Type = ucfirst $type;
167 NavigationBar $userid;
169 # Now display table and new entry
172 -action => 'add2' . $type . 'list.cgi',
176 print start_table {-align => 'center',
183 th {-class => 'tableleftend'}, 'Seq',
184 th {-class => 'tableheader'}, 'Username',
185 th {-class => 'tableheader'}, '@',
186 th {-class => 'tableheader'}, 'Domain',
187 th {-class => 'tableheader'}, 'Comments',
188 th {-class => 'tablerightend'}, 'Hit Count'
191 my @list = ReturnList $type, $next, $lines;
201 my $sequence = $record{sequence};
202 my $pattern = $record{pattern} ? $record{pattern} : ' ';
203 my $domain = $record{domain} ? $record{domain} : ' ';
204 my $comment = $record{comment} ? $record{comment} : ' ';
205 my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
208 td {-class => 'tableleftdata',
209 -align => 'center'}, $sequence,
210 td {-class => 'tabledata',
211 -align => 'right'}, $pattern,
212 td {-class => 'tabledata',
213 -align => 'center'}, '@',
214 td {-class => 'tabledata',
215 -align => 'left'}, $domain,
216 td {-class => 'tabledata',
217 -align => 'left'}, $comment,
218 td {-class => 'tablerightdata',
219 -align => 'right'}, $hit_count,
223 # Now the input line(s)
224 if (@selected == 0) {
225 PrintInputLine $nextseq, undef, 'tablebottomleft', 'tablebottomdata',
228 foreach (@selected) {
229 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
230 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
231 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
233 PrintInputLine $nextseq++, $_, $leftclass, $dataclass, $rightclass;
240 submit ({-name => 'update',
242 -onClick => 'return CheckEntry (document.list);'}),
243 submit ({-name => 'Reset',
245 -onClick => 'history.back(); return false'}),
255 my @selected = ReturnSequenceNbrs;
257 my $Type = ucfirst $type;
269 NavigationBar $userid;
271 # Redisplay the page but open up the lines that are getting modified
274 -action => 'modifyentries.cgi',
278 # Print some hidden fields to pass along
280 hidden ({-name => 'type',
282 hidden ({-name => 'next',
285 print start_table {-align => 'center',
292 th {-class => 'tableleftend'}, 'Seq',
293 th {-class => 'tableheader'}, 'Username',
294 th {-class => 'tableheader'}, '@',
295 th {-class => 'tableheader'}, 'Domain',
296 th {-class => 'tableheader'}, 'Comments',
297 th {-class => 'tablerightend'}, 'Hit Count',
300 my @list = ReturnList $type, $next, $lines;
308 my $sequence = $record{sequence};
309 my $leftclass = ($i eq $lines || $sequence eq $total) ?
310 'tablebottomleft' : 'tableleftdata';
311 my $dataclass = ($i eq $lines || $sequence eq $total) ?
312 'tablebottomdata' : 'tabledata';
313 my $rightclass = ($i eq $lines || $sequence eq $total) ?
314 'tablebottomright' : 'tablerightdata';
319 td {-class => $leftclass,
320 -align => 'center'}, $record{sequence};
322 if ($record{sequence} eq $selected[$s]) {
325 my $pattern = $record{pattern} ? $record{pattern} : '';
326 my $domain = $record{domain} ? $record{domain} : '';
327 my $comment = $record{comment} ? $record{comment} : '';
328 my $hit_count = $record{hit_count} ? $record{hit_count} : '';
331 td {-class => $dataclass,
333 (textfield {-class => 'inputfield',
334 -style => 'width:100%',
338 -name => "pattern$sequence",
339 -value => $pattern}),
340 td {-class => $dataclass,
341 -align => 'center'}, '@',
342 td {-class => $dataclass},
343 (textfield {-class => 'inputfield',
344 -style => 'width:100%',
348 -name => "domain$sequence",
350 td {-class => $dataclass},
351 (textfield {-class => 'inputfield',
352 -style => 'width:100%',
356 -name => "comment$sequence",
357 -value => $comment}),
358 td {-class => $rightclass},
359 (textfield {-class => 'inputfield',
360 -style => 'width:100%',
364 -name => "hit_count$sequence",
365 -value => $hit_count});
367 # Put in ' ' for undefined fields
368 my $pattern = $record{pattern} ? $record{pattern} : ' ';
369 my $domain = $record{domain} ? $record{domain} : ' ';
370 my $comment = $record{comment} ? $record{comment} : ' ';
371 my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
374 td {-class => $dataclass,
375 -align => 'right'}, $pattern,
376 td {-class => $dataclass,
377 -align => 'center'}, '@',
378 td {-class => $dataclass,
379 -align => 'left'}, $domain,
380 td {-class => $dataclass,
381 -align => 'left'}, $comment,
382 td {-class => $rightclass,
383 -align => 'left'}, $hit_count;
392 submit ({-name => 'update',
394 -onClick => 'return CheckEntry (document.list);'}),
395 submit ({-name => 'Reset',
397 -onClick => 'history.back(); return false'}),
404 sub WhitelistMarked {
405 AddNewEntry 'white', ReturnSequenceNbrs;
408 sub BlacklistMarked {
409 AddNewEntry 'black', ReturnSequenceNbrs;
413 AddNewEntry 'null', ReturnSequenceNbrs;
417 $userid ||= $ENV{USER};
421 my %options = GetUserOptions $userid;
423 $lines = $options{'Page'};
425 $total = MAPSDB::count 'list', "userid = \"$userid\" and type = \"$type\""
428 if ($action eq 'Add New Entry') {
430 } elsif ($action eq 'Delete Marked') {
432 } elsif ($action eq 'Modify Marked') {
434 } elsif ($action eq 'Whitelist Marked') {
436 } elsif ($action eq 'Blacklist Marked') {
438 } elsif ($action eq 'Nulllist Marked') {
444 "Unknown action ($action)",
445 "Unknown action ($action)"
448 NavigationBar $userid;
449 DisplayError "Unknown action encountered ($action)";