1st draft for z3950 client import.
[koha.git] / acqui.simple / marcimport.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 DBI;
35
36 # Koha modules used
37 use C4::Context;
38 use C4::Output;
39 use C4::Interface::CGI::Output;
40 use C4::Input;
41 use C4::Biblio;
42 use MARC::File::USMARC;
43 use HTML::Template;
44 use C4::Output;
45 use C4::Auth;
46 use C4::Breeding;
47
48 #------------------
49 # Constants
50
51 my $includes = C4::Context->config('includes') ||
52         "/usr/local/www/hdl/htdocs/includes";
53
54 # HTML colors for alternating lines
55 my $lc1='#dddddd';
56 my $lc2='#ddaaaa';
57
58 #-------------
59 #-------------
60 # Initialize
61
62 my $userid=$ENV{'REMOTE_USER'};
63
64 my $input = new CGI;
65 my $dbh = C4::Context->dbh;
66
67 my $uploadmarc=$input->param('uploadmarc');
68 my $overwrite_biblio = $input->param('overwrite_biblio');
69 my $filename = $input->param('filename');
70 my ($template, $loggedinuser, $cookie)
71         = get_template_and_user({template_name => "acqui.simple/marcimport.tmpl",
72                                         query => $input,
73                                         type => "intranet",
74                                         authnotrequired => 0,
75                                         flagsrequired => {parameters => 1},
76                                         debug => 1,
77                                         });
78
79 $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
80                                                 uploadmarc => $uploadmarc);
81 if ($uploadmarc && length($uploadmarc)>0) {
82         my $marcrecord='';
83         while (<$uploadmarc>) {
84                 $marcrecord.=$_;
85         }
86         my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename);
87
88         $template->param(imported => $imported,
89                                                         alreadyindb => $alreadyindb,
90                                                         alreadyinfarm => $alreadyinfarm,
91                                                         notmarcrecord => $notmarcrecord,
92                                                         total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord,
93                                                         );
94
95 }
96
97 output_html_with_http_headers $input, $cookie, $template->output;
98 my $menu;
99 my $file;
100
101
102 #---------------
103 # log cleared, as marcimport is (almost) rewritten from scratch.
104 # $Log$
105 # Revision 1.32  2003/04/22 12:22:54  tipaul
106 # 1st draft for z3950 client import.
107 # moving Breeding farm script to a perl package C4/Breeding.pm
108 #
109 # Revision 1.31  2003/02/19 01:01:07  wolfpac444
110 # Removed the unecessary $dbh argument from being passed.
111 # Resolved a few minor FIXMEs.
112 #
113 # Revision 1.30  2003/02/02 07:18:38  acli
114 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
115 #
116 # Create output_html_with_http_headers function to contain the "print $query
117 # ->header(-type => guesstype...),..." call. This is in preparation for
118 # non-HTML output (e.g., text/xml) and charset conversion before output in
119 # the future.
120 #
121 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
122 # to the CGI interface using HTML::Template
123 #
124 # Modified moremembers.pl to make the "sex" field localizable for languages
125 # where M and F doesn't make sense
126 #
127 # Revision 1.29  2003/01/28 15:28:31  tipaul
128 # removing use MARC::Charset
129 # Was a buggy test
130 #
131 # Revision 1.28  2003/01/28 15:00:31  tipaul
132 # 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
133 #
134 # Revision 1.27  2003/01/26 23:21:49  acli
135 # Handle non-latin1 charsets
136 #
137 # Revision 1.26  2003/01/23 12:26:41  tipaul
138 # upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
139 #
140 # Revision 1.25  2003/01/21 08:13:50  tipaul
141 # character encoding ISO646 => 8859-1, first draft
142 #
143 # Revision 1.24  2003/01/14 16:41:17  tipaul
144 # bugfix : use gettemplate_and_user instead of gettemplate.
145 # fix a blank screen in 1.3.3 in "import in breeding farm"
146 #
147 # Revision 1.23  2003/01/06 13:06:28  tipaul
148 # removing trailing #
149 #
150 # Revision 1.22  2002/11/12 15:58:43  tipaul
151 # road to 1.3.2 :
152 # * many bugfixes
153 # * 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)
154 #
155 # Revision 1.21  2002/10/22 15:50:23  tipaul
156 # road to 1.3.2 : adding a biblio in MARC format.
157 # seems to work a few.
158 # still to do :
159 # * manage html checks (mandatory subfields...)
160 # * add list of acceptable values (authorities)
161 # * manage ## in MARC format
162 # * manage correctly repeatable fields
163 # and probably a LOT of bugfixes
164 #
165 # Revision 1.20  2002/10/16 12:46:19  arensb
166 # Added a FIXME comment.
167 #
168 # Revision 1.19  2002/10/15 10:14:44  tipaul
169 # road to 1.3.2. Full rewrite of marcimport.pl.
170 # The acquisition system in MARC version will work like this :
171 # * marcimport will put marc records into a "breeding farm" table.
172 # * 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.
173 #
174 # This commit :
175 # * modify acqui.simple home page  (addbooks.pl)
176 # * adds import into breeding farm
177 #
178 # Please note that :
179 # * z3950 functionnality is dropped from "marcimport" will be added somewhere else.
180 # * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic
181 #