(no commit message)
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
index 25b8267..272ddcc 100755 (executable)
@@ -11,7 +11,7 @@
     </HTML>
 
 % } elsif ( $action eq 'bulk' ) {
-%   $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
+<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
 % } else {
 %   die "guru exception #5: action is neither change nor bulk!";
 % }
@@ -28,15 +28,32 @@ my @remove_pkgnums = map {
   $1;
 } $cgi->param('remove_pkg');
 
-my( $action, $error_redirect );
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my( $action, $error_redirect ) = ( '', '' );
 my @pkgparts = ();
-if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi
+if ( $cgi->param('action') eq 'change' ) { #came from misc/change_pkg.cgi
+
   $action = 'change';
   $error_redirect = "misc/change_pkg.cgi";
-  @pkgparts = ($1);
-} else { #came from edit/cust_pkg.cgi
+
+  die "access denied"
+    unless $curuser->access_right('Change customer package');
+
+  if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) {
+    @pkgparts = ($1);
+  } else {
+    $error = 'Select a new package';
+  }
+
+} elsif ( $cgi->param('action') eq 'bulk' ) { #came from edit/cust_pkg.cgi
+
   $action = 'bulk';
   $error_redirect = "edit/cust_pkg.cgi";
+
+  die "access denied"
+    unless $curuser->access_right('Bulk change customer packages');
+
   foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
     if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
       my $num_pkgs = $1;
@@ -48,6 +65,9 @@ if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi
       last;
     }
   }
+
+} else {
+  die "guru exception #5: action is neither change nor bulk!";
 }
 
 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);