bugfix on adding a subfield
[koha.git] / tools / import.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Script for handling import of MARC data into Koha db
6 #   and Z39.50 lookups
7
8 # Koha library project  www.koha.org
9
10 # Licensed under the GPL
11
12
13 # Copyright 2000-2002 Katipo Communications
14 #
15 # This file is part of Koha.
16 #
17 # Koha is free software; you can redistribute it and/or modify it under the
18 # terms of the GNU General Public License as published by the Free Software
19 # Foundation; either version 2 of the License, or (at your option) any later
20 # version.
21 #
22 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
23 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
24 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License along with
27 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
28 # Suite 330, Boston, MA  02111-1307 USA
29
30 use strict;
31
32 # standard or CPAN modules used
33 use CGI;
34 use MARC::File::USMARC;
35
36 # Koha modules used
37 use C4::Context;
38 use C4::Auth;
39 use C4::Input;
40 use C4::Output;
41 use C4::Biblio;
42 use C4::Breeding;
43
44 #------------------
45 # Constants
46
47 my $includes = C4::Context->config('includes') ||
48         "/usr/local/www/hdl/htdocs/includes";
49
50 # HTML colors for alternating lines
51 my $lc1='#dddddd';
52 my $lc2='#ddaaaa';
53
54 #-------------
55 #-------------
56 # Initialize
57
58 my $userid=$ENV{'REMOTE_USER'};
59
60 my $input = new CGI;
61 my $dbh = C4::Context->dbh;
62
63 my $uploadmarc=$input->param('uploadmarc');
64 my $overwrite_biblio = $input->param('overwrite_biblio');
65 my $filename = $input->param('filename');
66 my $syntax = $input->param('syntax');
67 my ($template, $loggedinuser, $cookie)
68         = get_template_and_user({template_name => "tools/import.tmpl",
69                                         query => $input,
70                                         type => "intranet",
71                                         authnotrequired => 0,
72                                         flagsrequired => {tools => 1},
73                                         debug => 1,
74                                         });
75
76 $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
77                                                 uploadmarc => $uploadmarc);
78 if ($uploadmarc && length($uploadmarc)>0) {
79         my $marcrecord='';
80         while (<$uploadmarc>) {
81                 $marcrecord.=$_;
82         }
83         my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename,$syntax,int(rand(99999)));
84
85         $template->param(imported => $imported,
86                                                         alreadyindb => $alreadyindb,
87                                                         alreadyinfarm => $alreadyinfarm,
88                                                         notmarcrecord => $notmarcrecord,
89                                                         total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord,
90                                                         );
91
92 }
93
94 output_html_with_http_headers $input, $cookie, $template->output;
95
96
97 #---------------
98 # log cleared, as marcimport is (almost) rewritten from scratch.
99 # $Log$
100 # Revision 1.5  2007/04/24 13:54:30  hdl
101 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
102 # So this implies quite a change for files.
103 # Sorry about conflicts which will be caused.
104 # directory Interface::CGI should now be dropped.
105 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
106 #
107 # Revision 1.4  2007/03/09 15:14:47  tipaul
108 # rel_3_0 moved to HEAD
109 #
110 # Revision 1.1.2.4  2006/12/22 17:13:49  tipaul
111 # removing "management" permission, that is useless (replaced by tools & admin)
112 #
113 # Revision 1.1.2.3  2006/12/18 16:35:20  toins
114 # removing use HTML::Template from *.pl.
115 #
116 # Revision 1.1.2.2  2006/10/03 12:27:32  toins
117 # the script was written twice into the file !
118 #
119 # Revision 1.1.2.1  2006/09/26 13:42:54  toins
120 # fix wrong link to breeding.tmpl
121 #
122 # Revision 1.1  2006/02/24 11:52:38  hdl
123 # Adding tools directory template and scripts
124 # Changing barcodes, export and import and letters directory.
125 # Changing export script name (marc.pl) to export.pl
126 # Changing import script name (breeding.pl) to import.pl
127 #
128 # Revision 1.4  2005/05/04 08:52:13  tipaul
129 # synch'ing 2.2 and head
130 #
131 # Revision 1.3  2005/03/23 09:57:47  doxulting
132 # Adding a parameter to allow acces to people with management/tools flags