View | Details | Raw Unified | Return to bug 6488
Collapse All | Expand All

(-)a/C4/Items.pm (-24 / +28 lines)
Lines 1629-1669 sub GetHiddenItemnumbers { Link Here
1629
    my @resultitems;
1629
    my @resultitems;
1630
1630
1631
    my $yaml = C4::Context->preference('OpacHiddenItems');
1631
    my $yaml = C4::Context->preference('OpacHiddenItems');
1632
    $yaml = "$yaml\n"; # YAML is anal on ending \n. Surplus does not hurt
1632
    my $hidingrules;
1633
    my $hidingrules;
1633
    eval {
1634
    eval {
1634
    	$hidingrules = YAML::Load($yaml);
1635
        $hidingrules = YAML::Load($yaml);
1635
    };
1636
    };
1636
    if ($@) {
1637
    if ($@) {
1637
    	warn "Unable to parse OpacHiddenItems syspref : $@";
1638
        warn "Unable to parse OpacHiddenItems syspref : $@";
1638
    	return ();
1639
        return ();
1639
    } else {
1640
    }
1640
    my $dbh = C4::Context->dbh;
1641
    my $dbh = C4::Context->dbh;
1641
1642
1642
	# For each item
1643
    # For each item
1643
	foreach my $item (@items) {
1644
    foreach my $item (@items) {
1644
1645
1645
	    # We check each rule
1646
        # We check each rule
1646
	    foreach my $field (keys %$hidingrules) {
1647
        foreach my $field (keys %$hidingrules) {
1647
		my $query = "SELECT $field from items where itemnumber = ?";
1648
            my $val;
1648
		my $sth = $dbh->prepare($query);	
1649
            if (exists $item->{$field}) {
1649
		$sth->execute($item->{'itemnumber'});
1650
                $val = $item->{$field};
1650
		my ($result) = $sth->fetchrow;
1651
            }
1652
            else {
1653
                my $query = "SELECT $field from items where itemnumber = ?";
1654
                $val = $dbh->selectrow_array($query, undef, $item->{'itemnumber'});
1655
            }
1656
            $val = '' unless defined $val;
1651
1657
1652
		# If the results matches the values in the yaml file
1658
            # If the results matches the values in the yaml file
1653
		if (any { $result eq $_ } @{$hidingrules->{$field}}) {
1659
            if (any { $val eq $_ } @{$hidingrules->{$field}}) {
1654
1660
1655
		    # We add the itemnumber to the list
1661
                # We add the itemnumber to the list
1656
		    push @resultitems, $item->{'itemnumber'};	    
1662
                push @resultitems, $item->{'itemnumber'};	    
1657
1663
1658
		    # If at least one rule matched for an item, no need to test the others
1664
                # If at least one rule matched for an item, no need to test the others
1659
		    last;
1665
                last;
1660
		}
1666
            }
1661
	    }
1667
        }
1662
	}
1663
	return @resultitems;
1664
    }
1668
    }
1665
1669
    return @resultitems;
1666
 }
