437569fb42f5c4190535381402ef3ac3a9622119
[freeside.git] / htdocs / edit / process / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_pkg.cgi,v 1.6 1999-02-28 00:03:44 ivan Exp $
4 #
5 # this is for changing packages around, not for editing things within the
6 # package
7 #
8 # Usage: post form to:
9 #        http://server.name/path/cust_pkg.cgi
10 #
11 # ivan@voicenet.com 97-mar-21 - 97-mar-24
12 #
13 # rewrote for new API
14 # ivan@voicenet.com 97-jul-7 - 15
15 #
16 # &cgisuidsetup($cgi) ivan@sisd.com 98-mar-7
17 #
18 # Changes to allow page to work at a relative position in server
19 #       bmccane@maxbaud.net     98-apr-3
20 #
21 # $Log: cust_pkg.cgi,v $
22 # Revision 1.6  1999-02-28 00:03:44  ivan
23 # removed misleading comments
24 #
25 # Revision 1.5  1999/02/07 09:59:26  ivan
26 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
27 #
28 # Revision 1.3  1999/01/19 05:13:54  ivan
29 # for mod_perl: no more top-level my() variables; use vars instead
30 # also the last s/create/new/;
31 #
32 # Revision 1.2  1998/12/17 08:40:23  ivan
33 # s/CGI::Request/CGI.pm/; etc
34 #
35
36 use strict;
37 use vars qw( $cgi $custnum @remove_pkgnums @pkgparts $pkgpart $error );
38 use CGI;
39 use CGI::Carp qw(fatalsToBrowser);
40 use FS::UID qw(cgisuidsetup);
41 use FS::CGI qw(popurl);
42 use FS::cust_pkg;
43
44 $cgi = new CGI; # create form object
45 &cgisuidsetup($cgi);
46 $error = '';
47
48 #untaint custnum
49 $cgi->param('custnum') =~ /^(\d+)$/;
50 $custnum = $1;
51
52 @remove_pkgnums = map {
53   /^(\d+)$/ or die "Illegal remove_pkg value!";
54   $1;
55 } $cgi->param('remove_pkg');
56
57 foreach $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
58   if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
59     my $num_pkgs = $1;
60     while ( $num_pkgs-- ) {
61       push @pkgparts,$pkgpart;
62     }
63   } else {
64     $error = "Illegal quantity";
65     last;
66   }
67 }
68
69 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
70
71 if ($error) {
72   $cgi->param('error', $error);
73   print $cgi->redirect(popurl(2). "cust_pkg.cgi?". $cgi->query_string );
74 } else {
75   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum#cust_pkg");
76 }
77