Bug 5502 - Patron card category search field should be menu
[koha.git] / circ / ypattrodue-attr-search-authvalue.pl
blob517c8c050f81e0cf00969ad4cb9b67a3b3bbf066
1 #!/usr/bin/perl
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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 use strict;
22 use warnings;
23 use CGI;
24 use C4::Context;
25 use C4::Auth qw/check_cookie_auth/;
26 use C4::Debug;
28 my $input = new CGI;
29 my $query = $input->param('term');
30 my $attrcode = $input->path_info || '';
31 $attrcode =~ s|^/||;
33 my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } );
34 exit 0 if $auth_status ne "ok";
36 binmode STDOUT, ":encoding(UTF-8)";
37 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
39 print STDERR ">> CALLING $0 (attrcode=$attrcode, query=$query)\n" if $debug;
41 my $dbh = C4::Context->dbh;
42 my $sql = qq(SELECT authorised_value, lib description
43 FROM borrower_attribute_types b, authorised_values v
44 WHERE b.code=?
45 AND b.authorised_value_category = v.category
46 AND v.lib like ?);
47 my $sth = $dbh->prepare($sql);
48 $sth->execute( $attrcode, "$query%" );
50 print "[";
51 my $i = 0;
52 while ( my $rec = $sth->fetchrow_hashref ) {
53 print STDERR ">> attrcode=$attrcode match '$query' ==> $rec->{description} ($rec->{authorised_value})\n" if $debug;
54 print "{\"description\":\"" . $rec->{description} . "\",\"" .
55 "authorised_value\":\"" . $rec->{authorised_value} . "\"" .
56 "}";
57 $i++;
59 print "]";