bug 2885: attempting to add library with existing code now gives error message
[koha.git] / circ / ypattrodue-attr-search-authvalue.pl
blob5ff1cd93b2722d60b9122d00dff3e4ac36707ff7
1 #!/usr/bin/perl
3 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
5 # This file is part of Koha.
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.
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Context;
24 use C4::Auth qw/check_cookie_auth/;
25 use C4::Debug;
27 my $input = new CGI;
28 my $query = $input->param('query');
29 my $attrcode = $input->path_info || '';
30 $attrcode =~ s|^/||;
32 my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } );
33 exit 0 if $auth_status ne "ok";
35 binmode STDOUT, ":utf8";
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
43 WHERE b.code=?
44 AND b.authorised_value_category = v.category
45 AND v.lib like ?);
46 my $sth = $dbh->prepare($sql);
47 $sth->execute( $attrcode, "$query%" );
48 while ( my $rec = $sth->fetchrow_hashref ) {
49 print STDERR ">> attrcode=$attrcode match '$query' ==> $rec->{description} ($rec->{authorised_value})\n" if $debug;
50 print "$rec->{description}\t$rec->{authorised_value}\n";