1670
}
1667
1671
1668
=head3 get_item_authorised_values
1672
=head3 get_item_authorised_values
1669
1673
(-)a/C4/Search.pm (-37 / +46 lines)
Lines 31-36 use C4::Branch; Link Here
31
use C4::Reserves;    # CheckReserves
31
use C4::Reserves;    # CheckReserves
32
use C4::Debug;
32
use C4::Debug;
33
use C4::Items;
33
use C4::Items;
34
use C4::Charset;
34
use YAML;
35
use YAML;
35
use URI::Escape;
36
use URI::Escape;
36
37
Lines 1413-1423 Format results in a form suitable for passing to the template Link Here
1413
# IMO this subroutine is pretty messy still -- it's responsible for
1414
# IMO this subroutine is pretty messy still -- it's responsible for
1414
# building the HTML output for the template
1415
# building the HTML output for the template
1415
sub searchResults {
1416
sub searchResults {
1416
    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults, $hidelostitems ) = @_;
1417
    my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_;
1417
    my $dbh = C4::Context->dbh;
1418
    my $dbh = C4::Context->dbh;
1418
    my @newresults;
1419
    my @newresults;
1419
1420
1420
    $search_context = 'opac' unless $search_context eq 'opac' or $search_context eq 'intranet';
1421
    $search_context = 'opac' if !$search_context || $search_context ne 'intranet';
1422
    my ($is_opac, $hidelostitems);
1423
    if ($search_context eq 'opac') {
1424
        $hidelostitems = C4::Context->preference('hidelostitems');
1425
        $is_opac       = 1;
1426
    }
1421
1427
1422
    #Build branchnames hash
1428
    #Build branchnames hash
1423
    #find branchname
1429
    #find branchname
Lines 1480-1491 sub searchResults { Link Here
1480
	my $marcflavour = C4::Context->preference("marcflavour");
1486
	my $marcflavour = C4::Context->preference("marcflavour");
1481
    # We get the biblionumber position in MARC
1487
    # We get the biblionumber position in MARC
1482
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1488
    my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber','');
1483
    my $fw;
1484
1489
1485
    # loop through all of the records we've retrieved
1490
    # loop through all of the records we've retrieved
1486
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1491
    for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
1487
        my $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
1492
        my $marcrecord = MARC::File::USMARC::decode( $marcresults->[$i] );
1488
        $fw = $scan
1493
        my $fw = $scan
1489
             ? undef
1494
             ? undef
1490
             : $bibliotag < 10
1495
             : $bibliotag < 10
1491
               ? GetFrameworkCode($marcrecord->field($bibliotag)->data)
1496
               ? GetFrameworkCode($marcrecord->field($bibliotag)->data)
Lines 1603-1620 sub searchResults { Link Here
1603
        my $other_count           = 0;
1608
        my $other_count           = 0;
1604
        my $wthdrawn_count        = 0;
1609
        my $wthdrawn_count        = 0;
1605
        my $itemlost_count        = 0;
1610
        my $itemlost_count        = 0;
1611
        my $hideatopac_count      = 0;
1606
        my $itembinding_count     = 0;
1612
        my $itembinding_count     = 0;
1607
        my $itemdamaged_count     = 0;
1613
        my $itemdamaged_count     = 0;
1608
        my $item_in_transit_count = 0;
1614
        my $item_in_transit_count = 0;
1609
        my $can_place_holds       = 0;
1615
        my $can_place_holds       = 0;
1610
	my $item_onhold_count     = 0;
1616
        my $item_onhold_count     = 0;
1611
        my $items_count           = scalar(@fields);
1617
        my $items_count           = scalar(@fields);
1612
        my $maxitems =
1618
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
1613
          ( C4::Context->preference('maxItemsinSearchResults') )
1619
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
1614
          ? C4::Context->preference('maxItemsinSearchResults') - 1
1615
          : 1;
1616
1620
1617
        # loop through every item
1621
        # loop through every item
1622
	      my @hiddenitems;
1618
        foreach my $field (@fields) {
1623
        foreach my $field (@fields) {
1619
            my $item;
1624
            my $item;
1620
1625
Lines 1624-1632 sub searchResults { Link Here
1624
            }
1629
            }
1625
1630
1626
	        # Hidden items
1631
	        # Hidden items
1627
	        my @items = ($item);
1632
            if ($is_opac) {
1628
	        my (@hiddenitems) = GetHiddenItemnumbers(@items);
1633
	            my @hi = GetHiddenItemnumbers($item);
1629
    	    $item->{'hideatopac'} = 1 if (@hiddenitems); 
1634
    	        $item->{'hideatopac'} = @hi; 
1635
              push @hiddenitems, @hi;
1636
            }
1630
1637
1631
            my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1638
            my $hbranch     = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch'    : 'holdingbranch';
1632
            my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
1639
            my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch';
Lines 1710-1715 sub searchResults { Link Here
1710
                    $wthdrawn_count++        if $item->{wthdrawn};
1717
                    $wthdrawn_count++        if $item->{wthdrawn};
1711
                    $itemlost_count++        if $item->{itemlost};
1718
                    $itemlost_count++        if $item->{itemlost};
1712
                    $itemdamaged_count++     if $item->{damaged};
1719
                    $itemdamaged_count++     if $item->{damaged};
1720
                    $hideatopac_count++      if $item->{hideatopac};
1713
                    $item_in_transit_count++ if $transfertwhen ne '';
1721
                    $item_in_transit_count++ if $transfertwhen ne '';
1714
		    $item_onhold_count++     if $reservestatus eq 'Waiting';
1722
		    $item_onhold_count++     if $reservestatus eq 'Waiting';
1715
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
1723
                    $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
Lines 1748-1758 sub searchResults { Link Here
1748
                }
1756
                }
1749
            }
1757
            }
1750
        }    # notforloan, item level and biblioitem level
1758
        }    # notforloan, item level and biblioitem level
