| Line 0
          
      
      
        Link Here | 
          
            
              | 0 | -  | 1 | #!/usr/bin/perl | 
            
              |  |  | 2 |  | 
            
              | 3 | # Copyright 2012 CatalystIT Ltd | 
            
              | 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 | =head1 opac/itemtypes.json | 
            
              | 21 |  | 
            
              | 22 | Returns json list of itemtype, description. Suitable for building drop down lists. | 
            
              | 23 |  | 
            
              | 24 | =cut | 
            
              | 25 |  | 
            
              | 26 | use strict; | 
            
              | 27 | use warnings; | 
            
              | 28 |  | 
            
              | 29 | use CGI; | 
            
              | 30 | use JSON; | 
            
              | 31 |  | 
            
              | 32 | use C4::Koha; | 
            
              | 33 | use C4::Context; | 
            
              | 34 | use C4::Auth; | 
            
              | 35 |  | 
            
              | 36 | my $input       = new CGI; | 
            
              | 37 | checkauth($input, C4::Context->preference("OpacPublic"), {}, "opac"); | 
            
              | 38 |  | 
            
              | 39 | my $dbh = C4::Context->dbh; | 
            
              | 40 | my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); | 
            
              | 41 | my ($ccl, @typesloop); | 
            
              | 42 | if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { | 
            
              | 43 |     my $itemtypes = GetItemTypes; | 
            
              | 44 |     my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; | 
            
              | 45 |     @typesloop = map { | 
            
              | 46 |         code        => $_, | 
            
              | 47 |         description => $itemtypes->{$_}->{'description'}, | 
            
              | 48 |         imageurl    => getitemtypeimagelocation( 'opac', $itemtypes->{$_}->{'imageurl'} ), | 
            
              | 49 |     }, sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes; | 
            
              | 50 |     $ccl = "$itype_or_itemtype,phr"; | 
            
              | 51 | } else { | 
            
              | 52 |     my $advsearchtypes = GetAuthorisedValues($advanced_search_types); | 
            
              | 53 |     @typesloop = map { | 
            
              | 54 |         code        => $_->{authorised_value}, | 
            
              | 55 |         description => $_->{'lib'}, | 
            
              | 56 |         imageurl    => getitemtypeimagelocation( 'opac', $_->{'imageurl'} ), | 
            
              | 57 |     }, @$advsearchtypes; | 
            
              | 58 |     $ccl = $advanced_search_types; | 
            
              | 59 | } | 
            
              | 60 |  | 
            
              | 61 | print $input->header('application/json'); | 
            
              | 62 | print to_json({ ccl => $advanced_search_types, types => \@typesloop }); |