Removed /usr/local from CDPATH
[clearscm.git] / clearadm / processnotification.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: processnotification.cgi,v $
6
7 Process a notification
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.3 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/02/14 14:53:07 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage processnotification.cgi: [-u|sage] [-ve|rbose] [-d|ebug]
34                                 action=[Add|Delete|Edit|Post] 
35                                 notification=<notificationname>
36
37  Where:
38    -u|sage:      Displays usage
39    -ve|rbose:    Be verbose
40    -d|ebug:      Output debug messages
41    
42    action:       Specifies to add, delete, edit or post an alert
43    notification: Name of notification to delete or edit
44
45 =head2 DESCRIPTION
46
47 This script adds, deletes, edits or posts a notification
48
49 =cut
50
51 use strict;
52 use warnings;
53
54 use FindBin;
55 use Getopt::Long;
56 use CGI qw (:standard :cgi-lib *table start_Tr end_Tr);
57 use CGI::Carp 'fatalsToBrowser';
58
59 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
60
61 use Clearadm;
62 use ClearadmWeb;
63 use Display;
64 use Utils;
65
66 my $VERSION  = '$Revision: 1.3 $';
67   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
68   
69 my $clearadm;
70
71 # Main
72 GetOptions (
73   usage      => sub { Usage },
74   verbose    => sub { set_verbose },
75   debug      => sub { set_debug },
76 ) or Usage 'Invalid parameter';
77
78 # Announce ourselves
79 verbose "$FindBin::Script v$VERSION";
80
81 $clearadm = Clearadm->new;
82
83 my %opts = Vars;
84
85 my $title = 'Notifications';
86
87 heading $title;
88
89 unless ($opts{'delete.x'} or $opts{'edit.x'} or $opts{action}) {
90   displayError 'Action not defined!';
91   exit 1;
92 } # unless
93
94 unless ($opts{action} eq 'Add') {
95   unless ($opts{name}) {
96     displayError 'Notification not defined!';
97     exit 1;
98   } # unless
99 } # unless
100
101 my ($err, $msg);
102
103 if ($opts{action} eq 'Add') {
104   display h1 {class => 'center'}, 'Add Notification';
105   editNotification; 
106 } elsif ($opts{'delete.x'}) {
107   ($err, $msg) = $clearadm->DeleteNotification ($opts{name});
108    
109   if ($msg !~ /Records deleted/) {
110     displayError "Unable to delete notification $opts{name}\n$msg";
111   } else {
112     display h1 {class => 'center'}, $title;
113     display h3 {class => 'center'}, "Notification '$opts{name}' deleted";
114     
115     displayNotification;
116   } # if
117 } elsif ($opts{'edit.x'}) {
118   display h1 {class => 'center'}, 'Edit Notification: ', $opts{name};
119   editNotification ($opts{name});
120 } elsif ($opts{action} eq 'Post') {
121   delete $opts{action};
122   
123   my %notification = $clearadm->GetNotification ($opts{name});
124   
125   # System and Filesystem are links to tables of the same name. If specified 
126   # they need to match up to an existing system or they can be null. If we
127   # have this as an edited field and the user puts nothing in them then we
128   # get '', which won't work. So change '' -> undef.
129   
130   # TODO: Should think about making these dropdowns instead (However that would
131   # require AJAX to update filesystem when system changes). For now let's do
132   # this.
133 #  $opts{system} = undef
134 #    if $opts{system} eq '';
135 #  $opts{filesystem} = undef
136 #    if $opts{filesystem} eq '';
137   
138   if (%notification or $opts{oldname}) {
139     my $name = delete $opts{oldname};
140     
141     $name ||= $opts{name};
142     
143     ($err, $msg) = $clearadm->UpdateNotification ($name, %opts);
144
145     if ($err) {
146       displayError "$msg (Status: $err)";
147     } else {
148       display h1 {class => 'center'}, $title;
149       display h3 {class => 'center'}, "Notification '$opts{name}' updated";
150     
151       displayNotification;
152     } # if
153   } else {
154     ($err, $msg) = $clearadm->AddNotification (%opts);
155
156     if ($err) {
157       displayError "$msg (Status: $err)";
158     } else {
159      
160       display h1 {class => 'center'}, $title;
161       display h3 {class => 'center'}, "Notification '$opts{name}' added";
162     
163       displayNotification;
164     } # if
165   } # if
166 } else {
167   displayError "Unknown action - $opts{action}";
168 } # if
169
170 footing;
171
172 =pod
173
174 =head1 CONFIGURATION AND ENVIRONMENT
175
176 DEBUG: If set then $debug is set to this level.
177
178 VERBOSE: If set then $verbose is set to this level.
179
180 TRACE: If set then $trace is set to this level.
181
182 =head1 DEPENDENCIES
183
184 =head2 Perl Modules
185
186 L<CGI>
187
188 L<CGI::Carp|CGI::Carp>
189
190 L<FindBin>
191
192 L<Getopt::Long|Getopt::Long>
193
194 =head2 ClearSCM Perl Modules
195
196 =begin man 
197
198  Clearadm
199  ClearadmWeb
200  Display
201  Utils
202
203 =end man
204
205 =begin html
206
207 <blockquote>
208 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
209 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
210 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
211 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
212 </blockquote>
213
214 =end html
215
216 =head1 BUGS AND LIMITATIONS
217
218 There are no known bugs in this script
219
220 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
221
222 =head1 LICENSE AND COPYRIGHT
223
224 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
225
226 =cut