3 # Copyright 2013 ByWater Solutions
4 # Based on circ/ysearch.pl: Copyright 2007 Tamil s.a.r.l.
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 batch_records_ajax.pl - A script for searching batch imported records via ajax
27 This script is to be used as a data source for DataTables that load and display
28 the records from an import batch.
35 use JSON qw( to_json );
38 use C4::Auth qw( check_cookie_auth );
39 use C4::ImportBatch qw( GetImportBatch GetImportRecordsRange GetImportRecordMatches );
44 qw/import_record_id title status overlay_status overlay_status/;
46 my $import_batch_id = $input->param('import_batch_id');
47 my $offset = $input->param('start');
48 my $results_per_page = $input->param('length');
49 # FIXME We handle sorting on one column only!
50 my $sorting_column = $sort_columns[ $input->param('order[0][column]') // 0 ];
51 my $sorting_direction = $input->param('order[0][dir]');
53 $results_per_page = undef if $results_per_page && $results_per_page == -1;
55 binmode STDOUT, ":encoding(UTF-8)";
56 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
59 check_cookie_auth( $input->cookie('CGISESSID'), { tools => 'manage_staged_marc' } );
60 if ( $auth_status ne "ok" ) {
64 my $batch = GetImportBatch($import_batch_id);
66 GetImportRecordsRange( $import_batch_id, $offset, $results_per_page, undef,
67 { order_by => $sorting_column, order_by_direction => $sorting_direction } );
69 foreach my $record (@$records) {
70 my $citation = $record->{'title'} || $record->{'authorized_heading'};
72 my $matches = GetImportRecordMatches( $record->{'import_record_id'} );
74 if ( scalar @$matches > 0 ) {
75 foreach my $match (@$matches){
76 my $match_citation = '';
77 if ( $match->{'record_type'} eq 'biblio' ) {
78 $match_citation .= $match->{'title'}
79 if defined( $match->{'title'} );
80 $match_citation .= ' ' . $match->{'author'}
81 if defined( $match->{'author'} );
82 $match->{'match_citation'} = $match_citation;
84 elsif ( $match->{'record_type'} eq 'auth' ) {
85 if ( defined( $match->{'authorized_heading'} ) ) {
86 $match_citation .= $match->{'authorized_heading'};
87 $match->{'match_citation'} = $match_citation;
95 DT_RowId => $record->{'import_record_id'},
96 import_record_id => $record->{'import_record_id'},
97 citation => $citation,
98 author => $record->{'author'},
99 issn => $record->{'issn'},
100 isbn => $record->{'isbn'},
101 status => $record->{'status'},
102 overlay_status => $record->{'overlay_status'},
103 matched => $record->{'matched_biblionumber'}
104 || $record->{'matched_authid'}
106 score => scalar @$matches > 0 ? $matches->[0]->{'score'} : 0,
108 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
113 recordsTotal => $batch->{num_records},
114 recordsFiltered => $batch->{num_records},
115 draw => $input->param('draw') || undef,
119 print to_json($data);