From 0822839ff2af7203ceeced027529f5e854ea7f1b 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. --- C4/Auth.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C4/Auth.pm b/C4/Auth.pm index e8575e9472..641db1c90f 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -635,6 +635,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.25.1