Finishing up the last of the tests
[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::Output;    # contains gettemplate
26 use C4::Biblio;
27 use CGI;
28 use C4::Auth;
29
30 my $outfile = $ARGV[0];
31 open( OUT, ">$outfile" ) or die $!;
32 my $query                = new CGI;
33 my $StartingBiblionumber = $query->param("StartingBiblionumber");
34 my $EndingBiblionumber   = $query->param("EndingBiblionumber");
35 my $dbh                  = C4::Context->dbh;
36 my $sth;
37
38 if ( $StartingBiblionumber && $EndingBiblionumber ) {
39     my $query =
40         "SELECT biblionumber
41          FROM   biblioitems
42          WHERE  biblionumber >=?
43           AND   biblionumber <=? 
44          ORDER BY biblionumber
45         ";
46     $sth = $dbh->prepare($query);
47     $sth->execute( $StartingBiblionumber, $EndingBiblionumber );
48 } else {
49     my $query = "
50         SELECT biblionumber
51         FROM   biblioitems
52         ORDER BY biblionumber
53     ";
54     $sth = $dbh->prepare($query);
55     $sth->execute;
56 }
57 binmode(OUT, 'utf8');
58 my $i = 0;
59 while ( my ($biblionumber) = $sth->fetchrow ) {
60     my $record = GetMarcBiblio($biblionumber);
61     print $i++ . "\n";
62
63     print OUT $record->as_usmarc();
64 }
65
66 close(OUT);