4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::AuthoritiesMarc;
31 use C4::Koha; # XXX subfield_is_koha_internal_p
32 use C4::Branch; # XXX subfield_is_koha_internal_p
35 use Date::Calc qw(Today);
36 use MARC::File::USMARC;
39 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
40 MARC::File::XML->default_record_format('UNIMARC');
43 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
45 =item MARCfindbreeding
47 $record = MARCfindbreeding($dbh, $breedingid);
49 Look up the breeding farm with database handle $dbh, for the
50 record with id $breedingid. If found, returns the decoded
51 MARC::Record; otherwise, -1 is returned (FIXME).
52 Returns as second parameter the character encoding.
56 sub MARCfindbreeding {
57 my ( $dbh, $id ) = @_;
59 $dbh->prepare("select file,marc,encoding from marc_breeding where id=?");
61 my ( $file, $marc, $encoding ) = $sth->fetchrow;
62 # remove the - in isbn, koha store isbn without any -
64 my $record = MARC::Record->new_from_usmarc($marc);
65 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn','');
66 if ( $record->field($isbnfield) ) {
67 foreach my $field ( $record->field($isbnfield) ) {
68 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
69 my $newisbn = $field->subfield($isbnsubfield);
71 $field->update( $isbnsubfield => $newisbn );
75 # fix the unimarc 100 coded field (with unicode information)
76 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
77 my $f100a=$record->subfield(100,'a');
78 my $f100 = $record->field(100);
79 my $f100temp = $f100->as_string;
80 $record->delete_field($f100);
81 if ( length($f100temp) > 28 ) {
82 substr( $f100temp, 26, 2, "50" );
83 $f100->update( 'a' => $f100temp );
84 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
85 $record->insert_fields_ordered($f100);
89 if ( ref($record) eq undef ) {
93 # normalize author : probably UNIMARC specific...
94 if ( C4::Context->preference("z3950NormalizeAuthor")
95 and C4::Context->preference("z3950AuthorAuthFields") )
97 my ( $tag, $subfield ) = GetMarcFromKohaField("biblio.author");
99 # my $summary = C4::Context->preference("z3950authortemplate");
101 C4::Context->preference("z3950AuthorAuthFields");
102 my @auth_fields = split /,/, $auth_fields;
105 if ( $record->field($tag) ) {
106 foreach my $tmpfield ( $record->field($tag)->subfields ) {
108 # foreach my $subfieldcode ($tmpfield->subfields){
109 my $subfieldcode = shift @$tmpfield;
110 my $subfieldvalue = shift @$tmpfield;
112 $field->add_subfields(
113 "$subfieldcode" => $subfieldvalue )
114 if ( $subfieldcode ne $subfield );
118 MARC::Field->new( $tag, "", "",
119 $subfieldcode => $subfieldvalue )
120 if ( $subfieldcode ne $subfield );
124 $record->delete_field( $record->field($tag) );
125 foreach my $fieldtag (@auth_fields) {
126 next unless ( $record->field($fieldtag) );
127 my $lastname = $record->field($fieldtag)->subfield('a');
128 my $firstname = $record->field($fieldtag)->subfield('b');
129 my $title = $record->field($fieldtag)->subfield('c');
130 my $number = $record->field($fieldtag)->subfield('d');
133 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
134 $field->add_subfields(
135 "$subfield" => ucfirst($title) . " "
136 . ucfirst($firstname) . " "
141 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
142 $field->add_subfields(
143 "$subfield" => ucfirst($firstname) . ", "
144 . ucfirst($lastname) );
147 $record->insert_fields_ordered($field);
149 return $record, $encoding;
155 =item build_authorized_values_list
159 sub build_authorized_values_list ($$$$$$$) {
160 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
162 my @authorised_values;
165 # builds list, depending on authorised value...
168 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
169 #Use GetBranches($onlymine)
170 my $onlymine=C4::Context->preference('IndependantBranches') &&
171 C4::Context->userenv &&
172 C4::Context->userenv->{flags}!=1 &&
173 C4::Context->userenv->{branch};
174 my $branches = GetBranches($onlymine);
176 foreach my $thisbranch ( sort keys %$branches ) {
177 push @authorised_values, $thisbranch;
178 $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
183 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
186 "select itemtype,description from itemtypes order by description");
188 push @authorised_values, ""
189 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
193 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
194 push @authorised_values, $itemtype;
195 $authorised_lib{$itemtype} = $description;
197 $value = $itemtype unless ($value);
201 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
202 push @authorised_values, ""
203 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
205 my $class_sources = GetClassSources();
207 my $default_source = C4::Context->preference("DefaultClassificationSource");
209 foreach my $class_source (sort keys %$class_sources) {
210 next unless $class_sources->{$class_source}->{'used'} or
211 ($value and $class_source eq $value) or
212 ($class_source eq $default_source);
213 push @authorised_values, $class_source;
214 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
215 $value = $class_source unless ($value);
216 $value = $default_source unless ($value);
218 #---- "true" authorised value
221 $authorised_values_sth->execute(
222 $tagslib->{$tag}->{$subfield}->{authorised_value} );
224 push @authorised_values, ""
225 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
227 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
228 push @authorised_values, $value;
229 $authorised_lib{$value} = $lib;
232 return CGI::scrolling_list(
233 -name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
234 -values => \@authorised_values,
236 -labels => \%authorised_lib,
241 -id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
242 -class => "input_marceditor",
248 Create a random value to set it into the input name
253 return int(rand(1000000));
256 =item GetMandatoryFieldZ3950
258 This function return an hashref which containts all mandatory field
259 to search with z3950 server.
263 sub GetMandatoryFieldZ3950($){
264 my $frameworkcode = shift;
265 my @isbn = GetMarcFromKohaField('biblioitems.isbn',$frameworkcode);
266 my @title = GetMarcFromKohaField('biblio.title',$frameworkcode);
267 my @author = GetMarcFromKohaField('biblio.author',$frameworkcode);
268 my @issn = GetMarcFromKohaField('biblioitems.issn',$frameworkcode);
271 $isbn[0].$isbn[1] => 'isbn',
272 $title[0].$title[1] => 'title',
273 $author[0].$author[1] => 'author',
274 $issn[0].$issn[1] => 'issn',
280 builds the <input ...> entry for a subfield.
285 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
287 my $index_subfield = CreateKey(); # create a specifique key for each subfield
289 $value =~ s/"/"/g;
291 # if there is no value provided but a default value in parameters, get it
293 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
295 # get today date & replace YYYY, MM, DD if provided in the default value
296 my ( $year, $month, $day ) = Today();
297 $month = sprintf( "%02d", $month );
298 $day = sprintf( "%02d", $day );
299 $value =~ s/YYYY/$year/g;
300 $value =~ s/MM/$month/g;
301 $value =~ s/DD/$day/g;
303 my $dbh = C4::Context->dbh;
304 my %subfield_data = (
306 subfield => $subfield,
307 marc_lib => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
308 marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib},
309 tag_mandatory => $tagslib->{$tag}->{mandatory},
310 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
311 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
312 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
314 id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
316 random => CreateKey(),
318 # deal with a <010 tag
319 if($subfield eq '@'){
320 $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield;
322 $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield;
325 if(exists $mandatory_z3950->{$tag.$subfield}){
326 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
328 # decide if the subfield must be expanded (visible) by default or not
329 # if it is mandatory, then expand. If it is hidden explicitly by the hidden flag, hidden anyway
330 $subfield_data{visibility} = "display:none;"
331 if ( ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''
332 or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
334 # always expand all subfields of a mandatory field
335 $subfield_data{visibility} = "" if $tagslib->{$tag}->{mandatory};
336 # it's an authorised field
337 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
338 $subfield_data{marc_value} =
339 build_authorized_values_list( $tag, $subfield, $value, $dbh,
340 $authorised_values_sth,$index_tag,$index_subfield );
342 # it's a thesaurus / authority field
344 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
345 $subfield_data{marc_value} =
346 "<input type=\"text\"
347 id=\"".$subfield_data{id}."\"
348 name=\"".$subfield_data{id}."\"
350 class=\"input_marceditor\"
355 <a href=\"#\" class=\"buttonDot\"
356 onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
358 # it's a plugin field
360 elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
362 # opening plugin. Just check wether we are on a developper computer on a production one
363 # (the cgidir differs)
364 my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
365 unless ( opendir( DIR, "$cgidir" ) ) {
366 $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
369 my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
371 my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
372 my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
374 $subfield_data{marc_value} =
375 "<input tabindex=\"1\"
377 id=\"".$subfield_data{id}."\"
378 name=\"".$subfield_data{id}."\"
380 class=\"input_marceditor\"
381 onfocus=\"Focus$function_name($index_tag)\"
384 onblur=\"Blur$function_name($index_tag); \" \/>
385 <a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id})'; return false;)\" title=\"Tag Editor\">...</a>
388 warn "Plugin Failed: $plugin";
389 # supply default input form
390 $subfield_data{marc_value} =
391 "<input type=\"text\"
392 id=\"".$subfield_data{id}."\"
393 name=\"".$subfield_data{id}."\"
398 class=\"input_marceditor\"
402 # it's an hidden field
404 elsif ( $tag eq '' ) {
405 $subfield_data{marc_value} =
406 "<input tabindex=\"1\"
408 id=\"".$subfield_data{id}."\"
409 name=\"".$subfield_data{id}."\"
415 elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
416 $subfield_data{marc_value} =
417 "<input type=\"text\"
418 id=\"".$subfield_data{id}."\"
419 name=\"".$subfield_data{id}."\"
420 class=\"input_marceditor\"
427 # it's a standard field
433 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
434 and $tag < 400 && $subfield eq 'a' )
437 && C4::Context->preference("marcflavour") eq "MARC21" )
440 $subfield_data{marc_value} =
441 "<textarea cols=\"70\"
443 id=\"".$subfield_data{id}."\"
444 name=\"".$subfield_data{id}."\"
445 class=\"input_marceditor\"
453 $subfield_data{marc_value} =
454 "<input type=\"text\"
455 id=\"".$subfield_data{id}."\"
456 name=\"".$subfield_data{id}."\"
461 class=\"input_marceditor\"
466 $subfield_data{'index_subfield'} = $index_subfield;
467 return \%subfield_data;
470 sub build_tabs ($$$$$) {
471 my ( $template, $record, $dbh, $encoding,$input ) = @_;
477 my $authorised_values_sth = $dbh->prepare(
478 "select authorised_value,lib
479 from authorised_values
480 where category=? order by lib"
483 # in this array, we will push all the 10 tabs
484 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
487 my @tab_data; # all tags to display
489 foreach my $used ( @$usedTagsLib ){
490 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
491 $seen{$used->{tagfield}}++;
495 foreach(@$usedTagsLib){
496 if($_->{tab} > -1 && $_->{tab} >= $max_num_tab && $_->{tagfield} != '995'){ # FIXME : MARC21 ?
497 $max_num_tab = $_->{tab};
500 if($max_num_tab >= 9){
503 # loop through each tab 0 through 9
504 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
505 my @loop_data = (); #innerloop in the template.
507 foreach my $tag (@tab_data) {
511 my $index_tag = CreateKey;
513 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
514 # if MARC::Record is empty => use tab as master loop.
515 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
517 if ( $tag ne '000' ) {
518 @fields = $record->field($tag);
521 push @fields, $record->leader(); # if tag == 000
523 # loop through each field
524 foreach my $field (@fields) {
528 my ( $value, $subfield );
529 if ( $tag ne '000' ) {
530 $value = $field->data();
537 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
539 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
540 'biblio.biblionumber' );
544 $tag, $subfield, $value, $index_tag, $tabloop, $record,
545 $authorised_values_sth,$input
550 my @subfields = $field->subfields();
551 foreach my $subfieldcount ( 0 .. $#subfields ) {
552 my $subfield = $subfields[$subfieldcount][0];
553 my $value = $subfields[$subfieldcount][1];
554 next if ( length $subfield != 1 );
555 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
559 $tag, $subfield, $value, $index_tag, $tabloop,
560 $record, $authorised_values_sth,$input
566 # now, loop again to add parameter subfield that are not in the MARC::Record
567 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
569 next if ( length $subfield != 1 );
570 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
571 next if ( $tag < 10 );
573 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
574 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 )
575 ); #check for visibility flag
576 next if ( defined( $field->subfield($subfield) ) );
580 $tag, $subfield, '', $index_tag, $tabloop, $record,
581 $authorised_values_sth,$input
585 if ( $#subfields_data >= 0 ) {
586 # build the tag entry.
587 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
588 # have twice the same "name" value, and cgi->param() will return only one, making
589 # all subfields to be merged in a single field.
593 tag_lib => $tagslib->{$tag}->{lib},
594 repeatable => $tagslib->{$tag}->{repeatable},
595 subfield_loop => \@subfields_data,
596 fixedfield => $tag < 10?1:0,
599 if ($tag >= 010){ # no indicator for theses tag
600 $tag_data{indicator} = $field->indicator(1).$field->indicator(2);
602 push( @loop_data, \%tag_data );
604 } # foreach $field end
606 # if breeding is empty
610 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
611 next if ( length $subfield != 1 );
613 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
614 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
615 ; #check for visibility flag
617 if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
621 $tag, $subfield, '', $index_tag, $tabloop, $record,
622 $authorised_values_sth,$input
626 if ( $#subfields_data >= 0 ) {
630 tag_lib => $tagslib->{$tag}->{lib},
631 repeatable => $tagslib->{$tag}->{repeatable},
632 indicator => $indicator,
633 subfield_loop => \@subfields_data,
634 tagfirstsubfield => $subfields_data[0],
635 fixedfield => $tag < 10?1:0,
638 push @loop_data, \%tag_data ;
642 if ( $#loop_data >= 0 ) {
645 innerloop => \@loop_data,
649 $template->param( BIG_LOOP => \@BIG_LOOP );
652 sub BiblioAddAuthorities{
653 my ( $record, $frameworkcode ) = @_;
654 my $dbh=C4::Context->dbh;
655 my $query=$dbh->prepare(qq|
656 SELECT authtypecode,tagfield
657 FROM marc_subfield_structure
658 WHERE frameworkcode=?
659 AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|);
660 # SELECT authtypecode,tagfield
661 # FROM marc_subfield_structure
662 # WHERE frameworkcode=?
663 # AND (authtypecode IS NOT NULL OR authtypecode<>\"\")|);
664 $query->execute($frameworkcode);
665 my ($countcreated,$countlinked);
666 while (my $data=$query->fetchrow_hashref){
667 if ($record->field($data->{tagfield})){
668 next if ($record->subfield($data->{tagfield},'3')||$record->subfield($data->{tagfield},'9'));
669 # No authorities id in the tag.
670 # Search if there is any authorities to link to.
671 my $query='at='.$data->{authtypecode}.' ';
672 map {$query.= " and he=".$_->[1] if ($_->[0]=~/[A-z]/)} $record->field($data->{tagfield})->subfields();
673 my ($error,$results)=SimpleSearch($query,"authorityserver");
674 # there is at least 1 result => return the 1st one
676 my $marcrecord = MARC::File::USMARC::decode($results->[0]);
677 $record->field($data->{tagfield})->add_subfields('9'=>$marcrecord->field('001')->data);
680 #There are no results, build authority record, add it to Authorities, get authid and add it to 9
681 ###NOTICE : This is only valid if a subfield is linked to one and only one authtypecode
683 my $authtypedata=GetAuthType($data->{authtypecode});
684 my $marcrecordauth=MARC::Record->new();
685 my $field=MARC::Field->new($authtypedata->{auth_tag_to_report},'','',"a"=>"".$record->subfield($data->{tagfield},'a'));
686 map { $field->add_subfields($_->[0]=>$_->[1]) if ($_->[0]=~/[A-z]/ && $_->[0] ne "a" )} $record->field($data->{tagfield})->subfields();
687 $marcrecordauth->insert_fields_ordered($field);
688 my $authid=AddAuthority($marcrecordauth,'',$data->{authtypecode});
690 $record->field($data->{tagfield})->add_subfields('9'=>$authid);
694 return ($countlinked,$countcreated);
697 # ========================
699 #=========================
701 my $error = $input->param('error');
702 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
703 my $breedingid = $input->param('breedingid');
704 my $z3950 = $input->param('z3950');
705 my $op = $input->param('op');
706 my $mode = $input->param('mode');
707 my $frameworkcode = $input->param('frameworkcode');
708 my $dbh = C4::Context->dbh;
710 $frameworkcode = &GetFrameworkCode($biblionumber)
711 if ( $biblionumber and not($frameworkcode) );
713 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
714 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
716 template_name => "cataloguing/addbiblio.tmpl",
719 authnotrequired => 0,
720 flagsrequired => { editcatalogue => 1 },
724 #Getting the list of all frameworks
725 my $queryfwk = $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
730 push @select_fwk, "Default";
731 $select_fwk{"Default"} = "Default";
733 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
734 push @select_fwk, $fwk;
735 $select_fwk{$fwk} = $description;
737 $curfwk = $frameworkcode;
738 my $framework = CGI::scrolling_list(
739 -name => 'Frameworks',
742 -onchange => 'Changefwk(this);',
743 -values => \@select_fwk,
744 -labels => \%select_fwk,
748 $template->param( framework => $framework, breedingid => $breedingid );
751 $tagslib = &GetMarcStructure( 1, $frameworkcode );
752 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
753 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
759 $biblionumbertagfield,
760 $biblionumbertagsubfield,
761 $biblioitemnumtagfield,
762 $biblioitemnumtagsubfield,
767 if (($biblionumber) && !($breedingid)){
768 $record = GetMarcBiblio($biblionumber);
771 ( $record, $encoding ) = MARCfindbreeding( $dbh, $breedingid ) ;
779 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
780 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
781 &GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode );
782 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
783 &GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
785 # search biblioitems value
786 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
787 $sth->execute($biblionumber);
788 ($biblioitemnumber) = $sth->fetchrow;
791 #-------------------------------------------------------------------------------------
792 if ( $op eq "addbiblio" ) {
793 #-------------------------------------------------------------------------------------
795 my @params = $input->param();
796 $record = TransformHtmlToMarc( \@params , $input );
797 # check for a duplicate
798 my ($duplicatebiblionumber,$duplicatetitle) = FindDuplicate($record) if (!$is_a_modif);
799 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
800 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
801 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
804 if (C4::Context->preference("BiblioAddsAuthorities")){
805 my ($countlinked,$countcreated)=BiblioAddAuthorities($record,$frameworkcode);
808 ModBiblioframework( $biblionumber, $frameworkcode );
809 ModBiblio( $record, $biblionumber, $frameworkcode );
812 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
815 if ($mode ne "popup"){
816 print $input->redirect(
817 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode"
822 biblionumber => $biblionumber,
826 $template->param( title => $record->subfield('200',"a") ) if ($record ne "-1" && C4::Context->preference('marcflavour') =~/unimarc/i);
827 $template->param( title => $record->title() ) if ($record ne "-1" && C4::Context->preference('marcflavour') eq "usmarc");
830 itemtype => $frameworkcode,
832 output_html_with_http_headers $input, $cookie, $template->output;
836 # it may be a duplicate, warn the user and do nothing
837 build_tabs ($template, $record, $dbh,$encoding,$input);
839 biblionumber => $biblionumber,
840 biblioitemnumber => $biblioitemnumber,
841 duplicatebiblionumber => $duplicatebiblionumber,
842 duplicatebibid => $duplicatebiblionumber,
843 duplicatetitle => $duplicatetitle,
847 elsif ( $op eq "delete" ) {
849 my $error = &DelBiblio($biblionumber);
851 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
852 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
856 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
860 #----------------------------------------------------------------------------
861 # If we're in a duplication case, we have to set to "" the biblionumber
862 # as we'll save the biblio as a new one.
863 if ( $op eq "duplicate" ) {
867 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
869 my $uxml = $record->as_xml;
870 MARC::Record::default_record_format("UNIMARC")
871 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
872 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
875 build_tabs( $template, $record, $dbh, $encoding,$input );
877 biblionumber => $biblionumber,
878 biblionumbertagfield => $biblionumbertagfield,
879 biblionumbertagsubfield => $biblionumbertagsubfield,
880 biblioitemnumtagfield => $biblioitemnumtagfield,
881 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
882 biblioitemnumber => $biblioitemnumber,
886 $template->param( title => $record->title() ) if ( $record ne "-1" );
889 frameworkcode => $frameworkcode,
890 itemtype => $frameworkcode,
893 output_html_with_http_headers $input, $cookie, $template->output;