Fixing up numbers and totals
[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
20 local $0 = $FindBin::Script;
21
22 use lib "$FindBin::Bin/../lib";
23 use lib "$FindBin::Bin/../../lib";
24
25 use Utils;
26
27 use MAPS;
28 use MAPSLog;
29 use MAPSWeb;
30
31 use CGI qw/:standard *table/;
32 use CGI::Carp 'fatalsToBrowser';
33
34 sub Add2List(%) {
35   my (%rec) = @_;
36
37   CheckParms(['userid', 'type'], \%rec);
38
39   my $nextseq  = GetNextSequenceNo(%rec);
40
41   my $Userid = ucfirst $rec{userid};
42
43   while () {
44     $rec{pattern}   = param "pattern$nextseq";
45     $rec{domain}    = param "domain$nextseq";
46     $rec{comment}   = param "comment$nextseq";
47     $rec{hit_count} = param "hit_count$nextseq";
48     $rec{retention} = param "retention$nextseq";
49
50     last unless $rec{pattern} or $rec{domain};
51
52     $rec{sender} = CheckEmail $rec{pattern}, $rec{domain};
53
54     my ($status, $rule) = OnNulllist($rec{sender});
55
56     if ($status) {
57       print br {-class => 'error'},
58         "The email address $rec{sender} is already on ${Userid}'s $rec{type} list";
59     } else {
60       my ($messages, $msg) = Add2Nulllist(%rec);
61
62       if ($messages < -1) {
63         print br {-class => 'error'}, "Unable to add $rec{sender} to $rec{type} list";
64         return;
65       } else {
66         print br "The email address, $rec{sender}, has been added to ${Userid}'s $rec{type} list";
67       } # if
68
69       # Now remove this entry from the other lists (if present)
70       for my $otherlist ('white', 'black') {
71         FindList(
72           userid => $rec{userid},
73           type   => $otherlist,
74           sender => $rec{sender},
75         );
76
77         my $seq = GetList;
78
79         if ($seq->{sequence}) {
80           my $err;
81
82           ($err, $msg) = DeleteList(
83             userid   => $rec{userid},
84             type     => $otherlist,
85             sequence => $seq->{sequence},
86           );
87
88           croak $msg if $err < 0;
89
90           print br "Removed $rec{sender} from ${Userid}'s " . ucfirst $otherlist . ' list'
91             if $err > 0;
92
93           ResequenceList(
94             userid => $rec{userid},
95             type   => $otherlist,
96           );
97         } # if
98       } # for
99     } # if
100
101     $nextseq++;
102   } # while
103
104   return;
105 } # Add2List
106
107 # Main
108 my $userid = Heading(
109   'getcookie',
110   '',
111   'Add to Null List',
112   'Add to Null List',
113 );
114
115 $userid ||= $ENV{USER};
116
117 SetContext($userid);
118
119 NavigationBar($userid);
120
121 my $type = 'null';
122
123 Add2List(
124   userid => $userid,
125   type   => $type,
126 );
127
128 print start_form {
129   -method => 'post',
130   -action => 'processaction.cgi',
131   -name   => 'list'
132 };
133
134 print '<p></p><center>',
135   hidden ({-name    => 'type',
136            -default => $type}),
137   submit ({-name    => 'action',
138            -value   => 'Add'}),
139   '</center>';
140
141 Footing;
142
143 exit;