fix slowness on change package and also make it into a popup
[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( $action, $error_redirect );
32 my @pkgparts = ();
33 if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi
34   $action = 'change';
35   $error_redirect = "misc/change_pkg.cgi";
36   @pkgparts = ($1);
37 } else { #came from edit/cust_pkg.cgi
38   $action = 'bulk';
39   $error_redirect = "edit/cust_pkg.cgi";
40   foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
41     if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
42       my $num_pkgs = $1;
43       while ( $num_pkgs-- ) {
44         push @pkgparts,$pkgpart;
45       }
46     } else {
47       $error = "Illegal quantity";
48       last;
49     }
50   }
51 }
52
53 $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
54
55 </%init>