A couple of fixes: Logs tab was not highlighted when chosen; Serials checkexpiration...
[koha.git] / tools / export.pl
blob67d4038fb09951b230a4aea5ac966d0d69570f32
1 #!/usr/bin/perl
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 require Exporter;
22 use C4::Auth;
23 use C4::Output; # contains gettemplate
24 use C4::Biblio; # GetMarcBiblio GetXmlBiblio
25 use CGI;
26 use C4::Koha; # GetItemTypes
27 use C4::Branch; # GetBranches
29 my $query = new CGI;
30 my $op=$query->param("op");
31 my $filename=$query->param("filename");
32 my $dbh=C4::Context->dbh;
33 my $marcflavour = C4::Context->preference("marcflavour");
35 my ($template, $loggedinuser, $cookie)
36 = get_template_and_user
39 template_name => "tools/export.tmpl",
40 query => $query,
41 type => "intranet",
42 authnotrequired => 0,
43 flagsrequired => {tools => 'export_catalog'},
44 debug => 1,
48 if ($op eq "export") {
49 binmode(STDOUT,":utf8");
50 print $query->header( -type => 'application/octet-stream',
51 -charset => 'utf-8',
52 -attachment=>$filename);
54 my $StartingBiblionumber = $query->param("StartingBiblionumber");
55 my $EndingBiblionumber = $query->param("EndingBiblionumber");
56 my $output_format = $query->param("output_format");
57 my $branch = $query->param("branch");
58 my $itemtype = $query->param("itemtype");
59 my $start_callnumber = $query->param("start_callnumber");
60 my $end_callnumber = $query->param("end_callnumber");
61 my $dont_export_items = $query->param("dont_export_item");
62 my $dont_export_fields = $query->param("dont_export_fields");
63 my @sql_params;
64 my $query = " SELECT DISTINCT biblioitems.biblionumber
65 FROM biblioitems,items
66 WHERE biblioitems.biblionumber=items.biblionumber ";
68 if ( $StartingBiblionumber ) {
69 $query .= " AND biblioitems.biblionumber >= ? ";
70 push @sql_params, $StartingBiblionumber;
73 if ( $EndingBiblionumber ) {
74 $query .= " AND biblioitems.biblionumber <= ? ";
75 push @sql_params, $EndingBiblionumber;
78 if ( $branch ) {
79 $query .= " AND biblioitems.biblionumber = items.biblionumber AND homebranch = ? ";
80 push @sql_params, $branch;
83 if ( $start_callnumber ) {
84 $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber <= ? ";
85 push @sql_params, $start_callnumber;
88 if ( $end_callnumber ) {
89 $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber >= ? ";
90 push @sql_params, $end_callnumber;
93 if ( $itemtype ) {
94 $query .= " AND biblioitems.itemtype = ?";
95 push @sql_params, $itemtype;
98 my $sth = $dbh->prepare($query);
99 $sth->execute(@sql_params);
101 while (my ($biblionumber) = $sth->fetchrow) {
102 my $record = GetMarcBiblio($biblionumber);
103 if ( $dont_export_items ) {
104 # now, find where the itemnumber is stored & extract only the item
105 my ( $itemnumberfield, $itemnumbersubfield ) =
106 GetMarcFromKohaField( 'items.itemnumber', '' );
108 # and delete it.
109 foreach ($record->field($itemnumberfield)){
110 $record->delete_field($record->field($itemnumberfield));
114 if ( $dont_export_fields ) {
115 my @fields = split " ", $dont_export_fields;
116 foreach ( @fields ) {
117 /^(\d*)(\w)?$/;
118 my $field = $1;
119 my $subfield = $2;
120 if( $subfield ) {
121 $record->field($field)->delete_subfields($subfield);
123 else {
124 $record->delete_field($record->field($field));
128 if ( $output_format eq "xml" ) {
129 print $record->as_xml_record($marcflavour);
131 else {
132 print $record->as_usmarc();
135 exit;
137 } # if export
139 else {
141 my $itemtypes = GetItemTypes;
142 my @itemtypesloop;
143 foreach my $thisitemtype (sort keys %$itemtypes) {
144 my %row =
146 value => $thisitemtype,
147 description => $itemtypes->{$thisitemtype}->{'description'},
149 push @itemtypesloop, \%row;
152 my $branches = GetBranches;
153 my $branch = GetBranch($query,$branches);
154 my @branchloop;
155 foreach my $thisbranch (keys %$branches) {
156 my $selected = 1 if $thisbranch eq $branch;
157 my %row = (
158 value => $thisbranch,
159 selected => $selected,
160 branchname => $branches->{$thisbranch}->{'branchname'},
162 push @branchloop, \%row;
165 $template->param(
166 branchloop => \@branchloop,
167 itemtypeloop => \@itemtypesloop
170 output_html_with_http_headers $query, $cookie, $template->output;