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
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
24 use C4::Interface::CGI::Output;
25 use C4::Output; # contains gettemplate
26 use C4::Biblio; # GetMarcBiblio GetXmlBiblio
28 use C4::Koha; # GetItemTypes
29 use C4::Branch; # GetBranches
32 my $op=$query->param("op");
33 my $dbh=C4::Context->dbh;
34 my $marcflavour = C4::Context->preference("marcflavour");
36 if ($op eq "export") {
38 print $query->header('Content-Type: text/marc');
40 my $StartingBiblionumber = $query->param("StartingBiblionumber");
41 my $EndingBiblionumber = $query->param("EndingBiblionumber");
42 my $output_format = $query->param("output_format");
43 my $branch = $query->param("branch");
44 my $itemtype = $query->param("itemtype");
45 my $start_callnumber = $query->param("start_callnumber");
46 my $end_callnumber = $query->param("end_callnumber");
47 my $dont_export_items = $query->param("dont_export_item");
48 my $dont_export_fields = $query->param("dont_export_fields");
50 my $query = " SELECT DISTINCT biblioitems.biblionumber
51 FROM biblioitems,items
52 WHERE biblioitems.biblionumber=items.biblionumber ";
54 if ( $StartingBiblionumber ) {
55 $query .= " AND biblioitems.biblionumber >= ? ";
56 push @sql_params, $StartingBiblionumber;
59 if ( $EndingBiblionumber ) {
60 $query .= " AND biblioitems.biblionumber <= ? ";
61 push @sql_params, $EndingBiblionumber;
65 $query .= " AND biblioitems.biblionumber = items.biblionumber AND homebranch = ? ";
66 push @sql_params, $branch;
69 if ( $start_callnumber ) {
70 $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber <= ? ";
71 push @sql_params, $start_callnumber;
74 if ( $end_callnumber ) {
75 $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber >= ? ";
76 push @sql_params, $end_callnumber;
80 $query .= " AND biblioitems.itemtype = ?";
81 push @sql_params, $itemtype;
84 my $sth = $dbh->prepare($query);
85 $sth->execute(@sql_params);
87 while (my ($biblionumber) = $sth->fetchrow) {
88 my $record = GetMarcBiblio($biblionumber);
89 if ( $dont_export_items ) {
90 # now, find where the itemnumber is stored & extract only the item
91 my ( $itemnumberfield, $itemnumbersubfield ) =
92 GetMarcFromKohaField( $dbh, 'items.itemnumber', '' );
95 foreach ($record->field($itemnumberfield)){
96 $record->delete_field($record->field($itemnumberfield));
100 if ( $dont_export_fields ) {
101 my @fields = split " ", $dont_export_fields;
102 foreach ( @fields ) {
107 $record->field($field)->delete_subfields($subfield);
110 $record->delete_field($record->field($field));
114 if ( $output_format eq "xml" ) {
115 print $record->as_xml_record($marcflavour);
118 print $record->as_formatted;
127 my $itemtypes = GetItemTypes;
129 foreach my $thisitemtype (sort keys %$itemtypes) {
132 value => $thisitemtype,
133 description => $itemtypes->{$thisitemtype}->{'description'},
135 push @itemtypesloop, \%row;
138 my $branches = GetBranches;
139 my $branch = GetBranch($query,$branches);
141 foreach my $thisbranch (keys %$branches) {
142 my $selected = 1 if $thisbranch eq $branch;
144 value => $thisbranch,
145 selected => $selected,
146 branchname => $branches->{$thisbranch}->{'branchname'},
148 push @branchloop, \%row;
151 my ($template, $loggedinuser, $cookie)
152 = get_template_and_user
155 template_name => "tools/export.tmpl",
158 authnotrequired => 0,
159 flagsrequired => {tools => 1},
165 branchloop => \@branchloop,
166 itemtypeloop => \@itemtypesloop
169 output_html_with_http_headers $query, $cookie, $template->output;