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