@@ -, +, @@ This mod creates the ability to search multiple branches using a jquery dropdown, instead of just one or all branches. --- C4/Auth.pm | 4 +- C4/Branch.pm | 26 +- C4/Koha.pm | 4 +- C4/Members/Attributes.pm | 14 +- installer/data/mysql/sysprefs.sql | 4 +- installer/data/mysql/updatedatabase.pl | 20 + .../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 | 60 ++- 20 files changed, 796 insertions(+), 19 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 @@ -383,7 +383,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 (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( @@ -429,7 +429,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); @@ -109,11 +111,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 @@ -717,7 +717,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', @@ -779,7 +779,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 @@ -118,24 +118,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 @@ -26,6 +26,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('delimiter',';','Define the default separator character for exporting reports',';|tabulation|,|/|\\|#|\|','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('expandedSearchOption',0,'If ON, set advanced search to be expanded by default',NULL,'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MultiBranchSelect',0,'If ON, Shows a muiltibranch dropdown instead of a single branch, in advanced search by branch',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('FineNotifyAtCheckin',0,'If ON notify librarians of overdue fines on the items they are checking in.',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('FinesLog',1,'If ON, log fines',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('hidelostitems',0,'If ON, disables display of\"lost\" items in OPAC.','','YesNo'); @@ -61,6 +62,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxreserves',50,'Define maximum number of holds a patron can place','','Integer'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxItemsInSearchResults',20,'Specify the maximum number of items to display for each result on a page of results',NULL,'free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('memberofinstitution',0,'If ON, patrons can be linked to institutions',NULL,'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('multibranch',0,'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.',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noissuescharge',5,'Define maximum amount withstanding before check outs are blocked','','Integer'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('NotifyBorrowerDeparture',30,'Define number of days before expiry where circulation is warned about patron account expiry',NULL,'Integer'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacAuthorities',1,'If ON, enables the search authorities link on OPAC',NULL,'YesNo'); @@ -119,7 +121,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SessionStorage','mysql','Use database or a temporary file for storing session data','mysql|Pg|tmp','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('CircAutocompl',1,'If ON, autocompletion is enabled for the Circulation input',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingSerials',1,'If ON, serials routing is enabled',NULL,'YesNo'); -INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SearchMyLibraryFirst',0,'If ON, OPAC searches return results limited by the user\'s library by default if they are logged in',NULL,'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SearchableBranches','all','Sets level of security, and search preference. all - default koha search all, or one specified library, all libraries is the default. preferhome - sets the patrons home library as the default search limit. securehome - Only patrons home library, and others specified by enviroment, and borrower extended attributes (If Patron - Multibranch is enabled), can be searched. Home library set by default.','all|preferhome|securehome','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('dontmerge',1,'If ON, modifying an authority record will not update all associated bibliographic records immediately, ask your system administrator to enable the merge_authorities.pl cron job',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('BiblioAddsAuthorities',0,'If ON, adding a new biblio will check for an existing authority record and create one on the fly if one doesn\'t exist',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo'); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -6055,6 +6055,26 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MultiBranchSelect',0,'If ON, Shows a muiltibranch dropdown instead of a single branch, in advanced search by branch',NULL,'YesNo');"); + print "Upgrade to $DBversion done (Bug 9055, Added MultiBranchSelect syspref)"; + SetVersion($DBversion); +} + +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SearchableBranches','all','Sets level of security, and search preference. all - default koha search all, or one specified library, all libraries is the default. preferhome - sets the patrons home library as the default search limit. securehome - Only patrons home library, and others specified by enviroment, and borrower extended attributes (If Patron - Multibranch is enabled), can be searched. Home library set by default.','all|preferhome|securehome','Choice');"); + print "Upgrade to $DBversion done (Bug 9055, Added SearchableBranches syspref)"; + SetVersion($DBversion); +} + +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('multibranch',0,'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.',NULL,'YesNo');"); + print "Upgrade to $DBversion done (Bug 9055, Added multibranch syspref"; + SetVersion($DBversion); +} =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -389,11 +389,13 @@ OPAC: no: Allow - patrons to select their branch on the OPAC or show branch names with callnumbers. - - - pref: SearchMyLibraryFirst - choices: - yes: Limit - no: "Don't limit" - - "patrons' searches to the library they are registered at." + - Search + - pref: SearchableBranches + choices: + all: All libraries + preferhome: Prefers patrons' home library (others may be searched) + securehome: Only patrons' home library and other assigned libraries (if any) can be searched + - Note, Other assigned libraries are only accessable by logged-in users. Otherwise, in Only mode, Home library is set via virtualhost option, and no other libraries are available. Multiple libraries can only be assigned when Multibranch is enabled, found in the Patron syspref page. # - # This system preference does not actually affect anything # - pref: OpacBrowser --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -91,6 +91,12 @@ Patrons: class: integer - characters long. - + - pref: multibranch + choices: + yes: "ON" + no: "off" + - 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. + - - Show a notice that a patron is about to expire - pref: NotifyBorrowerDeparture class: integer --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -78,6 +78,13 @@ Searching: - "fields (separate values with |). Tabs appear in the order listed.
" - "Currently supported values: Item types (itemtypes), Collection Codes (ccode) and Shelving Location (loc)." - + - pref: MultiBranchSelect + type: boolean + choices: + yes: Show + no: "Don't show" + - 'a multibranch dropdown instead of single branch.' + - - By default, - pref: expandedSearchOption type: boolean --- a/koha-tmpl/opac-tmpl/lib/jquery/plugins/css/jquery.multiSelect.css +++ a/koha-tmpl/opac-tmpl/lib/jquery/plugins/css/jquery.multiSelect.css @@ -0,0 +1,85 @@ +a.multiSelect { + background: #FFF url(../images/dropdown.blue.png) right center no-repeat; + border: solid 1px #BBB; + padding-right: 20px; + position: relative; + cursor: default; + text-decoration: none; + color: black; + display: -moz-inline-stack; + display: inline-block; + vertical-align: top; +} + +a.multiSelect:link, a.multiSelect:visited, a.multiSelect:hover, a.multiSelect:active { + color: black; + text-decoration: none; +} + +a.multiSelect span +{ + margin: 1px 0px 1px 3px; + overflow: hidden; + display: -moz-inline-stack; + display: inline-block; + white-space: nowrap; +} + +a.multiSelect.hover { + background-image: url(../images/dropdown.blue.hover.png); +} + +a.multiSelect.active, +a.multiSelect.focus { + border: inset 1px #000; +} + +a.multiSelect.active { + background-image: url(../images/dropdown.blue.active.png); +} + +.multiSelectOptions { + margin-top: -1px; + overflow-y: auto; + overflow-x: hidden; + border: solid 1px #B2B2B2; + background: #FFF; +} + +.multiSelectOptions LABEL { + padding: 0px 2px; + display: block; + white-space: nowrap; +} + +.multiSelectOptions LABEL.optGroup +{ + font-weight: bold; +} + +.multiSelectOptions .optGroupContainer LABEL +{ + padding-left: 10px; +} + +.multiSelectOptions.optGroupHasCheckboxes .optGroupContainer LABEL +{ + padding-left: 18px; +} + +.multiSelectOptions input{ + vertical-align: middle; +} + +.multiSelectOptions LABEL.checked { + background-color: #dce5f8; +} + +.multiSelectOptions LABEL.selectAll { + border-bottom: dotted 1px #CCC; +} + +.multiSelectOptions LABEL.hover { + background-color: #3399ff; + color: white; +} --- a/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.bgiframe.min.js +++ a/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.bgiframe.min.js @@ -0,0 +1,7 @@ +/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net) + * Licensed under the MIT License (LICENSE.txt). + * + * Version 2.1.3-pre + */ + +(function($){$.fn.bgiframe=($.browser.msie&&/msie 6\.0/i.test(navigator.userAgent)?function(s){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s);var html='