Patch from Joe Atzberger to remove $Id$ and $Log$ from scripts
[koha.git] / tools / breeding.pl
1 #!/usr/bin/perl
2
3
4 # Script for handling import of MARC data into Koha db
5 #   and Z39.50 lookups
6
7 # Koha library project  www.koha.org
8
9 # Licensed under the GPL
10
11
12 # Copyright 2000-2002 Katipo Communications
13 #
14 # This file is part of Koha.
15 #
16 # Koha is free software; you can redistribute it and/or modify it under the
17 # terms of the GNU General Public License as published by the Free Software
18 # Foundation; either version 2 of the License, or (at your option) any later
19 # version.
20 #
21 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
22 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License along with
26 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
27 # Suite 330, Boston, MA  02111-1307 USA
28
29 use strict;
30
31 # standard or CPAN modules used
32 use CGI;
33 use DBI;
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/breeding.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 my $menu;
96 my $file;
97
98
99 #---------------
100 # log cleared, as marcimport is (almost) rewritten from scratch.
101 # Revision 1.3  2007/04/24 13:54:30  hdl
102 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
103 # So this implies quite a change for files.
104 # Sorry about conflicts which will be caused.
105 # directory Interface::CGI should now be dropped.
106 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
107 #
108 # Revision 1.2  2007/03/09 15:47:55  tipaul
109 # rel_3_0 moved to HEAD (introducing new files)
110 #
111 # Revision 1.1.2.3  2006/12/22 17:13:49  tipaul
112 # removing "management" permission, that is useless (replaced by tools & admin)
113 #
114 # Revision 1.1.2.2  2006/12/18 16:35:20  toins
115 # removing use HTML::Template from *.pl.
116 #
117 # Revision 1.1.2.1  2006/09/26 13:35:33  toins
118 # breeding.pl moving from import/ to tools/
119 #
120 # Revision 1.5.2.1  2006/09/26 13:10:35  toins
121 # script was writed 2 times on the same file !
122 #
123 # Revision 1.5  2006/07/04 14:36:52  toins
124 # Head & rel_2_2 merged
125 #
126 # Revision 1.4  2005/05/04 08:52:13  tipaul
127 # synch'ing 2.2 and head
128 #
129 # Revision 1.2.4.1  2005/04/07 10:10:52  tipaul
130 # copying processz3950queue from 2.0 branch. The 2.2 version misses an important fix
131 #
132 # Revision 1.2  2003/10/06 09:10:38  slef
133 # Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39)
134 #
135 # Revision 1.1  2003/06/04 13:46:25  tipaul
136 # moving breeding farm import to parameters page (GUI) and to new import/ directory (code structure)
137 #
138 # Revision 1.33  2003/04/29 16:48:36  tipaul
139 # really proud of this commit :-)
140 # z3950 search and import seems to works fine.
141 # Let me explain how :
142 # * a "search z3950" button is added in the addbiblio template.
143 # * when clicked, a popup appears and z3950/search.pl is called
144 # * z3950/search.pl calls addz3950search in the DB
145 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
146 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
147 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
148 #
149 # Note :
150 # * 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.
151 # * 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.
152 #
153 # Revision 1.32  2003/04/22 12:22:54  tipaul
154 # 1st draft for z3950 client import.
155 # moving Breeding farm script to a perl package C4/Breeding.pm
156 #
157 # Revision 1.31  2003/02/19 01:01:07  wolfpac444
158 # Removed the unecessary $dbh argument from being passed.
159 # Resolved a few minor FIXMEs.
160 #
161 # Revision 1.30  2003/02/02 07:18:38  acli
162 # Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
163 #
164 # Create output_html_with_http_headers function to contain the "print $query
165 # ->header(-type => guesstype...),..." call. This is in preparation for
166 # non-HTML output (e.g., text/xml) and charset conversion before output in
167 # the future.
168 #
169 # Created C4/Interface/CGI/Template.pm to hold convenience functions specific
170 # to the CGI interface using HTML::Template
171 #
172 # Modified moremembers.pl to make the "sex" field localizable for languages
173 # where M and F doesn't make sense
174 #
175 # Revision 1.29  2003/01/28 15:28:31  tipaul
176 # removing use MARC::Charset
177 # Was a buggy test
178 #
179 # Revision 1.28  2003/01/28 15:00:31  tipaul
180 # 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
181 #
182 # Revision 1.27  2003/01/26 23:21:49  acli
183 # Handle non-latin1 charsets
184 #
185 # Revision 1.26  2003/01/23 12:26:41  tipaul
186 # upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
187 #
188 # Revision 1.25  2003/01/21 08:13:50  tipaul
189 # character encoding ISO646 => 8859-1, first draft
190 #
191 # Revision 1.24  2003/01/14 16:41:17  tipaul
192 # bugfix : use gettemplate_and_user instead of gettemplate.
193 # fix a blank screen in 1.3.3 in "import in breeding farm"
194 #
195 # Revision 1.23  2003/01/06 13:06:28  tipaul
196 # removing trailing #
197 #
198 # Revision 1.22  2002/11/12 15:58:43  tipaul
199 # road to 1.3.2 :
200 # * many bugfixes
201 # * 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)
202 #
203 # Revision 1.21  2002/10/22 15:50:23  tipaul
204 # road to 1.3.2 : adding a biblio in MARC format.
205 # seems to work a few.
206 # still to do :
207 # * manage html checks (mandatory subfields...)
208 # * add list of acceptable values (authorities)
209 # * manage ## in MARC format
210 # * manage correctly repeatable fields
211 # and probably a LOT of bugfixes
212 #
213 # Revision 1.20  2002/10/16 12:46:19  arensb
214 # Added a FIXME comment.
215 #
216 # Revision 1.19  2002/10/15 10:14:44  tipaul
217 # road to 1.3.2. Full rewrite of marcimport.pl.
218 # The acquisition system in MARC version will work like this :
219 # * marcimport will put marc records into a "breeding farm" table.
220 # * 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.
221 #
222 # This commit :
223 # * modify acqui.simple home page  (addbooks.pl)
224 # * adds import into breeding farm
225 #
226 # Please note that :
227 # * z3950 functionnality is dropped from "marcimport" will be added somewhere else.
228 # * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic
229 #