3 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
5 # Copyright 2007 Tamil s.a.r.l.
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 use JSON qw/ to_json /;
34 use C4::Auth qw/check_cookie_auth/;
40 qw/import_record_id title status overlay_status overlay_status/;
42 my $import_batch_id = $input->param('import_batch_id');
43 my $offset = $input->param('iDisplayStart');
44 my $results_per_page = $input->param('iDisplayLength');
45 my $sorting_column = $sort_columns[ $input->param('iSortCol_0') ];
46 my $sorting_direction = $input->param('sSortDir_0');
48 binmode STDOUT, ":encoding(UTF-8)";
49 print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
51 my ( $auth_status, $sessionID ) =
52 check_cookie_auth( $input->cookie('CGISESSID'), { editcatalogue => '*' } );
53 if ( $auth_status ne "ok" ) {
57 my $batch = GetImportBatch($import_batch_id);
59 GetImportRecordsRange( $import_batch_id, $offset, $results_per_page, undef,
60 { order_by => $sorting_column, order_by_direction => $sorting_direction } );
62 foreach my $record (@$records) {
63 my $citation = $record->{'title'} || $record->{'authorized_heading'};
64 $citation .= " $record->{'author'}" if $record->{'author'};
65 $citation .= " (" if $record->{'issn'} or $record->{'isbn'};
66 $citation .= $record->{'isbn'} if $record->{'isbn'};
67 $citation .= ", " if $record->{'issn'} and $record->{'isbn'};
68 $citation .= $record->{'issn'} if $record->{'issn'};
69 $citation .= ")" if $record->{'issn'} or $record->{'isbn'};
71 my $match = GetImportRecordMatches( $record->{'import_record_id'}, 1 );
72 my $match_citation = '';
74 if ( $#$match > -1 ) {
75 if ( $match->[0]->{'record_type'} eq 'biblio' ) {
76 $match_citation .= $match->[0]->{'title'}
77 if defined( $match->[0]->{'title'} );
78 $match_citation .= ' ' . $match->[0]->{'author'}
79 if defined( $match->[0]->{'author'} );
80 $match_id = $match->[0]->{'biblionumber'};
82 elsif ( $match->[0]->{'record_type'} eq 'auth' ) {
83 if ( defined( $match->[0]->{'authorized_heading'} ) ) {
84 $match_citation .= $match->[0]->{'authorized_heading'};
85 $match_id = $match->[0]->{'candidate_match_id'};
92 DT_RowId => $record->{'import_record_id'},
93 import_record_id => $record->{'import_record_id'},
94 citation => $citation,
95 status => $record->{'status'},
96 overlay_status => $record->{'overlay_status'},
97 match_citation => $match_citation,
98 matched => $record->{'matched_biblionumber'}
99 || $record->{'matched_authid'}
101 score => $#$match > -1 ? $match->[0]->{'score'} : 0,
102 match_id => $match_id,
107 $data->{'iTotalRecords'} = $batch->{'num_records'};
108 $data->{'iTotalDisplayRecords'} = $batch->{'num_records'};
109 $data->{'sEcho'} = $input->param('sEcho') || undef;
110 $data->{'aaData'} = \@list;
112 print to_json($data);