This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / htdocs / edit / process / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # process/cust_pkg.cgi: Add/edit packages (process form)
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 # Note: Should be run setuid root as user nobody.
12 #
13 # ivan@voicenet.com 97-mar-21 - 97-mar-24
14 #
15 # rewrote for new API
16 # ivan@voicenet.com 97-jul-7 - 15
17 #
18 # &cgisuidsetup($cgi) ivan@sisd.com 98-mar-7
19 #
20 # Changes to allow page to work at a relative position in server
21 #       bmccane@maxbaud.net     98-apr-3
22
23 use strict;
24 use CGI::Request;
25 use CGI::Carp qw(fatalsToBrowser);
26 use FS::UID qw(cgisuidsetup);
27 use FS::cust_pkg;
28
29 my($req)=new CGI::Request; # create form object
30
31 &cgisuidsetup($req->cgi);
32
33 #untaint custnum
34 $req->param('new_custnum') =~ /^(\d+)$/;
35 my($custnum)=$1;
36
37 my(@remove_pkgnums) = map {
38   /^(\d+)$/ or die "Illegal remove_pkg value!";
39   $1;
40 } $req->param('remove_pkg');
41
42 my(@pkgparts);
43 my($pkgpart);
44 foreach $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $req->params ) {
45   my($num_pkgs)=$req->param("pkg$pkgpart");
46   while ( $num_pkgs-- ) {
47     push @pkgparts,$pkgpart;
48   }
49 }
50
51 my($error) = FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
52
53 if ($error) {
54   CGI::Base::SendHeaders();
55   print <<END;
56 <HTML>
57   <HEAD>
58     <TITLE>Error updating packages</TITLE>
59   </HEAD>
60   <BODY>
61     <CENTER>
62     <H4>Error updating packages</H4>
63     </CENTER>
64     Your update did not occur because of the following error:
65     <P><B>$error</B>
66     <P>Hit the <I>Back</I> button in your web browser, correct this mistake, and submit the form again.
67   </BODY>
68 </HTML>
69 END
70 } else {
71   $req->cgi->redirect("../../view/cust_main.cgi?$custnum#cust_pkg");
72 }
73