rel_3_0 moved to HEAD (introducing new files)
[koha.git] / export / export.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 ## This script allows you to export a rel_2_2 bibliographic db in
19 #MARC21 format from the command line.
20 #
21
22 use strict;
23 require Exporter;
24 use C4::Auth;
25 use C4::Interface::CGI::Output;
26 use C4::Output;    # contains gettemplate
27 use C4::Biblio;
28 use CGI;
29 use C4::Auth;
30
31 my $outfile = $ARGV[0];
32 open( OUT, ">$outfile" ) or die $!;
33 my $query                = new CGI;
34 my $StartingBiblionumber = $query->param("StartingBiblionumber");
35 my $EndingBiblionumber   = $query->param("EndingBiblionumber");
36 my $dbh                  = C4::Context->dbh;
37 my $sth;
38
39 if ( $StartingBiblionumber && $EndingBiblionumber ) {
40     my $query =
41         "SELECT biblionumber
42          FROM   biblioitems
43          WHERE  biblionumber >=?
44           AND   biblionumber <=? 
45          ORDER BY biblionumber
46         ";
47     $sth = $dbh->prepare($query);
48     $sth->execute( $StartingBiblionumber, $EndingBiblionumber );
49 } else {
50     my $query = "
51         SELECT biblionumber
52         FROM   biblioitems
53         ORDER BY biblionumber
54     ";
55     $sth = $dbh->prepare($query);
56     $sth->execute;
57 }
58 binmode(OUT, 'utf8');
59 my $i = 0;
60 while ( my ($biblionumber) = $sth->fetchrow ) {
61     my $record = GetMarcBiblio($biblionumber);
62     print $i++ . "\n";
63
64     print OUT $record->as_usmarc();
65 }
66
67 close(OUT);