fixing syntax error in sysprefs.sql
[koha.git] / biblios / bib_profile
1 #!/usr/bin/perl
2
3 # Copyright 2007 LibLime
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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
19 #
20
21 use strict;
22 use CGI;
23 use C4::Auth qw/check_api_auth/;
24 use C4::Context;
25 use C4::Koha;
26 use XML::Simple;
27
28 my $query = new CGI;
29
30 my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 1} );
31
32 if ($status eq "ok") {
33     print $query->header(-type => 'text/xml', cookie => $cookie);
34 } else {
35     print $query->header(-type => 'text/xml', -status => '403 Forbidden');
36     print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
37     exit 0;
38 }
39
40 my $dbh = C4::Context->dbh;
41
42 # get list of required tags
43 my $result = {};
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'});
53
54 exit 0;
55
56 sub _get_mandatory_tags {
57     my $result = shift;
58     my $sth = $dbh->prepare_cached("SELECT tagfield FROM marc_tag_structure WHERE frameworkcode = '' AND mandatory = 1");
59     $sth->execute();
60     my @tags = ();
61     while (my $row = $sth->fetchrow_arrayref) {
62         push @tags, $row->[0];
63     }
64     $result->{'mandatory_tags'} = \@tags;
65 }
66
67 sub _get_mandatory_subfields {
68     my $result = shift;
69     my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield 
70                                     FROM marc_subfield_structure 
71                                     WHERE frameworkcode = '' 
72                                     AND tagsubfield <> '\@' 
73                                     AND mandatory = 1");
74     $sth->execute();
75     my @subfields = ();
76     while (my $row = $sth->fetchrow_arrayref) {
77         push @subfields, { tag => $row->[0], subfield_label => $row->[1] };
78     }
79     $result->{'mandatory_subfields'} = \@subfields;
80 }
81
82 sub _get_reserved_tags {
83     my $result = shift;
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')");
89     $sth->execute();
90     my @tags = ();
91     while (my $row = $sth->fetchrow_arrayref) {
92         push @tags, $row->[0];
93     }
94     $result->{'reserved_tags'} = \@tags;
95 }
96
97 sub _get_bib_number_tag {
98     my $result = shift;
99     my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield
100                                     FROM marc_subfield_structure 
101                                     WHERE frameworkcode = '' 
102                                     AND kohafield = 'biblio.biblionumber'");
103     $sth->execute();
104     my @tags = ();
105     while (my $row = $sth->fetchrow_arrayref) {
106         push @tags, { tag => $row->[0], subfield => $row->[1] };
107     }
108     $result->{'bib_number'} = \@tags;
109 }
110
111 sub _get_biblioitem_itemtypes {
112     my $result = shift;
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'");
118     $sth->execute();
119     my @tags = ();
120     while (my $row = $sth->fetchrow_arrayref) {
121         push @tags, { tag => $row->[0], subfield => $row->[1] };
122     }
123     my @valid_values = map { { code => $_,  description => $itemtypes->{$_}->{'description'} } } sort keys %$itemtypes;
124     $result->{'special_entry'} = { field => \@tags,  valid_values => \@valid_values };
125     
126 }