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) = @_;
89 if (defined $email_nbr && $email_nbr ne '') {
90 $email = param "email$email_nbr";
91 if ($email && $email ne '') {
92 ($pattern, $domain) = split /\@/, $email;
97 td {-class => $leftclass,
98 -align => 'center'}, "$nextseq",
99 td {-class => $dataclass,
101 (textfield {-class => 'inputfield',
102 -style => 'width:100%',
106 -name => "pattern$nextseq",
107 -value => $pattern}),
108 td {-class => $dataclass,
109 -align => 'center'}, '@',
110 td {-class => $dataclass},
111 (textfield {-class => 'inputfield',
112 -style => 'width:100%',
116 -name => "domain$nextseq",
118 td {-class => $rightclass},
119 (textfield {-class => 'inputfield',
120 -style => 'width:100%',
124 -name => "comment$nextseq",
130 my ($type, @selected) = @_;
132 # First display the last page and add the appropriate number of
133 # empty, editable entries (possibly filled in) for the user to add
135 my $selected = @selected;
136 my $nextseq = MAPSDB::GetNextSequenceNo $userid, $type;
137 my $next = ($nextseq - $lines) + $selected - 1;
142 my $Type = ucfirst $type;
154 NavigationBar $userid;
156 # Now display table and new entry
159 -action => 'add2' . $type . 'list.cgi',
163 print start_table {-align => 'center',
170 th {-class => 'tableleftend'}, 'Seq',
171 th {-class => 'tableheader'}, 'Username',
172 th {-class => 'tableheader'}, '@',
173 th {-class => 'tableheader'}, 'Domain',
174 th {-class => 'tablerightend'}, 'Comments'
177 my @list = ReturnList $type, $next, $lines;
187 my $sequence = $record{sequence};
188 my $pattern = $record{pattern} ? $record{pattern} : ' ';
189 my $domain = $record{domain} ? $record{domain} : ' ';
190 my $comment = $record{comment} ? $record{comment} : ' ';
193 td {-class => 'tableleftdata',
194 -align => 'center'}, $sequence,
195 td {-class => 'tabledata',
196 -align => 'right'}, $pattern,
197 td {-class => 'tabledata',
198 -align => 'center'}, '@',
199 td {-class => 'tabledata',
200 -align => 'left'}, $domain,
201 td {-class => 'tablerightdata',
202 -align => 'left'}, $comment
206 # Now the input line(s)
207 if (@selected eq 0) {
208 PrintInputLine $nextseq, undef, 'tablebottomleft', 'tablebottomdata',
211 foreach (@selected) {
212 my $leftclass = $i == $lines ? 'tablebottomleft' : 'tableleftdata';
213 my $dataclass = $i == $lines ? 'tablebottomdata' : 'tabledata';
214 my $rightclass = $i == $lines ? 'tablebottomright' : 'tablerightdata';
216 PrintInputLine $nextseq++, $_, $leftclass, $dataclass, $rightclass;
223 submit ({-name => 'update',
225 -onClick => 'return CheckEntry (document.list);'}),
226 submit ({-name => 'Reset',
228 -onClick => 'history.back(); return false'}),
236 my @selected = ReturnSequenceNbrs;
238 my $Type = ucfirst $type;
250 NavigationBar $userid;
252 # Redisplay the page but open up the lines that are getting modified
255 -action => 'modifyentries.cgi',
259 # Print some hidden fields to pass along
261 hidden ({-name => 'type',
263 hidden ({-name => 'next',
266 print start_table {-align => 'center',
273 th {-class => 'tableleftend'}, 'Seq',
274 th {-class => 'tableheader'}, 'Username',
275 th {-class => 'tableheader'}, '@',
276 th {-class => 'tableheader'}, 'Domain',
277 th {-class => 'tablerightend'}, 'Comments'
280 my @list = ReturnList $type, $next, $lines;
288 my $sequence = $record{sequence};
289 my $leftclass = ($i eq $lines || $sequence eq $total) ?
290 'tablebottomleft' : 'tableleftdata';
291 my $dataclass = ($i eq $lines || $sequence eq $total) ?
292 'tablebottomdata' : 'tabledata';
293 my $rightclass = ($i eq $lines || $sequence eq $total) ?
294 'tablebottomright' : 'tablerightdata';
299 td {-class => $leftclass,
300 -align => 'center'}, $record{sequence};
302 if ($record{sequence} eq $selected[$s]) {
305 my $pattern = $record{pattern} ? $record{pattern} : '';
306 my $domain = $record{domain} ? $record{domain} : '';
307 my $comment = $record{comment} ? $record{comment} : '';
310 td {-class => $dataclass,
312 (textfield {-class => 'inputfield',
313 -style => 'width:100%',
317 -name => "pattern$sequence",
318 -value => $pattern}),
319 td {-class => $dataclass,
320 -align => 'center'}, '@',
321 td {-class => $dataclass},
322 (textfield {-class => 'inputfield',
323 -style => 'width:100%',
327 -name => "domain$sequence",
329 td {-class => $rightclass},
330 (textfield {-class => 'inputfield',
331 -style => 'width:100%',
335 -name => "comment$sequence",
336 -value => $comment});
338 # Put in ' ' for undefined fields
339 my $pattern = $record{pattern} ? $record{pattern} : ' ';
340 my $domain = $record{domain} ? $record{domain} : ' ';
341 my $comment = $record{comment} ? $record{comment} : ' ';
344 td {-class => $dataclass,
345 -align => 'right'}, $pattern,
346 td {-class => $dataclass,
347 -align => 'center'}, '@',
348 td {-class => $dataclass,
349 -align => 'left'}, $domain,
350 td {-class => $rightclass,
351 -align => 'left'}, $comment;
360 submit ({-name => 'update',
362 -onClick => 'return CheckEntry (document.list);'}),
363 submit ({-name => 'Reset',
365 -onClick => 'history.back(); return false'}),
370 sub WhitelistMarked {
371 AddNewEntry 'white', ReturnSequenceNbrs;
374 sub BlacklistMarked {
375 AddNewEntry 'black', ReturnSequenceNbrs;
379 AddNewEntry 'null', ReturnSequenceNbrs;
383 $userid ||= $ENV{USER};
387 my %options = GetUserOptions $userid;
389 $lines = $options{'Page'};
391 $total = MAPSDB::count 'list', "userid = \"$userid\" and type = \"$type\""
394 if ($action eq 'Add New Entry') {
396 } elsif ($action eq 'Delete Marked') {
398 } elsif ($action eq 'Modify Marked') {
400 } elsif ($action eq 'Whitelist Marked') {
402 } elsif ($action eq 'Blacklist Marked') {
404 } elsif ($action eq 'Nulllist Marked') {
410 "Unknown action ($action)",
411 "Unknown action ($action)"
414 NavigationBar $userid;
415 DisplayError "Unknown action encountered ($action)";