Bug 5549 : move rollingloans.t to db_dependent tests
[koha.git] / opac / opac-search.pl
index 87d2890..eb9ee51 100755 (executable)
@@ -88,6 +88,14 @@ if ($template_name eq 'opac-results.tmpl') {
    $template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults'));
 }
 
+# get biblionumbers stored in the cart
+my @cart_list;
+
+if($cgi->cookie("bib_list")){
+    my $cart_list = $cgi->cookie("bib_list");
+    @cart_list = split(/\//, $cart_list);
+}
+
 if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') {
     $template->param($format => 1);
     $template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom'); 
@@ -157,40 +165,47 @@ $template->param(search_languages_loop => $languages_limit_loop,);
 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 => "$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( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
             );
-        $selected = 0; # set to zero after first pass through
-        push @itemtypesloop, \%row;
-    }
-} else {
-    my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac');
-    for my $thisitemtype (@$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, '', 'opac');
+        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( 'opac', $thisitemtype->{'imageurl'} ),
-            );
-        push @itemtypesloop, \%row;
+                description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'},
+                imageurl => getitemtypeimagelocation( 'opac', $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);
 
 # # load the itypes (Called item types in the template -- just authorized values for searching)
 # my ($itypecount,@itype_loop) = GetCcodes();
@@ -497,6 +512,10 @@ for (my $i=0;$i<@servers;$i++) {
         # in order to avoid problems generated by the default size value in TT
         foreach my $line (@newresults) {
             if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
+            # while we're checking each line, see if item is in the cart
+            if ( grep {$_ eq $line->{'biblionumber'}} @cart_list) {
+                $line->{'incart'} = 1;
+            }
         }
 
         my $tag_quantity;
@@ -613,8 +632,12 @@ for (my $i=0;$i<@servers;$i++) {
             }
             $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed;
             $template->param(results_per_page =>  $results_per_page);
-            $template->param(SEARCH_RESULTS => \@newresults,
-                                OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0),
+            my $hide = C4::Context->preference('OpacHiddenItems');
+            $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines
+            $template->param(
+                SEARCH_RESULTS => \@newresults,
+                OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0),
+                suppress_result_number => $hide,
                             );
            if (C4::Context->preference("OPACLocalCoverImages")){
                $template->param(OPACLocalCoverImages => 1);