whew, glad that change package bugfix was easy to find, closes: Bug#3241
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
1 % if ($error) {
2 %   $cgi->param('error', $error);
3 %   $cgi->redirect(popurl(3). $error_redirect. '?'. $cgi->query_string );
4 % } elsif ( $action eq 'change' ) {
5
6     <% header("Package changed") %>
7       <SCRIPT TYPE="text/javascript">
8         window.top.location.reload();
9       </SCRIPT>
10     </BODY>
11     </HTML>
12
13 % } elsif ( $action eq 'bulk' ) {
14 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
15 % } else {
16 %   die "guru exception #5: action is neither change nor bulk!";
17 % }
18 <%init>
19
20 my $error = '';
21
22 #untaint custnum
23 $cgi->param('custnum') =~ /^(\d+)$/;
24 my $custnum = $1;
25
26 my @remove_pkgnums = map {
27   /^(\d+)$/ or die "Illegal remove_pkg value!";
28   $1;
29 } $cgi->param('remove_pkg');
30
31 my $curuser = $FS::CurrentUser::CurrentUser;
32
33 my( $action, $error_redirect ) = ( '', '' );
34 my @pkgparts = ();
35 if ( $cgi->param('action') eq 'change' ) { #came from misc/change_pkg.cgi
36
37   $action = 'change';
38   $error_redirect = "misc/change_pkg.cgi";
39
40   die "access denied"
41     unless $curuser->access_right('Change customer package');
42
43   if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) {
44     @pkgparts = ($1);
45   } else {
46     $error = 'Select a new package';
47   }
48
49 } elsif ( $cgi->param('action') eq 'bulk' ) { #came from edit/cust_pkg.cgi
50
51   $action = 'bulk';
52   $error_redirect = "edit/cust_pkg.cgi";
53
54   die "access denied"
55     unless $curuser->access_right('Bulk change customer packages');
56
57   foreach my $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 } else {
70   die "guru exception #5: action is neither change nor bulk!";
71 }
72
73 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
74
75 </%init>