diff options
| -rwxr-xr-x | httemplate/edit/process/cust_pkg.cgi | 97 | ||||
| -rw-r--r-- | httemplate/elements/select-table.html | 51 | ||||
| -rwxr-xr-x | httemplate/misc/change_pkg.cgi | 69 | ||||
| -rwxr-xr-x | httemplate/view/cust_main/packages.html | 7 | 
4 files changed, 128 insertions, 96 deletions
diff --git a/httemplate/edit/process/cust_pkg.cgi b/httemplate/edit/process/cust_pkg.cgi index 817c88087..25b826758 100755 --- a/httemplate/edit/process/cust_pkg.cgi +++ b/httemplate/edit/process/cust_pkg.cgi @@ -1,44 +1,55 @@ -% -% -%my $error = ''; -% -%#untaint custnum -%$cgi->param('custnum') =~ /^(\d+)$/; -%my $custnum = $1; -% -%my @remove_pkgnums = map { -%  /^(\d+)$/ or die "Illegal remove_pkg value!"; -%  $1; -%} $cgi->param('remove_pkg'); -% -%my $error_redirect; -%my @pkgparts; -%if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi -%  $error_redirect = "misc/change_pkg.cgi"; -%  @pkgparts = ($1); -%} else { #came from edit/cust_pkg.cgi -%  $error_redirect = "edit/cust_pkg.cgi"; -%  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; -%    } -%  } -%} -% -%$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums); -% -%if ($error) { -%  $cgi->param('error', $error); -%  print $cgi->redirect(popurl(3). $error_redirect. '?'. $cgi->query_string ); -%} else { -%  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum"); -%} -% -% +% 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 = ''; + +#untaint custnum +$cgi->param('custnum') =~ /^(\d+)$/; +my $custnum = $1; + +my @remove_pkgnums = map { +  /^(\d+)$/ or die "Illegal remove_pkg value!"; +  $1; +} $cgi->param('remove_pkg'); + +my( $action, $error_redirect ); +my @pkgparts = (); +if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi +  $action = 'change'; +  $error_redirect = "misc/change_pkg.cgi"; +  @pkgparts = ($1); +} else { #came from edit/cust_pkg.cgi +  $action = 'bulk'; +  $error_redirect = "edit/cust_pkg.cgi"; +  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; +    } +  } +} + +$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums); + +</%init> diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 4bf3d1c4d..8bcbf2504 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -5,32 +5,38 @@ Example:    include( '/elements/select-table.html',      #required -    'table'    => 'table_name', -    'name_col' => 'name_column', +    'table'          => 'table_name', +    'name_col'       => 'name_column',      #strongly recommended (you want your forms to be "sticky" on errors, right?) -    'value'    => 'current_value', +    'curr_value'     => 'current_value', +    #'value' => #deprecated form of 'curr_value',      #opt -    'empty_label'   => '', #better specify it though, the default might change -    'hashref'       => {}, -    'extra_sql'     => '', -    'records'       => \@records, #instead of hashref -    'pre_options'   => [ 'value' => 'option' ], #before normal options -    'element_name ' => '', #HTML element name, defaults to the name of -                           # the primary key column -    'field'         => '', #synonym for element_name -    'element_etc'   => '', #additional attributes (i.e. "DISABLED") for the -                           #<SELECT> element -    'multiple'      => 0, # bool -    'disable_empty' => 0, # bool (implied by multiple) -    'debug'         => 0, #set true to enable - +    'empty_label'    => '', #better specify it though, the default might change +    'hashref'        => {}, +    'extra_sql'      => '', +    'records'        => \@records, #instead of hashref +    'pre_options'    => [ 'value' => 'option' ], #before normal options +    'element_name'   => '', #HTML element name, defaults to the name of +                            # the primary key column +    'field'          => '', #synonym for element_name +    'element_etc'    => '', #additional attributes (i.e. "DISABLED") for the +                            #<SELECT> element +    'onchange'       => '', #javascript code +    'multiple'       => 0, # bool +    'disable_empty'  => 0, # bool (implied by multiple) +    'debug'          => 0, #set true to enable +    'label_callback' => sub { my $record = shift; return "label"; },    )  </%doc> -<SELECT <% $opt{'multiple'} ? 'MULTIPLE' : '' %> NAME="<% $opt{'element_name'} || $opt{'field'} || $key %>" <% $opt{'element_etc'} %>> +<SELECT <% $opt{'multiple'} ? 'MULTIPLE' : '' %> +        NAME = "<% $opt{'element_name'} || $opt{'field'} || $key %>" +        <% $onchange %> +        <% $opt{'element_etc'} %> +>  % while ( @pre_options ) {       <OPTION VALUE="<% shift(@pre_options) %>"><% shift(@pre_options) %> @@ -47,7 +53,10 @@ Example:              <% ref($value) && $value->{$recvalue} || $value == $recvalue                 ? ' SELECTED' : ''              %> -    ><% $record->$name_col() %> +    ><% $opt{'label_callback'} +          ? &{ $opt{'label_callback'} }( $record ) +          : $record->$name_col() +     %>  % }   </SELECT> @@ -59,6 +68,10 @@ my( %opt ) = @_;  warn "elements/select-table.html: \n". Dumper(%opt)    if exists $opt{debug} && $opt{debug}; +my $onchange = $opt{'onchange'} +                 ? 'onChange="'. $opt{'onchange'}. '(this)"' +                 : ''; +  my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||  my $name_col = $opt{'name_col'}; diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi index 655799fc1..4bf15a1fa 100755 --- a/httemplate/misc/change_pkg.cgi +++ b/httemplate/misc/change_pkg.cgi @@ -1,55 +1,60 @@ -<% include('/elements/header.html', "Change Package") %> +<% include('/elements/header-popup.html', "Change Package") %>  % if ( $cgi->param('error') ) {    <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>    <BR><BR>  % } -<% small_custview( $cust_main, $conf->config('countrydefault') || '' , '',  -                      "${p}view/cust_main.cgi") -%> -  <FORM ACTION="<% $p %>edit/process/cust_pkg.cgi" METHOD=POST>  <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">  <INPUT TYPE="hidden" NAME="remove_pkg" VALUE="<% $pkgnum %>"> -<BR> -Current package: <% $part_pkg->pkg %> - <% $part_pkg->comment %> +<% ntable('#cccccc') %> + +  <TR> +    <TD>Current package: </TD> +    <TD> +      <B><% $part_pkg->pkgpart %>: <% $part_pkg->pkg %> - <% $part_pkg->comment %></B> +    </TD> +  </TR> +   +  <TR> +    <TD>New package: </TD> +    <TD><% include('/elements/select-cust-part_pkg.html', +                     'cust_main'    => $cust_main, +                     'element_name' => 'new_pkgpart', +                     'extra_sql'    => ' AND pkgpart != '. $cust_pkg->pkgpart, +                     'curr_value'   => ( $cgi->param('error') +                                           ? scalar($cgi->param('new_pkgpart')) +                                           : '' +                                       ), +                  ) +        %> +    </TD> +  </TR> + +</TABLE>  <BR> -New package: <SELECT NAME="new_pkgpart"><OPTION VALUE=0></OPTION> - -%foreach my $part_pkg ( -%  grep { ! $_->disabled && $_->pkgpart != $cust_pkg->pkgpart } -%    map { $_->part_pkg } $agent->agent_type->type_pkgs -%) { -%  my $pkgpart = $part_pkg->pkgpart; - -  <OPTION VALUE="<% $pkgpart %>" <% ( $cgi->param('error') && $cgi->param('new_pkgpart') == $pkgpart ) ? ' SELECTED' : '' %>> -    <% $pkgpart %>: <% $part_pkg->pkg %> - <% $part_pkg->comment %> -  </OPTION> +<INPUT TYPE="submit" VALUE="Change package"> -%} - -</SELECT> -<BR><BR><INPUT TYPE="submit" VALUE="Change package"> -    </FORM> -  </BODY> +</FORM> +</BODY>  </HTML> +  <%init> +die "access denied" +  unless $FS::CurrentUser::CurrentUser->access_right('Change customer package'); +  my $pkgnum;  if ( $cgi->param('error') ) { -  #$custnum = $cgi->param('custnum'); -  #%remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');    $pkgnum = ($cgi->param('remove_pkg'))[0];  } else { -  my($query) = $cgi->keywords; -  $query =~ /^(\d+)$/; -  #$custnum = $1; -  $pkgnum = $1; -  #%remove_pkg = (); +  $pkgnum = $cgi->param('pkgnum');  } +$pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum"; +$pkgnum = $1;  my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } )    or die "unknown pkgnum $pkgnum"; @@ -57,8 +62,6 @@ my $custnum = $cust_pkg->custnum;  my $conf = new FS::Conf; -my $p1 = popurl(1); -  my $cust_main = $cust_pkg->cust_main    or die "can't get cust_main record for custnum ". $cust_pkg->custnum.           " ( pkgnum ". cust_pkg->pkgnum. ")"; diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html index 5890726ae..deef909d0 100755 --- a/httemplate/view/cust_main/packages.html +++ b/httemplate/view/cust_main/packages.html @@ -497,7 +497,12 @@ Current packages  %  $strip;  %}  % -%sub pkg_change_link    { pkg_link('misc/change_pkg',    'Change package', @_ ); } +% sub pkg_change_link    { pkg_popup_link('misc/change_pkg.cgi?dummy=value', +%                                           'Change package', +%                                           'Change', +%                                           @_ +%                                        ); +%                        }  %  %sub pkg_suspend_link   { pkg_popup_link( 'misc/cancel_pkg.html?method=suspend',  %                                         'Suspend now',  | 
