Lines 22-27
use warnings;
Link Here
|
22 |
use C4::Auth; |
22 |
use C4::Auth; |
23 |
use C4::Output; |
23 |
use C4::Output; |
24 |
use C4::Biblio; # GetMarcBiblio GetXmlBiblio |
24 |
use C4::Biblio; # GetMarcBiblio GetXmlBiblio |
|
|
25 |
use C4::AuthoritiesMarc; # GetAuthority |
25 |
use CGI; |
26 |
use CGI; |
26 |
use C4::Koha; # GetItemTypes |
27 |
use C4::Koha; # GetItemTypes |
27 |
use C4::Branch; # GetBranches |
28 |
use C4::Branch; # GetBranches |
Lines 62-150
if ($op eq "export") {
Link Here
|
62 |
-charset => 'utf-8', |
63 |
-charset => 'utf-8', |
63 |
-attachment=>$filename); |
64 |
-attachment=>$filename); |
64 |
|
65 |
|
65 |
my $StartingBiblionumber = $query->param("StartingBiblionumber"); |
66 |
my $record_type = $query->param("record_type"); |
66 |
my $EndingBiblionumber = $query->param("EndingBiblionumber"); |
67 |
my $output_format = $query->param("output_format"); |
67 |
my $output_format = $query->param("output_format"); |
68 |
my $dont_export_fields = $query->param("dont_export_fields"); |
68 |
my $itemtype = $query->param("itemtype"); |
|
|
69 |
my $start_callnumber = $query->param("start_callnumber"); |
70 |
my $end_callnumber = $query->param("end_callnumber"); |
71 |
my $start_accession = ($query->param("start_accession")) ? C4::Dates->new($query->param("start_accession")) : '' ; |
72 |
my $end_accession = ($query->param("end_accession")) ? C4::Dates->new($query->param("end_accession")) : '' ; |
73 |
my $dont_export_items = $query->param("dont_export_item"); |
74 |
my $strip_nonlocal_items = $query->param("strip_nonlocal_items"); |
75 |
my $dont_export_fields = $query->param("dont_export_fields"); |
76 |
my @sql_params; |
69 |
my @sql_params; |
77 |
|
70 |
my $sql_query; |
78 |
my $items_filter = |
|
|
79 |
$branch || $start_callnumber || $end_callnumber || |
80 |
$start_accession || $end_accession || |
81 |
($itemtype && C4::Context->preference('item-level_itypes')); |
82 |
my $query = $items_filter ? |
83 |
"SELECT DISTINCT biblioitems.biblionumber |
84 |
FROM biblioitems JOIN items |
85 |
USING (biblionumber) WHERE 1" |
86 |
: |
87 |
"SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 "; |
88 |
|
89 |
if ( $StartingBiblionumber ) { |
90 |
$query .= " AND biblioitems.biblionumber >= ? "; |
91 |
push @sql_params, $StartingBiblionumber; |
92 |
} |
93 |
|
94 |
if ( $EndingBiblionumber ) { |
95 |
$query .= " AND biblioitems.biblionumber <= ? "; |
96 |
push @sql_params, $EndingBiblionumber; |
97 |
} |
98 |
|
71 |
|
99 |
if ($branch) { |
72 |
my $StartingBiblionumber = $query->param("StartingBiblionumber"); |
100 |
$query .= " AND homebranch = ? "; |
73 |
my $EndingBiblionumber = $query->param("EndingBiblionumber"); |
101 |
push @sql_params, $branch; |
74 |
my $itemtype = $query->param("itemtype"); |
102 |
} |
75 |
my $start_callnumber = $query->param("start_callnumber"); |
|
|
76 |
my $end_callnumber = $query->param("end_callnumber"); |
77 |
my $start_accession = |
78 |
( $query->param("start_accession") ) |
79 |
? C4::Dates->new( $query->param("start_accession") ) |
80 |
: ''; |
81 |
my $end_accession = |
82 |
( $query->param("end_accession") ) |
83 |
? C4::Dates->new( $query->param("end_accession") ) |
84 |
: ''; |
85 |
my $dont_export_items = $query->param("dont_export_item"); |
86 |
my $strip_nonlocal_items = $query->param("strip_nonlocal_items"); |
103 |
|
87 |
|
104 |
if ($start_callnumber) { |
88 |
my $starting_authid = $query->param('starting_authid'); |
105 |
$query .= " AND itemcallnumber <= ? "; |
89 |
my $ending_authid = $query->param('ending_authid'); |
106 |
push @sql_params, $start_callnumber; |
90 |
my $authtype = $query->param('authtype'); |
107 |
} |
|
|
108 |
|
91 |
|
109 |
if ($end_callnumber) { |
92 |
if ( $record_type eq 'bibs' ) { |
110 |
$query .= " AND itemcallnumber >= ? "; |
93 |
my $items_filter = |
111 |
push @sql_params, $end_callnumber; |
94 |
$branch || $start_callnumber || $end_callnumber || |
112 |
} |
95 |
$start_accession || $end_accession || |
113 |
if ($start_accession) { |
96 |
($itemtype && C4::Context->preference('item-level_itypes')); |
114 |
$query .= " AND dateaccessioned >= ? "; |
97 |
$sql_query = $items_filter ? |
115 |
push @sql_params, $start_accession->output('iso'); |
98 |
"SELECT DISTINCT biblioitems.biblionumber |
116 |
} |
99 |
FROM biblioitems JOIN items |
|
|
100 |
USING (biblionumber) WHERE 1" |
101 |
: |
102 |
"SELECT biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 "; |
103 |
|
104 |
if ( $StartingBiblionumber ) { |
105 |
$sql_query .= " AND biblioitems.biblionumber >= ? "; |
106 |
push @sql_params, $StartingBiblionumber; |
107 |
} |
108 |
|
109 |
if ( $EndingBiblionumber ) { |
110 |
$sql_query .= " AND biblioitems.biblionumber <= ? "; |
111 |
push @sql_params, $EndingBiblionumber; |
112 |
} |
113 |
|
114 |
if ($branch) { |
115 |
$sql_query .= " AND homebranch = ? "; |
116 |
push @sql_params, $branch; |
117 |
} |
118 |
|
119 |
if ($start_callnumber) { |
120 |
$sql_query .= " AND itemcallnumber <= ? "; |
121 |
push @sql_params, $start_callnumber; |
122 |
} |
123 |
|
124 |
if ($end_callnumber) { |
125 |
$sql_query .= " AND itemcallnumber >= ? "; |
126 |
push @sql_params, $end_callnumber; |
127 |
} |
128 |
if ($start_accession) { |
129 |
$sql_query .= " AND dateaccessioned >= ? "; |
130 |
push @sql_params, $start_accession->output('iso'); |
131 |
} |
132 |
|
133 |
if ($end_accession) { |
134 |
$sql_query .= " AND dateaccessioned <= ? "; |
135 |
push @sql_params, $end_accession->output('iso'); |
136 |
} |
117 |
|
137 |
|
118 |
if ($end_accession) { |
138 |
if ( $itemtype ) { |
119 |
$query .= " AND dateaccessioned <= ? "; |
139 |
$sql_query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?"; |
120 |
push @sql_params, $end_accession->output('iso'); |
140 |
push @sql_params, $itemtype; |
|
|
141 |
} |
121 |
} |
142 |
} |
122 |
|
143 |
elsif ( $record_type eq 'auths' ) { |
123 |
if ( $itemtype ) { |
144 |
$sql_query = |
124 |
$query .= (C4::Context->preference('item-level_itypes')) ? " AND items.itype = ? " : " AND biblioitems.itemtype = ?"; |
145 |
"SELECT DISTINCT auth_header.authid FROM auth_header WHERE 1"; |
125 |
push @sql_params, $itemtype; |
146 |
|
|
|
147 |
if ($starting_authid) { |
148 |
$sql_query .= " AND auth_header.authid >= ? "; |
149 |
push @sql_params, $starting_authid; |
150 |
} |
151 |
|
152 |
if ($ending_authid) { |
153 |
$sql_query .= " AND auth_header.authid <= ? "; |
154 |
push @sql_params, $ending_authid; |
155 |
} |
156 |
|
157 |
if ($authtype) { |
158 |
$sql_query .= " AND auth_header.authtypecode = ? "; |
159 |
push @sql_params, $authtype; |
160 |
} |
126 |
} |
161 |
} |
127 |
my $sth = $dbh->prepare($query); |
162 |
|
|
|
163 |
my $sth = $dbh->prepare($sql_query); |
128 |
$sth->execute(@sql_params); |
164 |
$sth->execute(@sql_params); |
129 |
|
165 |
|
130 |
while (my ($biblionumber) = $sth->fetchrow) { |
166 |
while ( my ($recordid) = $sth->fetchrow ) { |
131 |
my $record = eval{ GetMarcBiblio($biblionumber); }; |
167 |
my $record; |
132 |
# FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve |
168 |
if ( $record_type eq 'bibs' ) { |
133 |
if ($@) { |
169 |
$record = eval { GetMarcBiblio($recordid); }; |
134 |
next; |
170 |
|
135 |
} |
171 |
# FIXME: decide how to handle records GetMarcBiblio can't parse or retrieve |
136 |
next if not defined $record; |
172 |
if ($@) { |
137 |
C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) unless $dont_export_items; |
173 |
next; |
138 |
if ($strip_nonlocal_items || $limit_ind_branch) { |
174 |
} |
139 |
my ( $homebranchfield, $homebranchsubfield ) = |
175 |
next if not defined $record; |
140 |
GetMarcFromKohaField( 'items.homebranch', '' ); |
176 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $recordid ) |
141 |
for my $itemfield ($record->field($homebranchfield)){ |
177 |
unless $dont_export_items; |
142 |
# if stripping nonlocal items, use loggedinuser's branch if they didn't select one |
178 |
if ( $strip_nonlocal_items || $limit_ind_branch ) { |
143 |
$branch = C4::Context->userenv->{'branch'} unless $branch; |
179 |
my ( $homebranchfield, $homebranchsubfield ) = |
144 |
$record->delete_field($itemfield) if($itemfield->subfield($homebranchsubfield) ne $branch) ; |
180 |
GetMarcFromKohaField( 'items.homebranch', '' ); |
|
|
181 |
for my $itemfield ( $record->field($homebranchfield) ) { |
182 |
|
183 |
# if stripping nonlocal items, use loggedinuser's branch if they didn't select one |
184 |
$branch = C4::Context->userenv->{'branch'} unless $branch; |
185 |
$record->delete_field($itemfield) |
186 |
if ( |
187 |
$itemfield->subfield($homebranchsubfield) ne $branch ); |
188 |
} |
145 |
} |
189 |
} |
146 |
} |
190 |
} |
147 |
|
191 |
elsif ( $record_type eq 'auths' ) { |
|
|
192 |
$record = C4::AuthoritiesMarc::GetAuthority($recordid); |
193 |
next if not defined $record; |
194 |
} |
195 |
|
148 |
if ( $dont_export_fields ) { |
196 |
if ( $dont_export_fields ) { |
149 |
my @fields = split " ", $dont_export_fields; |
197 |
my @fields = split " ", $dont_export_fields; |
150 |
foreach ( @fields ) { |
198 |
foreach ( @fields ) { |
Lines 165-176
if ($op eq "export") {
Link Here
|
165 |
print $record->as_xml_record($marcflavour); |
213 |
print $record->as_xml_record($marcflavour); |
166 |
} |
214 |
} |
167 |
else { |
215 |
else { |
168 |
print $record->as_usmarc(); |
216 |
print $record->as_usmarc(); |
169 |
} |
217 |
} |
170 |
} |
218 |
} |
171 |
exit; |
219 |
exit; |
172 |
|
220 |
|
173 |
} # if export |
221 |
} # if export |
174 |
|
222 |
|
175 |
else { |
223 |
else { |
176 |
|
224 |
|
Lines 196-206
else {
Link Here
|
196 |
}; |
244 |
}; |
197 |
} |
245 |
} |
198 |
|
246 |
|
|
|
247 |
my $authtypes = getauthtypes; |
248 |
my @authtypesloop; |
249 |
foreach my $thisauthtype ( sort keys %$authtypes ) { |
250 |
next unless $thisauthtype; |
251 |
my %row = ( |
252 |
value => $thisauthtype, |
253 |
description => $authtypes->{$thisauthtype}->{'authtypetext'}, |
254 |
); |
255 |
push @authtypesloop, \%row; |
256 |
} |
257 |
|
199 |
$template->param( |
258 |
$template->param( |
200 |
branchloop => \@branchloop, |
259 |
branchloop => \@branchloop, |
201 |
itemtypeloop => \@itemtypesloop, |
260 |
itemtypeloop => \@itemtypesloop, |
202 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
261 |
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), |
|
|
262 |
authtypeloop => \@authtypesloop, |
203 |
); |
263 |
); |
204 |
|
264 |
|
205 |
output_html_with_http_headers $query, $cookie, $template->output; |
265 |
output_html_with_http_headers $query, $cookie, $template->output; |
206 |
} |
266 |
} |
207 |
- |
|
|