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 <> '\@'
73 AND kohafield <> 'biblioitems.itemtype'
77 while (my $row = $sth->fetchrow_arrayref) {
78 push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
80 $result->{'mandatory_subfields'} = \@subfields;
83 sub _get_reserved_tags {
85 my $sth = $dbh->prepare_cached("SELECT DISTINCT tagfield
86 FROM marc_subfield_structure
87 WHERE frameworkcode = ''
88 AND (kohafield = 'items.itemnumber' OR kohafield = 'biblioitems.itemtype' OR
89 kohafield = 'biblio.biblionumber')");
92 while (my $row = $sth->fetchrow_arrayref) {
93 push @tags, $row->[0];
95 $result->{'reserved_tags'} = \@tags;
98 sub _get_bib_number_tag {
100 my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
101 FROM marc_subfield_structure
102 WHERE frameworkcode = ''
103 AND kohafield = 'biblio.biblionumber'");
106 while (my $row = $sth->fetchrow_arrayref) {
107 push @tags, { tag => $row->[0], subfield => $row->[1] };
109 $result->{'bib_number'} = \@tags;
112 sub _get_biblioitem_itemtypes {
114 my $itemtypes = GetItemTypes;
115 my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
116 FROM marc_subfield_structure
117 WHERE frameworkcode = ''
118 AND kohafield = 'biblioitems.itemtype'");
121 while (my $row = $sth->fetchrow_arrayref) {
122 push @tags, { tag => $row->[0], subfield => $row->[1] };
124 my @valid_values = map { { code => $_, description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
125 $result->{'special_entry'} = { field => \@tags, valid_values => \@valid_values };