From cd51860be11f002070f2debaa1478a9874187f63 Mon Sep 17 00:00:00 2001 From: Waylon Robertson Date: Tue, 5 Nov 2013 22:33:34 -0600 Subject: [PATCH] Bug 9055: Mandumah.com's multiple branch search, multiple branch security mod This mod creates the ability to search multiple branches using a jquery dropdown, instead of just one or all branches. This mod also replaces SearchMyLibraryFirst preference, giving three options: All = no change from standard koha setup. Preferhome = Prefers patron's home library (others may be searched), koha's current functionality of SearchMyLibraryFirst. Securehome = Only patrons' home library and other assigned libraries (if any) can be searched. With multiple instances of branchcode inside Borrower extended attributes, a patron can be given multiple branches to search within. The Securehome concept also includes the branch given in the apache enviroment of the host/virtualhost contacted, from OPAC_SEARCH_LIMIT = "branch: blah" This patch not only filters the GetBranches results, filtering the patrons ability to see other branches other than the ones given, it also filters the branches given in the limit branch: search options, so that even if a user manually inputted a branch, they are still only getting what they are ment to get. This enhancement would be useful for big libraries, in which its members would be restricted to searching and borrowing from a subset of its books. Overall, the multiple branch search dropdown should prove useful, even with unsecure installations. What is not included yet, is a method to decide what branches to show to a guest, not-logged-in, user. To use this patch, you need to create a branchcode Patron Extended Attribute, and have the patron your working with, have one or more branchcode extended attributes. So, total branches that patron will get: OPAC_SEARCH_LIMIT branch + Patron record home branch + whatever branchcodes you put into Borrower_attributes. You also need to set the preferences. The three new preferences to set are: - OPAC: SearchableBranches - Patrons: multibranch - Searching: MultiBranchSelect --- C4/Auth.pm | 6 +- C4/Branch.pm | 26 +- C4/Koha.pm | 4 +- C4/Members/Attributes.pm | 14 +- installer/data/mysql/sysprefs.sql | 4 +- installer/data/mysql/updatedatabase.pl | 19 +- .../prog/en/modules/admin/preferences/opac.pref | 12 +- .../prog/en/modules/admin/preferences/patrons.pref | 6 + .../en/modules/admin/preferences/searching.pref | 7 + .../lib/jquery/plugins/css/jquery.multiSelect.css | 85 +++ .../jquery/plugins/images/dropdown.blue.active.png | Bin 0 -> 390 bytes .../jquery/plugins/images/dropdown.blue.hover.png | Bin 0 -> 389 bytes .../lib/jquery/plugins/images/dropdown.blue.png | Bin 0 -> 298 bytes .../lib/jquery/plugins/images/dropdown.gif | Bin 0 -> 61 bytes .../lib/jquery/plugins/images/dropdown_active.gif | Bin 0 -> 61 bytes .../lib/jquery/plugins/images/dropdown_hover.gif | Bin 0 -> 61 bytes .../lib/jquery/plugins/jquery.bgiframe.min.js | 7 + .../lib/jquery/plugins/jquery.multiSelect.js | 554 ++++++++++++++++++++ .../opac-tmpl/prog/en/modules/opac-advsearch.tt | 12 + opac/opac-search.pl | 63 ++- 20 files changed, 795 insertions(+), 24 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/css/jquery.multiSelect.css create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown.blue.active.png create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown.blue.hover.png create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown.blue.png create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown.gif create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown_active.gif create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/images/dropdown_hover.gif create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.bgiframe.min.js create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.multiSelect.js diff --git a/C4/Auth.pm b/C4/Auth.pm index 8b0bebe..ebb67e6 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -387,9 +387,7 @@ sub get_template_and_user { my $opac_name = ''; if (($opac_search_limit && $opac_search_limit =~ /branch:(\w+)/ && $opac_limit_override) || ($in->{'query'}->param('limit') && $in->{'query'}->param('limit') =~ /branch:(\w+)/)){ $opac_name = $1; # opac_search_limit is a branch, so we use it. - } elsif ( $in->{'query'}->param('multibranchlimit') ) { - $opac_name = $in->{'query'}->param('multibranchlimit'); - } elsif (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv && C4::Context->userenv->{'branch'}) { + } elsif (C4::Context->preference("SearchableBranches") ne "all" && C4::Context->userenv && C4::Context->userenv->{'branch'}) { $opac_name = C4::Context->userenv->{'branch'}; } $template->param( @@ -435,7 +433,7 @@ sub get_template_and_user { RequestOnOpac => C4::Context->preference("RequestOnOpac"), 'Version' => C4::Context->preference('Version'), hidelostitems => C4::Context->preference("hidelostitems"), - mylibraryfirst => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '', + mylibraryfirst => (C4::Context->preference("SearchableBranches") ne 'all' && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '', opaclayoutstylesheet => "" . C4::Context->preference("opaclayoutstylesheet"), opacbookbag => "" . C4::Context->preference("opacbookbag"), opaccredits => "" . C4::Context->preference("opaccredits"), diff --git a/C4/Branch.pm b/C4/Branch.pm index bdc01dc..4971bd6 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 require Exporter; use C4::Context; +use C4::Members::Attributes; +use C4::Members; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -113,11 +115,33 @@ sub GetBranches { my $sth; my $query="SELECT * FROM branches"; my @bind_parameters; + my $borrowernumber; + if(C4::Context->userenv){$borrowernumber = C4::Context->userenv->{number}}; + if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){ $query .= ' WHERE branchcode = ? '; push @bind_parameters, C4::Context->userenv->{branch}; + } elsif(C4::Context->preference("SearchableBranches") eq 'securehome' && C4::Context->userenv && $borrowernumber !=0) { # Preference is set to search only the branches specified in patron record. + my %borrower_branches; + if(C4::Context->preference("multibranch")) { + my $value = C4::Members::Attributes::GetBorrowerAttributeValue($borrowernumber, "branchcode",1); #calling for an arrayref with all values. + foreach my $branchcode (@{$value}) { + $borrower_branches{$$branchcode[0]} = 1; + } + } + my $members = GetMember( 'borrowernumber' => $borrowernumber ); + my $homebranch = $members->{'branchcode'}; + $borrower_branches{$homebranch} = 1 if $homebranch; + if($ENV{'OPAC_SEARCH_LIMIT'} =~ m/^branch:(.*)/){ + $borrower_branches{$1} = 1; + } + my @allowedbranches; + foreach my $branch (keys %borrower_branches) { + push @allowedbranches, $branch; + } + $query .= ' WHERE branchcode in (\''.join('\',\'',@allowedbranches).'\')';; } - $query.=" ORDER BY branchname"; + $query.=" ORDER BY branchname"; $sth = $dbh->prepare($query); $sth->execute( @bind_parameters ); diff --git a/C4/Koha.pm b/C4/Koha.pm index 937ac5f..5eacc5a 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -716,7 +716,7 @@ sub getFacets { ]; my $library_facet; - unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { + unless ( C4::Context->preference("singleBranchMode") || C4::Branch::GetBranchesCount() == 1 ) { $library_facet = { idx => 'branch', label => 'Libraries', @@ -777,7 +777,7 @@ sub getFacets { ]; my $library_facet; - unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { + unless ( C4::Context->preference("singleBranchMode") || C4::Branch::GetBranchesCount() == 1 ) { $library_facet = { idx => 'branch', label => 'Libraries', diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index f0ec07f..eeca1d9 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -120,24 +120,28 @@ sub GetAttributes { =head2 GetBorrowerAttributeValue - my $value = C4::Members::Attributes::GetBorrowerAttributeValue($borrowernumber, $attribute_code); + my $value = C4::Members::Attributes::GetBorrowerAttributeValue($borrowernumber, $attribute_code, $as_array); Retrieve the value of an extended attribute C<$attribute_code> associated with the -patron specified by C<$borrowernumber>. +patron specified by C<$borrowernumber>. If $as_array is true, gets all available values, and returns it as an arrayref. =cut sub GetBorrowerAttributeValue { my $borrowernumber = shift; my $code = shift; - + my $as_array = shift; my $dbh = C4::Context->dbh(); my $query = "SELECT attribute FROM borrower_attributes WHERE borrowernumber = ? AND code = ?"; - my $value = $dbh->selectrow_array($query, undef, $borrowernumber, $code); - return $value; + if ($as_array){ + return $dbh->selectall_arrayref($query,undef, $borrowernumber, $code); + } else { + my $value = $dbh->selectrow_array($query, undef, $borrowernumber, $code); + return $value; + } } =head2 SearchIdMatchingAttribute diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 6438483..f0e3973 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -182,6 +182,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('maxreserves','50','','Define maximum number of holds a patron can place','Integer'), ('memberofinstitution','0',NULL,'If ON, patrons can be linked to institutions','YesNo'), ('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'), +('multibranch',0,NULL,'If ON, patrons having borrower_attribute's of branchcode, will have them added to their branches allowed, list. Filters all branch lists and opac searches.','YesNo'), +('MultiBranchSelect',0,NULL,'If ON, Shows a muiltibranch dropdown instead of a single branch, in advanced search by branch','YesNo'), ('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''), ('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'), ('noItemTypeImages','0',NULL,'If ON, disables item-type images','YesNo'), @@ -328,8 +330,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'), ('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded