use MARC::File::XML;
use List::MoreUtils qw(uniq);
use C4::Auth;
-use C4::Branch; # GetBranches
-use C4::Csv;
-use C4::Koha; # GetItemTypes
use C4::Output;
+use Koha::Authority::Types;
use Koha::Biblioitems;
+use Koha::CsvProfiles;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Exporter::Record;
+use Koha::ItemTypes;
+use Koha::Libraries;
-my $query = new CGI;
+my $query = CGI->new;
my $dont_export_items = $query->param("dont_export_item") || 0;
my $record_type = $query->param("record_type");
my $op = $query->param("op") || '';
my $output_format = $query->param("format") || $query->param("output_format") || 'iso2709';
my $backupdir = C4::Context->config('backupdir');
-my $filename = $query->param("filename") || 'koha.mrc';
+my $filename;
+if ( $record_type eq 'auths' ) {
+ $filename = $query->param("filename_auth") || ( $output_format eq 'xml' ? 'koha.xml' : 'koha.mrc' );
+} else {
+ $filename = $query->param("filename") || ( $output_format eq 'csv' ? 'koha.csv' : 'koha.mrc' );
+}
$filename =~ s/(\r|\n)//;
my $dbh = C4::Context->dbh;
# biblionumbers is sent from circulation.pl only
if ( $query->param("biblionumbers") ) {
$record_type = 'bibs';
- @record_ids = $query->param("biblionumbers");
+ @record_ids = $query->multi_param("biblionumbers");
}
# Default value for output_format is 'iso2709'
template_name => "tools/export.tt",
query => $query,
type => "intranet",
- authnotrequired => 0,
flagsrequired => { tools => 'export_catalog' },
- debug => 1,
}
);
-my @branch = $query->param("branch");
-my $only_my_branch;
-# Limit to local branch if IndependentBranches and not superlibrarian
-if (
- (
- C4::Context->preference('IndependentBranches')
- && C4::Context->userenv
- && !C4::Context->IsSuperLibrarian()
- && C4::Context->userenv->{branch}
- )
- # Limit result to local branch strip_nonlocal_items
- or $query->param('strip_nonlocal_items')
-) {
- $only_my_branch = 1;
- @branch = ( C4::Context->userenv->{'branch'} );
+my @branch = $query->multi_param("branch");
+
+my @messages;
+if ( $op eq 'export' ) {
+ my $filename = $query->param('id_list_file');
+ if ( $filename ) {
+ my $mimetype = $query->uploadInfo($filename)->{'Content-Type'};
+ my @valid_mimetypes = qw( application/octet-stream text/csv text/plain application/vnd.ms-excel );
+ unless ( grep { $_ eq $mimetype } @valid_mimetypes ) {
+ push @messages, { type => 'alert', code => 'invalid_mimetype' };
+ $op = '';
+ }
+ }
}
-my %branchmap = map { $_ => 1 } @branch; # for quick lookups
-
if ( $op eq "export" ) {
my $export_remove_fields = $query->param("export_remove_fields") || q||;
- my @biblionumbers = $query->param("biblionumbers");
- my @itemnumbers = $query->param("itemnumbers");
- my @sql_params;
- my $sql_query;
+ my @biblionumbers = $query->multi_param("biblionumbers");
+ my @itemnumbers = $query->multi_param("itemnumbers");
+ my $strip_items_not_from_libraries = $query->param('strip_items_not_from_libraries');
+
+ my $libraries = Koha::Libraries->search_filtered->unblessed;
+ my $only_export_items_for_branches = $strip_items_not_from_libraries ? \@branch : undef;
+ my @branchcodes;
+ for my $branchcode ( @branch ) {
+ if ( grep { $_->{branchcode} eq $branchcode } @$libraries ) {
+ push @branchcodes, $branchcode;
+ }
+ }
if ( $record_type eq 'bibs' or $record_type eq 'auths' ) {
# No need to retrieve the record_ids if we already get them
my $end_callnumber = $query->param("end_callnumber");
my $start_accession =
( $query->param("start_accession") )
- ? dt_from_string( $query->param("start_accession") )
+ ? dt_from_string( scalar $query->param("start_accession") )
: '';
my $end_accession =
( $query->param("end_accession") )
- ? dt_from_string( $query->param("end_accession") )
+ ? dt_from_string( scalar $query->param("end_accession") )
: '';
}
)
: (),
+
( $start_callnumber or $end_callnumber )
? (
- callnumber => {
+ 'items.itemcallnumber' => {
( $start_callnumber ? ( '>=' => $start_callnumber ) : () ),
( $end_callnumber ? ( '<=' => $end_callnumber ) : () ),
}
)
: (),
+
( $start_accession or $end_accession )
? (
- dateaccessioned => {
+ 'items.dateaccessioned' => {
( $start_accession ? ( '>=' => $start_accession ) : () ),
( $end_accession ? ( '<=' => $end_accession ) : () ),
}
)
: (),
- ( @branch ? ( 'items.homebranch' => { in => \@branch } ) : () ),
+ ( @branchcodes ? ( 'items.homebranch' => { in => \@branchcodes } ) : () ),
( $itemtype
?
C4::Context->preference('item-level_itypes')
? ( 'items.itype' => $itemtype )
- : ( 'biblioitems.itemtype' => $itemtype )
+ : ( 'me.itemtype' => $itemtype )
: ()
),
};
- my $biblioitems = Koha::Biblioitems->search( $conditions, { join => 'items' } );
+ my $biblioitems = Koha::Biblioitems->search( $conditions, { join => 'items', columns => 'biblionumber' } );
while ( my $biblioitem = $biblioitems->next ) {
push @record_ids, $biblioitem->biblionumber;
}
: (),
( $authtype ? ( authtypecode => $authtype ) : () ),
};
- # Koha::Authority is not a Koha::Object...
+ # Koha::MetadataRecord::Authority is not a Koha::Object...
my $authorities = Koha::Database->new->schema->resultset('AuthHeader')->search( $conditions );
@record_ids = map { $_->authid } $authorities->all;
}
@record_ids = uniq @record_ids;
if ( @record_ids and my $filefh = $query->upload("id_list_file") ) {
my @filter_record_ids = <$filefh>;
- @filter_record_ids = map { my $id = $_; $id =~ s/[\r\n]*$// } @filter_record_ids;
+ @filter_record_ids = map { my $id = $_; $id =~ s/[\r\n]*$//; $id } @filter_record_ids;
# intersection
my %record_ids = map { $_ => 1 } @record_ids;
@record_ids = grep $record_ids{$_}, @filter_record_ids;
-attachment => $filename,
);
+ my $csv_profile_id = $query->param('csv_profile_id');
Koha::Exporter::Record::export(
{ record_type => $record_type,
record_ids => \@record_ids,
filename => $filename,
itemnumbers => \@itemnumbers,
dont_export_fields => $export_remove_fields,
- csv_profile_id => ( $query->param('csv_profile_id') || GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ) || undef ),
+ csv_profile_id => $csv_profile_id,
export_items => (not $dont_export_items),
+ only_export_items_for_branches => $only_export_items_for_branches,
}
);
}
else {
- my $itemtypes = GetItemTypes;
- my @itemtypesloop;
- foreach my $thisitemtype ( sort keys %$itemtypes ) {
- my %row = (
- value => $thisitemtype,
- description => $itemtypes->{$thisitemtype}->{translated_description},
- );
- push @itemtypesloop, \%row;
- }
- my $branches = GetBranches($only_my_branch);
- my @branchloop;
- for my $thisbranch (
- sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} }
- keys %{$branches}
- )
- {
- push @branchloop,
- {
- value => $thisbranch,
- selected => %branchmap ? $branchmap{$thisbranch} : 1,
- branchname => $branches->{$thisbranch}->{'branchname'},
- };
- }
+ my $itemtypes = Koha::ItemTypes->search_with_localization;
- my $authtypes = getauthtypes;
- my @authtypesloop;
- foreach my $thisauthtype ( sort keys %$authtypes ) {
- next unless $thisauthtype;
- my %row = (
- value => $thisauthtype,
- description => $authtypes->{$thisauthtype}->{'authtypetext'},
- );
- push @authtypesloop, \%row;
+ my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
+
+ my $libraries = Koha::Libraries->search_filtered({}, { order_by => ['branchname'] })->unblessed;
+ for my $library ( @$libraries ) {
+ $library->{selected} = 1 if grep { $library->{branchcode} eq $_ } @branch;
}
if ( $flags->{superlibrarian}
}
$template->param(
- branchloop => \@branchloop,
- itemtypeloop => \@itemtypesloop,
- authtypeloop => \@authtypesloop,
+ libraries => $libraries,
+ itemtypes => $itemtypes,
+ authority_types => $authority_types,
export_remove_fields => C4::Context->preference("ExportRemoveFields"),
- csv_profiles => C4::Csv::GetCsvProfiles('marc'),
+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
+ messages => \@messages,
);
output_html_with_http_headers $query, $cookie, $template->output;