3 # Copyright (C) 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 # standard or CPAN modules used
24 use MARC::File::USMARC;
35 my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl";
38 my $op = $input->param('op');
39 my $import_batch_id = $input->param('import_batch_id');
41 # record list displays
42 my $offset = $input->param('offset') || 0;
43 my $results_per_page = $input->param('results_per_page') || 10;
45 my ($template, $loggedinuser, $cookie)
46 = get_template_and_user({template_name => "tools/manage-marc-import.tmpl",
50 flagsrequired => {parameters => 1},
55 $template->param(script_name => $script_name, $op => 1);
57 $template->param(script_name => $script_name);
62 if ($import_batch_id eq "") {
63 import_batches_list($template, $offset, $results_per_page);
65 import_biblios_list($template, $import_batch_id, $offset, $results_per_page);
67 } elsif ($op eq "commit-batch") {
68 commit_batch($template, $import_batch_id);
69 import_biblios_list($template, $import_batch_id, $offset, $results_per_page);
70 } elsif ($op eq "revert-batch") {
71 revert_batch($template, $import_batch_id);
72 import_biblios_list($template, $import_batch_id, $offset, $results_per_page);
73 } elsif ($op eq "clean-batch") {
77 output_html_with_http_headers $input, $cookie, $template->output;
81 sub import_batches_list {
82 my ($template, $offset, $results_per_page) = @_;
83 my $batches = GetImportBatchRangeDesc($offset, $results_per_page);
86 foreach my $batch (@$batches) {
88 import_batch_id => $batch->{'import_batch_id'},
89 num_biblios => $batch->{'num_biblios'},
90 num_items => $batch->{'num_items'},
91 upload_timestamp => $batch->{'upload_timestamp'},
92 import_status => $batch->{'import_status'},
93 file_name => $batch->{'file_name'},
94 comments => $batch->{'comments'}
97 $template->param(batch_list => \@list);
98 my $num_batches = GetNumberOfNonZ3950ImportBatches();
99 add_page_numbers($template, $offset, $results_per_page, $num_batches);
100 $template->param(offset => $offset);
101 $template->param(range_top => $offset + $results_per_page - 1);
102 $template->param(num_results => $num_batches);
103 $template->param(results_per_page => $results_per_page);
108 my ($template, $import_batch_id) = @_;
109 my ($num_added, $num_updated, $num_items_added, $num_ignored) = BatchCommitBibRecords($import_batch_id);
110 $template->param(did_commit => 1);
111 $template->param(num_added => $num_added);
112 $template->param(num_updated => $num_updated);
113 $template->param(num_items_added => $num_items_added);
114 $template->param(num_ignored => $num_ignored);
118 my ($template, $import_batch_id) = @_;
119 my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) = BatchRevertBibRecords($import_batch_id);
120 $template->param(did_revert => 1);
121 $template->param(num_deleted => $num_deleted);
122 $template->param(num_items_deleted => $num_items_deleted);
123 $template->param(num_errors => $num_errors);
124 $template->param(num_reverted => $num_reverted);
125 $template->param(num_ignored => $num_ignored);
128 sub import_biblios_list {
129 my ($template, $import_batch_id, $offset, $results_per_page) = @_;
131 my $batch = GetImportBatch($import_batch_id);
132 my $biblios = GetImportBibliosRange($import_batch_id, $offset, $results_per_page);
134 foreach my $biblio (@$biblios) {
135 my $citation = $biblio->{'title'};
136 $citation .= " $biblio->{'author'}" if $biblio->{'author'};
137 $citation .= " (" if $biblio->{'issn'} or $biblio->{'isbn'};
138 $citation .= $biblio->{'isbn'} if $biblio->{'isbn'};
139 $citation .= ", " if $biblio->{'issn'} and $biblio->{'isbn'};
140 $citation .= $biblio->{'issn'} if $biblio->{'issn'};
141 $citation .= ")" if $biblio->{'issn'} or $biblio->{'isbn'};
142 my $match = GetImportRecordMatches($biblio->{'import_record_id'}, 1);
144 import_record_id => $biblio->{'import_record_id'},
145 citation => $citation,
146 status => $biblio->{'status'},
147 record_sequence => $biblio->{'record_sequence'},
148 overlay_status => $biblio->{'overlay_status'},
149 match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0,
150 match_citation => $#$match > -1 ? $match->[0]->{'title'} . ' ' . $match->[0]->{'author'} : '',
151 match_score => $#$match > -1 ? $match->[0]->{'score'} : 0,
154 my $num_biblios = $batch->{'num_biblios'};
155 $template->param(biblio_list => \@list);
156 add_page_numbers($template, $offset, $results_per_page, $num_biblios);
157 $template->param(offset => $offset);
158 $template->param(range_top => $offset + $results_per_page - 1);
159 $template->param(num_results => $num_biblios);
160 $template->param(results_per_page => $results_per_page);
161 $template->param(import_batch_id => $import_batch_id);
162 batch_info($template, $batch);
167 my ($template, $batch) = @_;
168 $template->param(batch_info => 1);
169 $template->param(file_name => $batch->{'file_name'});
170 $template->param(comments => $batch->{'comments'});
171 $template->param(import_status => $batch->{'import_status'});
172 $template->param(upload_timestamp => $batch->{'upload_timestamp'});
173 $template->param(num_biblios => $batch->{'num_biblios'});
174 $template->param(num_items => $batch->{'num_biblios'});
175 if ($batch->{'import_status'} eq 'staged' or $batch->{'import_status'} eq 'reverted') {
176 $template->param(can_commit => 1);
178 if ($batch->{'import_status'} eq 'imported') {
179 $template->param(can_revert => 1);
183 sub add_page_numbers {
184 my ($template, $offset, $results_per_page, $total_results) = @_;
185 my $max_pages = POSIX::ceil($total_results / $results_per_page);
186 return if $max_pages < 2;
187 my $current_page = int($offset / $results_per_page) + 1;
189 for (my $i = 1; $i <= $max_pages; $i++) {
192 current_page => ($current_page == $i) ? 1 : 0,
193 offset => ($i - 1) * $results_per_page
196 $template->param(pages => \@pages);