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>.
24 #use warnings; FIXME - Bug 2505
30 use C4::AuthoritiesMarc;
38 use Koha::BiblioFrameworks;
44 use Koha::BiblioFrameworks;
46 use Date::Calc qw(Today);
47 use MARC::File::USMARC;
51 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
52 MARC::File::XML->default_record_format('UNIMARC');
55 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
59 =head2 MARCfindbreeding
61 $record = MARCfindbreeding($breedingid);
63 Look up the import record repository for the record with
64 record with id $breedingid. If found, returns the decoded
65 MARC::Record; otherwise, -1 is returned (FIXME).
66 Returns as second parameter the character encoding.
70 sub MARCfindbreeding {
72 my ($marc, $encoding) = GetImportRecordMarc($id);
73 # remove the - in isbn, koha store isbn without any -
75 my $record = MARC::Record->new_from_usmarc($marc);
76 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn','');
77 if ( $record->field($isbnfield) ) {
78 foreach my $field ( $record->field($isbnfield) ) {
79 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
80 my $newisbn = $field->subfield($isbnsubfield);
82 $field->update( $isbnsubfield => $newisbn );
86 # fix the unimarc 100 coded field (with unicode information)
87 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
88 my $f100a=$record->subfield(100,'a');
89 my $f100 = $record->field(100);
90 my $f100temp = $f100->as_string;
91 $record->delete_field($f100);
92 if ( length($f100temp) > 28 ) {
93 substr( $f100temp, 26, 2, "50" );
94 $f100->update( 'a' => $f100temp );
95 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
96 $record->insert_fields_ordered($f100);
100 if ( !defined(ref($record)) ) {
104 # normalize author : UNIMARC specific...
105 if ( C4::Context->preference("z3950NormalizeAuthor")
106 and C4::Context->preference("z3950AuthorAuthFields")
107 and C4::Context->preference("marcflavour") eq 'UNIMARC' )
109 my ( $tag, $subfield ) = GetMarcFromKohaField("biblio.author", '');
111 # my $summary = C4::Context->preference("z3950authortemplate");
113 C4::Context->preference("z3950AuthorAuthFields");
114 my @auth_fields = split /,/, $auth_fields;
117 if ( $record->field($tag) ) {
118 foreach my $tmpfield ( $record->field($tag)->subfields ) {
120 # foreach my $subfieldcode ($tmpfield->subfields){
121 my $subfieldcode = shift @$tmpfield;
122 my $subfieldvalue = shift @$tmpfield;
124 $field->add_subfields(
125 "$subfieldcode" => $subfieldvalue )
126 if ( $subfieldcode ne $subfield );
130 MARC::Field->new( $tag, "", "",
131 $subfieldcode => $subfieldvalue )
132 if ( $subfieldcode ne $subfield );
136 $record->delete_field( $record->field($tag) );
137 foreach my $fieldtag (@auth_fields) {
138 next unless ( $record->field($fieldtag) );
139 my $lastname = $record->field($fieldtag)->subfield('a');
140 my $firstname = $record->field($fieldtag)->subfield('b');
141 my $title = $record->field($fieldtag)->subfield('c');
142 my $number = $record->field($fieldtag)->subfield('d');
145 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
146 $field->add_subfields(
147 "$subfield" => ucfirst($title) . " "
148 . ucfirst($firstname) . " "
153 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
154 $field->add_subfields(
155 "$subfield" => ucfirst($firstname) . ", "
156 . ucfirst($lastname) );
159 $record->insert_fields_ordered($field);
161 return $record, $encoding;
167 =head2 build_authorized_values_list
171 sub build_authorized_values_list {
172 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
174 my @authorised_values;
177 # builds list, depending on authorised value...
180 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
181 my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
182 while ( my $l = $libraries->next ) {
183 push @authorised_values, $l->branchcode;;
184 $authorised_lib{$l->branchcode} = $l->branchname;
187 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
188 push @authorised_values, ""
189 unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
190 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
193 my $itemtypes = Koha::ItemTypes->search_with_localization;
194 while ( $itemtype = $itemtypes->next ) {
195 push @authorised_values, $itemtype->itemtype;
196 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
198 $value = $itemtype unless ($value);
200 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
201 push @authorised_values, ""
202 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
204 my $class_sources = GetClassSources();
206 my $default_source = C4::Context->preference("DefaultClassificationSource");
208 foreach my $class_source (sort keys %$class_sources) {
209 next unless $class_sources->{$class_source}->{'used'} or
210 ($value and $class_source eq $value) or
211 ($class_source eq $default_source);
212 push @authorised_values, $class_source;
213 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
215 $value = $default_source unless $value;
218 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
219 $authorised_values_sth->execute(
220 $tagslib->{$tag}->{$subfield}->{authorised_value},
221 $branch_limit ? $branch_limit : (),
224 push @authorised_values, ""
225 unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
226 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
228 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
229 push @authorised_values, $value;
230 $authorised_lib{$value} = $lib;
233 $authorised_values_sth->finish;
236 id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
237 name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
239 values => \@authorised_values,
240 labels => \%authorised_lib,
247 Create a random value to set it into the input name
252 return int(rand(1000000));
255 =head2 GetMandatoryFieldZ3950
257 This function returns a hashref which contains all mandatory field
258 to search with z3950 server.
262 sub GetMandatoryFieldZ3950 {
263 my $frameworkcode = shift;
264 my @isbn = GetMarcFromKohaField('biblioitems.isbn',$frameworkcode);
265 my @title = GetMarcFromKohaField('biblio.title',$frameworkcode);
266 my @author = GetMarcFromKohaField('biblio.author',$frameworkcode);
267 my @issn = GetMarcFromKohaField('biblioitems.issn',$frameworkcode);
268 my @lccn = GetMarcFromKohaField('biblioitems.lccn',$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',
275 $lccn[0].$lccn[1] => 'lccn',
281 builds the <input ...> entry for a subfield.
286 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
288 my $index_subfield = CreateKey(); # create a specifique key for each subfield
290 $value =~ s/"/"/g;
292 # if there is no value provided but a default value in parameters, get it
293 if ( $value eq '' ) {
294 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
296 # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
297 my $today_dt = dt_from_string;
298 my $year = $today_dt->strftime('%Y');
299 my $month = $today_dt->strftime('%m');
300 my $day = $today_dt->strftime('%d');
301 $value =~ s/<<YYYY>>/$year/g;
302 $value =~ s/<<MM>>/$month/g;
303 $value =~ s/<<DD>>/$day/g;
304 # And <<USER>> with surname (?)
305 my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
306 $value=~s/<<USER>>/$username/g;
309 my $dbh = C4::Context->dbh;
311 # map '@' as "subfield" label for fixed fields
312 # to something that's allowed in a div id.
313 my $id_subfield = $subfield;
314 $id_subfield = "00" if $id_subfield eq "@";
316 my %subfield_data = (
318 subfield => $id_subfield,
319 marc_lib => $tagslib->{$tag}->{$subfield}->{lib},
320 tag_mandatory => $tagslib->{$tag}->{mandatory},
321 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
322 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
323 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
325 id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
327 maxlength => $tagslib->{$tag}->{$subfield}->{maxlength},
328 random => CreateKey(),
331 if(exists $mandatory_z3950->{$tag.$subfield}){
332 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
334 # Subfield is hidden depending of hidden and mandatory flag, and is always
335 # shown if it contains anything or if its field is mandatory.
336 my $tdef = $tagslib->{$tag};
337 $subfield_data{visibility} = "display:none;"
338 if $tdef->{$subfield}->{hidden} % 2 == 1 &&
340 !$tdef->{$subfield}->{mandatory} &&
342 # expand all subfields of 773 if there is a host item provided in the input
343 $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
346 # it's an authorised field
347 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
348 $subfield_data{marc_value} =
349 build_authorized_values_list( $tag, $subfield, $value, $dbh,
350 $authorised_values_sth,$index_tag,$index_subfield );
352 # it's a subfield $9 linking to an authority record - see bug 2206
354 elsif ($subfield eq "9" and
355 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
356 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
357 $tagslib->{$tag}->{'a'}->{authtypecode} ne '') {
359 $subfield_data{marc_value} = {
361 id => $subfield_data{id},
362 name => $subfield_data{id},
365 maxlength => $subfield_data{maxlength},
369 # it's a thesaurus / authority field
371 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
372 # when authorities auto-creation is allowed, do not set readonly
373 my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities");
375 $subfield_data{marc_value} = {
377 id => $subfield_data{id},
378 name => $subfield_data{id},
381 maxlength => $subfield_data{maxlength},
382 readonly => ($is_readonly) ? 1 : 0,
383 authtype => $tagslib->{$tag}->{$subfield}->{authtypecode},
386 # it's a plugin field
387 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
388 require Koha::FrameworkPlugin;
389 my $plugin = Koha::FrameworkPlugin->new( {
390 name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
392 my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
393 id => $subfield_data{id}, tabloop => $tabloop };
394 $plugin->build( $pars );
395 if( !$plugin->errstr ) {
396 $subfield_data{marc_value} = {
397 type => 'text_complex',
398 id => $subfield_data{id},
399 name => $subfield_data{id},
402 maxlength => $subfield_data{maxlength},
403 javascript => $plugin->javascript,
404 noclick => $plugin->noclick,
407 warn $plugin->errstr;
408 # supply default input form
409 $subfield_data{marc_value} = {
411 id => $subfield_data{id},
412 name => $subfield_data{id},
415 maxlength => $subfield_data{maxlength},
420 # it's an hidden field
421 } elsif ( $tag eq '' ) {
422 $subfield_data{marc_value} = {
424 id => $subfield_data{id},
425 name => $subfield_data{id},
428 maxlength => $subfield_data{maxlength},
433 # it's a standard field
437 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
438 and $tag < 400 && $subfield eq 'a' )
441 && C4::Context->preference("marcflavour") eq "MARC21" )
444 $subfield_data{marc_value} = {
446 id => $subfield_data{id},
447 name => $subfield_data{id},
453 $subfield_data{marc_value} = {
455 id => $subfield_data{id},
456 name => $subfield_data{id},
459 maxlength => $subfield_data{maxlength},
465 $subfield_data{'index_subfield'} = $index_subfield;
466 return \%subfield_data;
470 =head2 format_indicator
472 Translate indicator value for output form - specifically, map
473 indicator = ' ' to ''. This is for the convenience of a cataloger
474 using a mouse to select an indicator input.
478 sub format_indicator {
479 my $ind_value = shift;
480 return '' if not defined $ind_value;
481 return '' if $ind_value eq ' ';
486 my ( $template, $record, $dbh, $encoding,$input ) = @_;
492 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
493 my $query = "SELECT authorised_value, lib
494 FROM authorised_values";
495 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
496 $query .= " WHERE category = ?";
497 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
498 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
499 my $authorised_values_sth = $dbh->prepare( $query );
501 # in this array, we will push all the 10 tabs
502 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
505 my @tab_data; # all tags to display
507 foreach my $used ( @$usedTagsLib ){
508 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
509 $seen{$used->{tagfield}}++;
513 foreach(@$usedTagsLib){
514 if($_->{tab} > -1 && $_->{tab} >= $max_num_tab && $_->{tagfield} != '995'){ # FIXME : MARC21 ?
515 $max_num_tab = $_->{tab};
518 if($max_num_tab >= 9){
521 # loop through each tab 0 through 9
522 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
523 my @loop_data = (); #innerloop in the template.
525 foreach my $tag (@tab_data) {
528 my ($indicator1, $indicator2);
529 my $index_tag = CreateKey;
531 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
532 # if MARC::Record is empty => use tab as master loop.
533 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
535 if ( $tag ne '000' ) {
536 @fields = $record->field($tag);
539 push @fields, $record->leader(); # if tag == 000
541 # loop through each field
542 foreach my $field (@fields) {
546 my ( $value, $subfield );
547 if ( $tag ne '000' ) {
548 $value = $field->data();
555 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
557 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
558 'biblio.biblionumber' );
562 $tag, $subfield, $value, $index_tag, $tabloop, $record,
563 $authorised_values_sth,$input
568 my @subfields = $field->subfields();
569 foreach my $subfieldcount ( 0 .. $#subfields ) {
570 my $subfield = $subfields[$subfieldcount][0];
571 my $value = $subfields[$subfieldcount][1];
572 next if ( length $subfield != 1 );
573 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
577 $tag, $subfield, $value, $index_tag, $tabloop,
578 $record, $authorised_values_sth,$input
584 # now, loop again to add parameter subfield that are not in the MARC::Record
585 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
587 next if ( length $subfield != 1 );
588 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
589 next if ( $tag < 10 );
591 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
592 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
593 and not ( $subfield eq "9" and
594 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
595 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
596 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
598 ; #check for visibility flag
599 # if subfield is $9 in a field whose $a is authority-controlled,
600 # always include in the form regardless of the hidden setting - bug 2206
601 next if ( defined( $field->subfield($subfield) ) );
605 $tag, $subfield, '', $index_tag, $tabloop, $record,
606 $authorised_values_sth,$input
610 if ( $#subfields_data >= 0 ) {
611 # build the tag entry.
612 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
613 # have twice the same "name" value, and cgi->param() will return only one, making
614 # all subfields to be merged in a single field.
618 tag_lib => $tagslib->{$tag}->{lib},
619 repeatable => $tagslib->{$tag}->{repeatable},
620 mandatory => $tagslib->{$tag}->{mandatory},
621 subfield_loop => \@subfields_data,
622 fixedfield => $tag < 10?1:0,
625 if ($tag >= 10){ # no indicator for 00x tags
626 $tag_data{indicator1} = format_indicator($field->indicator(1)),
627 $tag_data{indicator2} = format_indicator($field->indicator(2)),
629 push( @loop_data, \%tag_data );
631 } # foreach $field end
633 # if breeding is empty
637 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
638 next if ( length $subfield != 1 );
640 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
641 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
642 and not ( $subfield eq "9" and
643 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
644 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
645 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
647 ; #check for visibility flag
648 # if subfield is $9 in a field whose $a is authority-controlled,
649 # always include in the form regardless of the hidden setting - bug 2206
651 if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
655 $tag, $subfield, '', $index_tag, $tabloop, $record,
656 $authorised_values_sth,$input
660 if ( $#subfields_data >= 0 ) {
664 tag_lib => $tagslib->{$tag}->{lib},
665 repeatable => $tagslib->{$tag}->{repeatable},
666 mandatory => $tagslib->{$tag}->{mandatory},
667 indicator1 => $indicator1,
668 indicator2 => $indicator2,
669 subfield_loop => \@subfields_data,
670 tagfirstsubfield => $subfields_data[0],
671 fixedfield => $tag < 10?1:0,
674 push @loop_data, \%tag_data ;
678 if ( $#loop_data >= 0 ) {
681 innerloop => \@loop_data,
685 $authorised_values_sth->finish;
686 $template->param( BIG_LOOP => \@BIG_LOOP );
689 # ========================
691 #=========================
693 my $error = $input->param('error');
694 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
695 my $parentbiblio = $input->param('parentbiblionumber');
696 my $breedingid = $input->param('breedingid');
697 my $z3950 = $input->param('z3950');
698 my $op = $input->param('op');
699 my $mode = $input->param('mode');
700 my $frameworkcode = $input->param('frameworkcode');
701 my $redirect = $input->param('redirect');
702 my $searchid = $input->param('searchid');
703 my $dbh = C4::Context->dbh;
704 my $hostbiblionumber = $input->param('hostbiblionumber');
705 my $hostitemnumber = $input->param('hostitemnumber');
706 # fast cataloguing datas in transit
707 my $fa_circborrowernumber = $input->param('circborrowernumber');
708 my $fa_barcode = $input->param('barcode');
709 my $fa_branch = $input->param('branch');
710 my $fa_stickyduedate = $input->param('stickyduedate');
711 my $fa_duedatespec = $input->param('duedatespec');
713 my $userflags = 'edit_catalogue';
715 my $changed_framework = $input->param('changed_framework');
716 $frameworkcode = &GetFrameworkCode($biblionumber)
717 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
719 if ($frameworkcode eq 'FA'){
720 $userflags = 'fast_cataloging';
723 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
724 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
726 template_name => "cataloguing/addbiblio.tt",
729 authnotrequired => 0,
730 flagsrequired => { editcatalogue => $userflags },
735 my $does_bib_exist = Koha::Biblios->find($biblionumber);
736 if (!defined $does_bib_exist){
737 $biblionumber = undef;
738 $template->param( bib_doesnt_exist => 1 );
742 if ($frameworkcode eq 'FA'){
743 # We need to grab and set some variables in the template for use on the additems screen
745 'circborrowernumber' => $fa_circborrowernumber,
746 'barcode' => $fa_barcode,
747 'branch' => $fa_branch,
748 'stickyduedate' => $fa_stickyduedate,
749 'duedatespec' => $fa_duedatespec,
751 } elsif ( $op ne "delete" && C4::Context->preference('EnableAdvancedCatalogingEditor') && $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' && !$breedingid ) {
752 # Only use the advanced editor for non-fast-cataloging.
753 # breedingid is not handled because those would only come off a Z39.50
754 # search initiated by the basic editor.
755 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( '#catalog/' . $biblionumber ) : '' ) );
759 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
761 frameworks => $frameworks,
762 breedingid => $breedingid,
766 $tagslib = &GetMarcStructure( 1, $frameworkcode );
767 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
768 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
774 $biblionumbertagfield,
775 $biblionumbertagsubfield,
776 $biblioitemnumtagfield,
777 $biblioitemnumtagsubfield,
781 if (($biblionumber) && !($breedingid)){
782 $record = GetMarcBiblio({ biblionumber => $biblionumber });
785 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
788 #populate hostfield if hostbiblionumber is available
789 if ($hostbiblionumber) {
790 my $marcflavour = C4::Context->preference("marcflavour");
791 $record = MARC::Record->new();
794 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
795 $record->append_fields($field);
798 # This is a child record
800 my $marcflavour = C4::Context->preference('marcflavour');
801 $record = MARC::Record->new();
802 SetMarcUnicodeFlag($record, $marcflavour);
803 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
805 $record->append_fields($hostfield);
813 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
814 $template->param( title => $title );
816 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
817 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
818 &GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode );
819 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
820 &GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
822 # search biblioitems value
823 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
824 $sth->execute($biblionumber);
825 ($biblioitemnumber) = $sth->fetchrow;
828 #-------------------------------------------------------------------------------------
829 if ( $op eq "addbiblio" ) {
830 #-------------------------------------------------------------------------------------
832 biblionumberdata => $biblionumber,
835 my @params = $input->multi_param();
836 $record = TransformHtmlToMarc( $input, 1 );
837 # check for a duplicate
838 my ( $duplicatebiblionumber, $duplicatetitle );
839 if ( !$is_a_modif ) {
840 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
842 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
843 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
844 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
846 if (C4::Context->preference("BiblioAddsAuthorities")){
847 BiblioAutoLink( $record, $frameworkcode );
850 ModBiblio( $record, $biblionumber, $frameworkcode );
853 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
855 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
856 if ($frameworkcode eq 'FA'){
857 print $input->redirect(
858 '/cgi-bin/koha/cataloguing/additem.pl?'
859 .'biblionumber='.$biblionumber
860 .'&frameworkcode='.$frameworkcode
861 .'&circborrowernumber='.$fa_circborrowernumber
862 .'&branch='.$fa_branch
863 .'&barcode='.uri_escape_utf8($fa_barcode)
864 .'&stickyduedate='.$fa_stickyduedate
865 .'&duedatespec='.$fa_duedatespec
870 print $input->redirect(
871 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
876 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
877 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
878 my $views = { C4::Search::enabled_staff_search_views };
879 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
880 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
881 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
882 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
883 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
884 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
886 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
891 elsif ($redirect eq "just_save"){
892 my $tab = $input->param('current_tab');
893 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
897 biblionumber => $biblionumber,
901 if ( $record ne '-1' ) {
902 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
903 $template->param( title => $title );
907 itemtype => $frameworkcode,
909 output_html_with_http_headers $input, $cookie, $template->output;
913 # it may be a duplicate, warn the user and do nothing
914 build_tabs ($template, $record, $dbh,$encoding,$input);
916 biblionumber => $biblionumber,
917 biblioitemnumber => $biblioitemnumber,
918 duplicatebiblionumber => $duplicatebiblionumber,
919 duplicatebibid => $duplicatebiblionumber,
920 duplicatetitle => $duplicatetitle,
924 elsif ( $op eq "delete" ) {
926 my $error = &DelBiblio($biblionumber);
928 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
929 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
933 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
937 #----------------------------------------------------------------------------
938 # If we're in a duplication case, we have to set to "" the biblionumber
939 # as we'll save the biblio as a new one.
941 biblionumberdata => $biblionumber,
944 if ( $op eq "duplicate" ) {
948 if($changed_framework eq "changed"){
949 $record = TransformHtmlToMarc( $input, 1 );
951 elsif( $record ne -1 ) {
952 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
954 my $uxml = $record->as_xml;
955 MARC::Record::default_record_format("UNIMARC")
956 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
957 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
961 build_tabs( $template, $record, $dbh, $encoding,$input );
963 biblionumber => $biblionumber,
964 biblionumbertagfield => $biblionumbertagfield,
965 biblionumbertagsubfield => $biblionumbertagsubfield,
966 biblioitemnumtagfield => $biblioitemnumtagfield,
967 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
968 biblioitemnumber => $biblioitemnumber,
969 hostbiblionumber => $hostbiblionumber,
970 hostitemnumber => $hostitemnumber
974 if ( $record ne '-1' ) {
975 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
976 $template->param( title => $title );
980 frameworkcode => $frameworkcode,
981 itemtype => $frameworkcode,
982 borrowernumber => $loggedinuser,
983 tab => scalar $input->param('tab')
985 $template->{'VARS'}->{'searchid'} = $searchid;
987 output_html_with_http_headers $input, $cookie, $template->output;