@@ -, +, @@ branch security mod 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. OPAC_SEARCH_LIMIT branch + Patron record home branch + whatever branchcodes you put into Borrower_attributes. - 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 --- a/C4/Auth.pm +++ a/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"), --- a/C4/Branch.pm +++ a/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 ); --- a/C4/Koha.pm +++ a/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', --- a/C4/Members/Attributes.pm +++ a/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 --- a/installer/data/mysql/sysprefs.sql +++ a/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