diff options
Diffstat (limited to 'httemplate')
| -rwxr-xr-x | httemplate/browse/part_pkg.cgi | 2 | ||||
| -rw-r--r-- | httemplate/edit/elements/edit.html | 5 | ||||
| -rwxr-xr-x | httemplate/edit/part_pkg.cgi | 43 | ||||
| -rwxr-xr-x | httemplate/edit/process/part_pkg.cgi | 19 | ||||
| -rw-r--r-- | httemplate/elements/select-agent_types.html | 2 | ||||
| -rw-r--r-- | httemplate/elements/select-cust-part_pkg.html | 8 | ||||
| -rw-r--r-- | httemplate/elements/select-part_pkg.html | 18 | ||||
| -rw-r--r-- | httemplate/elements/select-table.html | 4 | ||||
| -rw-r--r-- | httemplate/elements/tr-select-agent_types.html | 2 | ||||
| -rw-r--r-- | httemplate/search/elements/search.html | 74 | 
10 files changed, 124 insertions, 53 deletions
| diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 780f40b9f..cdaa2c92a 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -46,6 +46,7 @@ if ( $cgi->param('active') ) {  my $extra_sql = ''; +#false laziness w/elements/select-part_pkg.html  my $agentnums = join(',', $curuser->agentnums);  unless ( $acl_edit_global ) { @@ -62,6 +63,7 @@ unless ( $acl_edit_global ) {      )    ";  } +#eofalse  my $count_cust_pkg = "    SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum ) diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index f4e4195de..76fcd384b 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -254,7 +254,7 @@ Example:  %     'layer_values'  => $layer_values,  %     'html_between'  => $f->{'html_between'},  % -%     #umm. +%     #umm.  for select-agent_types at least  %     'disabled'      => $f->{'disabled'},  %   );  % @@ -641,7 +641,8 @@ if ( $cgi->param('error') ) {      $value = $query;    }    $value =~ /^(\d+)$/ or die "unparsable $pkey"; -  $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }); +  $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }) +    or die "$pkey $1 not found in $table";    warn "$table $pkey => $1"      if $opt{'debug'}; diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 4b519f5fa..3efc26cc3 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -1,12 +1,16 @@  <% include( 'elements/edit.html', -              'post_url'    => popurl(1).'process/part_pkg.cgi', -              'name'        => "Package definition", -              'table'       => 'part_pkg', -              #'viewall_dir' => 'browse', -              'viewall_url' => $p.'browse/part_pkg.cgi', -              'html_init'   => include('/elements/init_overlib.html'). -                               $freq_changed, -              'html_bottom' => $html_bottom, +              'post_url'         => popurl(1).'process/part_pkg.cgi', +              'name'             => "Package definition", +              'table'            => 'part_pkg', + +              'agent_virt'       => 1, +              'agent_null_right' => $edit_global, + +              #'viewall_dir'      => 'browse', +              'viewall_url'      => $p.'browse/part_pkg.cgi', +              'html_init'        => include('/elements/init_overlib.html'). +                                    $freq_changed, +              'html_bottom'      => $html_bottom,                'begin_callback'       => $begin_callback,                'end_callback'         => $end_callback, @@ -32,7 +36,7 @@                              'disabled'         => 'Disable new orders',                              'pay_weight'       => 'Payment weight',                              'credit_weight'    => 'Credit weight', -                            'agentnum'         => '', +                            'agentnum'         => 'Agent',                              'setup_fee'        => 'Setup fee',                              'recur_fee'        => 'Recurring fee',                              'bill_dst_pkgpart' => 'Include line item(s) from package', @@ -57,6 +61,11 @@                                  maxlength => 50,                                },                                {field=>'comment',  type=>'text', size=>40 }, #32 +                              { field         => 'agentnum', +                                type          => 'select-agent', +                                disable_empty => ! $acl_edit_global, +                                empty_label   => '(global)', +                              },                                {field=>'classnum', type=>'select-pkg_class' },                                {field=>'disabled', type=>$disabled_type, value=>'Y'}, @@ -125,8 +134,9 @@                              { type => 'columnnext' }, -                              { field=>'agent_type', -                                type => 'select-agent_types', +                              { field    => 'agent_type', +                                type     => 'select-agent_types', +                                disabled => ! $acl_edit_global,                                  curr_value_callback => sub {                                    my($cgi, $object, $field) = @_;                                    #in the other callbacks..?  hmm. @@ -175,19 +185,22 @@  my $curuser = $FS::CurrentUser::CurrentUser; -my $edit_right = $curuser->access_right('Edit package definitions') -              || $curuser->access_right('Edit global package definitions'); +my $edit_global = 'Edit global package definitions'; +my $acl_edit        = $curuser->access_right('Edit package definitions'); +my $acl_edit_global = $curuser->access_right($edit_global); + +my $acl_edit_either = $acl_edit || $acl_edit_global;  my $begin_callback = sub {    my( $cgi, $fields, $opt ) = @_;    die "access denied" -    unless $edit_right +    unless $acl_edit_either          || ( $cgi->param('pkgnum')               && $curuser->access_right('Customize customer package')             );  }; -my $disabled_type = $edit_right ? 'checkbox' : 'hidden'; +my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';  my $conf = new FS::Conf;  my $taxproducts = $conf->exists('enable_taxproducts'); diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index 669b75946..96c5b36b7 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -1,11 +1,12 @@  <% include( 'elements/process.html',                #'debug'             => 1,                'table'             => 'part_pkg', +              'agent_virt'        => 1, +              'agent_null_right'  => \@agent_null_right,                'redirect'          => $redirect_callback,                'viewall_dir'       => 'browse',                'viewall_ext'       => 'cgi',                'edit_ext'          => 'cgi', -              #XXX usable with cloning? #'agent_null_right'  => 'Edit global package definitions',                'precheck_callback' => $precheck_callback,                'args_callback'     => $args_callback,                'process_m2m'       => \@process_m2m, @@ -13,12 +14,21 @@  %>  <%init> +my $customizing = ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') ); +  my $curuser = $FS::CurrentUser::CurrentUser; +my $edit_global = 'Edit global package definitions'; +my $customize   = 'Customize customer package'; +  die "access denied"    unless $curuser->access_right('Edit package definitions') -      || $curuser->access_right('Edit global package definitions') -      || ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') ); +      || $curuser->access_right($edit_global) +      || ( $customizing && $curuser->access_right($customize) ); + +my @agent_null_right = ( $edit_global ); +push @agent_null_right, $customize if $customizing; +  my $precheck_callback = sub {    my( $cgi ) = @_; @@ -41,7 +51,8 @@ my $precheck_callback = sub {      unless scalar(@agents)             || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )             || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') ) -           || $cgi->param('disabled'); +           || $cgi->param('disabled') +           || $cgi->param('agentnum');    return ''; diff --git a/httemplate/elements/select-agent_types.html b/httemplate/elements/select-agent_types.html index e56fee43c..400b453b3 100644 --- a/httemplate/elements/select-agent_types.html +++ b/httemplate/elements/select-agent_types.html @@ -1,5 +1,5 @@  %# if ( $cgi->param('clone') ) { #XXX -% if ( $opt{'disable'} ) {  +% if ( $opt{'disabled'} ) {       <INPUT TYPE="hidden" NAME="agent_type" VALUE=""> diff --git a/httemplate/elements/select-cust-part_pkg.html b/httemplate/elements/select-cust-part_pkg.html index 57da5cd84..292662921 100644 --- a/httemplate/elements/select-cust-part_pkg.html +++ b/httemplate/elements/select-cust-part_pkg.html @@ -32,8 +32,10 @@ my $cust_main = $opt{'cust_main'}    or die "cust_main not specified";  $opt{'extra_sql'} .= -  ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '. -  '             WHERE typenum = '. $cust_main->agent->typenum. -  '             AND type_pkgs.pkgpart = part_pkg.pkgpart )'; +  ' AND ( agentnum IS NOT NULL '. +  '         OR 0 < ( SELECT COUNT(*) FROM type_pkgs '. +  '                    WHERE typenum = '. $cust_main->agent->typenum. +  '                      AND type_pkgs.pkgpart = part_pkg.pkgpart )'. +  '     )';  </%init> diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html index a1d5f40f2..cd6d24c28 100644 --- a/httemplate/elements/select-part_pkg.html +++ b/httemplate/elements/select-part_pkg.html @@ -17,6 +17,8 @@ Example:  <% include( '/elements/select-table.html',                'table'          => 'part_pkg', +              'agent_virt'     => 1, +              'agent_null'     => 1,                'name_col'       => 'pkg',                'empty_label'    => 'Select package', #should this be the default?                'label_callback' => sub { shift->pkg_comment }, @@ -31,4 +33,20 @@ my( %opt ) = @_;  $opt{'records'} = delete $opt{'part_pkg'}    if $opt{'part_pkg'}; +#false laziness w/browse/part_pkg.cgi +my $agentnums = join(',', $FS::CurrentUser::CurrentUser->agentnums); + +$opt{'extra_sql'} .= +  " AND ( agentnum IS NOT NULL +          OR 0 < ( SELECT COUNT(*) +                     FROM type_pkgs +                       LEFT JOIN agent_type USING ( typenum ) +                       LEFT JOIN agent AS typeagent USING ( typenum ) +                     WHERE type_pkgs.pkgpart = part_pkg.pkgpart +                       AND typeagent.agentnum IN ($agentnums) +                 ) +        ) +  "; +#eofalse +  </%init> diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 32a61e989..4efbcbaf3 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -24,6 +24,7 @@ Example:      'extra_sql'        => '',      'agent_virt'       => 0, #set true and make sure the result is JOINed to                               #something with agentnum (usually cust_main) +    'agent_null'       => 0, #set true to always show un-agented entries      'agent_null_right' => '', #right to see un-agented entries      #or      'records'        => \@records, #instead of search params @@ -120,7 +121,8 @@ if ( $opt{'agent_virt'} ) {    $extra_sql .=      ( $extra_sql =~ /WHERE/i || scalar(keys %$hashref ) ? ' AND ' : ' WHERE ' ).      $FS::CurrentUser::CurrentUser->agentnums_sql( -                                    'null_right' => $opt{'agent_null_right'} +                                    'null'       => $opt{'agent_null'}, +                                    'null_right' => $opt{'agent_null_right'},                                     );  } diff --git a/httemplate/elements/tr-select-agent_types.html b/httemplate/elements/tr-select-agent_types.html index 29ac7f1b4..efbf386a7 100644 --- a/httemplate/elements/tr-select-agent_types.html +++ b/httemplate/elements/tr-select-agent_types.html @@ -1,4 +1,4 @@ -% unless ( $opt{'disable'} || scalar(@all_agent_types) == 1 ) { +% unless ( $opt{'disabled'} || scalar(@all_agent_types) == 1 ) {  <% include('/elements/tr-justtitle.html', value=>'Agent (reseller) types') %> diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index dd0555c6d..23fe8f470 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -92,8 +92,8 @@ Example:      'footer'      => [],      #disabling things -    'disable_download' => '', # set true to hide the CSV/Excel download links -    'disable_total'    => '', # set true to hide the total" +    'disable_download'  => '', # set true to hide the CSV/Excel download links +    'disable_total'     => '', # set true to hide the total"      'disable_maxselect' => '', # set true to disable record/page selection      'disable_nonefound' => '', # set true to disable the "No matching Xs found"                                 # message @@ -110,12 +110,17 @@ Example:                                 # header & fields need to be defined)      #handling agent virtualization -    'agent_virt' => 1, # set true if this search should be agent-virtualized -    'agent_null_right' => 'Access Right', #opt. right to view global records -    'agent_pos' => 3, #optional position (starting from 0) to insert -                      #an Agent column  -                      #(query needs to be a qsearch hashref and -                      # header & fields need to be defined) +    'agent_virt'            => 1, # set true if this search should be +                                  # agent-virtualized +    'agent_null_right'      => 'Access Right', # optional right to view global +                                               # records +    'agent_null_right_link' => 'Access Right'  # optional right to link to +                                               # global records; defaults to +                                               # same as agent_null_right +    'agent_pos'             => 3, # optional position (starting from 0) to +                                  # insert an Agent column (query needs to be a +                                  # qsearch hashref and header & fields need to +                                  # be defined)      # link & display properties for fields @@ -581,23 +586,33 @@ Example:  %                       my $a = '';  %                       if ( $links ) {  %                         my $link = shift @$links; -%                         $link = &{$link}($row) -%                           if ref($link) eq 'CODE'; -%  %                         my $onclick = shift @$onclicks; -%                         $onclick = &{$onclick}($row) -%                           if ref($onclick) eq 'CODE'; -%                         $onclick = qq( onClick="$onclick") if $onclick; -% -%                         if ( $link ) { -%                           my( $url, $method ) = @{$link}; -%                           if ( ref($method) eq 'CODE' ) { -%                             $a = $url. &{$method}($row); -%                           } else { -%                             $a = $url. $row->$method(); +% +%                         if (    ! $opt{'agent_virt'} +%                              || ( $null_link && ! $row->agentnum ) +%                              || grep { $row->agentnum == $_ } +%                                      @link_agentnums +%                            ) { +%         +%                           $link = &{$link}($row) +%                             if ref($link) eq 'CODE'; +% +%                           $onclick = &{$onclick}($row) +%                             if ref($onclick) eq 'CODE'; +%                           $onclick = qq( onClick="$onclick") if $onclick; +% +%                           if ( $link ) { +%                             my( $url, $method ) = @{$link}; +%                             if ( ref($method) eq 'CODE' ) { +%                               $a = $url. &{$method}($row); +%                             } else { +%                               $a = $url. $row->$method(); +%                             } +%                             $a = qq(<A HREF="$a"$onclick>);  %                           } -%                           $a = qq(<A HREF="$a"$onclick>); +%  %                         } +%  %                       }  %  %                       my $font = ''; @@ -702,18 +717,25 @@ $opt{align} = [ map $align{$_}, split(//, $opt{align}) ],  $opt{disable_download} = 0    if $opt{disable_download} && $curuser->access_right('Configuration download'); +my @link_agentnums = (); +my $null_link = '';  if ( $opt{'agent_virt'} ) { +  @link_agentnums = $curuser->agentnums; +  $null_link = $curuser->access_right(    $opt{'agent_null_right_link'} +                                       || $opt{'agent_null_right'}      ); +    my $agentnums_sql = $curuser->agentnums_sql(                          'null_right' => $opt{'agent_null_right'}                        );    $opt{'query'}{'extra_sql'} .= -    ( $opt{'query'}       =~ /WHERE/i ? ' AND ' : ' WHERE ' ). -    $agentnums_sql; +    ( $opt{'query'}{'extra_sql'} =~ /WHERE/i || keys %{$opt{'query'}{'hashref'}} +      ? ' AND ' +      : ' WHERE ' ). $agentnums_sql; +    $opt{'count_query'} .= -    ( $opt{'count_query'} =~ /WHERE/i ? ' AND ' : ' WHERE ' ). -    $agentnums_sql; +    ( $opt{'count_query'} =~ /WHERE/i ? ' AND ' : ' WHERE ' ).  $agentnums_sql;    if ( $opt{'agent_pos'} || $opt{'agent_pos'} eq '0'         and scalar($curuser->agentnums) > 1           ) { | 
