3 # Script for handling import of MARC data into Koha db
6 # Koha library project www.koha.org
8 # Licensed under the GPL
10 # Copyright 2000-2002 Katipo Communications
12 # This file is part of Koha.
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA 02111-1307 USA
29 # standard or CPAN modules used
31 use MARC
::File
::USMARC
;
45 my $includes = C4
::Context
->config('includes') ||
46 "/usr/local/www/hdl/htdocs/includes";
48 # HTML colors for alternating lines
56 my $userid=$ENV{'REMOTE_USER'};
59 my $dbh = C4
::Context
->dbh;
61 my $uploadmarc=$input->param('uploadmarc');
62 my $check_for_matches = $input->param('check_for_matches');
63 my $parse_items = $input->param('parse_items');
64 my $comments = $input->param('comments');
65 my $syntax = $input->param('syntax');
66 my ($template, $loggedinuser, $cookie)
67 = get_template_and_user
({template_name
=> "tools/stage-marc-import.tmpl",
71 flagsrequired
=> {tools
=> 1},
75 $template->param(SCRIPT_NAME
=> $ENV{'SCRIPT_NAME'},
76 uploadmarc
=> $uploadmarc);
77 my $filename = $uploadmarc;
78 if ($uploadmarc && length($uploadmarc)>0) {
80 while (<$uploadmarc>) {
85 my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords
($syntax, $marcrecord, $filename,
86 $comments, '', $parse_items, 0);
87 my $matcher = C4
::Matcher
->new('biblio');
88 $matcher->add_matchpoint("020", "a", '', 'isbn', 1000);
89 my $num_with_matches = 0;
90 my $checked_matches = 0;
91 if ($check_for_matches) {
93 $num_with_matches = BatchFindBibDuplicates
($batch_id, $matcher);
96 $template->param(staged
=> $num_valid,
97 matched
=> $num_with_matches,
98 num_items
=> $num_items,
99 import_errors
=> scalar(@import_errors),
100 total
=> $num_valid + scalar(@import_errors),
101 checked_matches
=> $checked_matches,
102 import_batch_id
=> $batch_id
107 output_html_with_http_headers
$input, $cookie, $template->output;