Bug 16424: Add framework support to advanced MARC editor
[koha.git] / svc / bib_framework
1 #!/usr/bin/perl
2 # Copyright 2007 LibLime
3 # Copyright 2012 software.coop and MJ Ray
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 #
20 use strict;
21 use warnings;
22 use CGI qw ( -utf8 );
23 use C4::Auth qw/check_api_auth/;
24 use C4::Biblio;
25 use C4::Items;
26 use XML::Simple;
27
28 binmode STDOUT, ':encoding(UTF-8)';
29
30 my $query = new CGI;
31 my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 'edit_catalogue'} );
32 unless ($status eq 'ok') {
33     print $query->header(-type => 'text/xml', -status => '403 Forbidden');
34     print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
35     exit 0;
36 }
37
38 # do initial validation
39 my $path_info = $query->path_info();
40 my $biblionumber = undef;
41 if ($path_info =~ m!^/(\d+)$!) {
42     $biblionumber = $1;
43 } else {
44     print $query->header(-type => 'text/xml', -status => '400 Bad Request');
45 }
46 if ($query->request_method eq 'GET') {
47     fetch_bib_framework($query, $biblionumber);
48 } else {
49     print $query->header(-type => 'text/xml', -status => '405 Method not allowed');
50     print XMLout({ error => 'Method not allowed' }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
51     exit 0;
52 }
53 exit 0;
54
55 sub fetch_bib_framework {
56     my $query = shift;
57     my $biblionumber = shift;
58     my $frameworkcode = GetFrameworkCode( $biblionumber );
59     my $result = {
60         'frameworkcode' => $frameworkcode
61     };
62     print $query->header(-type => 'text/xml',-charset => 'utf-8',);
63     print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => 0);
64 }