1759
1760
        next if $is_opac       && $hideatopac_count >= $items_count;
1761
        next if $hidelostitems && $itemlost_count   >= $items_count;
1762
1751
        my ( $availableitemscount, $onloanitemscount, $otheritemscount );
1763
        my ( $availableitemscount, $onloanitemscount, $otheritemscount );
1752
        $maxitems =
1753
          ( C4::Context->preference('maxItemsinSearchResults') )
1754
          ? C4::Context->preference('maxItemsinSearchResults') - 1
1755
          : 1;
1756
        for my $key ( sort keys %$onloan_items ) {
1764
        for my $key ( sort keys %$onloan_items ) {
1757
            (++$onloanitemscount > $maxitems) and last;
1765
            (++$onloanitemscount > $maxitems) and last;
1758
            push @onloan_items_loop, $onloan_items->{$key};
1766
            push @onloan_items_loop, $onloan_items->{$key};
Lines 1766-1785 sub searchResults { Link Here
1766
            push @available_items_loop, $available_items->{$key}
1774
            push @available_items_loop, $available_items->{$key}
1767
        }
1775
        }
1768
1776
1769
        # XSLT processing of some stuff
1777
         # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
1770
	use C4::Charset;
1771
	SetUTF8Flag($marcrecord);
1772
	$debug && warn $marcrecord->as_formatted;
1773
        if (!$scan && $search_context eq 'opac' && C4::Context->preference("OPACXSLTResultsDisplay")) {
1774
            # FIXME note that XSLTResultsDisplay (use of XSLT to format staff interface bib search results)
1775
            # is not implemented yet
1776
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, 'Results', 
1777
                                                                $search_context, 1);
1778
                # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
1779
1780
        }
1781
1782
        # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
