4 # Copyright 2000-2002 Katipo Communications
5 # Copyright 2004-2010 BibLibre
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 use C4::AuthoritiesMarc;
37 use Koha::BiblioFrameworks;
43 use Koha::BiblioFrameworks;
45 use Date::Calc qw(Today);
46 use MARC::File::USMARC;
50 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
51 MARC::File::XML->default_record_format('UNIMARC');
54 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
58 =head2 MARCfindbreeding
60 $record = MARCfindbreeding($breedingid);
62 Look up the import record repository for the record with
63 record with id $breedingid. If found, returns the decoded
64 MARC::Record; otherwise, -1 is returned (FIXME).
65 Returns as second parameter the character encoding.
69 sub MARCfindbreeding {
71 my ($marc, $encoding) = GetImportRecordMarc($id);
72 # remove the - in isbn, koha store isbn without any -
74 my $record = MARC::Record->new_from_usmarc($marc);
75 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField( 'biblioitems.isbn' );
76 if ( $record->field($isbnfield) ) {
77 foreach my $field ( $record->field($isbnfield) ) {
78 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
79 my $newisbn = $field->subfield($isbnsubfield);
81 $field->update( $isbnsubfield => $newisbn );
85 # fix the unimarc 100 coded field (with unicode information)
86 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
87 my $f100a=$record->subfield(100,'a');
88 my $f100 = $record->field(100);
89 my $f100temp = $f100->as_string;
90 $record->delete_field($f100);
91 if ( length($f100temp) > 28 ) {
92 substr( $f100temp, 26, 2, "50" );
93 $f100->update( 'a' => $f100temp );
94 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
95 $record->insert_fields_ordered($f100);
99 if ( !defined(ref($record)) ) {
103 # normalize author : UNIMARC specific...
104 if ( C4::Context->preference("z3950NormalizeAuthor")
105 and C4::Context->preference("z3950AuthorAuthFields")
106 and C4::Context->preference("marcflavour") eq 'UNIMARC' )
108 my ( $tag, $subfield ) = GetMarcFromKohaField( "biblio.author" );
111 C4::Context->preference("z3950AuthorAuthFields");
112 my @auth_fields = split /,/, $auth_fields;
115 if ( $record->field($tag) ) {
116 foreach my $tmpfield ( $record->field($tag)->subfields ) {
118 my $subfieldcode = shift @$tmpfield;
119 my $subfieldvalue = shift @$tmpfield;
121 $field->add_subfields(
122 "$subfieldcode" => $subfieldvalue )
123 if ( $subfieldcode ne $subfield );
127 MARC::Field->new( $tag, "", "",
128 $subfieldcode => $subfieldvalue )
129 if ( $subfieldcode ne $subfield );
133 $record->delete_field( $record->field($tag) );
134 foreach my $fieldtag (@auth_fields) {
135 next unless ( $record->field($fieldtag) );
136 my $lastname = $record->field($fieldtag)->subfield('a');
137 my $firstname = $record->field($fieldtag)->subfield('b');
138 my $title = $record->field($fieldtag)->subfield('c');
139 my $number = $record->field($fieldtag)->subfield('d');
141 $field->add_subfields(
142 "$subfield" => ucfirst($title) . " "
143 . ucfirst($firstname) . " "
147 $field->add_subfields(
148 "$subfield" => ucfirst($firstname) . ", "
149 . ucfirst($lastname) );
152 $record->insert_fields_ordered($field);
154 return $record, $encoding;
160 =head2 build_authorized_values_list
164 sub build_authorized_values_list {
165 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
167 my @authorised_values;
170 # builds list, depending on authorised value...
173 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
174 my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
175 while ( my $l = $libraries->next ) {
176 push @authorised_values, $l->branchcode;;
177 $authorised_lib{$l->branchcode} = $l->branchname;
180 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
181 push @authorised_values, "";
184 my $itemtypes = Koha::ItemTypes->search_with_localization;
185 while ( $itemtype = $itemtypes->next ) {
186 push @authorised_values, $itemtype->itemtype;
187 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
189 $value = $itemtype unless ($value);
191 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
192 push @authorised_values, "";
194 my $class_sources = GetClassSources();
196 my $default_source = C4::Context->preference("DefaultClassificationSource");
198 foreach my $class_source (sort keys %$class_sources) {
199 next unless $class_sources->{$class_source}->{'used'} or
200 ($value and $class_source eq $value) or
201 ($class_source eq $default_source);
202 push @authorised_values, $class_source;
203 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
205 $value = $default_source unless $value;
208 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
209 $authorised_values_sth->execute(
210 $tagslib->{$tag}->{$subfield}->{authorised_value},
211 $branch_limit ? $branch_limit : (),
214 push @authorised_values, "";
216 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
217 push @authorised_values, $value;
218 $authorised_lib{$value} = $lib;
221 $authorised_values_sth->finish;
224 id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
225 name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
227 values => \@authorised_values,
228 labels => \%authorised_lib,
235 Create a random value to set it into the input name
240 return int(rand(1000000));
243 =head2 GetMandatoryFieldZ3950
245 This function returns a hashref which contains all mandatory field
246 to search with z3950 server.
250 sub GetMandatoryFieldZ3950 {
251 my $frameworkcode = shift;
252 my @isbn = GetMarcFromKohaField( 'biblioitems.isbn' );
253 my @title = GetMarcFromKohaField( 'biblio.title' );
254 my @author = GetMarcFromKohaField( 'biblio.author' );
255 my @issn = GetMarcFromKohaField( 'biblioitems.issn' );
256 my @lccn = GetMarcFromKohaField( 'biblioitems.lccn' );
259 $isbn[0].$isbn[1] => 'isbn',
260 $title[0].$title[1] => 'title',
261 $author[0].$author[1] => 'author',
262 $issn[0].$issn[1] => 'issn',
263 $lccn[0].$lccn[1] => 'lccn',
269 builds the <input ...> entry for a subfield.
274 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
276 my $index_subfield = CreateKey(); # create a specifique key for each subfield
278 # if there is no value provided but a default value in parameters, get it
279 if ( $value eq '' ) {
280 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{};
282 # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
283 my $today_dt = dt_from_string;
284 my $year = $today_dt->strftime('%Y');
285 my $month = $today_dt->strftime('%m');
286 my $day = $today_dt->strftime('%d');
287 $value =~ s/<<YYYY>>/$year/g;
288 $value =~ s/<<MM>>/$month/g;
289 $value =~ s/<<DD>>/$day/g;
290 # And <<USER>> with surname (?)
291 my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
292 $value=~s/<<USER>>/$username/g;
295 my $dbh = C4::Context->dbh;
297 # map '@' as "subfield" label for fixed fields
298 # to something that's allowed in a div id.
299 my $id_subfield = $subfield;
300 $id_subfield = "00" if $id_subfield eq "@";
302 my %subfield_data = (
304 subfield => $id_subfield,
305 marc_lib => $tagslib->{$tag}->{$subfield}->{lib},
306 tag_mandatory => $tagslib->{$tag}->{mandatory},
307 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
308 important => $tagslib->{$tag}->{$subfield}->{important},
309 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
310 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
312 id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
314 maxlength => $tagslib->{$tag}->{$subfield}->{maxlength},
315 random => CreateKey(),
318 if(exists $mandatory_z3950->{$tag.$subfield}){
319 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
321 # Subfield is hidden depending of hidden and mandatory flag, and is always
322 # shown if it contains anything or if its field is mandatory or important.
323 my $tdef = $tagslib->{$tag};
324 $subfield_data{visibility} = "display:none;"
325 if $tdef->{$subfield}->{hidden} % 2 == 1 &&
327 !$tdef->{$subfield}->{mandatory} &&
328 !$tdef->{mandatory} &&
329 !$tdef->{$subfield}->{important} &&
331 # expand all subfields of 773 if there is a host item provided in the input
332 $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
335 # it's an authorised field
336 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
337 $subfield_data{marc_value} =
338 build_authorized_values_list( $tag, $subfield, $value, $dbh,
339 $authorised_values_sth,$index_tag,$index_subfield );
341 # it's a subfield $9 linking to an authority record - see bug 2206
343 elsif ($subfield eq "9" and
344 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
345 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
346 $tagslib->{$tag}->{'a'}->{authtypecode} ne '') {
348 $subfield_data{marc_value} = {
350 id => $subfield_data{id},
351 name => $subfield_data{id},
354 maxlength => $subfield_data{maxlength},
358 # it's a thesaurus / authority field
360 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
361 # when authorities auto-creation is allowed, do not set readonly
362 my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities");
364 $subfield_data{marc_value} = {
366 id => $subfield_data{id},
367 name => $subfield_data{id},
370 maxlength => $subfield_data{maxlength},
371 readonly => ($is_readonly) ? 1 : 0,
372 authtype => $tagslib->{$tag}->{$subfield}->{authtypecode},
375 # it's a plugin field
376 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
377 require Koha::FrameworkPlugin;
378 my $plugin = Koha::FrameworkPlugin->new( {
379 name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
381 my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
382 id => $subfield_data{id}, tabloop => $tabloop };
383 $plugin->build( $pars );
384 if( !$plugin->errstr ) {
385 $subfield_data{marc_value} = {
386 type => 'text_complex',
387 id => $subfield_data{id},
388 name => $subfield_data{id},
391 maxlength => $subfield_data{maxlength},
392 javascript => $plugin->javascript,
393 plugin => $plugin->name,
394 noclick => $plugin->noclick,
397 warn $plugin->errstr;
398 # supply default input form
399 $subfield_data{marc_value} = {
401 id => $subfield_data{id},
402 name => $subfield_data{id},
405 maxlength => $subfield_data{maxlength},
410 # it's an hidden field
411 } elsif ( $tag eq '' ) {
412 $subfield_data{marc_value} = {
414 id => $subfield_data{id},
415 name => $subfield_data{id},
418 maxlength => $subfield_data{maxlength},
423 # it's a standard field
427 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
428 and $tag < 400 && $subfield eq 'a' )
431 && C4::Context->preference("marcflavour") eq "MARC21" )
434 $subfield_data{marc_value} = {
436 id => $subfield_data{id},
437 name => $subfield_data{id},
443 $subfield_data{marc_value} = {
445 id => $subfield_data{id},
446 name => $subfield_data{id},
449 maxlength => $subfield_data{maxlength},
455 $subfield_data{'index_subfield'} = $index_subfield;
456 return \%subfield_data;
460 =head2 format_indicator
462 Translate indicator value for output form - specifically, map
463 indicator = ' ' to ''. This is for the convenience of a cataloger
464 using a mouse to select an indicator input.
468 sub format_indicator {
469 my $ind_value = shift;
470 return '' if not defined $ind_value;
471 return '' if $ind_value eq ' ';
476 my ( $template, $record, $dbh, $encoding,$input ) = @_;
482 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
483 my $query = "SELECT authorised_value, lib
484 FROM authorised_values";
485 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
486 $query .= " WHERE category = ?";
487 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
488 $query .= " GROUP BY authorised_value,lib ORDER BY lib, lib_opac";
489 my $authorised_values_sth = $dbh->prepare( $query );
491 # in this array, we will push all the 10 tabs
492 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
495 my @tab_data; # all tags to display
498 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
499 foreach my $used ( @$usedTagsLib ){
501 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
502 $seen{$used->{tagfield}}++;
504 if ( $used->{tab} > -1
505 && $used->{tab} >= $max_num_tab
506 && $used->{tagfield} ne $itemtag )
508 $max_num_tab = $used->{tab};
511 if($max_num_tab >= 9){
514 # loop through each tab 0 through 9
515 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
516 my @loop_data = (); #innerloop in the template.
518 foreach my $tag (sort @tab_data) {
521 my ($indicator1, $indicator2);
522 my $index_tag = CreateKey;
524 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
525 # if MARC::Record is empty => use tab as master loop.
526 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
528 if ( $tag ne '000' ) {
529 @fields = $record->field($tag);
532 push @fields, $record->leader(); # if tag == 000
534 # loop through each field
535 foreach my $field (@fields) {
539 my ( $value, $subfield );
540 if ( $tag ne '000' ) {
541 $value = $field->data();
548 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
550 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
551 'biblio.biblionumber' );
555 $tag, $subfield, $value, $index_tag, $tabloop, $record,
556 $authorised_values_sth,$input
561 my @subfields = $field->subfields();
562 foreach my $subfieldcount ( 0 .. $#subfields ) {
563 my $subfield = $subfields[$subfieldcount][0];
564 my $value = $subfields[$subfieldcount][1];
565 next if ( length $subfield != 1 );
566 next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
570 $tag, $subfield, $value, $index_tag, $tabloop,
571 $record, $authorised_values_sth,$input
577 # now, loop again to add parameter subfield that are not in the MARC::Record
578 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
580 next if ( length $subfield != 1 );
581 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
582 next if ( $tag < 10 );
584 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
585 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
586 and not ( $subfield eq "9" and
587 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
588 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
589 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
591 ; #check for visibility flag
592 # if subfield is $9 in a field whose $a is authority-controlled,
593 # always include in the form regardless of the hidden setting - bug 2206
594 next if ( defined( $field->subfield($subfield) ) );
598 $tag, $subfield, '', $index_tag, $tabloop, $record,
599 $authorised_values_sth,$input
603 if ( $#subfields_data >= 0 ) {
604 # build the tag entry.
605 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
606 # have twice the same "name" value, and cgi->param() will return only one, making
607 # all subfields to be merged in a single field.
611 tag_lib => $tagslib->{$tag}->{lib},
612 repeatable => $tagslib->{$tag}->{repeatable},
613 mandatory => $tagslib->{$tag}->{mandatory},
614 important => $tagslib->{$tag}->{important},
615 subfield_loop => \@subfields_data,
616 fixedfield => $tag < 10?1:0,
619 if ($tag >= 10){ # no indicator for 00x tags
620 $tag_data{indicator1} = format_indicator($field->indicator(1)),
621 $tag_data{indicator2} = format_indicator($field->indicator(2)),
623 push( @loop_data, \%tag_data );
625 } # foreach $field end
627 # if breeding is empty
631 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
632 next if ( length $subfield != 1 );
634 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
635 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
636 and not ( $subfield eq "9" and
637 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
638 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
639 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
641 ; #check for visibility flag
642 # if subfield is $9 in a field whose $a is authority-controlled,
643 # always include in the form regardless of the hidden setting - bug 2206
645 if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
649 $tag, $subfield, '', $index_tag, $tabloop, $record,
650 $authorised_values_sth,$input
654 if ( $#subfields_data >= 0 ) {
658 tag_lib => $tagslib->{$tag}->{lib},
659 repeatable => $tagslib->{$tag}->{repeatable},
660 mandatory => $tagslib->{$tag}->{mandatory},
661 important => $tagslib->{$tag}->{important},
662 indicator1 => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value
663 indicator2 => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency
664 subfield_loop => \@subfields_data,
665 tagfirstsubfield => $subfields_data[0],
666 fixedfield => $tag < 10?1:0,
669 push @loop_data, \%tag_data ;
673 if ( $#loop_data >= 0 ) {
676 innerloop => \@loop_data,
680 $authorised_values_sth->finish;
681 $template->param( BIG_LOOP => \@BIG_LOOP );
684 # ========================
686 #=========================
688 my $error = $input->param('error');
689 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
690 my $parentbiblio = $input->param('parentbiblionumber');
691 my $breedingid = $input->param('breedingid');
692 my $z3950 = $input->param('z3950');
693 my $op = $input->param('op') // q{};
694 my $mode = $input->param('mode');
695 my $frameworkcode = $input->param('frameworkcode');
696 my $redirect = $input->param('redirect');
697 my $searchid = $input->param('searchid');
698 my $dbh = C4::Context->dbh;
699 my $hostbiblionumber = $input->param('hostbiblionumber');
700 my $hostitemnumber = $input->param('hostitemnumber');
701 # fast cataloguing datas in transit
702 my $fa_circborrowernumber = $input->param('circborrowernumber');
703 my $fa_barcode = $input->param('barcode');
704 my $fa_branch = $input->param('branch');
705 my $fa_stickyduedate = $input->param('stickyduedate');
706 my $fa_duedatespec = $input->param('duedatespec');
708 my $userflags = 'edit_catalogue';
710 my $changed_framework = $input->param('changed_framework') // q{};
711 $frameworkcode = &GetFrameworkCode($biblionumber)
712 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
714 if ($frameworkcode eq 'FA'){
715 $userflags = 'fast_cataloging';
718 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
719 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
721 template_name => "cataloguing/addbiblio.tt",
724 flagsrequired => { editcatalogue => $userflags },
729 my $does_bib_exist = Koha::Biblios->find($biblionumber);
730 if (!defined $does_bib_exist){
731 $biblionumber = undef;
732 $template->param( bib_doesnt_exist => 1 );
736 if ($frameworkcode eq 'FA'){
737 # We need to grab and set some variables in the template for use on the additems screen
739 'circborrowernumber' => $fa_circborrowernumber,
740 'barcode' => $fa_barcode,
741 'branch' => $fa_branch,
742 'stickyduedate' => $fa_stickyduedate,
743 'duedatespec' => $fa_duedatespec,
745 } elsif ( $op ne "delete" &&
746 C4::Context->preference('EnableAdvancedCatalogingEditor') &&
747 C4::Auth::haspermission(C4::Context->userenv->{id},{'editcatalogue'=>'advanced_editor'}) &&
748 $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' &&
750 # Only use the advanced editor for non-fast-cataloging.
751 # breedingid is not handled because those would only come off a Z39.50
752 # search initiated by the basic editor.
753 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( ($op eq 'duplicate'?'#duplicate/':'#catalog/') . $biblionumber ) : '' ) );
757 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
759 frameworks => $frameworks,
760 breedingid => $breedingid,
764 $tagslib = &GetMarcStructure( 1, $frameworkcode );
765 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
766 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
772 $biblionumbertagfield,
773 $biblionumbertagsubfield,
774 $biblioitemnumtagfield,
775 $biblioitemnumtagsubfield,
779 if (($biblionumber) && !($breedingid)){
780 $record = GetMarcBiblio({ biblionumber => $biblionumber });
783 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
786 #populate hostfield if hostbiblionumber is available
787 if ($hostbiblionumber) {
788 my $marcflavour = C4::Context->preference("marcflavour");
789 $record = MARC::Record->new();
792 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
793 $record->append_fields($field);
796 # This is a child record
798 my $marcflavour = C4::Context->preference('marcflavour');
799 $record = MARC::Record->new();
800 SetMarcUnicodeFlag($record, $marcflavour);
801 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
803 $record->append_fields($hostfield);
811 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
812 $template->param( title => $title );
814 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
815 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
816 &GetMarcFromKohaField( "biblio.biblionumber" );
817 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
818 &GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
820 # search biblioitems value
821 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
822 $sth->execute($biblionumber);
823 ($biblioitemnumber) = $sth->fetchrow;
826 #-------------------------------------------------------------------------------------
827 if ( $op eq "addbiblio" ) {
828 #-------------------------------------------------------------------------------------
830 biblionumberdata => $biblionumber,
833 my @params = $input->multi_param();
834 $record = TransformHtmlToMarc( $input, 1 );
835 # check for a duplicate
836 my ( $duplicatebiblionumber, $duplicatetitle );
837 if ( !$is_a_modif ) {
838 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
840 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
841 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
842 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
845 ModBiblio( $record, $biblionumber, $frameworkcode );
848 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
850 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
851 if ($frameworkcode eq 'FA'){
852 print $input->redirect(
853 '/cgi-bin/koha/cataloguing/additem.pl?'
854 .'biblionumber='.$biblionumber
855 .'&frameworkcode='.$frameworkcode
856 .'&circborrowernumber='.$fa_circborrowernumber
857 .'&branch='.$fa_branch
858 .'&barcode='.uri_escape_utf8($fa_barcode)
859 .'&stickyduedate='.$fa_stickyduedate
860 .'&duedatespec='.$fa_duedatespec
865 print $input->redirect(
866 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
871 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
872 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
873 my $views = { C4::Search::enabled_staff_search_views };
874 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
875 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
876 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
877 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
878 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
879 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
881 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
886 elsif ($redirect eq "just_save"){
887 my $tab = $input->param('current_tab');
888 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
892 biblionumber => $biblionumber,
896 if ( $record ne '-1' ) {
897 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
898 $template->param( title => $title );
902 itemtype => $frameworkcode,
904 output_html_with_http_headers $input, $cookie, $template->output;
908 # it may be a duplicate, warn the user and do nothing
909 build_tabs ($template, $record, $dbh,$encoding,$input);
911 biblionumber => $biblionumber,
912 biblioitemnumber => $biblioitemnumber,
913 duplicatebiblionumber => $duplicatebiblionumber,
914 duplicatebibid => $duplicatebiblionumber,
915 duplicatetitle => $duplicatetitle,
919 elsif ( $op eq "delete" ) {
921 my $error = &DelBiblio($biblionumber);
923 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
924 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
928 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
932 #----------------------------------------------------------------------------
933 # If we're in a duplication case, we have to set to "" the biblionumber
934 # as we'll save the biblio as a new one.
936 biblionumberdata => $biblionumber,
939 if ( $op eq "duplicate" ) {
943 if($changed_framework eq "changed"){
944 $record = TransformHtmlToMarc( $input, 1 );
946 elsif( $record ne -1 ) {
947 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
949 my $uxml = $record->as_xml;
950 MARC::Record::default_record_format("UNIMARC")
951 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
952 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
956 build_tabs( $template, $record, $dbh, $encoding,$input );
958 biblionumber => $biblionumber,
959 biblionumbertagfield => $biblionumbertagfield,
960 biblionumbertagsubfield => $biblionumbertagsubfield,
961 biblioitemnumtagfield => $biblioitemnumtagfield,
962 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
963 biblioitemnumber => $biblioitemnumber,
964 hostbiblionumber => $hostbiblionumber,
965 hostitemnumber => $hostitemnumber
969 if ( $record ne '-1' ) {
970 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
971 $template->param( title => $title );
975 frameworkcode => $frameworkcode,
976 itemtype => $frameworkcode,
977 borrowernumber => $loggedinuser,
978 tab => scalar $input->param('tab')
980 $template->{'VARS'}->{'searchid'} = $searchid;
982 output_html_with_http_headers $input, $cookie, $template->output;