5 # Script for handling import of MARC data into Koha db
8 # Koha library project www.koha.org
10 # Licensed under the GPL
13 # Copyright 2000-2002 Katipo Communications
15 # This file is part of Koha.
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
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.
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
32 # standard or CPAN modules used
39 use C4::Interface::CGI::Output;
42 use MARC::File::USMARC;
51 my $includes = C4::Context->config('includes') ||
52 "/usr/local/www/hdl/htdocs/includes";
54 # HTML colors for alternating lines
62 my $userid=$ENV{'REMOTE_USER'};
65 my $dbh = C4::Context->dbh;
67 my $uploadmarc=$input->param('uploadmarc');
68 my $overwrite_biblio = $input->param('overwrite_biblio');
69 my $filename = $input->param('filename');
70 my $syntax = $input->param('syntax');
71 my ($template, $loggedinuser, $cookie)
72 = get_template_and_user({template_name => "tools/import.tmpl",
76 flagsrequired => {parameters => 1, management => 1, tools => 1},
80 $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
81 uploadmarc => $uploadmarc);
82 if ($uploadmarc && length($uploadmarc)>0) {
84 while (<$uploadmarc>) {
87 my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename,$syntax,int(rand(99999)));
89 $template->param(imported => $imported,
90 alreadyindb => $alreadyindb,
91 alreadyinfarm => $alreadyinfarm,
92 notmarcrecord => $notmarcrecord,
93 total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord,
98 output_html_with_http_headers $input, $cookie, $template->output;
104 # log cleared, as marcimport is (almost) rewritten from scratch.
106 # Revision 1.1 2006/02/24 11:52:38 hdl
107 # Adding tools directory template and scripts
108 # Changing barcodes, export and import and letters directory.
109 # Changing export script name (marc.pl) to export.pl
110 # Changing import script name (breeding.pl) to import.pl
112 # Revision 1.4 2005/05/04 08:52:13 tipaul
113 # synch'ing 2.2 and head
115 # Revision 1.3 2005/03/23 09:57:47 doxulting
116 # Adding a parameter to allow acces to people with management/tools flags
118 # Revision 1.2 2003/10/06 09:10:38 slef
119 # Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39)
121 # Revision 1.1 2003/06/04 13:46:25 tipaul
122 # moving breeding farm import to parameters page (GUI) and to new import/ directory (code structure)
124 # Revision 1.33 2003/04/29 16:48:36 tipaul
125 # really proud of this commit :-)
126 # z3950 search and import seems to works fine.
127 # Let me explain how :
128 # * a "search z3950" button is added in the addbiblio template.
129 # * when clicked, a popup appears and z3950/search.pl is called
130 # * z3950/search.pl calls addz3950search in the DB
131 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
132 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
133 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
136 # * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
137 # * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
139 # Revision 1.32 2003/04/22 12:22:54 tipaul
140 # 1st draft for z3950 client import.
141 # moving Breeding farm script to a perl package C4/Breeding.pm
143 # Revision 1.31 2003/02/19 01:01:07 wolfpac444
144 # Removed the unecessary $dbh argument from being passed.
145 # Resolved a few minor FIXMEs.
147 # Revision 1.30 2003/02/02 07:18:38 acli
148 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
150 # Create output_html_with_http_headers function to contain the "print $query
151 # ->header(-type => guesstype...),..." call. This is in preparation for
152 # non-HTML output (e.g., text/xml) and charset conversion before output in
155 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
156 # to the CGI interface using HTML::Template
158 # Modified moremembers.pl to make the "sex" field localizable for languages
159 # where M and F doesn't make sense
161 # Revision 1.29 2003/01/28 15:28:31 tipaul
162 # removing use MARC::Charset
165 # Revision 1.28 2003/01/28 15:00:31 tipaul
166 # user can now search in breeding farm with isbn/issn or title. Title/name are stored in breeding farm and showed when a search is done
168 # Revision 1.27 2003/01/26 23:21:49 acli
169 # Handle non-latin1 charsets
171 # Revision 1.26 2003/01/23 12:26:41 tipaul
172 # upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
174 # Revision 1.25 2003/01/21 08:13:50 tipaul
175 # character encoding ISO646 => 8859-1, first draft
177 # Revision 1.24 2003/01/14 16:41:17 tipaul
178 # bugfix : use gettemplate_and_user instead of gettemplate.
179 # fix a blank screen in 1.3.3 in "import in breeding farm"
181 # Revision 1.23 2003/01/06 13:06:28 tipaul
182 # removing trailing #
184 # Revision 1.22 2002/11/12 15:58:43 tipaul
187 # * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
189 # Revision 1.21 2002/10/22 15:50:23 tipaul
190 # road to 1.3.2 : adding a biblio in MARC format.
191 # seems to work a few.
193 # * manage html checks (mandatory subfields...)
194 # * add list of acceptable values (authorities)
195 # * manage ## in MARC format
196 # * manage correctly repeatable fields
197 # and probably a LOT of bugfixes
199 # Revision 1.20 2002/10/16 12:46:19 arensb
200 # Added a FIXME comment.
202 # Revision 1.19 2002/10/15 10:14:44 tipaul
203 # road to 1.3.2. Full rewrite of marcimport.pl.
204 # The acquisition system in MARC version will work like this :
205 # * marcimport will put marc records into a "breeding farm" table.
206 # * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm.
209 # * modify acqui.simple home page (addbooks.pl)
210 # * adds import into breeding farm
213 # * z3950 functionnality is dropped from "marcimport" will be added somewhere else.
214 # * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic
220 # Script for handling import of MARC data into Koha db
223 # Koha library project www.koha.org
225 # Licensed under the GPL
228 # Copyright 2000-2002 Katipo Communications
230 # This file is part of Koha.
232 # Koha is free software; you can redistribute it and/or modify it under the
233 # terms of the GNU General Public License as published by the Free Software
234 # Foundation; either version 2 of the License, or (at your option) any later
237 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
238 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
239 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
241 # You should have received a copy of the GNU General Public License along with
242 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
243 # Suite 330, Boston, MA 02111-1307 USA
247 # standard or CPAN modules used
254 use C4::Interface::CGI::Output;
257 use MARC::File::USMARC;
266 my $includes = C4::Context->config('includes') ||
267 "/usr/local/www/hdl/htdocs/includes";
269 # HTML colors for alternating lines
277 my $userid=$ENV{'REMOTE_USER'};
280 my $dbh = C4::Context->dbh;
282 my $uploadmarc=$input->param('uploadmarc');
283 my $overwrite_biblio = $input->param('overwrite_biblio');
284 my $filename = $input->param('filename');
285 my $syntax = $input->param('syntax');
286 my ($template, $loggedinuser, $cookie)
287 = get_template_and_user({template_name => "import/breeding.tmpl",
290 authnotrequired => 0,
291 flagsrequired => {parameters => 1, management => 1, tools => 1},
295 $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
296 uploadmarc => $uploadmarc);
297 if ($uploadmarc && length($uploadmarc)>0) {
299 while (<$uploadmarc>) {
302 my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename,$syntax,int(rand(99999)));
304 $template->param(imported => $imported,
305 alreadyindb => $alreadyindb,
306 alreadyinfarm => $alreadyinfarm,
307 notmarcrecord => $notmarcrecord,
308 total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord,
313 output_html_with_http_headers $input, $cookie, $template->output;
319 # log cleared, as marcimport is (almost) rewritten from scratch.
321 # Revision 1.1 2006/02/24 11:52:38 hdl
322 # Adding tools directory template and scripts
323 # Changing barcodes, export and import and letters directory.
324 # Changing export script name (marc.pl) to export.pl
325 # Changing import script name (breeding.pl) to import.pl
327 # Revision 1.4 2005/05/04 08:52:13 tipaul
328 # synch'ing 2.2 and head
330 # Revision 1.2.4.1 2005/04/07 10:10:52 tipaul
331 # copying processz3950queue from 2.0 branch. The 2.2 version misses an important fix
333 # Revision 1.2 2003/10/06 09:10:38 slef
334 # Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39)
336 # Revision 1.1 2003/06/04 13:46:25 tipaul
337 # moving breeding farm import to parameters page (GUI) and to new import/ directory (code structure)
339 # Revision 1.33 2003/04/29 16:48:36 tipaul
340 # really proud of this commit :-)
341 # z3950 search and import seems to works fine.
342 # Let me explain how :
343 # * a "search z3950" button is added in the addbiblio template.
344 # * when clicked, a popup appears and z3950/search.pl is called
345 # * z3950/search.pl calls addz3950search in the DB
346 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
347 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
348 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
351 # * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
352 # * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
354 # Revision 1.32 2003/04/22 12:22:54 tipaul
355 # 1st draft for z3950 client import.
356 # moving Breeding farm script to a perl package C4/Breeding.pm
358 # Revision 1.31 2003/02/19 01:01:07 wolfpac444
359 # Removed the unecessary $dbh argument from being passed.
360 # Resolved a few minor FIXMEs.
362 # Revision 1.30 2003/02/02 07:18:38 acli
363 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
365 # Create output_html_with_http_headers function to contain the "print $query
366 # ->header(-type => guesstype...),..." call. This is in preparation for
367 # non-HTML output (e.g., text/xml) and charset conversion before output in
370 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
371 # to the CGI interface using HTML::Template
373 # Modified moremembers.pl to make the "sex" field localizable for languages
374 # where M and F doesn't make sense
376 # Revision 1.29 2003/01/28 15:28:31 tipaul
377 # removing use MARC::Charset
380 # Revision 1.28 2003/01/28 15:00:31 tipaul
381 # user can now search in breeding farm with isbn/issn or title. Title/name are stored in breeding farm and showed when a search is done
383 # Revision 1.27 2003/01/26 23:21:49 acli
384 # Handle non-latin1 charsets
386 # Revision 1.26 2003/01/23 12:26:41 tipaul
387 # upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
389 # Revision 1.25 2003/01/21 08:13:50 tipaul
390 # character encoding ISO646 => 8859-1, first draft
392 # Revision 1.24 2003/01/14 16:41:17 tipaul
393 # bugfix : use gettemplate_and_user instead of gettemplate.
394 # fix a blank screen in 1.3.3 in "import in breeding farm"
396 # Revision 1.23 2003/01/06 13:06:28 tipaul
397 # removing trailing #
399 # Revision 1.22 2002/11/12 15:58:43 tipaul
402 # * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
404 # Revision 1.21 2002/10/22 15:50:23 tipaul
405 # road to 1.3.2 : adding a biblio in MARC format.
406 # seems to work a few.
408 # * manage html checks (mandatory subfields...)
409 # * add list of acceptable values (authorities)
410 # * manage ## in MARC format
411 # * manage correctly repeatable fields
412 # and probably a LOT of bugfixes
414 # Revision 1.20 2002/10/16 12:46:19 arensb
415 # Added a FIXME comment.
417 # Revision 1.19 2002/10/15 10:14:44 tipaul
418 # road to 1.3.2. Full rewrite of marcimport.pl.
419 # The acquisition system in MARC version will work like this :
420 # * marcimport will put marc records into a "breeding farm" table.
421 # * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm.
424 # * modify acqui.simple home page (addbooks.pl)
425 # * adds import into breeding farm
428 # * z3950 functionnality is dropped from "marcimport" will be added somewhere else.
429 # * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic