Bug 9978: Replace license header with the correct license (GPLv3+)
[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
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 Modern::Perl;
21 use CGI qw ( -utf8 );
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';