Initial commit
[clearscm.git] / maps / bin / add2nulllist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: add2nulllist.cgi,v $
5 # Revision:        $Revision: 1.1 $
6 # Description:        Add an email address to the nulllist
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     Perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19 $0 = $FindBin::Script;
20
21 use lib $FindBin::Bin;
22
23 use MAPS;
24 use MAPSLog;
25 use MAPSWeb;
26
27 use CGI qw/:standard *table/;
28 use CGI::Carp 'fatalsToBrowser';
29
30 my $userid;
31 my $Userid;
32 my $type = 'null';
33
34 sub Add2List {
35   my $sender   = '';
36   my $nextseq  = MAPSDB::GetNextSequenceNo $userid, $type;
37
38   while () {
39     my $pattern = param "pattern$nextseq";
40     my $domain  = param "domain$nextseq";
41     my $comment = param "comment$nextseq";
42
43     last if ((!defined $pattern || $pattern eq '') &&
44               (!defined $domain  || $domain  eq ''));
45
46     $sender = lc "$pattern\@$domain";
47
48     my ($status, $rule) = OnNulllist $sender;
49
50     if ($status != 0) {
51       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
52     } else {
53       Add2Nulllist $sender, $userid, $comment;
54
55       print br "The email address, $sender, has been added to ${Userid}'s $type list";
56         
57       # Now remove this entry from the other lists (if present)
58       foreach my $otherlist ('white', 'black') {
59         my $sth = FindList $otherlist, $sender;
60         my ($sequence, $count);
61
62         ($_, $_, $_, $_, $_, $sequence) = GetList $sth;
63
64         if ($sequence) {
65           $count = DeleteList $otherlist, $sequence;
66
67           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
68             if $count > 0;
69
70           ResequenceList $userid, $otherlist;
71         } # if
72       } # foreach
73     } # if
74
75     $nextseq++;
76   } # while
77 } # Add2List
78
79 # Main
80 $userid = Heading (
81   'getcookie',
82   '',
83   'Add to Null List',
84   'Add to Null List',
85 );
86
87 SetContext $userid;
88
89 NavigationBar $userid;
90
91 $Userid = ucfirst $userid;
92
93 Add2List;
94
95 print start_form {
96   -method        => 'post',
97   -action        => 'processaction.cgi',
98   -name          => 'list'
99 };
100
101 print '<p></p><center>',
102   hidden ({-name        => 'type',
103            -default   => $type}),
104   submit ({-name        => 'action',
105            -value       => 'Add New Entry'}),
106   '</center>';
107
108 Footing;
109
110 exit;