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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #use warnings; FIXME - Bug 2505
29 use C4::AuthoritiesMarc;
33 use C4::Koha; # XXX subfield_is_koha_internal_p
34 use C4::Branch; # XXX subfield_is_koha_internal_p
39 use Date::Calc qw(Today);
40 use MARC::File::USMARC;
44 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
45 MARC::File::XML->default_record_format('UNIMARC');
48 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
52 =head2 MARCfindbreeding
54 $record = MARCfindbreeding($breedingid);
56 Look up the import record repository for the record with
57 record with id $breedingid. If found, returns the decoded
58 MARC::Record; otherwise, -1 is returned (FIXME).
59 Returns as second parameter the character encoding.
63 sub MARCfindbreeding {
65 my ($marc, $encoding) = GetImportRecordMarc($id);
66 # remove the - in isbn, koha store isbn without any -
68 my $record = MARC::Record->new_from_usmarc($marc);
69 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn','');
70 if ( $record->field($isbnfield) ) {
71 foreach my $field ( $record->field($isbnfield) ) {
72 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
73 my $newisbn = $field->subfield($isbnsubfield);
75 $field->update( $isbnsubfield => $newisbn );
79 # fix the unimarc 100 coded field (with unicode information)
80 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
81 my $f100a=$record->subfield(100,'a');
82 my $f100 = $record->field(100);
83 my $f100temp = $f100->as_string;
84 $record->delete_field($f100);
85 if ( length($f100temp) > 28 ) {
86 substr( $f100temp, 26, 2, "50" );
87 $f100->update( 'a' => $f100temp );
88 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
89 $record->insert_fields_ordered($f100);
93 if ( !defined(ref($record)) ) {
97 # normalize author : probably UNIMARC specific...
98 if ( C4::Context->preference("z3950NormalizeAuthor")
99 and C4::Context->preference("z3950AuthorAuthFields") )
101 my ( $tag, $subfield ) = GetMarcFromKohaField("biblio.author", '');
103 # my $summary = C4::Context->preference("z3950authortemplate");
105 C4::Context->preference("z3950AuthorAuthFields");
106 my @auth_fields = split /,/, $auth_fields;
109 if ( $record->field($tag) ) {
110 foreach my $tmpfield ( $record->field($tag)->subfields ) {
112 # foreach my $subfieldcode ($tmpfield->subfields){
113 my $subfieldcode = shift @$tmpfield;
114 my $subfieldvalue = shift @$tmpfield;
116 $field->add_subfields(
117 "$subfieldcode" => $subfieldvalue )
118 if ( $subfieldcode ne $subfield );
122 MARC::Field->new( $tag, "", "",
123 $subfieldcode => $subfieldvalue )
124 if ( $subfieldcode ne $subfield );
128 $record->delete_field( $record->field($tag) );
129 foreach my $fieldtag (@auth_fields) {
130 next unless ( $record->field($fieldtag) );
131 my $lastname = $record->field($fieldtag)->subfield('a');
132 my $firstname = $record->field($fieldtag)->subfield('b');
133 my $title = $record->field($fieldtag)->subfield('c');
134 my $number = $record->field($fieldtag)->subfield('d');
137 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
138 $field->add_subfields(
139 "$subfield" => ucfirst($title) . " "
140 . ucfirst($firstname) . " "
145 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
146 $field->add_subfields(
147 "$subfield" => ucfirst($firstname) . ", "
148 . ucfirst($lastname) );
151 $record->insert_fields_ordered($field);
153 return $record, $encoding;
159 =head2 build_authorized_values_list
163 sub build_authorized_values_list {
164 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
166 my @authorised_values;
169 # builds list, depending on authorised value...
172 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
173 #Use GetBranches($onlymine)
174 my $onlymine=C4::Context->preference('IndependantBranches') &&
175 C4::Context->userenv &&
176 C4::Context->userenv->{flags} % 2 == 0 &&
177 C4::Context->userenv->{branch};
178 my $branches = GetBranches($onlymine);
180 foreach my $thisbranch ( sort keys %$branches ) {
181 push @authorised_values, $thisbranch;
182 $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
187 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
190 "select itemtype,description from itemtypes order by description");
192 push @authorised_values, ""
193 unless ( $tagslib->{$tag}->{$subfield}->{defaultvalue} and $tagslib->{$tag}->{$subfield}->{mandatory} );
197 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
198 push @authorised_values, $itemtype;
199 $authorised_lib{$itemtype} = $description;
201 $value = $itemtype unless ($value);
205 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
206 push @authorised_values, ""
207 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
209 my $class_sources = GetClassSources();
211 my $default_source = C4::Context->preference("DefaultClassificationSource");
213 foreach my $class_source (sort keys %$class_sources) {
214 next unless $class_sources->{$class_source}->{'used'} or
215 ($value and $class_source eq $value) or
216 ($class_source eq $default_source);
217 push @authorised_values, $class_source;
218 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
220 $value = $default_source unless $value;
223 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
224 $authorised_values_sth->execute(
225 $tagslib->{$tag}->{$subfield}->{authorised_value},
226 $branch_limit ? $branch_limit : (),
229 push @authorised_values, ""
230 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
232 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
233 push @authorised_values, $value;
234 $authorised_lib{$value} = $lib;
237 $authorised_values_sth->finish;
238 return CGI::scrolling_list(
239 -name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
240 -values => \@authorised_values,
242 -labels => \%authorised_lib,
247 -id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
248 -class => "input_marceditor",
254 Create a random value to set it into the input name
259 return int(rand(1000000));
262 =head2 GetMandatoryFieldZ3950
264 This function return an hashref which containts all mandatory field
265 to search with z3950 server.
269 sub GetMandatoryFieldZ3950 {
270 my $frameworkcode = shift;
271 my @isbn = GetMarcFromKohaField('biblioitems.isbn',$frameworkcode);
272 my @title = GetMarcFromKohaField('biblio.title',$frameworkcode);
273 my @author = GetMarcFromKohaField('biblio.author',$frameworkcode);
274 my @issn = GetMarcFromKohaField('biblioitems.issn',$frameworkcode);
275 my @lccn = GetMarcFromKohaField('biblioitems.lccn',$frameworkcode);
278 $isbn[0].$isbn[1] => 'isbn',
279 $title[0].$title[1] => 'title',
280 $author[0].$author[1] => 'author',
281 $issn[0].$issn[1] => 'issn',
282 $lccn[0].$lccn[1] => 'lccn',
288 builds the <input ...> entry for a subfield.
293 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
295 my $index_subfield = CreateKey(); # create a specifique key for each subfield
297 $value =~ s/"/"/g;
299 # if there is no value provided but a default value in parameters, get it
300 if ( $value eq '' ) {
301 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
303 # get today date & replace YYYY, MM, DD if provided in the default value
304 my ( $year, $month, $day ) = Today();
305 $month = sprintf( "%02d", $month );
306 $day = sprintf( "%02d", $day );
307 $value =~ s/YYYY/$year/g;
308 $value =~ s/MM/$month/g;
309 $value =~ s/DD/$day/g;
310 my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
311 $value=~s/user/$username/g;
314 my $dbh = C4::Context->dbh;
316 # map '@' as "subfield" label for fixed fields
317 # to something that's allowed in a div id.
318 my $id_subfield = $subfield;
319 $id_subfield = "00" if $id_subfield eq "@";
321 my %subfield_data = (
323 subfield => $id_subfield,
324 marc_lib => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
325 marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib},
326 tag_mandatory => $tagslib->{$tag}->{mandatory},
327 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
328 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
329 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
331 id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
333 maxlength => $tagslib->{$tag}->{$subfield}->{maxlength},
334 random => CreateKey(),
337 if(exists $mandatory_z3950->{$tag.$subfield}){
338 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
340 # Subfield is hidden depending of hidden and mandatory flag, and is always
341 # shown if it contains anything or if its field is mandatory.
342 my $tdef = $tagslib->{$tag};
343 $subfield_data{visibility} = "display:none;"
344 if $tdef->{$subfield}->{hidden} % 2 == 1 &&
346 !$tdef->{$subfield}->{mandatory} &&
348 # expand all subfields of 773 if there is a host item provided in the input
349 $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
352 # it's an authorised field
353 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
354 $subfield_data{marc_value} =
355 build_authorized_values_list( $tag, $subfield, $value, $dbh,
356 $authorised_values_sth,$index_tag,$index_subfield );
358 # it's a subfield $9 linking to an authority record - see bug 2206
360 elsif ($subfield eq "9" and
361 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
362 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
363 $tagslib->{$tag}->{'a'}->{authtypecode} ne '') {
365 $subfield_data{marc_value} =
366 "<input type=\"text\"
367 id=\"".$subfield_data{id}."\"
368 name=\"".$subfield_data{id}."\"
370 class=\"input_marceditor readonly\"
373 maxlength=\"".$subfield_data{maxlength}."\"
374 readonly=\"readonly\"
377 # it's a thesaurus / authority field
379 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
380 # when authorities auto-creation is allowed, do not set readonly
381 my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities");
382 $subfield_data{marc_value} =
383 "<input type=\"text\"
384 id=\"".$subfield_data{id}."\"
385 name=\"".$subfield_data{id}."\"
387 class=\"input_marceditor readonly\"
390 maxlength=\"".$subfield_data{maxlength}."\"".
391 ($is_readonly ? "readonly=\"readonly\"" : "").
393 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot\"
394 onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode}."','biblio'); return false;\" tabindex=\"1\" title=\"Tag Editor\"><img src=\"/intranet-tmpl/prog/img/edit-tag.png\" alt=\"Tag Editor\" /></a></span>
396 # it's a plugin field
398 elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
400 # opening plugin. Just check whether we are on a developer computer on a production one
401 # (the cgidir differs)
402 my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
403 unless ( opendir( DIR, "$cgidir" ) ) {
404 $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
407 my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
409 my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
410 my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
412 $subfield_data{marc_value} =
413 "<input tabindex=\"1\"
415 id=\"".$subfield_data{id}."\"
416 name=\"".$subfield_data{id}."\"
418 class=\"input_marceditor\"
419 onfocus=\"Focus$function_name($index_tag)\"
421 maxlength=\"".$subfield_data{maxlength}."\"
422 onblur=\"Blur$function_name($index_tag); \" \/>
423 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" tabindex=\"1\" title=\"Tag Editor\"><img src=\"/intranet-tmpl/prog/img/edit-tag.png\" alt=\"Tag Editor\" /></a></span>
426 warn "Plugin Failed: $plugin";
427 # supply default input form
428 $subfield_data{marc_value} =
429 "<input type=\"text\"
430 id=\"".$subfield_data{id}."\"
431 name=\"".$subfield_data{id}."\"
435 maxlength=\"".$subfield_data{maxlength}."\"
436 class=\"input_marceditor\"
440 # it's an hidden field
442 elsif ( $tag eq '' ) {
443 $subfield_data{marc_value} =
444 "<input tabindex=\"1\"
446 id=\"".$subfield_data{id}."\"
447 name=\"".$subfield_data{id}."\"
449 maxlength=\"".$subfield_data{maxlength}."\"
454 # it's a standard field
458 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
459 and $tag < 400 && $subfield eq 'a' )
462 && C4::Context->preference("marcflavour") eq "MARC21" )
465 $subfield_data{marc_value} =
466 "<textarea cols=\"70\"
468 id=\"".$subfield_data{id}."\"
469 name=\"".$subfield_data{id}."\"
470 class=\"input_marceditor\"
476 $subfield_data{marc_value} =
477 "<input type=\"text\"
478 id=\"".$subfield_data{id}."\"
479 name=\"".$subfield_data{id}."\"
483 maxlength=\"".$subfield_data{maxlength}."\"
484 class=\"input_marceditor\"
489 $subfield_data{'index_subfield'} = $index_subfield;
490 return \%subfield_data;
494 =head2 format_indicator
496 Translate indicator value for output form - specifically, map
497 indicator = ' ' to ''. This is for the convenience of a cataloger
498 using a mouse to select an indicator input.
502 sub format_indicator {
503 my $ind_value = shift;
504 return '' if not defined $ind_value;
505 return '' if $ind_value eq ' ';
510 my ( $template, $record, $dbh, $encoding,$input ) = @_;
516 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
517 my $query = "SELECT authorised_value, lib
518 FROM authorised_values";
519 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
520 $query .= " WHERE category = ?";
521 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
522 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
523 my $authorised_values_sth = $dbh->prepare( $query );
525 # in this array, we will push all the 10 tabs
526 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
529 my @tab_data; # all tags to display
531 foreach my $used ( @$usedTagsLib ){
532 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
533 $seen{$used->{tagfield}}++;
537 foreach(@$usedTagsLib){
538 if($_->{tab} > -1 && $_->{tab} >= $max_num_tab && $_->{tagfield} != '995'){ # FIXME : MARC21 ?
539 $max_num_tab = $_->{tab};
542 if($max_num_tab >= 9){
545 # loop through each tab 0 through 9
546 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
547 my @loop_data = (); #innerloop in the template.
549 foreach my $tag (@tab_data) {
552 my ($indicator1, $indicator2);
553 my $index_tag = CreateKey;
555 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
556 # if MARC::Record is empty => use tab as master loop.
557 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
559 if ( $tag ne '000' ) {
560 @fields = $record->field($tag);
563 push @fields, $record->leader(); # if tag == 000
565 # loop through each field
566 foreach my $field (@fields) {
570 my ( $value, $subfield );
571 if ( $tag ne '000' ) {
572 $value = $field->data();
579 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
581 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
582 'biblio.biblionumber' );
586 $tag, $subfield, $value, $index_tag, $tabloop, $record,
587 $authorised_values_sth,$input
592 my @subfields = $field->subfields();
593 foreach my $subfieldcount ( 0 .. $#subfields ) {
594 my $subfield = $subfields[$subfieldcount][0];
595 my $value = $subfields[$subfieldcount][1];
596 next if ( length $subfield != 1 );
597 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
601 $tag, $subfield, $value, $index_tag, $tabloop,
602 $record, $authorised_values_sth,$input
608 # now, loop again to add parameter subfield that are not in the MARC::Record
609 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
611 next if ( length $subfield != 1 );
612 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
613 next if ( $tag < 10 );
615 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
616 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
617 and not ( $subfield eq "9" and
618 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
619 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
620 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
622 ; #check for visibility flag
623 # if subfield is $9 in a field whose $a is authority-controlled,
624 # always include in the form regardless of the hidden setting - bug 2206
625 next if ( defined( $field->subfield($subfield) ) );
629 $tag, $subfield, '', $index_tag, $tabloop, $record,
630 $authorised_values_sth,$input
634 if ( $#subfields_data >= 0 ) {
635 # build the tag entry.
636 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
637 # have twice the same "name" value, and cgi->param() will return only one, making
638 # all subfields to be merged in a single field.
642 tag_lib => $tagslib->{$tag}->{lib},
643 repeatable => $tagslib->{$tag}->{repeatable},
644 mandatory => $tagslib->{$tag}->{mandatory},
645 subfield_loop => \@subfields_data,
646 fixedfield => $tag < 10?1:0,
649 if ($tag >= 10){ # no indicator for 00x tags
650 $tag_data{indicator1} = format_indicator($field->indicator(1)),
651 $tag_data{indicator2} = format_indicator($field->indicator(2)),
653 push( @loop_data, \%tag_data );
655 } # foreach $field end
657 # if breeding is empty
661 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
662 next if ( length $subfield != 1 );
664 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
665 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
666 and not ( $subfield eq "9" and
667 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
668 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
669 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
671 ; #check for visibility flag
672 # if subfield is $9 in a field whose $a is authority-controlled,
673 # always include in the form regardless of the hidden setting - bug 2206
675 if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
679 $tag, $subfield, '', $index_tag, $tabloop, $record,
680 $authorised_values_sth,$input
684 if ( $#subfields_data >= 0 ) {
688 tag_lib => $tagslib->{$tag}->{lib},
689 repeatable => $tagslib->{$tag}->{repeatable},
690 mandatory => $tagslib->{$tag}->{mandatory},
691 indicator1 => $indicator1,
692 indicator2 => $indicator2,
693 subfield_loop => \@subfields_data,
694 tagfirstsubfield => $subfields_data[0],
695 fixedfield => $tag < 10?1:0,
698 push @loop_data, \%tag_data ;
702 if ( $#loop_data >= 0 ) {
705 innerloop => \@loop_data,
709 $authorised_values_sth->finish;
710 $template->param( BIG_LOOP => \@BIG_LOOP );
713 # ========================
715 #=========================
717 my $error = $input->param('error');
718 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
719 my $parentbiblio = $input->param('parentbiblionumber');
720 my $breedingid = $input->param('breedingid');
721 my $z3950 = $input->param('z3950');
722 my $op = $input->param('op');
723 my $mode = $input->param('mode');
724 my $frameworkcode = $input->param('frameworkcode');
725 my $redirect = $input->param('redirect');
726 my $dbh = C4::Context->dbh;
727 my $hostbiblionumber = $input->param('hostbiblionumber');
728 my $hostitemnumber = $input->param('hostitemnumber');
729 # fast cataloguing datas in transit
730 my $fa_circborrowernumber = $input->param('circborrowernumber');
731 my $fa_barcode = $input->param('barcode');
732 my $fa_branch = $input->param('branch');
733 my $fa_stickyduedate = $input->param('stickyduedate');
734 my $fa_duedatespec = $input->param('duedatespec');
736 my $userflags = 'edit_catalogue';
737 if ($frameworkcode eq 'FA'){
738 $userflags = 'fast_cataloging';
741 $frameworkcode = &GetFrameworkCode($biblionumber)
742 if ( $biblionumber and not($frameworkcode) and $op ne 'addbiblio' );
744 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
745 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
747 template_name => "cataloguing/addbiblio.tt",
750 authnotrequired => 0,
751 flagsrequired => { editcatalogue => $userflags },
755 if ($frameworkcode eq 'FA'){
756 # We need to grab and set some variables in the template for use on the additems screen
758 'circborrowernumber' => $fa_circborrowernumber,
759 'barcode' => $fa_barcode,
760 'branch' => $fa_branch,
761 'stickyduedate' => $fa_stickyduedate,
762 'duedatespec' => $fa_duedatespec,
766 # Getting the list of all frameworks
768 my $frameworks = getframeworks;
769 my @frameworkcodeloop;
770 foreach my $thisframeworkcode ( keys %$frameworks ) {
772 value => $thisframeworkcode,
773 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
775 if ($frameworkcode eq $thisframeworkcode){
776 $row{'selected'} = 1;
778 push @frameworkcodeloop, \%row;
780 $template->param( frameworkcodeloop => \@frameworkcodeloop,
781 breedingid => $breedingid );
784 $tagslib = &GetMarcStructure( 1, $frameworkcode );
785 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
786 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
792 $biblionumbertagfield,
793 $biblionumbertagsubfield,
794 $biblioitemnumtagfield,
795 $biblioitemnumtagsubfield,
800 if (($biblionumber) && !($breedingid)){
801 $record = GetMarcBiblio($biblionumber);
804 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
807 #populate hostfield if hostbiblionumber is available
808 if ($hostbiblionumber) {
809 my $marcflavour = C4::Context->preference("marcflavour");
810 $record = MARC::Record->new();
813 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
814 $record->append_fields($field);
817 # This is a child record
819 my $marcflavour = C4::Context->preference('marcflavour');
820 $record = MARC::Record->new();
821 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
823 $record->append_fields($hostfield);
831 $template->param( title => $record->title(), );
833 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
834 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
835 &GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode );
836 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
837 &GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
839 # search biblioitems value
840 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
841 $sth->execute($biblionumber);
842 ($biblioitemnumber) = $sth->fetchrow;
845 #-------------------------------------------------------------------------------------
846 if ( $op eq "addbiblio" ) {
847 #-------------------------------------------------------------------------------------
849 biblionumberdata => $biblionumber,
852 my @params = $input->param();
853 $record = TransformHtmlToMarc( $input );
854 # check for a duplicate
855 my ( $duplicatebiblionumber, $duplicatetitle );
856 if ( !$is_a_modif ) {
857 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
859 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
860 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
861 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
864 if (C4::Context->preference("BiblioAddsAuthorities")){
865 my ($countlinked,$countcreated)=BiblioAutoLink($record,$frameworkcode);
868 ModBiblioframework( $biblionumber, $frameworkcode );
869 ModBiblio( $record, $biblionumber, $frameworkcode );
872 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
874 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view")){
875 if ($frameworkcode eq 'FA'){
876 print $input->redirect(
877 '/cgi-bin/koha/cataloguing/additem.pl?'
878 .'biblionumber='.$biblionumber
879 .'&frameworkcode='.$frameworkcode
880 .'&circborrowernumber='.$fa_circborrowernumber
881 .'&branch='.$fa_branch
882 .'&barcode='.uri_escape($fa_barcode)
883 .'&stickyduedate='.$fa_stickyduedate
884 .'&duedatespec='.$fa_duedatespec
889 print $input->redirect(
890 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode"
895 elsif($is_a_modif || $redirect eq "view"){
896 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
897 my $views = { C4::Search::enabled_staff_search_views };
898 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
899 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber");
900 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
901 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
902 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
903 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber");
905 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber");
912 biblionumber => $biblionumber,
916 $template->param( title => $record->subfield('200',"a") ) if ($record ne "-1" && C4::Context->preference('marcflavour') =~/unimarc/i);
917 $template->param( title => $record->title() ) if ($record ne "-1" && C4::Context->preference('marcflavour') eq "usmarc");
920 itemtype => $frameworkcode,
922 output_html_with_http_headers $input, $cookie, $template->output;
926 # it may be a duplicate, warn the user and do nothing
927 build_tabs ($template, $record, $dbh,$encoding,$input);
929 biblionumber => $biblionumber,
930 biblioitemnumber => $biblioitemnumber,
931 duplicatebiblionumber => $duplicatebiblionumber,
932 duplicatebibid => $duplicatebiblionumber,
933 duplicatetitle => $duplicatetitle,
937 elsif ( $op eq "delete" ) {
939 my $error = &DelBiblio($biblionumber);
941 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
942 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
946 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
950 #----------------------------------------------------------------------------
951 # If we're in a duplication case, we have to set to "" the biblionumber
952 # as we'll save the biblio as a new one.
954 biblionumberdata => $biblionumber,
957 if ( $op eq "duplicate" ) {
961 if ( $record ne -1 ) {
962 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
964 my $uxml = $record->as_xml;
965 MARC::Record::default_record_format("UNIMARC")
966 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
967 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
971 build_tabs( $template, $record, $dbh, $encoding,$input );
973 biblionumber => $biblionumber,
974 biblionumbertagfield => $biblionumbertagfield,
975 biblionumbertagsubfield => $biblionumbertagsubfield,
976 biblioitemnumtagfield => $biblioitemnumtagfield,
977 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
978 biblioitemnumber => $biblioitemnumber,
979 hostbiblionumber => $hostbiblionumber,
980 hostitemnumber => $hostitemnumber
984 $template->param( title => $record->title() ) if ( $record ne "-1" );
987 frameworkcode => $frameworkcode,
988 itemtype => $frameworkcode,
989 borrowernumber => $loggedinuser,
992 output_html_with_http_headers $input, $cookie, $template->output;