@@ -, +, @@ - iso2709 with items: Export the items list in iso2709 format with item informations. - iso2709 without items: Export the items list in iso2709 format without item informations. - CSV: Export the items list based on a csv profil. - DontExportFields: a list of fields not to be export - CsvProfileForExport: The Csv profile name used for the csv export - Fill the CsvProfileForExport syspref - go on the borrower circulation page containing checkouts - Select one or more items and export them to the 3 different formats. - check if the result file is what you expected - Test there is no regression with the export authority - Test there is no regression using tools/export.pl with the command line interface --- C4/Biblio.pm | 6 +- C4/Csv.pm | 13 + C4/Record.pm | 59 +- circ/circulation.pl | 2 + installer/data/mysql/updatedatabase.pl | 18 + .../prog/en/includes/checkouts-table-footer.inc | 2 +- .../intranet-tmpl/prog/en/includes/prefs-menu.inc | 1 + .../en/modules/admin/preferences/circulation.pref | 6 + .../prog/en/modules/admin/preferences/tools.pref | 4 + .../prog/en/modules/circ/circulation.tt | 89 ++- .../intranet-tmpl/prog/en/modules/tools/export.tt | 2 +- tools/export.pl | 713 ++++++++++++-------- 12 files changed, 610 insertions(+), 305 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -2791,16 +2791,17 @@ sub GetNoZebraIndexes { =head2 EmbedItemsInMarcBiblio - EmbedItemsInMarcBiblio($marc, $biblionumber); + EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers); Given a MARC::Record object containing a bib record, modify it to include the items attached to it as 9XX per the bib's MARC framework. +if $itemnumbers is defined, only specified itemnumbers are embedded =cut sub EmbedItemsInMarcBiblio { - my ($marc, $biblionumber) = @_; + my ($marc, $biblionumber, $itemnumbers) = @_; croak "No MARC record" unless $marc; my $frameworkcode = GetFrameworkCode($biblionumber); @@ -2813,6 +2814,7 @@ sub EmbedItemsInMarcBiblio { my @item_fields; my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); while (my ($itemnumber) = $sth->fetchrow_array) { + next if $itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; require C4::Items; my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber); push @item_fields, $item_marc->field($itemtag); --- a/C4/Csv.pm +++ a/C4/Csv.pm @@ -35,6 +35,7 @@ $VERSION = 3.07.00.049; @EXPORT = qw( &GetCsvProfiles &GetCsvProfile + &GetCsvProfileId &GetCsvProfilesLoop &GetMarcFieldsForCsv ); @@ -64,6 +65,18 @@ sub GetCsvProfile { return ($sth->fetchrow_hashref); } +# Returns id of csv profile about a given csv profile name +sub GetCsvProfileId { + my ($name) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT export_format_id FROM export_format WHERE profile=?"; + + $sth = $dbh->prepare($query); + $sth->execute($name); + + return ( $sth->fetchrow ); +} + # Returns fields to extract for the given csv profile sub GetMarcFieldsForCsv { --- a/C4/Record.pm +++ a/C4/Record.pm @@ -358,7 +358,7 @@ sub marc2endnote { =head2 marc2csv - Convert several records from UNIMARC to CSV - my ($csv) = marc2csv($biblios, $csvprofileid); + my ($csv) = marc2csv($biblios, $csvprofileid, $itemnumbers); Pre and postprocessing can be done through a YAML file @@ -368,10 +368,12 @@ C<$biblio> - a list of biblionumbers C<$csvprofileid> - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv) +C<$itemnumbers> - a list of itemnumbers to export + =cut sub marc2csv { - my ($biblios, $id) = @_; + my ($biblios, $id, $itemnumbers) = @_; my $output; my $csv = Text::CSV::Encoded->new(); @@ -386,9 +388,17 @@ sub marc2csv { eval $preprocess if ($preprocess); my $firstpass = 1; - foreach my $biblio (@$biblios) { - $output .= marcrecord2csv($biblio, $id, $firstpass, $csv, $fieldprocessing) ; - $firstpass = 0; + if ( $itemnumbers ) { + for my $itemnumber ( @$itemnumbers) { + my $biblionumber = GetBiblionumberFromItemnumber $itemnumber; + $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ); + $firstpass = 0; + } + } else { + foreach my $biblio (@$biblios) { + $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing ); + $firstpass = 0; + } } # Postprocessing @@ -411,16 +421,21 @@ C<$header> - true if the headers are to be printed (typically at first pass) C<$csv> - an already initialised Text::CSV object +C<$fieldprocessing> + +C<$itemnumbers> a list of itemnumbers to export + =cut sub marcrecord2csv { - my ($biblio, $id, $header, $csv, $fieldprocessing) = @_; + my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_; my $output; # Getting the record - my $record = GetMarcBiblio($biblio, 1); + my $record = GetMarcBiblio($biblio); next unless $record; + C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblio, $itemnumbers ); # Getting the framework my $frameworkcode = GetFrameworkCode($biblio); @@ -527,18 +542,28 @@ sub marcrecord2csv { my @fields = ($record->field($marcfield)); my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef); - my @valuesarray; - foreach (@fields) { - my $value; - - # Getting authorised value - $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string; + my @valuesarray; + foreach (@fields) { + my $value; + + # If it is a control field + if ($_->is_control_field) { + $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string; + } else { + # If it is a field, we gather all subfields, joined by the subfield separator + my @subvaluesarray; + my @subfields = $_->subfields; + foreach my $subfield (@subfields) { + push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]); + } + $value = join ($subfieldseparator, @subvaluesarray); + } - # Field processing - eval $fieldprocessing if ($fieldprocessing); + # Field processing + eval $fieldprocessing if ($fieldprocessing); - push @valuesarray, $value; - } + push @valuesarray, $value; + } push (@fieldstab, join($fieldseparator, @valuesarray)); } }; --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -732,6 +732,8 @@ $template->param( AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), dateformat => C4::Context->preference("dateformat"), DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + dont_export_fields => C4::Context->preference("DontExportFields"), + csv_profile_for_export => C4::Context->preference("CsvProfileForExport"), canned_bor_notes_loop => $canned_notes, ); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -5684,6 +5684,24 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('DontExportFields','','List of fields for non export in circulation.pl (separated by a space)','',''); + }); + print "Upgrade to $DBversion done (Add system preference DontExportFields)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('CsvProfileForExport','','Set a profile name for CSV export','',''); + }); + print "Upgrade to $DBversion done (Adds New System preference CsvProfileForExport)\n"; + SetVersion($DBversion) +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc @@ -3,7 +3,7 @@
Renewal due date:
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-menu.inc @@ -15,6 +15,7 @@ [% IF ( searching ) %]