adding export feature to OPAC
authorJoshua Ferraro <jmf@liblime.com>
Sun, 18 Nov 2007 18:45:00 +0000 (12:45 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 20 Nov 2007 21:59:06 +0000 (15:59 -0600)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
opac/opac-export.pl [new file with mode: 0755]

diff --git a/opac/opac-export.pl b/opac/opac-export.pl
new file mode 100755 (executable)
index 0000000..11ec6d5
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+use HTML::Template;
+use strict;
+require Exporter;
+use C4::Record;
+use C4::Auth;
+use C4::Output;
+use C4::Biblio;
+use CGI;
+use C4::Auth;
+
+my $query = new CGI;
+my $op=$query->param("op");
+my $format=$query->param("format");
+if ($op eq "export") {
+       my $biblionumber = $query->param("bib");
+       my $dbh=C4::Context->dbh;
+       my $sth;
+       if ($biblionumber) {
+               $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
+               $sth->execute($biblionumber);
+       }
+       while (my ($marc) = $sth->fetchrow) {
+               if ($marc){
+
+                       if ($format =~ /endnote/) {
+                               $marc = marc2endnote($marc);
+                               $format = 'endnote';
+                       }
+                       elsif ($format =~ /marcxml/) {
+                               $marc = marc2marcxml($marc);
+                       }
+                       elsif ($format=~ /mods/) {
+                               $marc = marc2modsxml($marc);
+                       }
+                       elsif ($format =~ /dc/) {
+                               my $error;
+                               ($error,$marc) = marc2dcxml($marc,1);
+                               $format = "dublin-core.xml";
+                       }
+                       elsif ($format =~ /marc8/) {
+                               $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
+                               $marc = $marc->as_usmarc();
+                       }
+                       elsif ($format =~ /utf8/) {
+                               #default
+                       }
+                       print $query->header(
+                               -type => 'application/octet-stream',
+                -attachment=>"bib-$biblionumber.$format");
+                       print $marc;
+               }
+       }
+}