X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=catalogue%2Fsearch.pl;h=0052f664c5be428bada100e4675591c643030ef9;hb=b93e6df3a1b7051bc92220cf6bd829c2229bfa70;hp=30133200e9ac4135089ba3ef5005d2950557d999;hpb=1730e180cdbe11a7878ddfab54cec7291d12f430;p=koha_fer diff --git a/catalogue/search.pl b/catalogue/search.pl index 30133200e9..0052f664c5 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -147,7 +147,7 @@ use C4::Search; use C4::Languages qw(getAllLanguages); use C4::Koha; use C4::Members qw(GetMember); -use C4::VirtualShelves qw(GetRecentShelves); +use C4::VirtualShelves; use POSIX qw(ceil floor); use C4::Branch; # GetBranches @@ -239,44 +239,50 @@ my $categories = GetBranchCategories(undef,'searchdomain'); $template->param(branchloop => \@branch_loop, searchdomainloop => $categories); # load the Type stuff -# load the Type stuff my $itemtypes = GetItemTypes; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; -my @itemtypesloop; -my $selected=1; +my @advancedsearchesloop; my $cnt; -my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); - -if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my %row =( number=>$cnt++, - ccl => qq($itype_or_itemtype,phr), +my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; +my @advanced_search_types = split(/\|/, $advanced_search_types); + +foreach my $advanced_srch_type (@advanced_search_types) { + if ($advanced_srch_type eq 'itemtypes') { + # itemtype is a special case, since it's not defined in authorized values + my @itypesloop; + foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { + my %row =( number=>$cnt++, + ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - selected => $selected, description => $itemtypes->{$thisitemtype}->{'description'}, - count5 => $cnt % 4, imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ), ); - $selected = 0 if ($selected) ; - push @itemtypesloop, \%row; - } - $template->param(itemtypeloop => \@itemtypesloop); -} else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types); - for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) { - my %row =( - number=>$cnt++, - ccl => $advanced_search_types, + push @itypesloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@itypesloop ); + push @advancedsearchesloop, \%search_code; + } else { + # covers all the other cases: non-itemtype authorized values + my $advsearchtypes = GetAuthorisedValues($advanced_srch_type); + my @authvalueloop; + for my $thisitemtype (@$advsearchtypes) { + my %row =( + number=>$cnt++, + ccl => $advanced_srch_type, code => $thisitemtype->{authorised_value}, - selected => $selected, description => $thisitemtype->{'lib'}, - count5 => $cnt % 4, - imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ), - ); - push @itemtypesloop, \%row; + imageurl => getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ), + ); + push @authvalueloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@authvalueloop ); + push @advancedsearchesloop, \%search_code; } - $template->param(itemtypeloop => \@itemtypesloop); } +$template->param(advancedsearchesloop => \@advancedsearchesloop); # The following should only be loaded if we're bringing up the advanced search template if ( $template_type eq 'advsearch' ) { @@ -440,18 +446,18 @@ if ($params->{'limit-yr'}) { # $ %z3950p will be a hash ref if the indexes are present (advacned search), otherwise undef my $z3950par; my $indexes2z3950 = { - kw=>'title', au=>'author', 'au,phr'=>'author', nb=>'isbn', ns=>'issn', - 'lcn,phr'=>'dewey', su=>'subject', 'su,phr'=>'subject', - ti=>'title', 'ti,phr'=>'title', se=>'title' + kw=>'title', au=>'author', 'au,phr'=>'author', nb=>'isbn', ns=>'issn', + 'lcn,phr'=>'dewey', su=>'subject', 'su,phr'=>'subject', + ti=>'title', 'ti,phr'=>'title', se=>'title' }; for (my $ii = 0; $ii < @operands; ++$ii) { - my $name = $indexes2z3950->{$indexes[$ii]}; - if (defined $name && defined $operands[$ii]) - { - $z3950par ||= {}; - $z3950par->{$name} = $operands[$ii] if !exists $z3950par->{$name}; - } + my $name = $indexes2z3950->{$indexes[$ii]}; + if (defined $name && defined $operands[$ii]) + { + $z3950par ||= {}; + $z3950par->{$name} = $operands[$ii] if !exists $z3950par->{$name}; + } } @@ -484,9 +490,9 @@ for my $this_cgi ( split('&',$query_cgi) ) { my $input_name = $1; my $input_value = $2; push @query_inputs, { input_name => $input_name, input_value => $input_value }; - if ($input_name eq 'idx') { - $scan_index_to_use = $input_value; # unless $scan_index_to_use; - } + if ($input_name eq 'idx') { + $scan_index_to_use = $input_value; # unless $scan_index_to_use; + } } $template->param ( QUERY_INPUTS => \@query_inputs, scan_index_to_use => $scan_index_to_use ); @@ -547,13 +553,13 @@ for (my $i=0;$i<@servers;$i++) { $hits = $results_hashref->{$server}->{"hits"}; my $page = $cgi->param('page') || 0; my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan, - @{$results_hashref->{$server}->{"RECORDS"}}); + $results_hashref->{$server}->{"RECORDS"}); $total = $total + $results_hashref->{$server}->{"hits"}; ## If there's just one result, redirect to the detail page if ($total == 1) { my $biblionumber = $newresults[0]->{biblionumber}; - my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); - my $views = { C4::Search::enabled_staff_search_views }; + my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); + my $views = { C4::Search::enabled_staff_search_views }; if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { print $cgi->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber"); } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { @@ -578,14 +584,18 @@ for (my $i=0;$i<@servers;$i++) { $template->param(limit_desc => $limit_desc); $template->param(offset => $offset); $template->param(DisplayMultiPlaceHold => $DisplayMultiPlaceHold); - $template->param (z3950_search_params => C4::Search::z3950_search_args($query_desc)); + $template->param (z3950_search_params => C4::Search::z3950_search_args($query_desc)); if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); } $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed; $template->param(results_per_page => $results_per_page); + # must define a value for size if not present in DB + # in order to avoid problems generated by the default size value in TT + foreach my $line (@newresults) { + if ( not exists $line->{'size'} ) { $line->{'size'} = "" } + } $template->param(SEARCH_RESULTS => \@newresults); - ## FIXME: add a global function for this, it's better than the current global one ## Build the page numbers on the bottom of the page my @page_numbers; @@ -649,7 +659,7 @@ for (my $i=0;$i<@servers;$i++) { # no hits else { $template->param(searchdesc => 1,query_desc => $query_desc,limit_desc => $limit_desc); - $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc)); + $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc)); } } # end of the if local @@ -679,7 +689,7 @@ $template->param( total => $total, opacfacets => 1, facets_loop => $facets, - displayFacetCount=> C4::Context->preference('displayFacetCount')||0, + displayFacetCount=> C4::Context->preference('displayFacetCount')||0, scan => $scan, search_error => $error, ); @@ -691,21 +701,13 @@ if ($query_desc || $limit_desc) { # VI. BUILD THE TEMPLATE # Build drop-down list for 'Add To:' menu... - -my $row_count = 10; # FIXME:This probably should be a syspref -my ($pubshelves, $total) = GetRecentShelves(2, $row_count, undef); -my ($barshelves, $total) = GetRecentShelves(1, $row_count, $borrowernumber); - -if (@{$pubshelves}) { - $template->param( addpubshelves => scalar @{$pubshelves}); - $template->param( addpubshelvesloop => $pubshelves); -} - -if (@{$barshelves}) { - $template->param( addbarshelves => scalar @{$barshelves}); - $template->param( addbarshelvesloop => $barshelves); -} - - +my ($totalref, $pubshelves, $barshelves)= + C4::VirtualShelves::GetSomeShelfNames($borrowernumber,'COMBO',1); +$template->param( + addbarshelves => $totalref->{bartotal}, + addbarshelvesloop => $barshelves, + addpubshelves => $totalref->{pubtotal}, + addpubshelvesloop => $pubshelves, + ); output_html_with_http_headers $cgi, $cookie, $template->output;