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',$frameworkcode);
253 my @title = GetMarcFromKohaField
('biblio.title',$frameworkcode);
254 my @author = GetMarcFromKohaField
('biblio.author',$frameworkcode);
255 my @issn = GetMarcFromKohaField
('biblioitems.issn',$frameworkcode);
256 my @lccn = GetMarcFromKohaField
('biblioitems.lccn',$frameworkcode);
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 $value =~ s/"/"/g;
280 # if there is no value provided but a default value in parameters, get it
281 if ( $value eq '' ) {
282 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue
} // q{};
284 # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
285 my $today_dt = dt_from_string
;
286 my $year = $today_dt->strftime('%Y');
287 my $month = $today_dt->strftime('%m');
288 my $day = $today_dt->strftime('%d');
289 $value =~ s/<<YYYY>>/$year/g;
290 $value =~ s/<<MM>>/$month/g;
291 $value =~ s/<<DD>>/$day/g;
292 # And <<USER>> with surname (?)
293 my $username=(C4
::Context
->userenv?C4
::Context
->userenv->{'surname'}:"superlibrarian");
294 $value=~s/<<USER>>/$username/g;
297 my $dbh = C4
::Context
->dbh;
299 # map '@' as "subfield" label for fixed fields
300 # to something that's allowed in a div id.
301 my $id_subfield = $subfield;
302 $id_subfield = "00" if $id_subfield eq "@";
304 my %subfield_data = (
306 subfield
=> $id_subfield,
307 marc_lib
=> $tagslib->{$tag}->{$subfield}->{lib
},
308 tag_mandatory
=> $tagslib->{$tag}->{mandatory
},
309 mandatory
=> $tagslib->{$tag}->{$subfield}->{mandatory
},
310 repeatable
=> $tagslib->{$tag}->{$subfield}->{repeatable
},
311 kohafield
=> $tagslib->{$tag}->{$subfield}->{kohafield
},
313 id
=> "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
315 maxlength
=> $tagslib->{$tag}->{$subfield}->{maxlength
},
316 random
=> CreateKey
(),
319 if(exists $mandatory_z3950->{$tag.$subfield}){
320 $subfield_data{z3950_mandatory
} = $mandatory_z3950->{$tag.$subfield};
322 # Subfield is hidden depending of hidden and mandatory flag, and is always
323 # shown if it contains anything or if its field is mandatory.
324 my $tdef = $tagslib->{$tag};
325 $subfield_data{visibility
} = "display:none;"
326 if $tdef->{$subfield}->{hidden
} % 2 == 1 &&
328 !$tdef->{$subfield}->{mandatory
} &&
330 # expand all subfields of 773 if there is a host item provided in the input
331 $subfield_data{visibility
} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
334 # it's an authorised field
335 if ( $tagslib->{$tag}->{$subfield}->{authorised_value
} ) {
336 $subfield_data{marc_value
} =
337 build_authorized_values_list
( $tag, $subfield, $value, $dbh,
338 $authorised_values_sth,$index_tag,$index_subfield );
340 # it's a subfield $9 linking to an authority record - see bug 2206
342 elsif ($subfield eq "9" and
343 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
344 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
345 $tagslib->{$tag}->{'a'}->{authtypecode
} ne '') {
347 $subfield_data{marc_value
} = {
349 id
=> $subfield_data{id
},
350 name
=> $subfield_data{id
},
353 maxlength
=> $subfield_data{maxlength
},
357 # it's a thesaurus / authority field
359 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode
} ) {
360 # when authorities auto-creation is allowed, do not set readonly
361 my $is_readonly = !C4
::Context
->preference("BiblioAddsAuthorities");
363 $subfield_data{marc_value
} = {
365 id
=> $subfield_data{id
},
366 name
=> $subfield_data{id
},
369 maxlength
=> $subfield_data{maxlength
},
370 readonly
=> ($is_readonly) ?
1 : 0,
371 authtype
=> $tagslib->{$tag}->{$subfield}->{authtypecode
},
374 # it's a plugin field
375 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
376 require Koha
::FrameworkPlugin
;
377 my $plugin = Koha
::FrameworkPlugin
->new( {
378 name
=> $tagslib->{$tag}->{$subfield}->{'value_builder'},
380 my $pars= { dbh
=> $dbh, record
=> $rec, tagslib
=> $tagslib,
381 id
=> $subfield_data{id
}, tabloop
=> $tabloop };
382 $plugin->build( $pars );
383 if( !$plugin->errstr ) {
384 $subfield_data{marc_value
} = {
385 type
=> 'text_complex',
386 id
=> $subfield_data{id
},
387 name
=> $subfield_data{id
},
390 maxlength
=> $subfield_data{maxlength
},
391 javascript
=> $plugin->javascript,
392 noclick
=> $plugin->noclick,
395 warn $plugin->errstr;
396 # supply default input form
397 $subfield_data{marc_value
} = {
399 id
=> $subfield_data{id
},
400 name
=> $subfield_data{id
},
403 maxlength
=> $subfield_data{maxlength
},
408 # it's an hidden field
409 } elsif ( $tag eq '' ) {
410 $subfield_data{marc_value
} = {
412 id
=> $subfield_data{id
},
413 name
=> $subfield_data{id
},
416 maxlength
=> $subfield_data{maxlength
},
421 # it's a standard field
425 ( C4
::Context
->preference("marcflavour") eq "UNIMARC" && $tag >= 300
426 and $tag < 400 && $subfield eq 'a' )
429 && C4
::Context
->preference("marcflavour") eq "MARC21" )
432 $subfield_data{marc_value
} = {
434 id
=> $subfield_data{id
},
435 name
=> $subfield_data{id
},
441 $subfield_data{marc_value
} = {
443 id
=> $subfield_data{id
},
444 name
=> $subfield_data{id
},
447 maxlength
=> $subfield_data{maxlength
},
453 $subfield_data{'index_subfield'} = $index_subfield;
454 return \
%subfield_data;
458 =head2 format_indicator
460 Translate indicator value for output form - specifically, map
461 indicator = ' ' to ''. This is for the convenience of a cataloger
462 using a mouse to select an indicator input.
466 sub format_indicator
{
467 my $ind_value = shift;
468 return '' if not defined $ind_value;
469 return '' if $ind_value eq ' ';
474 my ( $template, $record, $dbh, $encoding,$input ) = @_;
480 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
481 my $query = "SELECT authorised_value, lib
482 FROM authorised_values";
483 $query .= qq{ LEFT JOIN authorised_values_branches ON
( id
= av_id
)} if $branch_limit;
484 $query .= " WHERE category = ?";
485 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
486 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
487 my $authorised_values_sth = $dbh->prepare( $query );
489 # in this array, we will push all the 10 tabs
490 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
493 my @tab_data; # all tags to display
495 foreach my $used ( @
$usedTagsLib ){
496 push @tab_data,$used->{tagfield
} if not $seen{$used->{tagfield
}};
497 $seen{$used->{tagfield
}}++;
501 foreach(@
$usedTagsLib){
502 if($_->{tab
} > -1 && $_->{tab
} >= $max_num_tab && $_->{tagfield
} != '995'){ # FIXME : MARC21 ?
503 $max_num_tab = $_->{tab
};
506 if($max_num_tab >= 9){
509 # loop through each tab 0 through 9
510 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
511 my @loop_data = (); #innerloop in the template.
513 foreach my $tag (@tab_data) {
516 my ($indicator1, $indicator2);
517 my $index_tag = CreateKey
;
519 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
520 # if MARC::Record is empty => use tab as master loop.
521 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
523 if ( $tag ne '000' ) {
524 @fields = $record->field($tag);
527 push @fields, $record->leader(); # if tag == 000
529 # loop through each field
530 foreach my $field (@fields) {
534 my ( $value, $subfield );
535 if ( $tag ne '000' ) {
536 $value = $field->data();
543 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
545 if ( $tagslib->{$tag}->{$subfield}->{kohafield
} eq
546 'biblio.biblionumber' );
550 $tag, $subfield, $value, $index_tag, $tabloop, $record,
551 $authorised_values_sth,$input
556 my @subfields = $field->subfields();
557 foreach my $subfieldcount ( 0 .. $#subfields ) {
558 my $subfield = $subfields[$subfieldcount][0];
559 my $value = $subfields[$subfieldcount][1];
560 next if ( length $subfield != 1 );
561 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
565 $tag, $subfield, $value, $index_tag, $tabloop,
566 $record, $authorised_values_sth,$input
572 # now, loop again to add parameter subfield that are not in the MARC::Record
573 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
575 next if ( length $subfield != 1 );
576 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
577 next if ( $tag < 10 );
579 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
580 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
581 and not ( $subfield eq "9" and
582 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
583 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
584 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
586 ; #check for visibility flag
587 # if subfield is $9 in a field whose $a is authority-controlled,
588 # always include in the form regardless of the hidden setting - bug 2206
589 next if ( defined( $field->subfield($subfield) ) );
593 $tag, $subfield, '', $index_tag, $tabloop, $record,
594 $authorised_values_sth,$input
598 if ( $#subfields_data >= 0 ) {
599 # build the tag entry.
600 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
601 # have twice the same "name" value, and cgi->param() will return only one, making
602 # all subfields to be merged in a single field.
606 tag_lib
=> $tagslib->{$tag}->{lib
},
607 repeatable
=> $tagslib->{$tag}->{repeatable
},
608 mandatory
=> $tagslib->{$tag}->{mandatory
},
609 subfield_loop
=> \
@subfields_data,
610 fixedfield
=> $tag < 10?
1:0,
613 if ($tag >= 10){ # no indicator for 00x tags
614 $tag_data{indicator1
} = format_indicator
($field->indicator(1)),
615 $tag_data{indicator2
} = format_indicator
($field->indicator(2)),
617 push( @loop_data, \
%tag_data );
619 } # foreach $field end
621 # if breeding is empty
625 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
626 next if ( length $subfield != 1 );
628 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
629 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
630 and not ( $subfield eq "9" and
631 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
632 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
633 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
635 ; #check for visibility flag
636 # if subfield is $9 in a field whose $a is authority-controlled,
637 # always include in the form regardless of the hidden setting - bug 2206
639 if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
643 $tag, $subfield, '', $index_tag, $tabloop, $record,
644 $authorised_values_sth,$input
648 if ( $#subfields_data >= 0 ) {
652 tag_lib
=> $tagslib->{$tag}->{lib
},
653 repeatable
=> $tagslib->{$tag}->{repeatable
},
654 mandatory
=> $tagslib->{$tag}->{mandatory
},
655 indicator1
=> ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue
} ), #if not set, try to load the default value
656 indicator2
=> ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue
} ), #use short-circuit operator for efficiency
657 subfield_loop
=> \
@subfields_data,
658 tagfirstsubfield
=> $subfields_data[0],
659 fixedfield
=> $tag < 10?
1:0,
662 push @loop_data, \
%tag_data ;
666 if ( $#loop_data >= 0 ) {
669 innerloop
=> \
@loop_data,
673 $authorised_values_sth->finish;
674 $template->param( BIG_LOOP
=> \
@BIG_LOOP );
677 # ========================
679 #=========================
681 my $error = $input->param('error');
682 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
683 my $parentbiblio = $input->param('parentbiblionumber');
684 my $breedingid = $input->param('breedingid');
685 my $z3950 = $input->param('z3950');
686 my $op = $input->param('op') // q{};
687 my $mode = $input->param('mode');
688 my $frameworkcode = $input->param('frameworkcode');
689 my $redirect = $input->param('redirect');
690 my $searchid = $input->param('searchid');
691 my $dbh = C4
::Context
->dbh;
692 my $hostbiblionumber = $input->param('hostbiblionumber');
693 my $hostitemnumber = $input->param('hostitemnumber');
694 # fast cataloguing datas in transit
695 my $fa_circborrowernumber = $input->param('circborrowernumber');
696 my $fa_barcode = $input->param('barcode');
697 my $fa_branch = $input->param('branch');
698 my $fa_stickyduedate = $input->param('stickyduedate');
699 my $fa_duedatespec = $input->param('duedatespec');
701 my $userflags = 'edit_catalogue';
703 my $changed_framework = $input->param('changed_framework') // q{};
704 $frameworkcode = &GetFrameworkCode
($biblionumber)
705 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
707 if ($frameworkcode eq 'FA'){
708 $userflags = 'fast_cataloging';
711 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
712 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
714 template_name
=> "cataloguing/addbiblio.tt",
717 authnotrequired
=> 0,
718 flagsrequired
=> { editcatalogue
=> $userflags },
723 my $does_bib_exist = Koha
::Biblios
->find($biblionumber);
724 if (!defined $does_bib_exist){
725 $biblionumber = undef;
726 $template->param( bib_doesnt_exist
=> 1 );
730 if ($frameworkcode eq 'FA'){
731 # We need to grab and set some variables in the template for use on the additems screen
733 'circborrowernumber' => $fa_circborrowernumber,
734 'barcode' => $fa_barcode,
735 'branch' => $fa_branch,
736 'stickyduedate' => $fa_stickyduedate,
737 'duedatespec' => $fa_duedatespec,
739 } elsif ( $op ne "delete" && C4
::Context
->preference('EnableAdvancedCatalogingEditor') && $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' && !$breedingid ) {
740 # Only use the advanced editor for non-fast-cataloging.
741 # breedingid is not handled because those would only come off a Z39.50
742 # search initiated by the basic editor.
743 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ?
( '#catalog/' . $biblionumber ) : '' ) );
747 my $frameworks = Koha
::BiblioFrameworks
->search({}, { order_by
=> ['frameworktext'] });
749 frameworks
=> $frameworks,
750 breedingid
=> $breedingid,
754 $tagslib = &GetMarcStructure
( 1, $frameworkcode );
755 $usedTagsLib = &GetUsedMarcStructure
( $frameworkcode );
756 $mandatory_z3950 = GetMandatoryFieldZ3950
($frameworkcode);
762 $biblionumbertagfield,
763 $biblionumbertagsubfield,
764 $biblioitemnumtagfield,
765 $biblioitemnumtagsubfield,
769 if (($biblionumber) && !($breedingid)){
770 $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
773 ( $record, $encoding ) = MARCfindbreeding
( $breedingid ) ;
776 #populate hostfield if hostbiblionumber is available
777 if ($hostbiblionumber) {
778 my $marcflavour = C4
::Context
->preference("marcflavour");
779 $record = MARC
::Record
->new();
782 PrepHostMarcField
( $hostbiblionumber, $hostitemnumber, $marcflavour );
783 $record->append_fields($field);
786 # This is a child record
788 my $marcflavour = C4
::Context
->preference('marcflavour');
789 $record = MARC
::Record
->new();
790 SetMarcUnicodeFlag
($record, $marcflavour);
791 my $hostfield = prepare_host_field
($parentbiblio,$marcflavour);
793 $record->append_fields($hostfield);
801 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
802 $template->param( title
=> $title );
804 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
805 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
806 &GetMarcFromKohaField
( "biblio.biblionumber", $frameworkcode );
807 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
808 &GetMarcFromKohaField
( "biblioitems.biblioitemnumber", $frameworkcode );
810 # search biblioitems value
811 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
812 $sth->execute($biblionumber);
813 ($biblioitemnumber) = $sth->fetchrow;
816 #-------------------------------------------------------------------------------------
817 if ( $op eq "addbiblio" ) {
818 #-------------------------------------------------------------------------------------
820 biblionumberdata
=> $biblionumber,
823 my @params = $input->multi_param();
824 $record = TransformHtmlToMarc
( $input, 1 );
825 # check for a duplicate
826 my ( $duplicatebiblionumber, $duplicatetitle );
827 if ( !$is_a_modif ) {
828 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate
($record);
830 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
831 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
832 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
835 ModBiblio
( $record, $biblionumber, $frameworkcode );
838 ( $biblionumber, $oldbibitemnum ) = AddBiblio
( $record, $frameworkcode );
840 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
841 if ($frameworkcode eq 'FA'){
842 print $input->redirect(
843 '/cgi-bin/koha/cataloguing/additem.pl?'
844 .'biblionumber='.$biblionumber
845 .'&frameworkcode='.$frameworkcode
846 .'&circborrowernumber='.$fa_circborrowernumber
847 .'&branch='.$fa_branch
848 .'&barcode='.uri_escape_utf8
($fa_barcode)
849 .'&stickyduedate='.$fa_stickyduedate
850 .'&duedatespec='.$fa_duedatespec
855 print $input->redirect(
856 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
861 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
862 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
863 my $views = { C4
::Search
::enabled_staff_search_views
};
864 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
865 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
866 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
867 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
868 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
869 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
871 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
876 elsif ($redirect eq "just_save"){
877 my $tab = $input->param('current_tab');
878 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
882 biblionumber
=> $biblionumber,
886 if ( $record ne '-1' ) {
887 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
888 $template->param( title
=> $title );
892 itemtype
=> $frameworkcode,
894 output_html_with_http_headers
$input, $cookie, $template->output;
898 # it may be a duplicate, warn the user and do nothing
899 build_tabs
($template, $record, $dbh,$encoding,$input);
901 biblionumber
=> $biblionumber,
902 biblioitemnumber
=> $biblioitemnumber,
903 duplicatebiblionumber
=> $duplicatebiblionumber,
904 duplicatebibid
=> $duplicatebiblionumber,
905 duplicatetitle
=> $duplicatetitle,
909 elsif ( $op eq "delete" ) {
911 my $error = &DelBiblio
($biblionumber);
913 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
914 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
918 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
922 #----------------------------------------------------------------------------
923 # If we're in a duplication case, we have to set to "" the biblionumber
924 # as we'll save the biblio as a new one.
926 biblionumberdata
=> $biblionumber,
929 if ( $op eq "duplicate" ) {
933 if($changed_framework eq "changed"){
934 $record = TransformHtmlToMarc
( $input, 1 );
936 elsif( $record ne -1 ) {
937 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
939 my $uxml = $record->as_xml;
940 MARC
::Record
::default_record_format
("UNIMARC")
941 if ( C4
::Context
->preference("marcflavour") eq "UNIMARC" );
942 my $urecord = MARC
::Record
::new_from_xml
( $uxml, 'UTF-8' );
946 build_tabs
( $template, $record, $dbh, $encoding,$input );
948 biblionumber
=> $biblionumber,
949 biblionumbertagfield
=> $biblionumbertagfield,
950 biblionumbertagsubfield
=> $biblionumbertagsubfield,
951 biblioitemnumtagfield
=> $biblioitemnumtagfield,
952 biblioitemnumtagsubfield
=> $biblioitemnumtagsubfield,
953 biblioitemnumber
=> $biblioitemnumber,
954 hostbiblionumber
=> $hostbiblionumber,
955 hostitemnumber
=> $hostitemnumber
959 if ( $record ne '-1' ) {
960 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
961 $template->param( title
=> $title );
965 frameworkcode
=> $frameworkcode,
966 itemtype
=> $frameworkcode,
967 borrowernumber
=> $loggedinuser,
968 tab
=> scalar $input->param('tab')
970 $template->{'VARS'}->{'searchid'} = $searchid;
972 output_html_with_http_headers
$input, $cookie, $template->output;