Merge remote-tracking branch 'origin/new/bug_8523'
[koha.git] / authorities / ysearch.pl
index ff6adbb..6584123 100755 (executable)
@@ -3,6 +3,7 @@
 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
 
 # Copyright 2011 BibLibre
+# Parts copyright 2012 Athens County Public Libraries
 #
 # This file is part of Koha.
 #
@@ -35,7 +36,7 @@ use C4::Auth qw/check_cookie_auth/;
 
 my $query = new CGI;
 
-binmode STDOUT, ":utf8";
+binmode STDOUT, ':encoding(UTF-8)';
 print $query->header( -type => 'text/plain', -charset => 'UTF-8' );
 
 my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), { } );
@@ -43,7 +44,7 @@ if ( $auth_status ne "ok" ) {
     exit 0;
 }
 
-    my $searchstr = $query->param('query');
+    my $searchstr = $query->param('term');
     my $searchtype = $query->param('querytype');
     my @value;
     given ($searchtype) {
@@ -62,10 +63,18 @@ if ( $auth_status ne "ok" ) {
     my $startfrom = 0;
 
     my ( $results, $total ) = SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value, $startfrom * $resultsperpage, $resultsperpage, $authtypecode, $orderby );
-    foreach (@$results) {
-       my ($value) = $_->{'summary'};
-        # Removes new lines
-        $value =~ s/<br \/>/ /g;
-        $value =~ s/\n//g;
-       print nsb_clean($value) . "\n";
+
+print "[";
+my $i = 0;
+    foreach my $result (@$results) {
+        if($i > 0){ print ","; }
+        my $value = '';
+        my $authorized = $result->{'summary'}->{'authorized'};
+        foreach my $heading (@$authorized) {
+            $value .= $heading->{'heading'} . ' ';
+        }
+        $value = "{\"summary\":\"" . $value . "\"" . "}";
+        print nsb_clean($value) . "\n";
+        $i++;
     }
+print "]";