diff options
author | ivan <ivan> | 2009-01-10 23:56:59 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-01-10 23:56:59 +0000 |
commit | 705f7d564546e7211844773f3566a89f0ae87a2c (patch) | |
tree | c9210d7215cce0870207f9865dd8e9c981f63037 /httemplate/edit/process | |
parent | a661ced3f9f678a645780eaa0b183d2de5f100fa (diff) |
implement package changes w/location change, RT#4499
Diffstat (limited to 'httemplate/edit/process')
-rw-r--r-- | httemplate/edit/process/change-cust_pkg.html | 46 | ||||
-rwxr-xr-x | httemplate/edit/process/cust_pkg.cgi | 64 |
2 files changed, 61 insertions, 49 deletions
diff --git a/httemplate/edit/process/change-cust_pkg.html b/httemplate/edit/process/change-cust_pkg.html new file mode 100644 index 000000000..7356e6122 --- /dev/null +++ b/httemplate/edit/process/change-cust_pkg.html @@ -0,0 +1,46 @@ +% if ($error) { +% $cgi->param('error', $error); +% $cgi->redirect(popurl(3). 'misc/change_pkg.cgi?'. $cgi->query_string ); +% } else { + + <% header("Package changed") %> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + </BODY> + </HTML> + +% } +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right('Change customer package'); + +my $cust_pkg = qsearchs({ + #'select' => 'cust_pkg.*', + 'table' => 'cust_pkg', + 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'pkgnum' => scalar($cgi->param('pkgnum')), }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, +}); +die 'unknown pkgnum' unless $cust_pkg; + +my %change = map { $_ => scalar($cgi->param($_)) } + qw( locationnum pkgpart ); + +if ( $cgi->param('locationnum') == -1 ) { + my $cust_location = new FS::cust_location { + 'custnum' => $cust_pkg->custnum, + map { $_ => scalar($cgi->param($_)) } + qw( address1 address2 city county state zip country ) + }; + $change{'cust_location'} = $cust_location; +} + +my $pkg_or_error = $cust_pkg->change( \%change ); + +my $error = ref($pkg_or_error) ? '' : $pkg_or_error; + +</%init> diff --git a/httemplate/edit/process/cust_pkg.cgi b/httemplate/edit/process/cust_pkg.cgi index 272ddcc47..94c084eae 100755 --- a/httemplate/edit/process/cust_pkg.cgi +++ b/httemplate/edit/process/cust_pkg.cgi @@ -1,22 +1,15 @@ % 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") %> +% $cgi->redirect(popurl(3). 'edit/cust_pkg.cgi?'. $cgi->query_string ); % } else { -% die "guru exception #5: action is neither change nor bulk!"; -% } +<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right('Bulk change customer packages'); + my $error = ''; #untaint custnum @@ -28,46 +21,19 @@ my @remove_pkgnums = map { $1; } $cgi->param('remove_pkg'); -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 = '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; - while ( $num_pkgs-- ) { - push @pkgparts,$pkgpart; - } - } else { - $error = "Illegal quantity"; - last; +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; } - -} else { - die "guru exception #5: action is neither change nor bulk!"; } $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums); |