|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Copyright Anonymous |
| 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 |
=head SYNOPSIS |
| 21 |
|
| 22 |
Gets the shelving locations and the Koha-to-MARC-mapping on demand. |
| 23 |
Returns a JSON hash. |
| 24 |
|
| 25 |
Valid parameters: |
| 26 |
|
| 27 |
branch - The branchcode, eg CPL, FFL, JNS |
| 28 |
framework - The Framework code or don't define. Returns the field and subfield for the shelving location defined in the given framework code |
| 29 |
eg. ACQ, BKS. |
| 30 |
Reverts to the default framework if defined as 0 (zero). |
| 31 |
|
| 32 |
=cut |
| 33 |
use Modern::Perl; |
| 34 |
|
| 35 |
use CGI; |
| 36 |
#use C4::Auth qw/check_cookie_auth/; |
| 37 |
use JSON qw/to_json/; |
| 38 |
use C4::Koha qw/GetAuthorisedValues/; |
| 39 |
use C4::Biblio qw(GetMarcFromKohaField); |
| 40 |
|
| 41 |
my $input = new CGI; |
| 42 |
|
| 43 |
#No need to authenticate since shelving locations are quite public. |
| 44 |
#my ( $auth_status, $sessionID ) = |
| 45 |
# check_cookie_auth( |
| 46 |
# $input->cookie('CGISESSID'), |
| 47 |
# { 'catalogue' => '*' } ); |
| 48 |
# |
| 49 |
#if ( $auth_status ne "ok" ) { |
| 50 |
# exit 0; |
| 51 |
#} |
| 52 |
|
| 53 |
## Getting the input parameters ## |
| 54 |
|
| 55 |
my $branch = $input->param('branch'); |
| 56 |
my $framework = $input->param('framework'); #The MARC framework |
| 57 |
|
| 58 |
#shloc as shelving location, not to be mixed with http://www.schlockmercenary.com/ |
| 59 |
my $shlocs = C4::Koha::GetAuthorisedValues('LOC', undef, undef, $branch); |
| 60 |
my ( $shloc_field, $shloc_subfield ); |
| 61 |
|
| 62 |
my $ret = {}; #Prepare the return value. |
| 63 |
|
| 64 |
if (defined $framework) { |
| 65 |
( $ret->{field}, $ret->{subfield} ) = C4::Biblio::GetMarcFromKohaField( "items.location", $framework ); |
| 66 |
} |
| 67 |
|
| 68 |
#Build a sane return value, don't bash around huge JSON blobs needlessly! |
| 69 |
my $ret_locations = $ret->{locations} = {}; #Create a reference point so locations-hash need not be dereferenced for each iteration of @$shloc |
| 70 |
foreach my $av (@$shlocs) { |
| 71 |
$ret_locations->{ $av->{authorised_value} } = $av->{lib}; |
| 72 |
} |
| 73 |
|
| 74 |
binmode STDOUT, ":encoding(UTF-8)"; |
| 75 |
|
| 76 |
print $input->header( |
| 77 |
-type => 'application/json', |
| 78 |
-charset => 'UTF-8' |
| 79 |
); |
| 80 |
|
| 81 |
print to_json( $ret); |