From d4915dd4c842ada0c774170b313bb1b4ea1cdb31 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Tue, 14 Feb 2012 13:11:21 -0500
Subject: [PATCH] Bug 7515 - authorized value code showing in opac for public note

This alters C4::Items::GetItemsInfo() to look up the authorised value
for the itemnotes value if the field has been assigned an authorised
value rather than being a free text field.

A new boolean parameter $opac has been added to let GetItemsInfo know if the
data is destined for the opac or intranet view. Defaults to intranet view.
---
 C4/Items.pm             |    6 +++++-
 opac/opac-ISBDdetail.pl |    2 +-
 opac/opac-detail.pl     |    4 ++--
 opac/opac-reserve.pl    |    2 +-
 opac/opac-sendbasket.pl |    2 +-
 opac/opac-sendshelf.pl  |    2 +-
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 04cb417..800c678 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1164,7 +1164,7 @@ If this is set, it is set to C<One Order>.
 =cut
 
 sub GetItemsInfo {
-    my ( $biblionumber ) = @_;
+    my ( $biblionumber, $opac ) = @_;
     my $dbh   = C4::Context->dbh;
     # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
     my $query = "
@@ -1269,6 +1269,10 @@ sub GetItemsInfo {
             $data->{notforloanvalue} = $lib;
         }
 
+        # get itemnotes authorised value if applicable
+        ($authorised_valuecode) = C4::Koha::GetAuthValCode('items.itemnotes', $data->{frameworkcode});
+        $data->{itemnotes} = C4::Koha::GetKohaAuthorisedValueLib($authorised_valuecode, $data->{itemnotes}, $opac);
+
         # get restricted status and description if applicable
         my $restrictedstatus = $dbh->prepare(
             'SELECT authorised_value
diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl
index 3373787..06021b3 100755
--- a/opac/opac-ISBDdetail.pl
+++ b/opac/opac-ISBDdetail.pl
@@ -127,7 +127,7 @@ $template->param(
 
 my $norequests = 1;
 my $res = GetISBDView($biblionumber, "opac");
-my @items = GetItemsInfo( $biblionumber );
+my @items = GetItemsInfo( $biblionumber, 1 );
 
 my $itemtypes = GetItemTypes();
 for my $itm (@items) {
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index dd41bbb..22f637a 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -372,7 +372,7 @@ $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
 
 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); 
 # change back when ive fixed request.pl
-my @all_items = GetItemsInfo( $biblionumber );
+my @all_items = GetItemsInfo( $biblionumber, 1 );
 
 # adding items linked via host biblios
 my $marcflavour  = C4::Context->preference("marcflavour");
@@ -386,7 +386,7 @@ if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
 foreach my $hostfield ( $record->field($analyticfield)) {
     my $hostbiblionumber = $hostfield->subfield("0");
     my $linkeditemnumber = $hostfield->subfield("9");
-    my @hostitemInfos = GetItemsInfo($hostbiblionumber);
+    my @hostitemInfos = GetItemsInfo( $hostbiblionumber, 1);
     foreach my $hostitemInfo (@hostitemInfos){
         if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
             push(@all_items, $hostitemInfo);
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index b2144a9..813c972 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -123,7 +123,7 @@ foreach my $biblioNumber (@biblionumbers) {
     my $biblioData = GetBiblioData($biblioNumber);
     $biblioDataHash{$biblioNumber} = $biblioData;
 
-    my @itemInfos = GetItemsInfo($biblioNumber);
+    my @itemInfos = GetItemsInfo($biblioNumber,1);
 
     my $marcrecord= GetMarcBiblio($biblioNumber);
 
diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl
index 6a6e825..00a32e7 100755
--- a/opac/opac-sendbasket.pl
+++ b/opac/opac-sendbasket.pl
@@ -81,7 +81,7 @@ if ( $email_add ) {
         my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
         my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
 
-        my @items = GetItemsInfo( $biblionumber );
+        my @items = GetItemsInfo( $biblionumber, 1 );
 
         my $hasauthors = 0;
         if($dat->{'author'} || @$marcauthorsarray) {
diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl
index 6e60bc9..c92d6af 100755
--- a/opac/opac-sendshelf.pl
+++ b/opac/opac-sendshelf.pl
@@ -89,7 +89,7 @@ if ( $email ) {
         my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
         my $subtitle         = GetRecordValue('subtitle', $record, $fw);
 
-        my @items = GetItemsInfo( $biblionumber );
+        my @items = GetItemsInfo( $biblionumber, 1 );
 
         $dat->{MARCNOTES}      = $marcnotesarray;
         $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
-- 
1.7.2.5