08454fbeee
svc/bib and svc/new_bib had two problems related to UTF-8 character conversion: [1] Couple instances of "Wide character" warnings [2] When saving a new (MARC21) bib whose Leader/09 was not 'a', did not apply default character conversion and set the Leader/09 to 'a'. Fix includes two parts: [1] Setting :utf8 on STDOUT [2] Doing default MARC-8 to UTF-8 conversion if applicable This patch also turns on warnings in all scripts under svc per bug 2505. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
129 lines
4.5 KiB
Perl
Executable file
129 lines
4.5 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright 2007 LibLime
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with
|
|
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
|
|
# Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use CGI;
|
|
use C4::Auth qw/check_api_auth/;
|
|
use C4::Context;
|
|
use C4::Koha;
|
|
use XML::Simple;
|
|
|
|
my $query = new CGI;
|
|
|
|
my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
|
|
|
|
if ($status eq "ok") {
|
|
print $query->header(-type => 'text/xml', cookie => $cookie);
|
|
} else {
|
|
print $query->header(-type => 'text/xml', -status => '403 Forbidden');
|
|
print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
|
|
exit 0;
|
|
}
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
# get list of required tags
|
|
my $result = {};
|
|
$result->{'auth_status'} = $status;
|
|
_get_mandatory_tags($result);
|
|
_get_mandatory_subfields($result);
|
|
_get_reserved_tags($result);
|
|
_get_bib_number_tag($result);
|
|
_get_biblioitem_itemtypes($result);
|
|
print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1,
|
|
GroupTags => {mandatory_tags => 'tag', mandatory_subfields => 'subfield', reserved_tags => 'tag',
|
|
valid_values => 'value'});
|
|
|
|
exit 0;
|
|
|
|
sub _get_mandatory_tags {
|
|
my $result = shift;
|
|
my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
|
|
$sth->execute();
|
|
my @tags = ();
|
|
while (my $row = $sth->fetchrow_arrayref) {
|
|
push @tags, $row->[0];
|
|
}
|
|
$result->{'mandatory_tags'} = \@tags;
|
|
}
|
|
|
|
sub _get_mandatory_subfields {
|
|
my $result = shift;
|
|
my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
|
|
FROM marc_subfield_structure
|
|
WHERE frameworkcode = ''
|
|
AND tagsubfield <> '\@'
|
|
AND kohafield <> 'biblioitems.itemtype'
|
|
AND mandatory = 1");
|
|
$sth->execute();
|
|
my @subfields = ();
|
|
while (my $row = $sth->fetchrow_arrayref) {
|
|
push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
|
|
}
|
|
$result->{'mandatory_subfields'} = \@subfields;
|
|
}
|
|
|
|
sub _get_reserved_tags {
|
|
my $result = shift;
|
|
my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
|
|
FROM marc_subfield_structure
|
|
WHERE frameworkcode = ''
|
|
AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
|
|
kohafield = 'biblio.biblionumber')");
|
|
$sth->execute();
|
|
my @tags = ();
|
|
while (my $row = $sth->fetchrow_arrayref) {
|
|
push @tags, $row->[0];
|
|
}
|
|
$result->{'reserved_tags'} = \@tags;
|
|
}
|
|
|
|
sub _get_bib_number_tag {
|
|
my $result = shift;
|
|
my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
|
|
FROM marc_subfield_structure
|
|
WHERE frameworkcode = ''
|
|
AND kohafield = 'biblio.biblionumber'");
|
|
$sth->execute();
|
|
my @tags = ();
|
|
while (my $row = $sth->fetchrow_arrayref) {
|
|
push @tags, { tag => $row->[0], subfield => $row->[1] };
|
|
}
|
|
$result->{'bib_number'} = \@tags;
|
|
}
|
|
|
|
sub _get_biblioitem_itemtypes {
|
|
my $result = shift;
|
|
my $itemtypes = GetItemTypes;
|
|
my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
|
|
FROM marc_subfield_structure
|
|
WHERE frameworkcode = ''
|
|
AND kohafield = 'biblioitems.itemtype'");
|
|
$sth->execute();
|
|
my @tags = ();
|
|
while (my $row = $sth->fetchrow_arrayref) {
|
|
push @tags, { tag => $row->[0], subfield => $row->[1] };
|
|
}
|
|
my @valid_values = map { { code => $_, description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
|
|
$result->{'special_entry'} = { field => \@tags, valid_values => \@valid_values };
|
|
|
|
}
|