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
23 use C4
::Output
; # contains gettemplate
24 use C4
::Biblio
; # GetMarcBiblio GetXmlBiblio
26 use C4
::Koha
; # GetItemTypes
27 use C4
::Branch
; # GetBranches
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",
43 flagsrequired
=> {tools
=> 'export_catalog'},
48 if ($op eq "export") {
49 binmode(STDOUT
,":utf8");
50 print $query->header( -type
=> 'application/octet-stream',
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");
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;
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;
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', '' );
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 ) {
121 $record->field($field)->delete_subfields($subfield);
124 $record->delete_field($record->field($field));
128 if ( $output_format eq "xml" ) {
129 print $record->as_xml_record($marcflavour);
132 print $record->as_usmarc();
141 my $itemtypes = GetItemTypes
;
143 foreach my $thisitemtype (sort keys %$itemtypes) {
146 value
=> $thisitemtype,
147 description
=> $itemtypes->{$thisitemtype}->{'description'},
149 push @itemtypesloop, \
%row;
152 my $branches = GetBranches
;
153 my $branch = GetBranch
($query,$branches);
155 foreach my $thisbranch (keys %$branches) {
156 my $selected = 1 if $thisbranch eq $branch;
158 value
=> $thisbranch,
159 selected
=> $selected,
160 branchname
=> $branches->{$thisbranch}->{'branchname'},
162 push @branchloop, \
%row;
166 branchloop
=> \
@branchloop,
167 itemtypeloop
=> \
@itemtypesloop
170 output_html_with_http_headers
$query, $cookie, $template->output;