Bug 9307: QA Followup
[koha.git] / authorities / ysearch.pl
blob65841232f9b7069ea199a38a2cc96c132ade0ce7
1 #!/usr/bin/perl
3 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
5 # Copyright 2011 BibLibre
6 # Parts copyright 2012 Athens County Public Libraries
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 =head1 ysearch.pl
25 This script allows ajax call for dynamic authorities search
26 (used in auth_finder.pl)
28 =cut
30 use CGI;
31 use Modern::Perl;
32 use C4::Context;
33 use C4::Charset;
34 use C4::AuthoritiesMarc;
35 use C4::Auth qw/check_cookie_auth/;
37 my $query = new CGI;
39 binmode STDOUT, ':encoding(UTF-8)';
40 print $query->header( -type => 'text/plain', -charset => 'UTF-8' );
42 my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), { } );
43 if ( $auth_status ne "ok" ) {
44 exit 0;
47 my $searchstr = $query->param('term');
48 my $searchtype = $query->param('querytype');
49 my @value;
50 given ($searchtype) {
51 when (/^marclist$/) { @value = (undef, undef, $searchstr); }
52 when (/^mainentry$/) { @value = (undef, $searchstr, undef); }
53 when (/^mainmainentry$/) { @value = ($searchstr, undef, undef); }
55 my @marclist = ($searchtype);
56 my $authtypecode = $query->param('authtypecode');
57 my @and_or = $query->param('and_or');
58 my @excluding = $query->param('excluding');
59 my @operator = $query->param('operator');
60 my $orderby = $query->param('orderby');
62 my $resultsperpage = 50;
63 my $startfrom = 0;
65 my ( $results, $total ) = SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value, $startfrom * $resultsperpage, $resultsperpage, $authtypecode, $orderby );
67 print "[";
68 my $i = 0;
69 foreach my $result (@$results) {
70 if($i > 0){ print ","; }
71 my $value = '';
72 my $authorized = $result->{'summary'}->{'authorized'};
73 foreach my $heading (@$authorized) {
74 $value .= $heading->{'heading'} . ' ';
76 $value = "{\"summary\":\"" . $value . "\"" . "}";
77 print nsb_clean($value) . "\n";
78 $i++;
80 print "]";