From 630ccb97b810099559b58bd4a430c96a37384ae9 Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Fri, 2 Jul 2021 11:10:37 -0600 Subject: [PATCH] Bug 28658 - With SearchMyLibraryFirst guess the opac clients library If the SearchMyLibraryFirst syspref is set, the OPAC uses the logged in users branchcode to limit searches to their library. If it's an anonymous session that doesn't happen. This tries to guess the client library by checking for the client ip address in each libraries branchip setting. Signed-off-by: Laura Escamilla --- C4/Auth.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C4/Auth.pm b/C4/Auth.pm index e2af3dd1ff..b01bc02c18 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -609,6 +609,18 @@ sub get_template_and_user { ); $template->param( OpacPublic => '1' ) if ( $user || C4::Context->preference("OpacPublic") ); + + # guess the branch by ip if it isn't set already + if ( C4::Context->preference("SearchMyLibraryFirst") && ! $template->param('mylibraryfirst') ) { + my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search }; + my $ip = $ENV{'REMOTE_ADDR'}; + foreach my $br ( keys %$branches ) { + my $domain = $branches->{$br}->{'branchip'}; + if ( in_iprange($domain) ) { + $template->param( mylibraryfirst => $branches->{$br}->{'branchcode'} ); + } + } + } } # Check if we were asked using parameters to force a specific language -- 2.30.2