3 # Copyright 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use C4::Auth qw/check_api_auth/;
30 my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
32 if ($status eq "ok") {
33 print $query->header(-type => 'text/xml', cookie => $cookie);
35 print $query->header(-type => 'text/xml', -status => '403 Forbidden');
36 print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
40 my $dbh = C4::Context->dbh;
42 # get list of required tags
44 $result->{'auth_status'} = $status;
45 _get_mandatory_tags($result);
46 _get_mandatory_subfields($result);
47 _get_reserved_tags($result);
48 _get_bib_number_tag($result);
49 _get_biblioitem_itemtypes($result);
50 print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1,
51 GroupTags => {mandatory_tags => 'tag', mandatory_subfields => 'subfield', reserved_tags => 'tag',
52 valid_values => 'value'});
56 sub _get_mandatory_tags {
58 my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
61 while (my $row = $sth->fetchrow_arrayref) {
62 push @tags, $row->[0];
64 $result->{'mandatory_tags'} = \@tags;
67 sub _get_mandatory_subfields {
69 my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
70 FROM marc_subfield_structure
71 WHERE frameworkcode = ''
72 AND tagsubfield <> '\@'
76 while (my $row = $sth->fetchrow_arrayref) {
77 push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
79 $result->{'mandatory_subfields'} = \@subfields;
82 sub _get_reserved_tags {
84 my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
85 FROM marc_subfield_structure
86 WHERE frameworkcode = ''
87 AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
88 kohafield = 'biblio.biblionumber')");
91 while (my $row = $sth->fetchrow_arrayref) {
92 push @tags, $row->[0];
94 $result->{'reserved_tags'} = \@tags;
97 sub _get_bib_number_tag {
99 my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
100 FROM marc_subfield_structure
101 WHERE frameworkcode = ''
102 AND kohafield = 'biblio.biblionumber'");
105 while (my $row = $sth->fetchrow_arrayref) {
106 push @tags, { tag => $row->[0], subfield => $row->[1] };
108 $result->{'bib_number'} = \@tags;
111 sub _get_biblioitem_itemtypes {
113 my $itemtypes = GetItemTypes;
114 my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
115 FROM marc_subfield_structure
116 WHERE frameworkcode = ''
117 AND kohafield = 'biblioitems.itemtype'");
120 while (my $row = $sth->fetchrow_arrayref) {
121 push @tags, { tag => $row->[0], subfield => $row->[1] };
123 my @valid_values = map { { code => $_, description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
124 $result->{'special_entry'} = { field => \@tags, valid_values => \@valid_values };