templates!!!
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
1 <%
2 #
3 # $Id: cust_pkg.cgi,v 1.1 2001-07-30 07:36:04 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.1  2001-07-30 07:36:04  ivan
23 # templates!!!
24 #
25 # Revision 1.7  1999/04/07 15:24:06  ivan
26 # don't use anchor in redirect
27 #
28 # Revision 1.6  1999/02/28 00:03:44  ivan
29 # removed misleading comments
30 #
31 # Revision 1.5  1999/02/07 09:59:26  ivan
32 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
33 #
34 # Revision 1.3  1999/01/19 05:13:54  ivan
35 # for mod_perl: no more top-level my() variables; use vars instead
36 # also the last s/create/new/;
37 #
38 # Revision 1.2  1998/12/17 08:40:23  ivan
39 # s/CGI::Request/CGI.pm/; etc
40 #
41
42 use strict;
43 use vars qw( $cgi $custnum @remove_pkgnums @pkgparts $pkgpart $error );
44 use CGI;
45 use CGI::Carp qw(fatalsToBrowser);
46 use FS::UID qw(cgisuidsetup);
47 use FS::CGI qw(popurl);
48 use FS::cust_pkg;
49
50 $cgi = new CGI; # create form object
51 &cgisuidsetup($cgi);
52 $error = '';
53
54 #untaint custnum
55 $cgi->param('custnum') =~ /^(\d+)$/;
56 $custnum = $1;
57
58 @remove_pkgnums = map {
59   /^(\d+)$/ or die "Illegal remove_pkg value!";
60   $1;
61 } $cgi->param('remove_pkg');
62
63 foreach $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
64   if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
65     my $num_pkgs = $1;
66     while ( $num_pkgs-- ) {
67       push @pkgparts,$pkgpart;
68     }
69   } else {
70     $error = "Illegal quantity";
71     last;
72   }
73 }
74
75 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
76
77 if ($error) {
78   $cgi->param('error', $error);
79   print $cgi->redirect(popurl(2). "cust_pkg.cgi?". $cgi->query_string );
80 } else {
81   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
82 }
83
84 %>