View | Details | Raw Unified | Return to bug 18743
Collapse All | Expand All

(-)a/C4/Suggestions.pm (-9 / +15 lines)
Lines 135-144 sub SearchSuggestion { Link Here
135
    }
135
    }
136
136
137
    # filter on user branch
137
    # filter on user branch
138
    if ( C4::Context->preference('IndependentBranches') ) {
138
    if (   C4::Context->preference('IndependentBranches')
139
        && !C4::Context->IsSuperLibrarian() )
140
    {
141
        # If IndependentBranches is set and the logged in user is not superlibrarian
142
        # Then we want to filter by the user's library (i.e. cannot see suggestions from other libraries)
139
        my $userenv = C4::Context->userenv;
143
        my $userenv = C4::Context->userenv;
140
        if ($userenv) {
144
        if ($userenv) {
141
            if ( !C4::Context->IsSuperLibrarian() && !$suggestion->{branchcode} )
142
            {
145
            {
143
                push @sql_params, $$userenv{branch};
146
                push @sql_params, $$userenv{branch};
144
                push @query,      q{
147
                push @query,      q{
Lines 146-158 sub SearchSuggestion { Link Here
146
                };
149
                };
147
            }
150
            }
148
        }
151
        }
149
    } else {
152
    }
150
        if ( defined $suggestion->{branchcode} && $suggestion->{branchcode} ) {
153
    elsif (defined $suggestion->{branchcode}
151
            unless ( $suggestion->{branchcode} eq '__ANY__' ) {
154
        && $suggestion->{branchcode}
152
                push @sql_params, $suggestion->{branchcode};
155
        && $suggestion->{branchcode} ne '__ANY__' )
153
                push @query,      qq{ AND suggestions.branchcode=? };
156
    {
154
            }
157
        # If IndependentBranches is not set OR the logged in user is not superlibrarian
155
        }
158
        # AND the branchcode filter is passed and not '__ANY__'
159
        # Then we want to filter using this parameter
160
        push @sql_params, $suggestion->{branchcode};
161
        push @query,      qq{ AND suggestions.branchcode=? };
156
    }
162
    }
157
163
158
    # filter on nillable fields
164
    # filter on nillable fields
(-)a/suggestion/suggestion.pl (-5 / +10 lines)
Lines 117-122 my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user( Link Here
117
117
118
$borrowernumber = $input->param('borrowernumber') if ( $input->param('borrowernumber') );
118
$borrowernumber = $input->param('borrowernumber') if ( $input->param('borrowernumber') );
119
$template->param('borrowernumber' => $borrowernumber);
119
$template->param('borrowernumber' => $borrowernumber);
120
my $branchfilter = $input->param('branchcode') || C4::Context->userenv->{'branch'};
120
121
121
#########################################
122
#########################################
122
##  Operations
123
##  Operations
Lines 255-261 if ($op=~/else/) { Link Here
255
    $op='else';
256
    $op='else';
256
    
257
    
257
    $displayby||="STATUS";
258
    $displayby||="STATUS";
258
    delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode");
259
    # distinct values of display by
259
    # distinct values of display by
260
    my $criteria_list=GetDistinctValues("suggestions.".$displayby);
260
    my $criteria_list=GetDistinctValues("suggestions.".$displayby);
261
    my (@criteria_dv, $criteria_has_empty);
261
    my (@criteria_dv, $criteria_has_empty);
Lines 269-274 if ($op=~/else/) { Link Here
269
    # aggregate null and empty values under empty value
269
    # aggregate null and empty values under empty value
270
    push @criteria_dv, '' if $criteria_has_empty;
270
    push @criteria_dv, '' if $criteria_has_empty;
271
271
272
    # Hack to not modify GetDistinctValues for this specific case
273
    if (   $displayby eq 'branchcode'
274
        && C4::Context->preference('IndependentBranches')
275
        && not C4::Context->IsSuperLibrarian )
276
    {
277
        @criteria_dv = ( C4::Context->userenv->{'branch'} );
278
    }
279
272
    my @allsuggestions;
280
    my @allsuggestions;
273
    foreach my $criteriumvalue ( @criteria_dv ) {
281
    foreach my $criteriumvalue ( @criteria_dv ) {
274
        # By default, display suggestions from current working branch
282
        # By default, display suggestions from current working branch
Lines 277-283 if ($op=~/else/) { Link Here
277
        }
285
        }
278
        my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
286
        my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
279
287
280
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue );
288
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' or $branchfilter ne '__ANY__' );
281
        $$suggestion_ref{$displayby} = $criteriumvalue;
289
        $$suggestion_ref{$displayby} = $criteriumvalue;
282
290
283
        my $suggestions = &SearchSuggestion($suggestion_ref);
291
        my $suggestions = &SearchSuggestion($suggestion_ref);
Lines 332-339 if(defined($returnsuggested) and $returnsuggested ne "noone") Link Here
332
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
340
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
333
}
341
}
334
342
335
my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : C4::Context->userenv->{'branch'};
336
337
$template->param(
343
$template->param(
338
    branchfilter => $branchfilter,
344
    branchfilter => $branchfilter,
339
);
345
);
340
- 

Return to bug 18743