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