Guess the branch of anonymous opac sessions using the client IP address
So SearchMyLibraryFirst will work even when no patron is logged in.
---
C4/Auth.pm | 35 ++++++++++++++++++++-
koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc | 4 +-
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/C4/Auth.pm b/C4/Auth.pm
index f919fa1..4e08801 100755
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -742,6 +742,39 @@ sub checkauth {
$session->param('ip',$session->remote_addr());
$session->param('lasttime',time());
$session->param('sessiontype','anon');
+
+ # Guess branchcode from ip addr
+ $debug and warn "Looking for anonymous branchcode";
+ my $branchcode = $session->param('branch');
+ my $branches = GetBranches();
+ my $ip = $session->remote_addr();
+ if ( ! $branchcode &&
C4::Context->boolean_preference('SearchMyLibraryFirst') ){
+ # Let's find their location
+ my @branchesloop;
+ foreach my $br ( keys %$branches ) {
+ # now we work with the treatment of ip
+ my $domain =
$branches->{$br}->{'branchip'};
+ foreach my $subdomain ( split /\|/,
$domain ) {
+ if ( $subdomain && $ip =~
/^$subdomain/ ) {
+ $branchcode =
$branches->{$br}->{'branchcode'};
+ }
+ }
+ }
+ }
+ if ( $branchcode ) {
+ # Some things have to be set for SearchMyLibraryFirst
+ $debug and warn "got anonymous branchcode:
$branchcode";
+ my $branchname =
$branches->{$branchcode}->{'branchname'};
+ $session->param('branch',$branchcode);
+ $session->param('branchname',$branchname);
+ C4::Context::set_userenv(
+ undef, undef,
+ undef, undef,
+ undef, $branchcode,
+ $branchname, undef,
+ undef, undef
+ );
+ }
}
} # END unless ($userid)
my $insecure = C4::Context->boolean_preference('insecure');
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
index a0e67ea..e0457dc 100755
--- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
@@ -17,7 +17,7 @@
<div id="fluid">
<div id="fluid-offset">
<!-- TMPL_UNLESS NAME="advsearch" --><form name="searchform" method="get"
action="/cgi-bin/koha/opac-search.pl" id="searchform">
- <label for="masthead_search" class="left"> Search <!-- TMPL_IF
name="mylibraryfirst" --> <!-- TMPL_IF name="loggedinusername" -->(in <!--
TMPL_VAR name="LoginBranchcode" --> only)<!-- /TMPL_IF --><!-- /TMPL_IF
--></label>
+ <label for="masthead_search" class="left"> Search <!-- TMPL_IF
name="mylibraryfirst" --> <!-- TMPL_IF name="LoginBranchname" -->(in <!--
TMPL_VAR name="LoginBranchcode" --> only)<!-- /TMPL_IF --><!-- /TMPL_IF
--></label>
<select name="idx" id="masthead_search" class="left"
style="max-width:9em;width:9em;">
<!-- TMPL_IF NAME="ms_kw" -->
<option selected="selected" value="">Library Catalog</option>
@@ -59,7 +59,7 @@
<!-- TMPL_ELSE -->
<input type="text" name="q" class="left" style="width: 35%; font-size:
111%;" />
<!-- /TMPL_IF -->
- <!-- TMPL_IF name="mylibraryfirst" --><!-- TMPL_IF
name="loggedinusername" -->
+ <!-- TMPL_IF name="mylibraryfirst" --><!-- TMPL_IF
name="LoginBranchname" -->
<input name="limit" value="<!-- TMPL_VAR name="LoginBranchcode"
-->" type="hidden" />
<!-- /TMPL_IF --><!-- /TMPL_IF -->
<input type="submit" value="Go" id="searchsubmit" class="left" />
--
1.5.4.3
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches