Finalized XML version for intranet
[koha.git] / tools / export.pl
1 #!/usr/bin/perl
2 use strict;
3
4 use C4::Auth;
5 use C4::Interface::CGI::Output;
6 use C4::Biblio;
7 use CGI;
8 use C4::Auth;
9 use MARC::Record;
10 use MARC::File::XML;
11 my $query = new CGI;
12 my $op=$query->param("op");
13 if ($op eq "export") {
14         print $query->header('Content-Type: text/marc');
15         my $start_bib = $query->param("start_bib");
16         my $end_bib = $query->param("end_bib");
17         my $dbh=C4::Context->dbh;
18         my $sth;
19         if ($start_bib && $end_bib) {
20                 $sth=$dbh->prepare("select marcxml from biblio where biblionumber >=? and biblionumber <=? order by biblionumber");
21                 $sth->execute($start_bib,$end_bib);
22         } elsif ($start_bib ) {
23                 $sth=$dbh->prepare("select marcxml from biblio where biblionumber >=?  order by biblionumber");
24                 $sth->execute($start_bib);
25         }else {
26                 $sth=$dbh->prepare("select marcxml from biblio order by biblionumber");
27                 $sth->execute();
28         }
29         while (my ($marc) = $sth->fetchrow) {
30 my $record=MARC::Record->new_from_xml($marc,"UTF-8");
31         
32                 print $record->as_usmarc;;
33         
34         }
35 } else {
36         my ($template, $loggedinuser, $cookie)
37         = get_template_and_user({template_name => "tools/marc.tmpl",
38                                         query => $query,
39                                         type => "intranet",
40                                         authnotrequired => 0,
41                                         flagsrequired => {parameters => 1, management => 1, tools => 1},
42                                         debug => 1,
43                                         });
44         output_html_with_http_headers $query, $cookie, $template->output;
45 }
46