re-adding oldbiblionumber for the sake of the plugin
[koha.git] / cataloguing / addbiblio.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Output;
26 use C4::Interface::CGI::Output;
27 use C4::Biblio;
28 use C4::Search;
29 use C4::SearchMarc; # also includes Biblio.pm, SearchMarc is used to FindDuplicate
30 use C4::Context;
31 use C4::Log;
32 use C4::Koha; # XXX subfield_is_koha_internal_p
33 use HTML::Template;
34 use MARC::File::USMARC;
35 use MARC::File::XML;
36
37 use vars qw( $tagslib);
38 use vars qw( $authorised_values_sth);
39 use vars qw( $is_a_modif );
40
41 my $itemtype; # created here because it can be used in build_authorized_values_list sub
42
43 =item find_value
44
45     ($indicators, $value) = find_value($tag, $subfield, $record,$encoding);
46
47 Find the given $subfield in the given $tag in the given
48 MARC::Record $record.  If the subfield is found, returns
49 the (indicators, value) pair; otherwise, (undef, undef) is
50 returned.
51
52 =cut
53
54 sub find_value {
55         my ($tagfield,$insubfield,$record,$encoding) = @_;
56         my @result;
57         my $indicator;
58         if ($tagfield <10) {
59                 if ($record->field($tagfield)) {
60                         push @result, $record->field($tagfield)->data();
61                 } else {
62                         push @result,"";
63                 }
64         } else {
65                 foreach my $field ($record->field($tagfield)) {
66                         my @subfields = $field->subfields();
67                         foreach my $subfield (@subfields) {
68                                 if (@$subfield[0] eq $insubfield) {
69                                         push @result,@$subfield[1];
70                                         $indicator = $field->indicator(1).$field->indicator(2);
71                                 }
72                         }
73                 }
74         }
75         return($indicator,@result);
76 }
77
78
79 =item MARCfindbreeding
80
81     $record = MARCfindbreeding($dbh, $breedingid);
82
83 Look up the breeding farm with database handle $dbh, for the
84 record with id $breedingid.  If found, returns the decoded
85 MARC::Record; otherwise, -1 is returned (FIXME).
86 Returns as second parameter the character encoding.
87
88 =cut
89
90 sub MARCfindbreeding {
91         my ($dbh,$id) = @_;
92         my $sth = $dbh->prepare("select file,marc,encoding from marc_breeding where id=?");
93         $sth->execute($id);
94         my ($file,$marc,$encoding) = $sth->fetchrow;
95         if ($marc) {
96                 my $record = MARC::File::USMARC::decode($marc);
97                 if (ref($record) eq undef) {
98                         return -1;
99                 } else {
100                         return $record,$encoding;
101                 }
102         }
103         return -1;
104 }
105
106
107 =item build_authorized_values_list
108
109 =cut
110
111 sub build_authorized_values_list ($$$$$) {
112         my($tag, $subfield, $value, $dbh,$authorised_values_sth) = @_;
113
114         my @authorised_values;
115         my %authorised_lib;
116
117         # builds list, depending on authorised value...
118
119         #---- branch
120         if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
121         my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname");
122         $sth->execute;
123         push @authorised_values, ""
124                 unless ($tagslib->{$tag}->{$subfield}->{mandatory});
125
126         while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
127                 push @authorised_values, $branchcode;
128                 $authorised_lib{$branchcode}=$branchname;
129         }
130
131         #----- itemtypes
132         } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
133                 my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description");
134                 $sth->execute;
135                 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
136         
137                 while (my ($itemtype,$description) = $sth->fetchrow_array) {
138                         push @authorised_values, $itemtype;
139                         $authorised_lib{$itemtype}=$description;
140                 }
141                 $value=$itemtype unless ($value);
142
143         #---- "true" authorised value
144         } else {
145                 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
146
147                 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
148         
149                 while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) {
150                         push @authorised_values, $value;
151                         $authorised_lib{$value}=$lib;
152                 }
153     }
154     return CGI::scrolling_list( -name     => 'field_value',
155                                 -values   => \@authorised_values,
156                                 -default  => $value,
157                                 -labels   => \%authorised_lib,
158                                 -override => 1,
159                                 -size     => 1,
160                                 -multiple => 0 );
161 }
162
163 =item create_input
164  builds the <input ...> entry for a subfield.
165 =cut
166 sub create_input () {
167         my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_;
168         $value =~ s/"/&quot;/g;
169         my $dbh = C4::Context->dbh;
170         my %subfield_data;
171         $subfield_data{tag}=$tag;
172         $subfield_data{subfield}=$subfield;
173         $subfield_data{marc_lib}="<span id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
174         $subfield_data{marc_lib_plain}=$tagslib->{$tag}->{$subfield}->{lib};
175         $subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory};
176         $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
177         $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
178         $subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield};
179         $subfield_data{index} = $i;
180         $subfield_data{visibility} = "display:none" unless (($tagslib->{$tag}->{$subfield}->{hidden}%2==0) or $value ne ''); #check parity
181         # it's an authorised field
182         if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
183                 $subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh,$authorised_values_sth);
184         # it's a thesaurus / authority field
185         } elsif ($tagslib->{$tag}->{$subfield}->{authtypecode}) {
186                 $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00;'\"\" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" DISABLE READONLY> <a  style=\"cursor: help;\" href=\"javascript:Dopop('../authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$i',$i)\">...</a>";
187         # it's a plugin field
188         } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
189                 # opening plugin. Just check wether we are on a developper computer on a production one
190                 # (the cgidir differs)
191                 my $cgidir = C4::Context->intranetdir ."/cgi-bin/value_builder";
192                 unless (opendir(DIR, "$cgidir")) {
193                         $cgidir = C4::Context->intranetdir."/value_builder";
194                 } 
195                 my $plugin=$cgidir."/".$tagslib->{$tag}->{$subfield}->{'value_builder'}; 
196                 require $plugin;
197                 my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop);
198                 my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop);
199                 $subfield_data{marc_value}="<input tabindex=\"1\" type=\"text\" name=\"field_value\"  value=\"$value\" size=\"70\" maxlength=\"255\" OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i); \"> <a  style=\"cursor: help;\" href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
200         # it's an hidden field
201         } elsif  ($tag eq '') {
202                  $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"hidden\" name=\"field_value\" value=\"$value\">";
203         } elsif  ($tagslib->{$tag}->{$subfield}->{'hidden'}) {
204                 $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\" maxlength=\"255\" >";
205         # it's a standard field
206         } else {
207                 if (length($value) >100) {
208                         $subfield_data{marc_value}="<textarea name=\"field_value\" cols=\"70\" rows=\"5\" >$value</textarea>";
209                 } else {
210                         $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"70\">"; #"
211                 }
212         }
213         return \%subfield_data;
214 }
215
216 sub build_tabs ($$$$) {
217     my($template, $record, $dbh,$encoding) = @_;
218     # fill arrays
219     my @loop_data =();
220     my $tag;
221     my $i=0;
222         my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
223                 from authorised_values
224                 where category=? order by lib");
225
226 # loop through each tab 0 through 9
227         for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
228                 my @loop_data = ();
229                 foreach my $tag (sort(keys (%{$tagslib}))) {
230                         my $indicator;
231         # if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
232         # if MARC::Record is empty => use tab as master loop.
233                         if ($record ne -1 && ($record->field($tag) || $tag eq '000')) {
234                                 my @fields;
235                                 if ($tag ne '000') {
236                                         @fields = $record->field($tag);
237                                 } else {
238                                         push @fields,$record->leader();
239                                 }
240                                 foreach my $field (@fields)  {
241                                         my @subfields_data;
242                                         if ($tag<10) {
243                                                 my ($value,$subfield);
244                                                 if ($tag ne '000') {
245                                                         $value=$field->data();
246                                                         $subfield="@";
247                                                 } else {
248                                                         $value = $field;
249                                                         $subfield='@';
250                                                 }
251                                                 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
252                                                 next if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'biblio.biblionumber');
253                                                 push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
254                                                 $i++;
255                                         } else {
256                                                 my @subfields=$field->subfields();
257                                                 foreach my $subfieldcount (0..$#subfields) {
258                                                         my $subfield=$subfields[$subfieldcount][0];
259                                                         my $value=$subfields[$subfieldcount][1];
260                                                         next if (length $subfield !=1);
261                                                         next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
262                                                         push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
263                                                         $i++;
264                                                 }
265                                         }
266 # now, loop again to add parameter subfield that are not in the MARC::Record
267                                         foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
268                                                 next if (length $subfield !=1);
269                                                 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
270                                                 next if ($tag<10);
271                                                 next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-4) or ($tagslib->{$tag}->{$subfield}->{hidden}>=5) ); #check for visibility flag
272                                                 next if (defined($field->subfield($subfield)));
273                                                 push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
274                                                 $i++;
275                                         }
276                                         if ($#subfields_data >= 0) {
277                                                 my %tag_data;
278                                                 $tag_data{tag} = $tag;
279                                                 $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
280                                                 $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
281                                                 $tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10);
282                                                 $tag_data{subfield_loop} = \@subfields_data;
283                                                 if ($tag<10) {
284                                                                                                         $tag_data{fixedfield} = 1;
285                                             }
286
287                                                 push (@loop_data, \%tag_data);
288                                         }
289 # If there is more than 1 field, add an empty hidden field as separator.
290                                         if ($#fields >=1 && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
291                                                 my @subfields_data;
292                                                 my %tag_data;
293                                                 push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth));
294                                                 $tag_data{tag} = '';
295                                                 $tag_data{tag_lib} = '';
296                                                 $tag_data{indicator} = '';
297                                                 $tag_data{subfield_loop} = \@subfields_data;
298                                                 if ($tag<10) {
299                                                     $tag_data{fixedfield} = 1;
300                                                                                         }
301                                                 push (@loop_data, \%tag_data);
302                                                 $i++;
303                                         }
304                                 }
305         # if breeding is empty
306                         } else {
307                                 my @subfields_data;
308                                 foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
309                                         next if (length $subfield !=1);
310                                         next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-5) or ($tagslib->{$tag}->{$subfield}->{hidden}>=4) ); #check for visibility flag
311                                         next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
312                                         push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
313                                         $i++;
314                                 }
315                                 if ($#subfields_data >= 0) {
316                                         my %tag_data;
317                                         $tag_data{tag} = $tag;
318                                         $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
319                                         $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
320                                         $tag_data{indicator} = $indicator;
321                                         $tag_data{subfield_loop} = \@subfields_data;
322                                         $tag_data{tagfirstsubfield} = $tag_data{subfield_loop}[0];
323                                         if ($tag<10) {
324                         $tag_data{fixedfield} = 1;
325                     }
326                                         push (@loop_data, \%tag_data);
327                                 }
328                         }
329                 }
330                 $template->param($tabloop."XX" =>\@loop_data);
331         }
332 }
333
334
335 sub build_hidden_data () {
336     # build hidden data =>
337     # we store everything, even if we show only requested subfields.
338
339     my @loop_data =();
340     my $i=0;
341     foreach my $tag (keys %{$tagslib}) {
342         my $previous_tag = '';
343
344         # loop through each subfield
345         foreach my $subfield (keys %{$tagslib->{$tag}}) {
346             next if ($subfield eq 'lib');
347             next if ($subfield eq 'tab');
348             next if ($subfield eq 'mandatory');
349                 next if ($subfield eq 'repeatable');
350             next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "-1");
351             my %subfield_data;
352             $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
353             $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
354             $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
355             $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
356             push(@loop_data, \%subfield_data);
357             $i++
358         }
359     }
360 }
361
362
363 # ======================== 
364 #          MAIN 
365 #=========================
366 my $input = new CGI;
367 my $error = $input->param('error');
368 my $biblionumber=$input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
369 if (!$biblionumber){
370     $biblionumber=$input->param('oldbiblionumber');
371         warn "OLDBIBLIONUMBER".$biblionumber;
372     }
373 my $breedingid = $input->param('breedingid');
374 my $z3950 = $input->param('z3950');
375 my $op = $input->param('op');
376 my $frameworkcode = $input->param('frameworkcode');
377 my $dbh = C4::Context->dbh;
378
379 $frameworkcode = &MARCfind_frameworkcode($dbh,$biblionumber) if ($biblionumber and not ($frameworkcode));
380 $frameworkcode='' if ($frameworkcode eq 'Default');
381 my ($template, $loggedinuser, $cookie)
382     = get_template_and_user({template_name => "acqui.simple/addbiblio.tmpl",
383                              query => $input,
384                              type => "intranet",
385                              authnotrequired => 0,
386                              flagsrequired => {editcatalogue => 1},
387                              debug => 1,
388                              });
389
390 #Getting the list of all frameworks
391 my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
392 $queryfwk->execute;
393 my %select_fwk;
394 my @select_fwk;
395 my $curfwk;
396 push @select_fwk,"Default";
397 $select_fwk{"Default"} = "Default";
398 while (my ($description, $fwk) =$queryfwk->fetchrow) {
399         push @select_fwk, $fwk;
400         $select_fwk{$fwk} = $description;
401 }
402 $curfwk=$frameworkcode;
403 my $framework=CGI::scrolling_list( -name     => 'Frameworks',
404                         -id => 'Frameworks',
405                         -default => $curfwk,
406                         -OnChange => 'Changefwk(this);',
407                         -values   => \@select_fwk,
408                         -labels   => \%select_fwk,
409                         -size     => 1,
410                         -multiple => 0 );
411 $template->param( framework => $framework);
412
413 $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
414 my $record=-1;
415 my $encoding="";
416 #$record = MARCgetbiblio($dbh,$biblionumber) if ($biblionumber);
417 $record=get_record($biblionumber) if ($biblionumber);
418
419 ($record,$encoding) = MARCfindbreeding($dbh,$breedingid) if ($breedingid);
420
421 $is_a_modif=0;
422 my ($biblionumtagfield,$biblionumtagsubfield);
423 my ($biblioitemnumtagfield,$biblioitemnumtagsubfield,$bibitem,$biblioitemnumber);
424 if ($biblionumber) {
425         $is_a_modif=1;
426         # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
427         ($biblionumtagfield,$biblionumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblio.biblionumber",$frameworkcode);
428         ($biblioitemnumtagfield,$biblioitemnumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblioitems.biblioitemnumber",$frameworkcode);
429         # search biblioitems value
430         my $sth=$dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
431         $sth->execute($biblionumber);
432         ($biblioitemnumber) = $sth->fetchrow;
433 }
434 #------------------------------------------------------------------------------------------------------------------------------
435 if ($op eq "addbiblio") {
436 #------------------------------------------------------------------------------------------------------------------------------
437         # rebuild
438         my @tags = $input->param('tag');
439         my @subfields = $input->param('subfield');
440         my @values = $input->param('field_value');
441         # build indicator hash.
442         my @ind_tag = $input->param('ind_tag');
443         my @indicator = $input->param('indicator');
444         my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
445     my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
446         # check for a duplicate
447         my ($duplicatebiblionumber,$duplicatebibid,$duplicatetitle) = FindDuplicate($record) if ($op eq "addbiblio") && (!$is_a_modif);
448         my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
449         # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
450         if (!$duplicatebiblionumber or $confirm_not_duplicate) {
451                 # MARC::Record built => now, record in DB
452                 if ($is_a_modif) {
453                 warn "CONFIRM ITS A MODIF : .$biblionumber";
454                         NEWmodbiblioframework($dbh,$biblionumber,$frameworkcode);
455                         NEWmodbiblio($dbh,$record,$biblionumber,$frameworkcode);
456                 } else {
457                         my $biblioitemnumber;
458                         ($biblionumber,$biblioitemnumber) = NEWnewbiblio($dbh,$record,$frameworkcode);
459                         logaction($loggedinuser,"acqui.simple","add",$biblionumber,"record : ".$record->as_formatted) if (C4::Context->preference("Activate_Log"));
460                 }
461         # now, redirect to additem page
462                 print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
463                 exit;
464         } else {
465         # it may be a duplicate, warn the user and do nothing
466                 build_tabs ($template, $record, $dbh,$encoding);
467                 build_hidden_data;
468                 $template->param(
469                         oldbiblionumber          => $biblionumber,
470                         biblionumber             => $biblionumber,
471                         biblionumtagfield        => $biblionumtagfield,
472                         biblionumtagsubfield     => $biblionumtagsubfield,
473                         biblioitemnumtagfield    => $biblioitemnumtagfield,
474                         biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
475                         biblioitemnumber         => $biblioitemnumber,
476                         duplicatebiblionumber           => $duplicatebiblionumber,
477                         duplicatetitle                          => $duplicatetitle,
478                          );
479         }
480 #------------------------------------------------------------------------------------------------------------------------------
481 } elsif ($op eq "addfield") {
482 #------------------------------------------------------------------------------------------------------------------------------
483         my $addedfield = $input->param('addfield_field');
484         my $tagaddfield_subfield = $input->param('addfield_subfield');
485         my @tags = $input->param('tag');
486         my @subfields = $input->param('subfield');
487         my @values = $input->param('field_value');
488         my @ind_tag = $input->param('ind_tag');
489         my @indicator = $input->param('indicator');
490         my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
491     my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
492         # adding an empty field
493         my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => "");
494         $record->append_fields($field);
495         build_tabs ($template, $record, $dbh,$encoding);
496         build_hidden_data;
497         $template->param(
498                 oldbiblionumber          => $biblionumber,
499                 biblionumber             => $biblionumber,
500                 biblionumtagfield        => $biblionumtagfield,
501                 biblionumtagsubfield     => $biblionumtagsubfield,
502                 biblioitemnumtagfield    => $biblioitemnumtagfield,
503                 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
504                 biblioitemnumber         => $biblioitemnumber );
505 } elsif ($op eq "delete") {
506 #------------------------------------------------------------------------------------------------------------------------------
507         &NEWdelbiblio($dbh,$biblionumber);
508         logaction($loggedinuser,"acqui.simple","del",$biblionumber,"") if (logstatus);
509         
510         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/cgi-bin/koha/search.marc/search.pl?type=intranet\"></html>";
511         exit;
512 #------------------------------------------------------------------------------------------------------------------------------
513 #------------------------------------------------------------------------------------------------------------------------------
514 } else {
515 #------------------------------------------------------------------------------------------------------------------------------
516         # If we're in a duplication case, we have to set to "" the bibid and biblionumber
517         # as we'll save the biblio as a new one.
518         if ($op eq "duplicate")
519         {
520                 $biblionumber= "";
521         }
522         #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
523         eval {
524         my $uxml = $record->as_xml;
525         my $urecord = MARC::Record::new_from_xml($uxml, 'UTF-8'); 
526                 $record = $urecord;
527         };
528         build_tabs ($template, $record, $dbh,$encoding);
529         build_hidden_data;
530         $template->param(
531             oldbiblionumber                      => $biblionumber,
532                 biblionumber             => $biblionumber,
533                 biblionumtagfield        => $biblionumtagfield,
534                 biblionumtagsubfield     => $biblionumtagsubfield,
535                 biblioitemnumtagfield    => $biblioitemnumtagfield,
536                 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
537                 biblioitemnumber         => $biblioitemnumber,
538                 );
539 }
540 $template->param(
541                 frameworkcode => $frameworkcode,
542                 itemtype => $frameworkcode, # HINT: if the library has itemtype = framework, itemtype is auto filled !
543                 hide_marc => C4::Context->preference('hide_marc'),
544                 );
545 output_html_with_http_headers $input, $cookie, $template->output;