3 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
5 # Parts copyright 2012 Athens County Public Libraries
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use C4::Auth qw/check_cookie_auth/;
28 my $query = $input->param('term');
29 my $attrcode = $input->path_info || '';
32 my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } );
33 exit 0 if $auth_status ne "ok";
35 binmode STDOUT, ":encoding(UTF-8)";
36 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
38 print STDERR ">> CALLING $0 (attrcode=$attrcode, query=$query)\n" if $debug;
40 my $dbh = C4::Context->dbh;
41 my $sql = qq(SELECT authorised_value, lib description
42 FROM borrower_attribute_types b, authorised_values v
44 AND b.authorised_value_category = v.category
46 my $sth = $dbh->prepare($sql);
47 $sth->execute( $attrcode, "$query%" );
51 while ( my $rec = $sth->fetchrow_hashref ) {
52 print STDERR ">> attrcode=$attrcode match '$query' ==> $rec->{description} ($rec->{authorised_value})\n" if $debug;
53 print "{\"description\":\"" . $rec->{description} . "\",\"" .
54 "authorised_value\":\"" . $rec->{authorised_value} . "\"" .