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>.
22 use JSON qw( to_json );
24 use C4::Auth qw( check_api_auth );
25 use C4::Biblio qw( GetMarcStructure );
26 use C4::Output qw( output_with_http_headers );
29 use Koha::AuthorisedValues;
35 my ( $status, $cookie, $sessionID ) = C4::Auth::check_api_auth( $cgi, { acquisition => 'order_receive' } );
36 unless ($status eq "ok") {
37 print $cgi->header(-type => 'application/json', -status => '403 Forbidden');
38 print to_json({ auth_status => $status });
43 my $itemnumber = $cgi->param('itemnumber');
45 my $item_unblessed = {};
47 my $acq_fw = GetMarcStructure(1, 'ACQ');
48 my $fw = ($acq_fw) ? 'ACQ' : '';
49 $item = Koha::Items->find($itemnumber);
50 $item_unblessed = $item->unblessed; # FIXME Not needed, call home_branch and holding_branch in the templates instead
52 if($item->homebranch) { # This test should not be needed, homebranch and holdingbranch are mandatory
53 $item_unblessed->{homebranchname} = $item->home_branch->branchname;
56 if($item->holdingbranch) {
57 $item_unblessed->{holdingbranchname} = $item->holding_branch->branchname;
61 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->notforloan });
62 $item_unblessed->{notforloan} = $descriptions->{lib} // '';
64 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->restricted });
65 $item_unblessed->{restricted} = $descriptions->{lib} // '';
67 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->location });
68 $item_unblessed->{location} = $descriptions->{lib} // '';
70 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.ccode', authorised_value => $item->ccode });
71 $item_unblessed->{collection} = $descriptions->{lib} // '';
73 $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->materials });
74 $item_unblessed->{materials} = $descriptions->{lib} // '';
76 my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
77 # We should not do that here, but call ->itemtype->description when needed instea
78 $item_unblessed->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
81 my $json_text = to_json( $item_unblessed, { utf8 => 1 } );
83 output_with_http_headers $cgi, undef, $json_text, 'json';