(no commit message)
[freeside.git] / httemplate / edit / process / cust_pkg.cgi
index 25b3201..272ddcc 100755 (executable)
@@ -1,5 +1,21 @@
-<!-- $Id: cust_pkg.cgi,v 1.3 2002-01-30 14:18:09 ivan Exp $ -->
-<%
+% if ($error) {
+%   $cgi->param('error', $error);
+%   $cgi->redirect(popurl(3). $error_redirect. '?'. $cgi->query_string );
+% } elsif ( $action eq 'change' ) {
+
+    <% header("Package changed") %>
+      <SCRIPT TYPE="text/javascript">
+        window.top.location.reload();
+      </SCRIPT>
+    </BODY>
+    </HTML>
+
+% } elsif ( $action eq 'bulk' ) {
+<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
+% } else {
+%   die "guru exception #5: action is neither change nor bulk!";
+% }
+<%init>
 
 my $error = '';
 
@@ -12,26 +28,48 @@ my @remove_pkgnums = map {
   $1;
 } $cgi->param('remove_pkg');
 
-my @pkgparts;
-foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
-  if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
-    my $num_pkgs = $1;
-    while ( $num_pkgs-- ) {
-      push @pkgparts,$pkgpart;
-    }
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my( $action, $error_redirect ) = ( '', '' );
+my @pkgparts = ();
+if ( $cgi->param('action') eq 'change' ) { #came from misc/change_pkg.cgi
+
+  $action = 'change';
+  $error_redirect = "misc/change_pkg.cgi";
+
+  die "access denied"
+    unless $curuser->access_right('Change customer package');
+
+  if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) {
+    @pkgparts = ($1);
   } else {
-    $error = "Illegal quantity";
-    last;
+    $error = 'Select a new package';
   }
-}
 
-$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
+} 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;
+      while ( $num_pkgs-- ) {
+        push @pkgparts,$pkgpart;
+      }
+    } else {
+      $error = "Illegal quantity";
+      last;
+    }
+  }
 
-if ($error) {
-  $cgi->param('error', $error);
-  print $cgi->redirect(popurl(2). "cust_pkg.cgi?". $cgi->query_string );
 } else {
-  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
+  die "guru exception #5: action is neither change nor bulk!";
 }
 
-%>
+$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
+
+</%init>