Bug 22831: Elasticsearch - add a maintenance script for checking DB vs index counts
[koha.git] / catalogue / export.pl
blobac8a202dad0e6d909ecaac467fa0c0228f8758cf
1 #!/usr/bin/perl
2 use Modern::Perl;
4 use C4::Record;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Biblio;
8 use CGI qw ( -utf8 );
9 use C4::Ris;
13 my $query = new CGI;
14 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
15 template_name => "tools/export.tt",
16 query => $query,
17 type => "intranet",
18 authnotrequired => 0,
19 flagsrequired => { catalogue => 1 },
20 debug => 1,
21 });
23 my $op=$query->param("op");
24 my $format=$query->param("format");
25 my $error = '';
26 if ($op eq "export") {
27 my $biblionumber = $query->param("bib");
28 if ($biblionumber){
30 my $marc = GetMarcBiblio({
31 biblionumber => $biblionumber,
32 embed_items => 1 });
34 if ($format =~ /endnote/) {
35 $marc = marc2endnote($marc);
36 $format = 'endnote';
38 elsif ($format =~ /marcxml/) {
39 $marc = marc2marcxml($marc);
40 $format = "marcxml";
42 elsif ($format=~ /mods/) {
43 $marc = marc2modsxml($marc);
44 $format = "mods";
46 elsif ($format =~ /ris/) {
47 $marc = marc2ris($marc);
48 $format = "ris";
50 elsif ($format =~ /bibtex/) {
51 $marc = marc2bibtex($marc);
52 $format = "bibtex";
54 elsif ($format =~ /dc$/) {
55 $marc = marc2dcxml(undef, undef, $biblionumber, $format);
56 $format = "dublin-core.xml";
58 elsif ($format =~ /marc8/) {
59 $marc = changeEncoding($marc,"MARC","MARC21","MARC-8");
60 $marc = $marc->as_usmarc();
61 $format = "marc8";
63 elsif ($format =~ /utf8/) {
64 C4::Charset::SetUTF8Flag($marc, 1);
65 $marc = $marc->as_usmarc();
66 $format = "utf8";
68 elsif ($format =~ /marcstd/) {
69 C4::Charset::SetUTF8Flag($marc,1);
70 ($error, $marc) = marc2marc($marc, 'marcstd', C4::Context->preference('marcflavour'));
71 $format = "marcstd";
73 if ( $format =~ /utf8/ or $format =~ /marcstd/ ) {
74 binmode STDOUT, ':encoding(UTF-8)';
76 print $query->header(
77 -type => 'application/octet-stream',
78 -attachment=>"bib-$biblionumber.$format");
79 print $marc;