Bug 23271: Replace search_limited with search_with_library_limits
[koha-ffzg.git] / tools / batch_records_ajax.pl
index 57d7bc0..4ddb0f5 100755 (executable)
@@ -5,18 +5,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -31,7 +31,7 @@ the records from an import batch.
 
 use Modern::Perl;
 
-use CGI;
+use CGI qw ( -utf8 );
 use JSON qw/ to_json /;
 
 use C4::Context;
@@ -39,7 +39,7 @@ use C4::Charset;
 use C4::Auth qw/check_cookie_auth/;
 use C4::ImportBatch;
 
-my $input = new CGI;
+my $input = CGI->new;
 
 my @sort_columns =
   qw/import_record_id title status overlay_status overlay_status/;
@@ -47,10 +47,10 @@ my @sort_columns =
 my $import_batch_id   = $input->param('import_batch_id');
 my $offset            = $input->param('iDisplayStart');
 my $results_per_page  = $input->param('iDisplayLength');
-my $sorting_column    = $sort_columns[ $input->param('iSortCol_0') ];
+my $sorting_column    = $sort_columns[ $input->param('iSortCol_0') // 0 ];
 my $sorting_direction = $input->param('sSortDir_0');
 
-$results_per_page = undef if ( $results_per_page == -1 );
+$results_per_page = undef if $results_per_page && $results_per_page == -1;
 
 binmode STDOUT, ":encoding(UTF-8)";
 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
@@ -68,12 +68,6 @@ my $records =
 my @list = ();
 foreach my $record (@$records) {
     my $citation = $record->{'title'} || $record->{'authorized_heading'};
-    $citation .= " $record->{'author'}" if $record->{'author'};
-    $citation .= " (" if $record->{'issn'} or $record->{'isbn'};
-    $citation .= $record->{'isbn'} if $record->{'isbn'};
-    $citation .= ", " if $record->{'issn'} and $record->{'isbn'};
-    $citation .= $record->{'issn'} if $record->{'issn'};
-    $citation .= ")" if $record->{'issn'} or $record->{'isbn'};
 
     my $match = GetImportRecordMatches( $record->{'import_record_id'}, 1 );
     my $match_citation = '';
@@ -99,6 +93,9 @@ foreach my $record (@$records) {
         DT_RowId        => $record->{'import_record_id'},
         import_record_id => $record->{'import_record_id'},
         citation        => $citation,
+        author          => $record->{'author'},
+        issn            => $record->{'issn'},
+        isbn            => $record->{'isbn'},
         status          => $record->{'status'},
         overlay_status  => $record->{'overlay_status'},
         match_citation  => $match_citation,
@@ -107,7 +104,7 @@ foreach my $record (@$records) {
           || q{},
         score => $#$match > -1 ? $match->[0]->{'score'} : 0,
         match_id => $match_id,
-        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?importid=$record->{import_record_id}&id=$match_id" : undef
+        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id&type=$record->{record_type}" : undef
       };
 }