This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / bin / freeside-disable-reasons
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_t $opt_e);
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
8 use FS::reason_type;
9 use FS::reason;
10
11 getopts('t:e');
12
13 my $user = shift or die &usage;
14 adminsuidsetup $user;
15
16 die &usage
17   unless ($opt_t);
18
19 $FS::Record::nowarn_identical = 1;
20
21 my @reason = ();
22 if ( $opt_t ) {
23   $opt_t =~ /^(\d+)$/ or die "invalid reason_type";
24   @reason = qsearch('reason', { reason_type => $1 } );
25   die "no reasons found\n" unless @reason;
26 } else {
27   die "no reason_type specified\n";
28 }
29
30 foreach my $reason ( @reason ) {
31   if ( $opt_e ) {
32     $reason->disabled('');
33   }else{
34     $reason->disabled('Y');
35   }
36   my $error = $reason->replace
37     if $reason->modified;     
38   die $error if $error;
39 }
40
41
42 sub usage {
43   die "Usage:\n\n  freeside-disable-reasons -t reason_type [ -e ] user\n";
44 }
45
46 =head1 NAME
47
48 freeside-disable-reasons - Command line tool to set the disabled column for reasons
49
50 =head1 SYNOPSIS
51
52   freeside-disable-reasons -t reason_type [ -e ] user
53
54 =head1 DESCRIPTION
55
56   Disables the reasons of the specified reason type.
57   Enables instead if -e is specified.
58
59 =head1 SEE ALSO
60
61 L<FS::reason>, L<FS::reason_type>
62
63 =cut
64