Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2013 ByWater Solutions |
4 |
# Based on circ/ysearch.pl: Copyright 2007 Tamil s.a.r.l. |
5 |
# |
6 |
# This file is part of Koha. |
7 |
# |
8 |
# Koha is free software; you can redistribute it and/or modify it under the |
9 |
# terms of the GNU General Public License as published by the Free Software |
10 |
# Foundation; either version 3 of the License, or (at your option) any later |
11 |
# version. |
12 |
# |
13 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
14 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
15 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License along |
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
21 |
=head1 NAME |
22 |
|
23 |
batch_records_ajax.pl - A script for searching batch imported records via ajax |
24 |
|
25 |
=head1 SYNOPSIS |
26 |
|
27 |
This script is to be used as a data source for DataTables that load and display |
28 |
the records from an import batch. |
29 |
|
30 |
=cut |
31 |
|
32 |
use Modern::Perl; |
33 |
|
34 |
use CGI qw ( -utf8 ); |
35 |
use JSON qw/ to_json /; |
36 |
|
37 |
use C4::Context; |
38 |
use C4::Charset; |
39 |
use C4::Auth qw/check_cookie_auth/; |
40 |
use C4::ImportBatch; |
41 |
use Data::Dumper; |
42 |
|
43 |
my $input = new CGI; |
44 |
|
45 |
my @sort_columns = |
46 |
qw/import_record_id title status overlay_status overlay_status/; |
47 |
|
48 |
my $import_batch_id = $input->param('import_batch_id'); |
49 |
my $offset = $input->param('iDisplayStart'); |
50 |
my $results_per_page = $input->param('iDisplayLength'); |
51 |
my $sorting_column = $sort_columns[ $input->param('iSortCol_0') // 0 ]; |
52 |
my $sorting_direction = $input->param('sSortDir_0'); |
53 |
|
54 |
$results_per_page = undef if $results_per_page && $results_per_page == -1; |
55 |
|
56 |
binmode STDOUT, ":encoding(UTF-8)"; |
57 |
print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); |
58 |
|
59 |
my ( $auth_status, $sessionID ) = |
60 |
check_cookie_auth( $input->cookie('CGISESSID'), { tools => 'manage_staged_marc' } ); |
61 |
if ( $auth_status ne "ok" ) { |
62 |
exit 0; |
63 |
} |
64 |
|
65 |
my $batch = GetImportBatch($import_batch_id); |
66 |
my $records = |
67 |
GetImportRecordsRange( $import_batch_id, $offset, $results_per_page, undef, |
68 |
{ order_by => $sorting_column, order_by_direction => $sorting_direction } ); |
69 |
my @list = (); |
70 |
foreach my $record (@$records) { |
71 |
my $citation = $record->{'title'} || $record->{'authorized_heading'}; |
72 |
$citation .= " $record->{'author'}" if $record->{'author'}; |
73 |
$citation .= " (" if $record->{'issn'} or $record->{'isbn'}; |
74 |
$citation .= $record->{'isbn'} if $record->{'isbn'}; |
75 |
$citation .= ", " if $record->{'issn'} and $record->{'isbn'}; |
76 |
$citation .= $record->{'issn'} if $record->{'issn'}; |
77 |
$citation .= ")" if $record->{'issn'} or $record->{'isbn'}; |
78 |
|
79 |
my $match = GetImportRecordMatches( $record->{'import_record_id'}, 1 ); |
80 |
my $match_citation = ''; |
81 |
my $match_id; |
82 |
if ( $#$match > -1 ) { |
83 |
if ( $match->[0]->{'record_type'} eq 'biblio' ) { |
84 |
$match_citation .= $match->[0]->{'title'} |
85 |
if defined( $match->[0]->{'title'} ); |
86 |
$match_citation .= ' ' . $match->[0]->{'author'} |
87 |
if defined( $match->[0]->{'author'} ); |
88 |
$match_id = $match->[0]->{'biblionumber'}; |
89 |
} |
90 |
elsif ( $match->[0]->{'record_type'} eq 'auth' ) { |
91 |
if ( defined( $match->[0]->{'authorized_heading'} ) ) { |
92 |
$match_citation .= $match->[0]->{'authorized_heading'}; |
93 |
$match_id = $match->[0]->{'candidate_match_id'}; |
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
push @list, |
99 |
{ |
100 |
DT_RowId => $record->{'import_record_id'}, |
101 |
import_record_id => $record->{'import_record_id'}, |
102 |
citation => $citation, |
103 |
status => $record->{'status'}, |
104 |
overlay_status => $record->{'overlay_status'}, |
105 |
match_citation => $match_citation, |
106 |
matched => $record->{'matched_biblionumber'} |
107 |
|| $record->{'matched_authid'} |
108 |
|| q{}, |
109 |
score => $#$match > -1 ? $match->[0]->{'score'} : 0, |
110 |
match_id => $match_id, |
111 |
diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id" : undef, |
112 |
catalog_link => "/cgi-bin/koha/cataloguing/addbiblio.pl?breedingid=$record->{import_record_id}", |
113 |
delete_link =>"/cgi-bin/koha/cataloguing/draftrecords.pl?biblionumber=$record->{import_record_id}&delete_record=1", |
114 |
}; |
115 |
} |
116 |
warn Dumper(@list); |
117 |
my $data; |
118 |
$data->{'iTotalRecords'} = $batch->{'num_records'}; |
119 |
$data->{'iTotalDisplayRecords'} = $batch->{'num_records'}; |
120 |
$data->{'sEcho'} = $input->param('sEcho') || undef; |
121 |
$data->{'aaData'} = \@list; |
122 |
|
123 |
print to_json($data); |