&GetAuthorisedValues
&GetAuthorisedValueCategories
&GetKohaAuthorisedValues
+ &GetKohaAuthorisedValuesFromField
&GetAuthValCode
&GetNormalizedUPC
&GetNormalizedISBN
return $authvalcode;
}
+=head2 GetAuthValCodeFromField
+
+$authvalcode = GetAuthValCodeFromField($field,$subfield,$frameworkcode);
+
+C<$subfield> can be undefined
+
+=cut
+
+sub GetAuthValCodeFromField {
+ my ($field,$subfield,$fwcode) = @_;
+ my $dbh = C4::Context->dbh;
+ $fwcode='' unless $fwcode;
+ my $sth;
+ if (defined $subfield) {
+ $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?');
+ $sth->execute($field,$subfield,$fwcode);
+ } else {
+ $sth = $dbh->prepare('select authorised_value from marc_tag_structure where tagfield=? and frameworkcode=?');
+ $sth->execute($field,$fwcode);
+ }
+ my ($authvalcode) = $sth->fetchrow_array;
+ return $authvalcode;
+}
+
=head2 GetAuthorisedValues
$authvalues = GetAuthorisedValues([$category], [$selected]);
}
}
+=head2 GetKohaAuthorisedValuesFromField
+
+ Takes $field, $subfield $fwcode as parameters.
+ If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
+ $subfield can be undefined
+ Returns hashref of Code => description
+ Returns undef
+ if no authorised value category is defined for the given field and subfield
+
+=cut
+
+sub GetKohaAuthorisedValuesFromField {
+ my ($field, $subfield, $fwcode,$opac) = @_;
+ $fwcode='' unless $fwcode;
+ my %values;
+ my $dbh = C4::Context->dbh;
+ my $avcode = GetAuthValCodeFromField($field, $subfield, $fwcode);
+ if ($avcode) {
+ my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
+ $sth->execute($avcode);
+ while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
+ $values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
+ }
+ return \%values;
+ } else {
+ return undef;
+ }
+}
+
=head2 display_marc_indicators
=over 4
use XML::LibXML;
use C4::Biblio; #marc2bibtex
use C4::Csv; #marc2csv
-use Text::CSV; #marc2csv
+use C4::Koha; #marc2csv
+use Text::CSV::Encoded; #marc2csv
use vars qw($VERSION @ISA @EXPORT);
=over 4
-my ($csv) = marc2csv($record, $csvprofileid);
+my ($csv) = marc2csv($record, $csvprofileid, $header);
Returns a CSV scalar
=over 2
-C<$record> - a MARC::Record object
+C<$biblio> - a biblionumber
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)
sub marc2csv {
- my ($record, $id, $header) = @_;
+ my ($biblio, $id, $header) = @_;
my $output;
- # Get the information about the csv profile
+ # Getting the record
+ my $record = GetMarcBiblio($biblio);
+
+ # Getting the framework
+ my $frameworkcode = GetFrameworkCode($biblio);
+
+ # Getting information about the csv profile
my $profile = GetCsvProfile($id);
+ # Getting output encoding
+ my $encoding = $profile->{encoding} || 'utf8';
+
# Getting separators
my $csvseparator = $profile->{csv_separator} || ',';
my $fieldseparator = $profile->{field_separator} || '#';
if ($subfieldseparator eq '\t') { $subfieldseparator = "\t" }
# Init CSV
- my $csv = Text::CSV->new({ sep_char => $csvseparator });
+ my $csv = Text::CSV::Encoded->new({ sep_char => $csvseparator });
+ $csv = $csv->encoding_out($encoding) if ($encoding ne 'utf8');
# Getting the marcfields
my $marcfieldslist = $profile->{marcfields};
if (exists $_->{header}) {
push @marcfieldsheaders, $_->{header};
} else {
-warn "else";
# If not, we get the matching tag name from koha
if (index($field, '$') > 0) {
my ($fieldtag, $subfieldtag) = split('\$', $field);
my $sth = $dbh->prepare($query);
$sth->execute($fieldtag, $subfieldtag);
my @results = $sth->fetchrow_array();
-warn "subfield $fieldtag, $subfieldtag";
push @marcfieldsheaders, $results[0];
} else {
my $query = "SELECT liblibrarian FROM marc_tag_structure WHERE tagfield=?";
my $sth = $dbh->prepare($query);
$sth->execute($field);
my @results = $sth->fetchrow_array();
-warn "field $results[0]";
push @marcfieldsheaders, $results[0];
}
}
# We take every matching subfield
my @subfields = $field->subfield($subfieldtag);
foreach my $subfield (@subfields) {
- push @tmpfields, $subfield;
+
+ # Getting authorised value
+ my $authvalues = GetKohaAuthorisedValuesFromField($fieldtag, $subfieldtag, $frameworkcode, undef);
+ push @tmpfields, (defined $authvalues->{$subfield}) ? $authvalues->{$subfield} : $subfield;
}
}
push (@fieldstab, join($subfieldseparator, @tmpfields));
# Or a field
} else {
my @fields = ($record->field($marcfield));
- push (@fieldstab, join($fieldseparator, map($_->as_string(), @fields)));
+ my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
+ push (@fieldstab, join($fieldseparator, map((defined $authvalues->{$_->as_string}) ? $authvalues->{$_->as_string} : $_->as_string, @fields)));
}
};
'Test::More' => 0.80,
'Text::CSV' => 0.01,
'Text::CSV_XS' => 0.32,
+ 'Text::CSV::Encoded' => 0.09,
'Text::Iconv' => 1.7,
'Text::Wrap' => 2005.082401,
'Time::HiRes' => 1.86,
Test::More
Text::CSV
Text::CSV_XS
+Text::CSV::Encoded
Text::Iconv
Text::Wrap
Time::HiRes
case "ris" { $output .= marc2ris($record); }
case "bibtex" { $output .= marc2bibtex($record, $biblio); }
# We're in the case of a csv profile (firstpass is used for headers printing) :
- case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); }
+ case /^\d+$/ { $output .= marc2csv($biblio, $format, $firstpass); }
}
$firstpass = 0;
`profile` varchar(255) NOT NULL,
`description` mediumtext NOT NULL,
`marcfields` mediumtext NOT NULL,
+ `csv_separator` varchar(2) NOT NULL,
+ `field_separator` varchar(2) NOT NULL,
+ `subfield_separator` varchar(2) NOT NULL,
+ `encoding` varchar(255) NOT NULL,
PRIMARY KEY (`export_format_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
SetVersion ($DBversion);
}
+$DBversion = "3.01.00.102";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do(qq{
+ ALTER TABLE `export_format` ADD `encoding` VARCHAR(255) NOT NULL AFTER `subfield_separator`
+ });
+ print "Upgrade done (added encoding for csv export)\n";
+ SetVersion ($DBversion);
+}
=item DropAllForeignKeys($table)
<option value="\t">Tabulation (\t)</option>
</select>
<br /><br />
+
+ <label for="encoding">Encoding :</label>
+ <select name="encoding">
+ <!-- TMPL_LOOP NAME="encodings" -->
+ <option<!-- TMPL_IF EXPR="encoding eq 'utf8'" --> selected="selected" <!-- /TMPL_IF -->><!-- TMPL_VAR NAME="encoding" --></option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ <br /><br />
+
<label for="profile_content">Profile marcfields :</label>
<textarea cols="50" rows="2" name="profile_content" id="profile_content"></textarea>
<p>You have to define which fields or subfields you want to export, separated by pipes.<br />
You can also use your own headers (instead of the ones from koha) by prefixing the field number with an header, followed by the equal sign.<br />
- Example : Personal name=200|Entry element=210$a|300
+ Example : Personal name=200|Entry element=210$a|300|009
</p>
</fieldset>
<input type="hidden" name="action" value="create" />
</select>
<br /><br />
+ <label for="encoding">Encoding :</label>
+ <select name="encoding">
+ <!-- TMPL_LOOP NAME="encodings" -->
+ <option<!-- TMPL_IF EXPR="selected_encoding eq encoding" --> selected="selected" <!-- /TMPL_IF -->><!-- TMPL_VAR NAME="encoding" --></option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ <br /><br />
+
+
<label for="modify_profile_content">Profile marcfields :</label>
<textarea cols="50" rows="2" name="profile_content" id="modify_profile_content"><!-- TMPL_VAR NAME="selected_profile_marcfields" --></textarea></li>
case "ris" { $output .= marc2ris($record); }
case "bibtex" { $output .= marc2bibtex($record, $biblio); }
# We're in the case of a csv profile (firstpass is used for headers printing) :
- case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); }
+ case /^\d+$/ { $output .= marc2csv($biblio, $format, $firstpass); }
}
$firstpass = 0;
case "ris" { $output .= marc2ris($record); }
case "bibtex" { $output .= marc2bibtex($record, $biblionumber); }
# We're in the case of a csv profile (firstpass is used for headers printing) :
- case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); }
+ case /^\d+$/ { $output .= marc2csv($biblionumber, $format, $firstpass); }
}
$firstpass = 0;
}
use strict;
use Data::Dumper;
+use Encode;
use C4::Auth;
use C4::Context;
}
);
+# Getting available encodings list
+my @encodings = Encode->encodings();
+my @encodings_loop = map{{encoding => $_}} @encodings;
+$template->param(encodings => \@encodings_loop);
my $profile_name = $input->param("profile_name");
my $profile_description = $input->param("profile_description");
my $csv_separator = $input->param("csv_separator");
my $field_separator = $input->param("field_separator");
my $subfield_separator = $input->param("subfield_separator");
+my $encoding = $input->param("encoding");
my $action = $input->param("action");
my $delete = $input->param("delete");
my $id = $input->param("id");
my $rows;
if ($action eq "create") {
- my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator) VALUES (NULL, ?, ?, ?, ?, ?, ?)";
+ my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)";
my $sth = $dbh->prepare($query);
- $rows = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator);
+ $rows = $sth->execute($profile_name, $profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding);
}
if ($action eq "edit") {
- my $query = "UPDATE export_format SET description=?, marcfields=?, csv_separator=?, field_separator=?, subfield_separator=? WHERE export_format_id=? LIMIT 1";
+ my $query = "UPDATE export_format SET description=?, marcfields=?, csv_separator=?, field_separator=?, subfield_separator=?, encoding=? WHERE export_format_id=? LIMIT 1";
my $sth = $dbh->prepare($query);
- $rows = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $profile_name);
-warn "id $id";
+ $rows = $sth->execute($profile_description, $profile_content, $csv_separator, $field_separator, $subfield_separator, $encoding, $profile_name);
}
if ($action eq "delete") {
# If a profile has been selected for modification
if ($id) {
- my $query = "SELECT export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator FROM export_format WHERE export_format_id = ?";
+ my $query = "SELECT export_format_id, profile, description, marcfields, csv_separator, field_separator, subfield_separator, encoding FROM export_format WHERE export_format_id = ?";
my $sth;
$sth = $dbh->prepare($query);
$sth->execute($id);
my $selected_profile = $sth->fetchrow_arrayref();
- warn "value : " . $selected_profile->[4];
$template->param(
selected_profile_id => $selected_profile->[0],
selected_profile_name => $selected_profile->[1],
selected_profile_marcfields => $selected_profile->[3],
selected_csv_separator => $selected_profile->[4],
selected_field_separator => $selected_profile->[5],
- selected_subfield_separator => $selected_profile->[6]
+ selected_subfield_separator => $selected_profile->[6],
+ selected_encoding => $selected_profile->[7]
);
}
case "ris" { $output .= marc2ris($record); }
case "bibtex" { $output .= marc2bibtex($record, $biblionumber); }
# We're in the case of a csv profile (firstpass is used for headers printing) :
- case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); }
+ case /^\d+$/ { $output .= marc2csv($biblionumber, $format, $firstpass); }
}
$firstpass = 0;
}