3 # This file is part of Koha.
5 # Copyright (C) 2014 BibLibre
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.
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.
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>.
24 use HTTP
::Request
::Common
;
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
36 template_name
=> "opac-idref.tt",
39 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
40 flagsrequired
=> { borrow
=> 1 },
44 my $ua = LWP
::UserAgent
->new;
46 my $base = 'http://www.idref.fr/services/biblio/';
47 my $unimarc3 = $cgi->param('unimarc3');
49 my $request = HTTP
::Request
->new(
51 $base . $unimarc3 . ".json",
53 $request->protocol('HTTP/1.1');
54 my $response = $ua->request($request);
55 if ( not $response->is_success) {
56 $template->param(error
=> $base.$unimarc3.'.json');
57 output_html_with_http_headers
$cgi, $cookie, $template->output;
61 my $content = Encode
::decode
("utf8", $response->content);
62 my $json = from_json
( $content );
66 my @results = ref $json->{sudoc
}{result
} eq "ARRAY"
67 ? @
{ $json->{sudoc
}{result
} }
68 : ($json->{sudoc
}{result
});
70 for my $role_node ( @results ) {
71 while ( my ( $k, $v ) = each %$role_node ) {
72 next unless $k eq "role";
76 my @nodes = ref $v eq "ARRAY"
79 for my $node ( @nodes ) {
80 while ( ( $k, $v ) = each %$node ) {
81 if ( $k eq 'roleName' ) {
83 $role_data->{role_name
} = $role_name;
85 elsif ( $k eq 'count' ) {
86 $role_data->{count
} = $v;
88 elsif ( $k eq 'doc' ) {
89 push @
{ $role_data->{docs
} }, $v;
99 unimarc3
=> $unimarc3,
102 output_html_with_http_headers
$cgi, $cookie, $template->output;