Bug 10860: In-House Use
[koha.git] / catalogue / getitem-ajax.pl
1 #!/usr/bin/perl
2
3 # Copyright BibLibre 2012
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21 use CGI;
22 use JSON;
23
24 use C4::Biblio;
25 use C4::Branch;
26 use C4::Items;
27 use C4::Koha;
28 use C4::Output;
29
30 my $cgi = new CGI;
31 my $item = {};
32 my $itemnumber = $cgi->param('itemnumber');
33
34 if($itemnumber) {
35     my $acq_fw = GetMarcStructure(1, 'ACQ');
36     my $fw = ($acq_fw) ? 'ACQ' : '';
37     $item = GetItem($itemnumber);
38
39     if($item->{homebranch}) {
40         $item->{homebranchname} = GetBranchName($item->{homebranch});
41     }
42
43     if($item->{holdingbranch}) {
44         $item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
45     }
46
47     if(my $code = GetAuthValCode("items.notforloan", $fw)) {
48         $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
49     }
50
51     if(my $code = GetAuthValCode("items.restricted", $fw)) {
52         $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
53     }
54
55     if(my $code = GetAuthValCode("items.location", $fw)) {
56         $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
57     }
58
59     if(my $code = GetAuthValCode("items.ccode", $fw)) {
60         $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
61     }
62
63     if(my $code = GetAuthValCode("items.materials", $fw)) {
64         $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
65     }
66
67     my $itemtype = getitemtypeinfo($item->{itype});
68     $item->{itemtype} = $itemtype->{description};
69 }
70
71 my $json_text = to_json( $item, { utf8 => 1 } );
72
73 output_with_http_headers $cgi, undef, $json_text, 'json';