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 253-259 if ($op=~/else/) { Link Here
253
    $op='else';
254
    $op='else';
254
    
255
    
255
    $displayby||="STATUS";
256
    $displayby||="STATUS";
256
    delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode");
257
    # distinct values of display by
257
    # distinct values of display by
258
    my $criteria_list=GetDistinctValues("suggestions.".$displayby);
258
    my $criteria_list=GetDistinctValues("suggestions.".$displayby);
259
    my (@criteria_dv, $criteria_has_empty);
259
    my (@criteria_dv, $criteria_has_empty);
Lines 267-272 if ($op=~/else/) { Link Here
267
    # aggregate null and empty values under empty value
267
    # aggregate null and empty values under empty value
268
    push @criteria_dv, '' if $criteria_has_empty;
268
    push @criteria_dv, '' if $criteria_has_empty;
269
269
270
    # Hack to not modify GetDistinctValues for this specific case
271
    if (   $displayby eq 'branchcode'
272
        && C4::Context->preference('IndependentBranches')
273
        && not C4::Context->IsSuperLibrarian )
274
    {
275
        @criteria_dv = ( C4::Context->userenv->{'branch'} );
276
    }
277
270
    my @allsuggestions;
278
    my @allsuggestions;
271
    foreach my $criteriumvalue ( @criteria_dv ) {
279
    foreach my $criteriumvalue ( @criteria_dv ) {
272
        # By default, display suggestions from current working branch
280
        # By default, display suggestions from current working branch
Lines 275-281 if ($op=~/else/) { Link Here
275
        }
283
        }
276
        my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
284
        my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
277
285
278
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue );
286
        next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue ) and ($displayby ne 'branchcode' or $branchfilter ne '__ANY__' );
279
        $$suggestion_ref{$displayby} = $criteriumvalue;
287
        $$suggestion_ref{$displayby} = $criteriumvalue;
280
288
281
        my $suggestions = &SearchSuggestion($suggestion_ref);
289
        my $suggestions = &SearchSuggestion($suggestion_ref);
Lines 330-337 if(defined($returnsuggested) and $returnsuggested ne "noone") Link Here
330
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
338
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
331
}
339
}
332
340
333
my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : C4::Context->userenv->{'branch'};
334
335
$template->param(
341
$template->param(
336
    branchfilter => $branchfilter,
342
    branchfilter => $branchfilter,
337
);
343
);
338
- 

Return to bug 18743