ACLs
[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('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi
36
37   $action = 'change';
38   $error_redirect = "misc/change_pkg.cgi";
39   @pkgparts = ($1);
40
41   die "access denied"
42     unless $curuser->access_right('Change customer package');
43
44 } else { #came from edit/cust_pkg.cgi
45
46   $action = 'bulk';
47   $error_redirect = "edit/cust_pkg.cgi";
48
49   die "access denied"
50     unless $curuser->access_right('Bulk change customer packages');
51
52   foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
53     if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
54       my $num_pkgs = $1;
55       while ( $num_pkgs-- ) {
56         push @pkgparts,$pkgpart;
57       }
58     } else {
59       $error = "Illegal quantity";
60       last;
61     }
62   }
63
64 }
65
66 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
67
68 </%init>