implement package changes w/location change, RT#4499
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
1 % if ($error) {
2 %   $cgi->param('error', $error);
3 %   $cgi->redirect(popurl(3). 'edit/cust_pkg.cgi?'. $cgi->query_string );
4 % } else {
5 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
6 <%init>
7
8 my $curuser = $FS::CurrentUser::CurrentUser;
9
10 die "access denied"
11   unless $curuser->access_right('Bulk change customer packages');
12
13 my $error = '';
14
15 #untaint custnum
16 $cgi->param('custnum') =~ /^(\d+)$/;
17 my $custnum = $1;
18
19 my @remove_pkgnums = map {
20   /^(\d+)$/ or die "Illegal remove_pkg value!";
21   $1;
22 } $cgi->param('remove_pkg');
23
24 my( $action, $error_redirect ) = ( '', '' );
25 my @pkgparts = ();
26
27 foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
28   if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
29     my $num_pkgs = $1;
30     while ( $num_pkgs-- ) {
31       push @pkgparts,$pkgpart;
32     }
33   } else {
34     $error = "Illegal quantity";
35     last;
36   }
37 }
38
39 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
40
41 </%init>