Bug 16443: [QA Follow-up] Add two tests for get_fields
[koha.git] / catalogue / getitem-ajax.pl
blobfd69a74322336f67d7a4817449d27afee5e043f0
1 #!/usr/bin/perl
3 # Copyright BibLibre 2012
5 # This file is part of Koha.
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>.
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use JSON;
24 use C4::Auth;
25 use C4::Biblio;
26 use C4::Branch;
27 use C4::Items;
28 use C4::Koha;
29 use C4::Output;
31 my $cgi = new CGI;
33 my ( $status, $cookie, $sessionID ) = C4::Auth::check_api_auth( $cgi, { acquisition => 'order_receive' } );
34 unless ($status eq "ok") {
35 print $cgi->header(-type => 'application/json', -status => '403 Forbidden');
36 print to_json({ auth_status => $status });
37 exit 0;
40 my $item = {};
41 my $itemnumber = $cgi->param('itemnumber');
43 if($itemnumber) {
44 my $acq_fw = GetMarcStructure(1, 'ACQ');
45 my $fw = ($acq_fw) ? 'ACQ' : '';
46 $item = GetItem($itemnumber);
48 if($item->{homebranch}) {
49 $item->{homebranchname} = GetBranchName($item->{homebranch});
52 if($item->{holdingbranch}) {
53 $item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
56 if(my $code = GetAuthValCode("items.notforloan", $fw)) {
57 $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
60 if(my $code = GetAuthValCode("items.restricted", $fw)) {
61 $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
64 if(my $code = GetAuthValCode("items.location", $fw)) {
65 $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
68 if(my $code = GetAuthValCode("items.ccode", $fw)) {
69 $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
72 if(my $code = GetAuthValCode("items.materials", $fw)) {
73 $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
76 my $itemtype = getitemtypeinfo($item->{itype});
77 $item->{itemtype} = $itemtype->{description};
80 my $json_text = to_json( $item, { utf8 => 1 } );
82 output_with_http_headers $cgi, undef, $json_text, 'json';