Removed /usr/local from CDPATH
[clearscm.git] / clearadm / processtask.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: processtask.cgi,v $
6
7 Process a task
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.2 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/04/09 05:38:26 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage processtask.cgi: [-u|sage] [-ve|rbose] [-d|ebug]
34                         action=[Add|Delete|Edit|Post] 
35                         task=<task>
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    task:      Task to delete or edit
44
45 =head2 DESCRIPTION
46
47 This script adds, deletes, edits or posts a schedule
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.2 $';
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 = 'Tasks';
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 'Task 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 Task';
105   editTask; 
106 } elsif ($opts{'delete.x'}) {
107   ($err, $msg) = $clearadm->DeleteTask ($opts{name});
108    
109   if ($msg !~ /Records deleted/) { 
110     displayError "Unable to delete task $opts{name}\n$msg"; 
111   } else {
112     display h1 {class => 'center'}, $title;
113     display h3 {class => 'center'}, "Task $opts{name} deleted";
114     
115     displayTask;
116   } # if
117 } elsif ($opts{'edit.x'}) {
118   display h1 {class => 'center'}, 'Edit Task: ', $opts{name};
119   editTask ($opts{name});
120 } elsif ($opts{action} eq 'Post') {
121   delete $opts{action};
122   
123   my %task = $clearadm->GetTask ($opts{name});
124   
125   if (%task or $opts{oldname}) {
126     my $name = delete $opts{oldname};
127
128     $name ||= $opts{name};
129     
130     ($err, $msg) = $clearadm->UpdateTask ($name, %opts);
131
132     if ($err) {
133       displayError "$msg (Status: $err)";
134     } else {
135       display h1 {class => 'center'}, $title;
136       display h3 {class => 'center'}, "Task $opts{name} updated";
137     
138       displayTask;
139     } # if
140   } else {
141     ($err, $msg) = $clearadm->AddTask (%opts);
142
143     if ($err) {
144       displayError "$msg (Status: $err)";
145     } else {
146      
147       display h1 {class => 'center'}, $title;
148       display h3 {class => 'center'}, "Task $opts{name} added";
149     
150       displayTask;
151     } # if
152   } # if
153 } else {
154   displayError "Unknown action - $opts{action}";
155 } # if
156
157 footing;
158
159 =pod
160
161 =head1 CONFIGURATION AND ENVIRONMENT
162
163 DEBUG: If set then $debug is set to this level.
164
165 VERBOSE: If set then $verbose is set to this level.
166
167 TRACE: If set then $trace is set to this level.
168
169 =head1 DEPENDENCIES
170
171 =head2 Perl Modules
172
173 L<CGI>
174
175 L<CGI::Carp|CGI::Carp>
176
177 L<FindBin>
178
179 L<Getopt::Long|Getopt::Long>
180
181 =head2 ClearSCM Perl Modules
182
183 =begin man 
184
185  Clearadm
186  ClearadmWeb
187  Display
188  Utils
189
190 =end man
191
192 =begin html
193
194 <blockquote>
195 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
196 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
197 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
198 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
199 </blockquote>
200
201 =end html
202
203 =head1 BUGS AND LIMITATIONS
204
205 There are no known bugs in this script
206
207 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
208
209 =head1 LICENSE AND COPYRIGHT
210
211 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
212
213 =cut