1783
        if (!C4::Context->preference("item-level_itypes")) {
1778
        if (!C4::Context->preference("item-level_itypes")) {
1784
            if ($itemtypes{ $oldbiblio->{itemtype} }->{notforloan}) {
1779
            if ($itemtypes{ $oldbiblio->{itemtype} }->{notforloan}) {
1785
                $can_place_holds = 0;
1780
                $can_place_holds = 0;
Lines 1803-1810 sub searchResults { Link Here
1803
        $oldbiblio->{intransitcount}       = $item_in_transit_count;
1798
        $oldbiblio->{intransitcount}       = $item_in_transit_count;
1804
        $oldbiblio->{onholdcount}          = $item_onhold_count;
1799
        $oldbiblio->{onholdcount}          = $item_onhold_count;
1805
        $oldbiblio->{orderedcount}         = $ordered_count;
1800
        $oldbiblio->{orderedcount}         = $ordered_count;
1806
        $oldbiblio->{isbn} =~
1801
        # deleting - in isbn to enable amazon content
1807
          s/-//g;    # deleting - in isbn to enable amazon content
1802
        $oldbiblio->{isbn} =~ s/-//g;
1808
1803
1809
        if (C4::Context->preference("AlternateHoldingsField") && $items_count == 0) {
1804
        if (C4::Context->preference("AlternateHoldingsField") && $items_count == 0) {
1810
            my $fieldspec = C4::Context->preference("AlternateHoldingsField");
1805
            my $fieldspec = C4::Context->preference("AlternateHoldingsField");
Lines 1834-1843 sub searchResults { Link Here
1834
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
1829
            $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
1835
        }
1830
        }
1836
1831
1837
        push( @newresults, $oldbiblio )
1832
       # XSLT processing of some stuff
1838
            if(not $hidelostitems
1833
        if (!$scan && $search_context eq 'opac' && C4::Context->preference("OPACXSLTResultsDisplay")) {
1839
               or (($items_count > $itemlost_count )
1834
            SetUTF8Flag($marcrecord);
1840
                    && $hidelostitems));
1835
            $debug && warn $marcrecord->as_formatted;
1836
            # FIXME note that XSLTResultsDisplay (use of XSLT to format staff interface bib search results)
1837
            # is not implemented yet
1838
            $oldbiblio->{XSLTResultsRecord}
1839
              = XSLTParse4Display($oldbiblio->{biblionumber},
1840
                                  $marcrecord,
1841
                                  'Results', 
1842
                                  $search_context,
1843
                                  1, # clean up the problematic ampersand entities that Zebra outputs
1844
                                  \@hiddenitems
1845
                                );
1846
1847
        }
1848
1849
        push( @newresults, $oldbiblio );
1841
    }
1850
    }
1842
1851
1843
    return @newresults;
1852
    return @newresults;
(-)a/C4/XSLT.pm (-3 / +8 lines)
Lines 121-132 sub getAuthorisedValues4MARCSubfields { Link Here
121
my $stylesheet;
121
my $stylesheet;
122
122
123
sub XSLTParse4Display {
123
sub XSLTParse4Display {
124
    my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps ) = @_;
124
    my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps, $hidden_items ) = @_;
125
    $interface = 'opac' unless $interface;
125
    $interface = 'opac' unless $interface;
126
    # grab the XML, run it through our stylesheet, push it out to the browser
126
    # grab the XML, run it through our stylesheet, push it out to the browser
127
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
127
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
128
    #return $record->as_formatted();
128
    #return $record->as_formatted();
129
    my $itemsxml  = buildKohaItemsNamespace($biblionumber);
129
    my $itemsxml  = buildKohaItemsNamespace($biblionumber, $hidden_items);
130
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
130
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
131
    my $sysxml = "<sysprefs>\n";
131
    my $sysxml = "<sysprefs>\n";
132
    foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow
132
    foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow
Lines 180-187 sub XSLTParse4Display { Link Here
180
}
180
}
181
181
182
sub buildKohaItemsNamespace {
182
sub buildKohaItemsNamespace {
183
    my ($biblionumber) = @_;
183
    my ($biblionumber, $hidden_items) = @_;
184
184
    my @items = C4::Items::GetItemsInfo($biblionumber);
185
    my @items = C4::Items::GetItemsInfo($biblionumber);
186
    if ($hidden_items && @$hidden_items) {
187
        my %hi = map {$_ => 1} @$hidden_items;
188
        @items = grep { !$hi{$_->{itemnumber}} } @items;
189
    }
185
    my $branches = GetBranches();
190
    my $branches = GetBranches();
186
    my $itemtypes = GetItemTypes();
191
    my $itemtypes = GetItemTypes();
187
    my $xml = '';
192
    my $xml = '';
(-)a/catalogue/search.pl (-1 / +1 lines)
Lines 547-553 for (my $i=0;$i<@servers;$i++) { Link Here
547
        $hits = $results_hashref->{$server}->{"hits"};
547
        $hits = $results_hashref->{$server}->{"hits"};
548
        my $page = $cgi->param('page') || 0;
548
        my $page = $cgi->param('page') || 0;
549
        my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan,
549
        my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan,
550
                                       @{$results_hashref->{$server}->{"RECORDS"}});
550
                                       $results_hashref->{$server}->{"RECORDS"});
551
        $total = $total + $results_hashref->{$server}->{"hits"};
551
        $total = $total + $results_hashref->{$server}->{"hits"};
552
        ## If there's just one result, redirect to the detail page
552
        ## If there's just one result, redirect to the detail page
553
        if ($total == 1) {         
553
        if ($total == 1) {         
(-)a/cataloguing/addbooks.pl (-1 / +1 lines)
Lines 86-92 if ($query) { Link Here
86
    # format output
86
    # format output
87
    # SimpleSearch() give the results per page we want, so 0 offet here
87
    # SimpleSearch() give the results per page we want, so 0 offet here
88
    my $total = @{$marcresults};
88
    my $total = @{$marcresults};
89
    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, @{$marcresults} );
89
    my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
90
    foreach my $line (@newresults) {
90
    foreach my $line (@newresults) {
91
        if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
91
        if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
92
    }
92
    }
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (-1 lines)
Lines 380-386 $(document).ready(function(){ Link Here
380
                <td class="select selectcol">[% IF ( opacbookbag ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% ELSE %]
380
                <td class="select selectcol">[% IF ( opacbookbag ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% ELSE %]
381
[% IF ( virtualshelves ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% ELSE %]
381
[% IF ( virtualshelves ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% ELSE %]
382
[% IF ( RequestOnOpac ) %][% UNLESS ( SEARCH_RESULT.norequests ) %][% IF ( opacuserlogin ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% END %][% END %][% END %][% END %][% END %]</td>
382
[% IF ( RequestOnOpac ) %][% UNLESS ( SEARCH_RESULT.norequests ) %][% IF ( opacuserlogin ) %]<input type="checkbox" id="bib[% SEARCH_RESULT.biblionumber %]" name="biblionumber" value="[% SEARCH_RESULT.biblionumber %]" /> <label for="bib[% SEARCH_RESULT.biblionumber %]"></label>[% END %][% END %][% END %][% END %][% END %]</td>
383
                <td class="select selectcol">[% SEARCH_RESULT.result_number %].</td>
384
383
385
				[% UNLESS ( item_level_itypes ) %]
384
				[% UNLESS ( item_level_itypes ) %]
386
                [% UNLESS ( noItemTypeImages ) %]
385
                [% UNLESS ( noItemTypeImages ) %]
(-)a/opac/opac-search.pl (-3 / +2 lines)
Lines 485-496 for (my $i=0;$i<@servers;$i++) { Link Here
485
                # we want as specified by $offset and $results_per_page,
485
                # we want as specified by $offset and $results_per_page,
486
                # we need to set the offset parameter of searchResults to 0
486
                # we need to set the offset parameter of searchResults to 0
487
                my @group_results = searchResults( 'opac', $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
487
                my @group_results = searchResults( 'opac', $query_desc, $group->{'group_count'},$results_per_page, 0, $scan,
488
                                                   @{ $group->{"RECORDS"} }, C4::Context->preference('hidelostitems'));
488
                                                   $group->{"RECORDS"});
489
                push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
489
                push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
490
            }
490
            }
491
        } else {
491
        } else {
492
            @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
492
            @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
493
                                        @{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems'));
493
                                        $results_hashref->{$server}->{"RECORDS"});
494
        }
494
        }
495
495
496
        # must define a value for size if not present in DB
496
        # must define a value for size if not present in DB
497
- 

Return to bug 6488