permits exporting bibliographic data as MARC from the command line.
[koha.git] / export / export.pl
1 #!/usr/bin/perl
2 ## This script allows you to export a rel_2_2 bibliographic db in 
3 #MARC21 format from the command line.
4 #
5 use HTML::Template;
6 use strict;
7 require Exporter;
8 use C4::Database;
9 use C4::Auth;
10 use C4::Interface::CGI::Output;
11 use C4::Output;  # contains gettemplate
12 use C4::Biblio;
13 use CGI;
14 use C4::Auth;
15 my $outfile = $ARGV[0];
16 open(OUT,">$outfile") or die $!;
17 my $query = new CGI;
18         my $start_bib = $query->param("start_bib");
19         my $end_bib = $query->param("end_bib");
20         my $dbh=C4::Context->dbh;
21         my $sth;
22         if ($start_bib && $end_bib) {
23                 $sth=$dbh->prepare("select bibid from marc_biblio where bibid >=? and bibid <=? order by bibid");
24                 $sth->execute($start_bib,$end_bib);
25         } else {
26                 $sth=$dbh->prepare("select bibid from marc_biblio order by bibid");
27                 $sth->execute();
28         }
29         while (my ($bibid) = $sth->fetchrow) {
30                 my $record = MARCgetbiblio($dbh,$bibid);
31
32                 print OUT $record->as_usmarc();
33         }
34 close(OUT);