5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
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
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.
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
31 use C4::Koha; # XXX subfield_is_koha_internal_p
32 use Date::Calc qw(Today);
34 use MARC::File::USMARC;
36 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
37 MARC::File::XML->default_record_format( 'UNIMARC' );
40 use vars qw( $tagslib);
41 use vars qw( $authorised_values_sth);
42 use vars qw( $is_a_modif );
44 my $itemtype; # created here because it can be used in build_authorized_values_list sub
48 ($indicators, $value) = find_value($tag, $subfield, $record,$encoding);
50 Find the given $subfield in the given $tag in the given
51 MARC::Record $record. If the subfield is found, returns
52 the (indicators, value) pair; otherwise, (undef, undef) is
58 my ($tagfield,$insubfield,$record,$encoding) = @_;
62 if ($record->field($tagfield)) {
63 push @result, $record->field($tagfield)->data();
68 foreach my $field ($record->field($tagfield)) {
69 my @subfields = $field->subfields();
70 foreach my $subfield (@subfields) {
71 if (@$subfield[0] eq $insubfield) {
72 push @result,@$subfield[1];
73 $indicator = $field->indicator(1).$field->indicator(2);
78 return($indicator,@result);
82 =item MARCfindbreeding
84 $record = MARCfindbreeding($dbh, $breedingid);
86 Look up the breeding farm with database handle $dbh, for the
87 record with id $breedingid. If found, returns the decoded
88 MARC::Record; otherwise, -1 is returned (FIXME).
89 Returns as second parameter the character encoding.
93 sub MARCfindbreeding {
95 my $sth = $dbh->prepare("select file,marc,encoding from marc_breeding where id=?");
97 my ($file,$marc,$encoding) = $sth->fetchrow;
99 my $record = MARC::Record->new_from_usmarc($marc);
100 if ($record->field('010')){
101 foreach my $field ($record->field('010'))
103 foreach my $subfield ($field->subfield('a')){
104 my $newisbn = $field->subfield('a');
106 $field->update( 'a' => $newisbn );
108 # $record->insert_fields_ordered($record->field('010'));
111 if ($record->subfield(100,'a')) {
112 my $f100a=$record->subfield(100,'a');
113 my $f100 = $record->field(100);
114 my $f100temp = $f100->as_string;
115 $record->delete_field($f100);
116 if (length($f100temp)>28) {
117 substr($f100temp,26,2,"50");
118 $f100->update('a' => $f100temp);
119 my $f100 = MARC::Field->new('100','','','a' => $f100temp);
120 $record->insert_fields_ordered($f100);
123 if (ref($record) eq undef) {
126 if (C4::Context->preference("z3950NormalizeAuthor") and C4::Context->preference("z3950AuthorAuthFields")){
127 my ($tag,$subfield) = GetMarcFromKohaField("biblio.author");
128 # my $summary = C4::Context->preference("z3950authortemplate");
129 my $auth_fields = C4::Context->preference("z3950AuthorAuthFields");
130 my @auth_fields= split /,/,$auth_fields;
132 #warn $record->as_formatted;
133 if ($record->field($tag)){
134 foreach my $tmpfield ($record->field($tag)->subfields){
135 # foreach my $subfieldcode ($tmpfield->subfields){
136 my $subfieldcode=shift @$tmpfield;
137 my $subfieldvalue=shift @$tmpfield;
139 $field->add_subfields("$subfieldcode"=>$subfieldvalue) if ($subfieldcode ne $subfield);
141 $field=MARC::Field->new($tag,"","",$subfieldcode=>$subfieldvalue) if ($subfieldcode ne $subfield);
144 # warn $field->as_formatted;
147 $record->delete_field($record->field($tag));
148 foreach my $fieldtag (@auth_fields){
149 next unless ($record->field($fieldtag));
150 my $lastname = $record->field($fieldtag)->subfield('a');
151 my $firstname= $record->field($fieldtag)->subfield('b');
152 my $title = $record->field($fieldtag)->subfield('c');
153 my $number= $record->field($fieldtag)->subfield('d');
155 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
156 $field->add_subfields("$subfield"=>ucfirst($title)." ".ucfirst($firstname)." ".$number);
158 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
159 $field->add_subfields("$subfield"=>ucfirst($firstname).", ".ucfirst($lastname));
162 $record->insert_fields_ordered($field);
164 return $record,$encoding;
171 =item build_authorized_values_list
175 sub build_authorized_values_list ($$$$$) {
176 my($tag, $subfield, $value, $dbh,$authorised_values_sth) = @_;
178 my @authorised_values;
181 # builds list, depending on authorised value...
184 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
185 my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname");
187 push @authorised_values, ""
188 unless ($tagslib->{$tag}->{$subfield}->{mandatory});
190 while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
191 push @authorised_values, $branchcode;
192 $authorised_lib{$branchcode}=$branchname;
196 } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
197 my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description");
199 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
201 while (my ($itemtype,$description) = $sth->fetchrow_array) {
202 push @authorised_values, $itemtype;
203 $authorised_lib{$itemtype}=$description;
205 $value=$itemtype unless ($value);
207 #---- "true" authorised value
209 $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
211 push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
213 while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) {
214 push @authorised_values, $value;
215 $authorised_lib{$value}=$lib;
218 return CGI::scrolling_list( -name => 'field_value',
219 -values => \@authorised_values,
221 -labels => \%authorised_lib,
229 builds the <input ...> entry for a subfield.
233 sub create_input () {
234 my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_;
235 # must be encoded as utf-8 before it reaches the editor
237 #$value = encode('utf-8', $value);
238 $value =~ s/"/"/g;
239 # if there is no value provided but a default value in parameters, get it
241 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
242 # get today date & replace YYYY, MM, DD if provided in the default value
243 my ($year,$month,$day) = Today();
244 $month = sprintf("%02d",$month);
245 $day = sprintf("%02d",$day);
246 $value =~ s/YYYY/$year/g;
247 $value =~ s/MM/$month/g;
248 $value =~ s/DD/$day/g;
251 my $dbh = C4::Context->dbh;
253 $subfield_data{tag}=$tag;
254 $subfield_data{subfield}=$subfield;
255 $subfield_data{marc_lib}="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".substr($tagslib->{$tag}->{$subfield}->{lib},0,15)."</span>";
256 $subfield_data{marc_lib_plain}=$tagslib->{$tag}->{$subfield}->{lib};
257 $subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory};
258 $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
259 $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
260 $subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield};
261 $subfield_data{index} = $i;
262 $subfield_data{visibility} = "display:none" unless (($tagslib->{$tag}->{$subfield}->{hidden}%2==0) or $value ne ''); #check parity
263 # it's an authorised field
264 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
265 $subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh,$authorised_values_sth);
266 # it's a thesaurus / authority field
267 } elsif ($tagslib->{$tag}->{$subfield}->{authtypecode}) {
268 $subfield_data{marc_value}="<input type=\"text\" 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>";
269 # it's a plugin field
270 } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
271 # opening plugin. Just check wether we are on a developper computer on a production one
272 # (the cgidir differs)
273 my $cgidir = C4::Context->intranetdir ."/cgi-bin/cataloguing/value_builder";
274 unless (opendir(DIR, "$cgidir")) {
275 $cgidir = C4::Context->intranetdir."/cataloguing/value_builder";
277 my $plugin=$cgidir."/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
279 my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop);
280 my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop);
281 $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";
282 # it's an hidden field
283 } elsif ($tag eq '') {
284 $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffff00'; \" tabindex=\"1\" type=\"hidden\" name=\"field_value\" value=\"$value\">";
285 } elsif ($tagslib->{$tag}->{$subfield}->{'hidden'}) {
286 $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\" >";
287 # it's a standard field
289 if (length($value) >100 or (C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >=300 and $tag <400 && $subfield eq 'a') or ($tag >=500 and $tag <600 && C4::Context->preference("marcflavour") eq "MARC21")) {
290 $subfield_data{marc_value}="<textarea tabindex=\"1\" name=\"field_value\" cols=\"70\" rows=\"5\" >$value</textarea>";
292 $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\">"; #"
295 return \%subfield_data;
298 sub build_tabs ($$$$) {
299 my($template, $record, $dbh,$encoding) = @_;
304 my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
305 from authorised_values
306 where category=? order by lib");
308 # in this array, we will push all the 10 tabs
309 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
312 # loop through each tab 0 through 9
313 for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
315 foreach my $tag (sort(keys (%{$tagslib}))) {
317 # if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
318 # if MARC::Record is empty => use tab as master loop.
319 if ($record ne -1 && ($record->field($tag) || $tag eq '000')) {
322 @fields = $record->field($tag);
324 push @fields,$record->leader();
326 foreach my $field (@fields) {
329 my ($value,$subfield);
331 $value=$field->data();
337 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
338 next if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'biblio.biblionumber');
339 push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
342 my @subfields=$field->subfields();
343 foreach my $subfieldcount (0..$#subfields) {
344 my $subfield=$subfields[$subfieldcount][0];
345 my $value=$subfields[$subfieldcount][1];
346 next if (length $subfield !=1);
347 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
348 push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
352 # now, loop again to add parameter subfield that are not in the MARC::Record
353 foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
354 next if (length $subfield !=1);
355 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
357 next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-4) or ($tagslib->{$tag}->{$subfield}->{hidden}>=5) ); #check for visibility flag
358 next if (defined($field->subfield($subfield)));
359 push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
362 if ($#subfields_data >= 0) {
364 $tag_data{tag} = $tag;
365 $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
366 $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
367 $tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10);
368 $tag_data{subfield_loop} = \@subfields_data;
370 $tag_data{fixedfield} = 1;
373 push (@loop_data, \%tag_data);
375 # If there is more than 1 field, add an empty hidden field as separator.
376 if ($#fields >=1 && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
379 push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth));
381 $tag_data{tag_lib} = '';
382 $tag_data{indicator} = '';
383 $tag_data{subfield_loop} = \@subfields_data;
385 $tag_data{fixedfield} = 1;
387 push (@loop_data, \%tag_data);
391 # if breeding is empty
394 foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
395 next if (length $subfield !=1);
396 next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-5) or ($tagslib->{$tag}->{$subfield}->{hidden}>=4) ); #check for visibility flag
397 next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
398 push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
401 if ($#subfields_data >= 0) {
403 $tag_data{tag} = $tag;
404 $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
405 $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
406 $tag_data{indicator} = $indicator;
407 $tag_data{subfield_loop} = \@subfields_data;
408 $tag_data{tagfirstsubfield} = $tag_data{subfield_loop}[0];
410 $tag_data{fixedfield} = 1;
412 push (@loop_data, \%tag_data);
416 if ($#loop_data >=0) {
418 $big_loop_line{number}=$tabloop;
419 $big_loop_line{innerloop}=\@loop_data;
420 push @BIG_LOOP,\%big_loop_line;
422 # $template->param($tabloop."XX" =>\@loop_data);
424 $template->param(BIG_LOOP => \@BIG_LOOP);
429 sub build_hidden_data () {
430 # build hidden data =>
431 # we store everything, even if we show only requested subfields.
435 foreach my $tag (keys %{$tagslib}) {
436 my $previous_tag = '';
438 # loop through each subfield
439 foreach my $subfield (keys %{$tagslib->{$tag}}) {
440 next if ($subfield eq 'lib');
441 next if ($subfield eq 'tab');
442 next if ($subfield eq 'mandatory');
443 next if ($subfield eq 'repeatable');
444 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1");
446 $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
447 $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
448 $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
449 $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
450 push(@loop_data, \%subfield_data);
457 # ========================
459 #=========================
461 my $error = $input->param('error');
462 my $biblionumber=$input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
463 my $breedingid = $input->param('breedingid');
464 my $z3950 = $input->param('z3950');
465 my $op = $input->param('op');
466 my $mode = $input->param('mode');
467 my $frameworkcode = $input->param('frameworkcode');
468 my $dbh = C4::Context->dbh;
470 $frameworkcode = &GetFrameworkCode($biblionumber) if ($biblionumber and not ($frameworkcode));
472 $frameworkcode='' if ($frameworkcode eq 'Default');
473 my ($template, $loggedinuser, $cookie)
474 = get_template_and_user({template_name => "cataloguing/addbiblio.tmpl",
477 authnotrequired => 0,
478 flagsrequired => {editcatalogue => 1},
482 #Getting the list of all frameworks
483 my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
488 push @select_fwk,"Default";
489 $select_fwk{"Default"} = "Default";
490 while (my ($description, $fwk) =$queryfwk->fetchrow) {
491 push @select_fwk, $fwk;
492 $select_fwk{$fwk} = $description;
494 $curfwk=$frameworkcode;
495 my $framework=CGI::scrolling_list(
496 -name => 'Frameworks',
499 -OnChange => 'Changefwk(this);',
500 -values => \@select_fwk,
501 -labels => \%select_fwk,
504 $template->param( framework => $framework, breedingid => $breedingid);
506 $tagslib = &GetMarcStructure(1,$frameworkcode);
509 $record = GetMarcBiblio( $biblionumber ) if ($biblionumber);
510 ($record,$encoding) = MARCfindbreeding($dbh,$breedingid) if ($breedingid);
512 # warn "biblionumber : $biblionumber = ".$record->as_formatted;
514 my ($biblionumtagfield,$biblionumtagsubfield);
515 my ($biblioitemnumtagfield,$biblioitemnumtagsubfield,$bibitem,$biblioitemnumber);
518 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
519 ($biblionumtagfield,$biblionumtagsubfield) = &GetMarcFromKohaField("biblio.biblionumber",$frameworkcode);
520 ($biblioitemnumtagfield,$biblioitemnumtagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber",$frameworkcode);
521 # search biblioitems value
522 my $sth=$dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
523 $sth->execute($biblionumber);
524 ($biblioitemnumber) = $sth->fetchrow;
526 #-------------------------------------------------------------------------------------
527 if ($op eq "addbiblio") {
528 #-------------------------------------------------------------------------------------
530 my @tags = $input->param('tag');
531 my @subfields = $input->param('subfield');
532 my @values = $input->param('field_value');
533 # build indicator hash.
534 my @ind_tag = $input->param('ind_tag');
535 my @indicator = $input->param('indicator');
536 if (C4::Context->preference('TemplateEncoding') eq "iso-8859-1") {
537 $record = TransformHtmlToMarc($dbh,\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
539 my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
540 $record=MARC::Record->new_from_xml($xml,C4::Context->preference('TemplateEncoding'),C4::Context->preference('marcflavour'));
541 # warn "MARC :".$record->as_formatted;
544 # check for a duplicate
545 my ($duplicatebiblionumber,$duplicatetitle) = FindDuplicate($record) if (!$is_a_modif);
546 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
547 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
548 if (!$duplicatebiblionumber or $confirm_not_duplicate) {
549 # MARC::Record built => now, record in DB
553 ModBiblioframework($biblionumber,$frameworkcode);
554 ModBiblio($record,$biblionumber,$frameworkcode);
557 ($biblionumber,$oldbibitemnum) = AddBiblio($record,$frameworkcode);
559 # now, redirect to additem page
560 if ($mode ne "popup"){
561 print $input->redirect("/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
565 biblionumber => $biblionumber,
569 $template->param( title => $record->subfield('200',"a") ) if ($record ne "-1" && C4::Context->preference('marcflavour') =~/unimarc/i);
570 $template->param( title => $record->title() ) if ($record ne "-1" && C4::Context->preference('marcflavour') eq "usmarc");
573 itemtype => $frameworkcode, # HINT: if the library has itemtype = framework, itemtype is auto filled !
575 output_html_with_http_headers $input, $cookie, $template->output;
579 # it may be a duplicate, warn the user and do nothing
580 build_tabs ($template, $record, $dbh,$encoding);
583 biblionumber => $biblionumber,
584 biblionumtagfield => $biblionumtagfield,
585 biblionumtagsubfield => $biblionumtagsubfield,
586 biblioitemnumtagfield => $biblioitemnumtagfield,
587 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
588 biblioitemnumber => $biblioitemnumber,
589 duplicatebiblionumber => $duplicatebiblionumber,
590 duplicatebibid => $duplicatebiblionumber,
591 duplicatetitle => $duplicatetitle,
594 #--------------------------------------------------------------------------
595 } elsif ($op eq "addfield") {
596 #--------------------------------------------------------------------------
597 my $addedfield = $input->param('addfield_field');
598 my $cntrepeatfield=$input->param('repeat_field');
599 $cntrepeatfield=1 unless ($cntrepeatfield);
600 my $tagaddfield_subfield = $input->param('addfield_subfield');
601 my @tags = $input->param('tag');
602 my @subfields = $input->param('subfield');
603 my @values = $input->param('field_value');
604 # build indicator hash.
605 my @ind_tag = $input->param('ind_tag');
606 my @indicator = $input->param('indicator');
607 my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
609 if (C4::Context->preference('TemplateEncoding') eq "iso-8859-1") {
611 for (my $i=0;$i<=$#ind_tag;$i++) {
612 $indicators{$ind_tag[$i]} = $indicator[$i];
614 $record = TransformHtmlToMarc($dbh,\@tags,\@subfields,\@values,%indicators);
616 my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
617 $record=MARC::Record->new_from_xml($xml,C4::Context->preference('TemplateEncoding'),C4::Context->preference('marcflavour'));
619 for (my $i=1;$i<=$cntrepeatfield;$i++){
620 my $field = MARC::Field->new("$addedfield",'','',"$tagaddfield_subfield" => "");
621 $record->append_fields($field);
623 #warn "result : ".$record->as_formatted;
624 build_tabs ($template, $record, $dbh,$encoding);
627 biblionumber => $biblionumber,
628 biblionumtagfield => $biblionumtagfield,
629 biblionumtagsubfield => $biblionumtagsubfield,
630 biblioitemnumtagfield => $biblioitemnumtagfield,
631 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
632 biblioitemnumber => $biblioitemnumber );
633 } elsif ($op eq "delete") {
634 #-----------------------------------------------------------------------------
635 my $error = &DelBiblio($biblionumber);
637 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
638 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
640 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/cgi-bin/koha/catalogue/search.pl?type=intranet\"></html>";
643 #----------------------------------------------------------------------------
645 #----------------------------------------------------------------------------
646 # If we're in a duplication case, we have to set to "" the biblionumber
647 # as we'll save the biblio as a new one.
648 if ($op eq "duplicate")
652 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
654 my $uxml = $record->as_xml;
655 MARC::Record::default_record_format("UNIMARC") if (C4::Context->preference("marcflavour") eq "UNIMARC");
656 my $urecord = MARC::Record::new_from_xml($uxml, 'UTF-8');
659 build_tabs ($template, $record, $dbh,$encoding);
662 biblionumber => $biblionumber,
663 biblionumtagfield => $biblionumtagfield,
664 biblionumtagsubfield => $biblionumtagsubfield,
665 biblioitemnumtagfield => $biblioitemnumtagfield,
666 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
667 biblioitemnumber => $biblioitemnumber,
670 $template->param( title => $record->title() ) if ($record ne "-1");
673 frameworkcode => $frameworkcode,
674 itemtype => $frameworkcode, # HINT: if the library has itemtype = framework, itemtype is auto filled !
675 hide_marc => C4::Context->preference('hide_marc'),
676 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
677 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
678 IntranetNav => C4::Context->preference("IntranetNav"),
679 advancedMARCEditor => C4::Context->preference("advancedMARCEditor"),
681 output_html_with_http_headers $input, $cookie, $template->output;