MT 1926 : Adding Internal notes to serials list display
[koha.git] / C4 / Record.pm
index ec00367..2be4751 100644 (file)
@@ -18,7 +18,6 @@ package C4::Record;
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 #
-# $Id$
 #
 use strict;# use warnings; #FIXME: turn off warnings before release
 
@@ -26,6 +25,7 @@ use strict;# use warnings; #FIXME: turn off warnings before release
 use MARC::Record; # marc2marcxml, marcxml2marc, html2marc, changeEncoding
 use MARC::File::XML; # marc2marcxml, marcxml2marc, html2marcxml, changeEncoding
 use MARC::Crosswalk::DublinCore; # marc2dcxml
+use Biblio::EndnoteStyle;
 use Unicode::Normalize; # _entity_encode
 use XML::LibXSLT;
 use XML::LibXML;
@@ -33,14 +33,14 @@ use XML::LibXML;
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g;
-                shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+$VERSION = 3.00;
 
 @ISA = qw(Exporter);
 
 # only export API methods
 
 @EXPORT = qw(
+  &marc2endnote
   &marc2marc
   &marc2marcxml
   &marcxml2marc
@@ -248,7 +248,7 @@ sub marc2dcxml {
                $crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 );
        }
        my $dcxml = $crosswalk->as_dublincore($marc_record_obj);
-       my $dcxmlfinal = "<?xml version=\"1.0\"?>\n";
+       my $dcxmlfinal = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        $dcxmlfinal .= "<metadata
   xmlns=\"http://example.org/myapp/\"
   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
@@ -257,7 +257,7 @@ sub marc2dcxml {
   xmlns:dcterms=\"http://purl.org/dc/terms/\">";
 
        foreach my $element ( $dcxml->elements() ) {
-                $dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."</"."dc:".$element->name()."\n";
+                $dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."</"."dc:".$element->name().">\n";
     }
        $dcxmlfinal .= "\n</metadata>";
        return ($error,$dcxmlfinal);
@@ -278,7 +278,7 @@ sub marc2modsxml {
        my ($marc) = @_;
        # grab the XML, run it through our stylesheet, push it out to the browser
        my $xmlrecord = marc2marcxml($marc);
-       my $xslfile = C4::Context->config('intranetdir')."/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MODS3-1.xsl";
+       my $xslfile = C4::Context->config('intrahtdocs')."/prog/en/xslt/MARC21slim2MODS3-1.xsl";
        my $parser = XML::LibXML->new();
        my $xslt = XML::LibXSLT->new();
        my $source = $parser->parse_string($xmlrecord);
@@ -288,6 +288,41 @@ sub marc2modsxml {
        my $newxmlrecord = $stylesheet->output_string($results);
        return ($newxmlrecord);
 }
+
+sub marc2endnote {
+    my ($marc) = @_;
+       my $marc_rec_obj =  MARC::Record->new_from_usmarc($marc);
+       my $f260 = $marc_rec_obj->field('260');
+       my $f260a = $f260->subfield('a') if $f260;
+    my $f710 = $marc_rec_obj->field('710');
+    my $f710a = $f710->subfield('a') if $f710;
+       my $f500 = $marc_rec_obj->field('500');
+       my $abstract = $f500->subfield('a') if $f500;
+       my $fields = {
+               DB => C4::Context->preference("LibraryName"),
+               Title => $marc_rec_obj->title(),        
+               Author => $marc_rec_obj->author(),      
+               Publisher => $f710a,
+               City => $f260a,
+               Year => $marc_rec_obj->publication_date,
+               Abstract => $abstract,
+       };
+       my $endnote;
+       my $style = new Biblio::EndnoteStyle();
+       my $template;
+       $template.= "DB - DB\n" if C4::Context->preference("LibraryName");
+       $template.="T1 - Title\n" if $marc_rec_obj->title();
+       $template.="A1 - Author\n" if $marc_rec_obj->author();
+       $template.="PB - Publisher\n" if  $f710a;
+       $template.="CY - City\n" if $f260a;
+       $template.="Y1 - Year\n" if $marc_rec_obj->publication_date;
+       $template.="AB - Abstract\n" if $abstract;
+       my ($text, $errmsg) = $style->format($template, $fields);
+       return ($text);
+       
+}
+
+
 =head2 html2marcxml
 
 =over 4
@@ -346,7 +381,7 @@ sub html2marcxml {
                                                $marcxml.="<leader>@$values[$i]</leader>\n";
                                                $first=1;
                                        # rest of the fixed fields
-                                       } elsif (@$tags[$i] < 010) { #FIXME: <10 was the way it was, there might even be a better way
+                                       } elsif (@$tags[$i] lt '010') { # don't compare numerically 010 == 8
                                                $marcxml.="<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
                                                $first=1;
                                        } else {
@@ -568,6 +603,5 @@ Joshua Ferraro <jmf@liblime.com>
 
 =head1 MODIFICATIONS
 
-# $Id$
 
 =cut