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