(bug #3762) fix warnings in GetCoinsBiblio
[koha.git] / C4 / Biblio.pm
index 8f8629d..e5471b2 100755 (executable)
@@ -62,6 +62,7 @@ BEGIN {
                &GetBiblioItemInfosOf
                &GetBiblioItemByBiblioNumber
                &GetBiblioFromItemNumber
+               &GetBiblioSummary
                
                &GetRecordValue
                &GetFieldMapping
@@ -742,13 +743,17 @@ Return the ISBD view which can be included in opac and intranet
 =cut
 
 sub GetISBDView {
-    my $biblionumber    = shift;
+    my ($biblionumber, $template) = @_;
     my $record          = GetMarcBiblio($biblionumber);
     my $itemtype        = &GetFrameworkCode($biblionumber);
     my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
     my $tagslib      = &GetMarcStructure( 1, $itemtype );
     
     my $ISBD = C4::Context->preference('ISBD');
+    if($template eq "opac"){
+        $ISBD = C4::Context->preference('OPACISBD');
+    }
+    
     my $bloc = $ISBD;
     my $res;
     my $blocres;
@@ -786,7 +791,6 @@ sub GetISBDView {
                     my $tagsubf = $tag . $subfvalue;
                     $calculated =~
                           s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
-                    $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
                 
                     # field builded, store the result
                     if ( $calculated && !$hasputtextbefore )
@@ -825,9 +829,6 @@ sub GetISBDView {
                                   $valuecode     # replace by the value code
                                /gx;
     
-                $calculated =~
-            s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
-            $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
                 }
     
                 # field builded, store the result
@@ -1199,8 +1200,8 @@ sub GetCOinSBiblio {
         $genre = ($mtx eq 'dc') ? "&rft.type=$genre" : "&rft.genre=$genre";
 
         # Setting datas
-        $aulast     = $record->subfield('700','a');
-        $aufirst    = $record->subfield('700','b');
+        $aulast     = $record->subfield('700','a') || '';
+        $aufirst    = $record->subfield('700','b') || '';
         $oauthors   = "&rft.au=$aufirst $aulast";
         # others authors
         if($record->field('200')){
@@ -1210,10 +1211,10 @@ sub GetCOinSBiblio {
         }
         $title      = ( $mtx eq 'dc' ) ? "&rft.title=".$record->subfield('200','a') :
                                          "&rft.title=".$record->subfield('200','a')."&rft.btitle=".$record->subfield('200','a');
-        $pubyear    = $record->subfield('210','d');
-        $publisher  = $record->subfield('210','c');
-        $isbn       = $record->subfield('010','a');
-        $issn       = $record->subfield('011','a');
+        $pubyear    = $record->subfield('210','d') || '';
+        $publisher  = $record->subfield('210','c') || '';
+        $isbn       = $record->subfield('010','a') || '';
+        $issn       = $record->subfield('011','a') || '';
     }else{
         # MARC21 need some improve
         my $fmts;
@@ -1246,6 +1247,119 @@ sub GetCOinSBiblio {
     return $coins_value;
 }
 
+=head2 GetBiblioSummary
+
+=over 4
+
+$summary = GetBiblioSummary($marcrecord);
+
+Return the summary of a record.
+
+=back
+
+=cut
+
+sub GetBiblioSummary {
+    my $recorddata =shift @_;
+    
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $marc=MARC::Record::new_from_xml($recorddata,"utf-8",$marcflavour);
+    
+    my $str;
+    
+    if($marcflavour eq "MARC21"){
+        $str="<b>".$marc->subfield('245',"a")."</b>" if $marc->subfield('245','a');
+        $str.= " <i>".$marc->subfield('245',"b")."</i> " if $marc->subfield('245','b');
+        
+        if ($marc->field('245')){
+            $str.=" / ";
+            foreach ($marc->field('100')->subfield("a")) {
+                $str.=$_." ; ";
+            }
+            $str=~s/ ; $/. /; 
+        }
+      
+        if ($marc->field('260')){
+            $str.=" - ";
+            $str.=$marc->subfield('260',"a")." " if $marc->subfield('260','a');
+            $str.=" : ".$marc->subfield('260',"b")." " if $marc->subfield('260','b');
+            $str.=", ".$marc->subfield('260',"c")." " if $marc->subfield('260','c');
+        }
+        if ($marc->field('300')){
+            $str.=" - ";
+            $str.=$marc->subfield('300','a') if ($marc->subfield(300,'a'));
+            $str.=" ; ".$marc->subfield('300','b') if $marc->subfield('300','b');
+            $str.=" ; ".$marc->subfield('300','c') if $marc->subfield('300','c');
+            $str.=" ; ".$marc->subfield('300','e') if $marc->subfield('300','e');
+        }
+        foreach ($marc->field('500')){
+            $str.= " - ";
+            foreach ($_->subfield("a")){
+                $str.=$_."; "
+            } 
+        }
+        my $itemtypes=GetItemTypes();
+        $str.=" - <u>".$itemtypes->{$marc->subfield('942','c')}->{'description'}."</u> ";
+        $str.="<br />\n";
+       
+    }else{
+        $str = "<b>".$marc->subfield('200','a')."</b>"   if $marc->subfield('200','a');
+        $str.= " <i>".$marc->subfield('200','e')."</i> " if $marc->subfield('200','e');
+        if ($marc->field('200')){
+            $str.=" / ";
+            foreach ($marc->field('200')->subfield("f")) {
+                $str.=$_." ; ";
+            }
+            $str=~s/ ; $/. /; 
+        }
+        
+        if ($marc->subfield('200','g')){
+            $str.=" ; ";
+            foreach ($marc->field('200')->subfield("g")){
+                $str.=$_." ; ";
+            } 
+            $str=~s/ ; $/. /; 
+        }
+        
+        if ($marc->field('461')){
+            $str.="- In :";
+            $str.=     $marc->subfield('461','t') if $marc->subfield('461','t');
+            $str.=", ".$marc->subfield('461','d') if $marc->subfield('461','d');
+            $str.=", ".$marc->subfield('461','v') if $marc->subfield('461','v');
+            $str.=", ".$marc->subfield('461','h') if $marc->subfield('461','h');
+            $str.=" ; ".$marc->subfield('461','x') if $marc->subfield('461','x');
+        }
+        
+        if ($marc->field('210')){
+            $str.=" - ";
+            $str.=$marc->subfield('210',"a")." " if $marc->subfield('210','a');
+            $str.=" : ".$marc->subfield('210',"c")." " if $marc->subfield('210','c');
+            $str.=", ".$marc->subfield('210',"d")." " if $marc->subfield('210','d');
+        }
+        
+        if ($marc->field('215')){
+            $str.=" - ";
+            $str.=$marc->subfield('215','a') if ($marc->subfield(215,'a'));
+            $str.=" ; ".$marc->subfield('215','d') if $marc->subfield('215','d');
+            $str.=" ; ".$marc->subfield('215','c') if $marc->subfield('215','c');
+            $str.=" ; ".$marc->subfield('215','e') if $marc->subfield('215','e');
+        }
+        foreach ($marc->field('300')){
+            $str.=" - ";
+            foreach ($_->subfield("a")){
+                $str.=$_."; "
+            } 
+        }
+        
+        my $itemtypes=GetItemTypes;
+        if($itemtypes->{$marc->subfield('200','b')}){
+            $str.=" - <u>".$itemtypes->{$marc->subfield('200','b')}->{'description'}."</u> ";
+        }
+        $str.="<br />\n";         
+    }    
+    return $str;
+}
+
 =head2 GetAuthorisedValueDesc
 
 =over 4
@@ -1744,7 +1858,6 @@ sub TransformHtmlToXml {
     my $prevtag = -1;
     my $first   = 1;
     my $j       = -1;
-       @$indicator=map{sprintf("%2s",$_) unless ( length($_)<2)}@$indicator;
     for ( my $i = 0 ; $i < @$tags ; $i++ ) {
         if (C4::Context->preference('marcflavour') eq 'UNIMARC' and @$tags[$i] eq "100" and @$subfields[$i] eq "a") {
             # if we have a 100 field and it's values are not correct, skip them.
@@ -1766,20 +1879,22 @@ sub TransformHtmlToXml {
 #         }
         if ( ( @$tags[$i] ne $prevtag ) ) {
             $j++ unless ( @$tags[$i] eq "" );
+                       my $indicator1=eval{substr( @$indicator[$j], 0, 1 )};
+                       my $indicator2=eval{substr( @$indicator[$j], 1, 1 )};
+            my $ind1 = _default_ind_to_space($indicator1);
+            my $ind2;
+            if ( @$indicator[$j] ) {
+               $ind2 = _default_ind_to_space($indicator2);
+            }
+            else {
+               warn "Indicator in @$tags[$i] is empty";
+               $ind2 = " ";
+            }
             if ( !$first ) {
                 $xml .= "</datafield>\n";
                 if (   ( @$tags[$i] && @$tags[$i] > 10 )
                     && ( @$values[$i] ne "" ) )
                 {
-                    my $ind1 = _default_ind_to_space(substr( @$indicator[$j], 0, 1 ));
-                    my $ind2;
-                    if ( @$indicator[$j] ) {
-                        $ind2 = _default_ind_to_space(substr( @$indicator[$j], 1, 1 ));
-                    }
-                    else {
-                        warn "Indicator in @$tags[$i] is empty";
-                        $ind2 = " ";
-                    }
                     $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
                     $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
                     $first = 0;
@@ -1803,8 +1918,6 @@ sub TransformHtmlToXml {
                         $first = 1;
                     }
                     else {
-                        my $ind1 = _default_ind_to_space( substr( @$indicator[$j], 0, 1 ) );
-                        my $ind2 = _default_ind_to_space( substr( @$indicator[$j], 1, 1 ) );
                         $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
                         $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
                         $first = 0;
@@ -1813,12 +1926,21 @@ sub TransformHtmlToXml {
             }
         }
         else {    # @$tags[$i] eq $prevtag
-            if ( @$values[$i] eq "" ) {
+                       my $indicator1=eval{substr( @$indicator[$j], 0, 1 )};
+                       my $indicator2=eval{substr( @$indicator[$j], 1, 1 )};
+            my $ind1 = _default_ind_to_space($indicator1);
+            my $ind2;
+            if ( @$indicator[$j] ) {
+               $ind2 = _default_ind_to_space($indicator2);
+            }
+            else {
+               warn "Indicator in @$tags[$i] is empty";
+               $ind2 = " ";
+            }
+         if ( @$values[$i] eq "" ) {
             }
             else {
                 if ($first) {
-                    my $ind1 = _default_ind_to_space( substr( @$indicator[$j], 0, 1 ) );
-                    my $ind2 = _default_ind_to_space( substr( @$indicator[$j], 1, 1 ) );
                     $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
                     $first = 0;
                 }
@@ -2275,6 +2397,9 @@ sub PrepareItemrecordDisplay {
       &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
     my $tagslib = &GetMarcStructure( 1, $frameworkcode );
     my $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum) if ($itemnum);
+       # FIXME : I'd rather have GetMarcBiblio called out of this.
+       # Since it gets the whole Biblio record for each item
+    my $marcrecord = GetMarcBiblio( $bibnum) if ($bibnum);
     my @loop_data;
     my $authorised_values_sth =
       $dbh->prepare(
@@ -2327,7 +2452,7 @@ sub PrepareItemrecordDisplay {
                       substr( C4::Context->preference('itemcallnumber'), 0, 3 );
                     my $CNsubfield =
                       substr( C4::Context->preference('itemcallnumber'), 3, 1 );
-                    my $temp = $itemrecord->field($CNtag) if ($itemrecord);
+                    my $temp = $marcrecord->field($CNtag) if ($marcrecord);
                     if ($temp) {
                         $value = $temp->subfield($CNsubfield);
                     }