adding branchcode for subscriptions details
[koha.git] / opac / opac-ISBDdetail.pl
index df7f45d..db25603 100755 (executable)
@@ -17,7 +17,6 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id$
 
 =head1 NAME
 
@@ -47,7 +46,6 @@ require Exporter;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use CGI;
 use MARC::Record;
 use C4::Biblio;
@@ -63,7 +61,7 @@ my $dbh = C4::Context->dbh;
 
 my $biblionumber = $query->param('biblionumber');
 my $itemtype     = &GetFrameworkCode($biblionumber);
-my $tagslib      = &GetMarcStructure( $dbh, 1, $itemtype );
+my $tagslib      = &GetMarcStructure( 1, $itemtype );
 
 my $record = GetMarcBiblio($biblionumber);
 
@@ -77,6 +75,7 @@ foreach my $subscription (@subscriptions) {
     my %cell;
     $cell{subscriptionid}    = $subscription->{subscriptionid};
     $cell{subscriptionnotes} = $subscription->{notes};
+    $cell{branchcode}        = $subscription->{branchcode};
 
     #get the three latest serials.
     $cell{latestserials} =
@@ -109,6 +108,8 @@ my $res;
 #     $bloc =~ s/\n//g;
 my $bloc = $ISBD;
 my $blocres;
+my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
+
 foreach my $isbdfield ( split /#/, $bloc ) {
 
     #         $isbdfield= /(.?.?.?)/;
@@ -121,38 +122,41 @@ foreach my $isbdfield ( split /#/, $bloc ) {
     #         warn "==> $1 / $2 / $3 / $4";
     #         my $fieldvalue=substr($isbdfield,0,3);
     if ( $fieldvalue > 0 ) {
+        my $hasputtextbefore = 0;
+        my @fieldslist = $record->field($fieldvalue);
+        @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
 
         #         warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
         #             warn "FV : $fieldvalue";
-        my $hasputtextbefore = 0;
-        foreach my $field ( $record->field($fieldvalue) ) {
-            my $calculated = $analysestring;
-            my $tag        = $field->tag();
-            if ( $tag < 10 ) {
+        foreach my $field ( @fieldslist ) {
+          my $calculated = $analysestring;
+          my $tag        = $field->tag();
+          if ( $tag < 10 ) {
+          }
+          else {
+            my @subf = $field->subfields;
+            for my $i ( 0 .. $#subf ) {
+            my $subfieldcode  = $subf[$i][0];
+            my $subfieldvalue =
+            GetAuthorisedValueDesc( $tag, $subf[$i][0],
+              $subf[$i][1], '', $tagslib );
+            my $tagsubf = $tag . $subfieldcode;
+            $calculated =~
+        s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
+        $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
             }
-            else {
-                my @subf = $field->subfields;
-                for my $i ( 0 .. $#subf ) {
-                    my $subfieldcode  = $subf[$i][0];
-                    my $subfieldvalue =
-                      GetAuthorisedValueDesc( $tag, $subf[$i][0],
-                        $subf[$i][1], '', $tagslib );
-                    my $tagsubf = $tag . $subfieldcode;
-                    $calculated =~
-s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
-                }
-
-                # field builded, store the result
-                if ( $calculated && !$hasputtextbefore )
-                {    # put textbefore if not done
-                    $blocres .= $textbefore;
-                    $hasputtextbefore = 1;
-                }
-
-                # remove punctuation at start
-                $calculated =~ s/^( |;|:|\.|-)*//g;
-                $blocres .= $calculated;
+        
+            # field builded, store the result
+            if ( $calculated && !$hasputtextbefore )
+            {    # put textbefore if not done
+            $blocres .= $textbefore;
+            $hasputtextbefore = 1;
             }
+        
+            # remove punctuation at start
+            $calculated =~ s/^( |;|:|\.|-)*//g;
+            $blocres .= $calculated;
+          }
         }
         $blocres .= $textafter if $hasputtextbefore;
     }
@@ -173,7 +177,7 @@ $res =~ s/\(\)//g;
 my $reviews = getreviews( $biblionumber, 1 );
 foreach ( @$reviews ) {
     my $borrower_number_review = $_->{borrowernumber};
-    my $borrowerData           = GetMember('',$borrower_number_review);
+    my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
     # setting some borrower info into this hash
     $_->{title}     = $borrowerData->{'title'};
     $_->{surname}   = $borrowerData->{'surname'};