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 : UNIMARC specific...
98 if ( C4::Context->preference("z3950NormalizeAuthor")
99 and C4::Context->preference("z3950AuthorAuthFields")
100 and C4::Context->preference("marcflavour") eq 'UNIMARC' )
102 my ( $tag, $subfield ) = GetMarcFromKohaField("biblio.author", '');
104 # my $summary = C4::Context->preference("z3950authortemplate");
106 C4::Context->preference("z3950AuthorAuthFields");
107 my @auth_fields = split /,/, $auth_fields;
110 if ( $record->field($tag) ) {
111 foreach my $tmpfield ( $record->field($tag)->subfields ) {
113 # foreach my $subfieldcode ($tmpfield->subfields){
114 my $subfieldcode = shift @$tmpfield;
115 my $subfieldvalue = shift @$tmpfield;
117 $field->add_subfields(
118 "$subfieldcode" => $subfieldvalue )
119 if ( $subfieldcode ne $subfield );
123 MARC::Field->new( $tag, "", "",
124 $subfieldcode => $subfieldvalue )
125 if ( $subfieldcode ne $subfield );
129 $record->delete_field( $record->field($tag) );
130 foreach my $fieldtag (@auth_fields) {
131 next unless ( $record->field($fieldtag) );
132 my $lastname = $record->field($fieldtag)->subfield('a');
133 my $firstname = $record->field($fieldtag)->subfield('b');
134 my $title = $record->field($fieldtag)->subfield('c');
135 my $number = $record->field($fieldtag)->subfield('d');
138 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
139 $field->add_subfields(
140 "$subfield" => ucfirst($title) . " "
141 . ucfirst($firstname) . " "
146 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
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 #Use GetBranches($onlymine)
176 C4::Context->preference('IndependentBranches')
177 && C4::Context->userenv
178 && !C4::Context->IsSuperLibrarian()
179 && C4::Context->userenv->{branch};
180 my $branches = GetBranches($onlymine);
182 foreach my $thisbranch ( sort keys %$branches ) {
183 push @authorised_values, $thisbranch;
184 $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
189 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
192 "select itemtype,description from itemtypes order by description");
194 push @authorised_values, ""
195 unless ( $tagslib->{$tag}->{$subfield}->{defaultvalue} and $tagslib->{$tag}->{$subfield}->{mandatory} );
199 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
200 push @authorised_values, $itemtype;
201 $authorised_lib{$itemtype} = $description;
203 $value = $itemtype unless ($value);
207 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
208 push @authorised_values, ""
209 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
211 my $class_sources = GetClassSources();
213 my $default_source = C4::Context->preference("DefaultClassificationSource");
215 foreach my $class_source (sort keys %$class_sources) {
216 next unless $class_sources->{$class_source}->{'used'} or
217 ($value and $class_source eq $value) or
218 ($class_source eq $default_source);
219 push @authorised_values, $class_source;
220 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
222 $value = $default_source unless $value;
225 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
226 $authorised_values_sth->execute(
227 $tagslib->{$tag}->{$subfield}->{authorised_value},
228 $branch_limit ? $branch_limit : (),
231 push @authorised_values, ""
232 unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
234 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
235 push @authorised_values, $value;
236 $authorised_lib{$value} = $lib;
239 $authorised_values_sth->finish;
240 return CGI::scrolling_list(
241 -name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
242 -values => \@authorised_values,
244 -labels => \%authorised_lib,
249 -id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
250 -class => "input_marceditor",
256 Create a random value to set it into the input name
261 return int(rand(1000000));
264 =head2 GetMandatoryFieldZ3950
266 This function return an hashref which containts all mandatory field
267 to search with z3950 server.
271 sub GetMandatoryFieldZ3950 {
272 my $frameworkcode = shift;
273 my @isbn = GetMarcFromKohaField('biblioitems.isbn',$frameworkcode);
274 my @title = GetMarcFromKohaField('biblio.title',$frameworkcode);
275 my @author = GetMarcFromKohaField('biblio.author',$frameworkcode);
276 my @issn = GetMarcFromKohaField('biblioitems.issn',$frameworkcode);
277 my @lccn = GetMarcFromKohaField('biblioitems.lccn',$frameworkcode);
280 $isbn[0].$isbn[1] => 'isbn',
281 $title[0].$title[1] => 'title',
282 $author[0].$author[1] => 'author',
283 $issn[0].$issn[1] => 'issn',
284 $lccn[0].$lccn[1] => 'lccn',
290 builds the <input ...> entry for a subfield.
295 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
297 my $index_subfield = CreateKey(); # create a specifique key for each subfield
299 $value =~ s/"/"/g;
301 # if there is no value provided but a default value in parameters, get it
302 if ( $value eq '' ) {
303 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
305 # get today date & replace YYYY, MM, DD if provided in the default value
306 my ( $year, $month, $day ) = Today();
307 $month = sprintf( "%02d", $month );
308 $day = sprintf( "%02d", $day );
309 $value =~ s/YYYY/$year/g;
310 $value =~ s/MM/$month/g;
311 $value =~ s/DD/$day/g;
312 my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
313 $value=~s/user/$username/g;
316 my $dbh = C4::Context->dbh;
318 # map '@' as "subfield" label for fixed fields
319 # to something that's allowed in a div id.
320 my $id_subfield = $subfield;
321 $id_subfield = "00" if $id_subfield eq "@";
323 my %subfield_data = (
325 subfield => $id_subfield,
326 marc_lib => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
327 marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib},
328 tag_mandatory => $tagslib->{$tag}->{mandatory},
329 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
330 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
331 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
333 id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
335 maxlength => $tagslib->{$tag}->{$subfield}->{maxlength},
336 random => CreateKey(),
339 if(exists $mandatory_z3950->{$tag.$subfield}){
340 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
342 # Subfield is hidden depending of hidden and mandatory flag, and is always
343 # shown if it contains anything or if its field is mandatory.
344 my $tdef = $tagslib->{$tag};
345 $subfield_data{visibility} = "display:none;"
346 if $tdef->{$subfield}->{hidden} % 2 == 1 &&
348 !$tdef->{$subfield}->{mandatory} &&
350 # expand all subfields of 773 if there is a host item provided in the input
351 $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
354 # it's an authorised field
355 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
356 $subfield_data{marc_value} =
357 build_authorized_values_list( $tag, $subfield, $value, $dbh,
358 $authorised_values_sth,$index_tag,$index_subfield );
360 # it's a subfield $9 linking to an authority record - see bug 2206
362 elsif ($subfield eq "9" and
363 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
364 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
365 $tagslib->{$tag}->{'a'}->{authtypecode} ne '') {
367 $subfield_data{marc_value} =
368 "<input type=\"text\"
369 id=\"".$subfield_data{id}."\"
370 name=\"".$subfield_data{id}."\"
372 class=\"input_marceditor readonly\"
375 maxlength=\"".$subfield_data{maxlength}."\"
376 readonly=\"readonly\"
379 # it's a thesaurus / authority field
381 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
382 # when authorities auto-creation is allowed, do not set readonly
383 my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities");
384 $subfield_data{marc_value} =
385 "<input type=\"text\"
386 id=\"".$subfield_data{id}."\"
387 name=\"".$subfield_data{id}."\"
389 class=\"input_marceditor readonly\"
392 maxlength=\"".$subfield_data{maxlength}."\"".
393 ($is_readonly ? "readonly=\"readonly\"" : "").
395 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\"
396 onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode}."','biblio'); return false;\" tabindex=\"1\">Tag editor</a></span>
398 # it's a plugin field
400 elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
402 # opening plugin. Just check whether we are on a developer computer on a production one
403 # (the cgidir differs)
404 my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
405 unless ( opendir( DIR, "$cgidir" ) ) {
406 $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
409 my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
411 my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
412 my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
414 $subfield_data{marc_value} =
415 "<input tabindex=\"1\"
417 id=\"".$subfield_data{id}."\"
418 name=\"".$subfield_data{id}."\"
420 class=\"input_marceditor\"
421 onfocus=\"Focus$function_name($index_tag)\"
423 maxlength=\"".$subfield_data{maxlength}."\"
424 onblur=\"Blur$function_name($index_tag); \" \/>
425 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" tabindex=\"1\">Tag editor</a></span>
428 warn "Plugin Failed: $plugin";
429 # supply default input form
430 $subfield_data{marc_value} =
431 "<input type=\"text\"
432 id=\"".$subfield_data{id}."\"
433 name=\"".$subfield_data{id}."\"
437 maxlength=\"".$subfield_data{maxlength}."\"
438 class=\"input_marceditor\"
442 # it's an hidden field
444 elsif ( $tag eq '' ) {
445 $subfield_data{marc_value} =
446 "<input tabindex=\"1\"
448 id=\"".$subfield_data{id}."\"
449 name=\"".$subfield_data{id}."\"
451 maxlength=\"".$subfield_data{maxlength}."\"
456 # it's a standard field
460 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
461 and $tag < 400 && $subfield eq 'a' )
464 && C4::Context->preference("marcflavour") eq "MARC21" )
467 $subfield_data{marc_value} =
468 "<textarea cols=\"70\"
470 id=\"".$subfield_data{id}."\"
471 name=\"".$subfield_data{id}."\"
472 class=\"input_marceditor\"
478 $subfield_data{marc_value} =
479 "<input type=\"text\"
480 id=\"".$subfield_data{id}."\"
481 name=\"".$subfield_data{id}."\"
485 maxlength=\"".$subfield_data{maxlength}."\"
486 class=\"input_marceditor\"
491 $subfield_data{'index_subfield'} = $index_subfield;
492 return \%subfield_data;
496 =head2 format_indicator
498 Translate indicator value for output form - specifically, map
499 indicator = ' ' to ''. This is for the convenience of a cataloger
500 using a mouse to select an indicator input.
504 sub format_indicator {
505 my $ind_value = shift;
506 return '' if not defined $ind_value;
507 return '' if $ind_value eq ' ';
512 my ( $template, $record, $dbh, $encoding,$input ) = @_;
518 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
519 my $query = "SELECT authorised_value, lib
520 FROM authorised_values";
521 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
522 $query .= " WHERE category = ?";
523 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
524 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
525 my $authorised_values_sth = $dbh->prepare( $query );
527 # in this array, we will push all the 10 tabs
528 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
531 my @tab_data; # all tags to display
533 foreach my $used ( @$usedTagsLib ){
534 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
535 $seen{$used->{tagfield}}++;
539 foreach(@$usedTagsLib){
540 if($_->{tab} > -1 && $_->{tab} >= $max_num_tab && $_->{tagfield} != '995'){ # FIXME : MARC21 ?
541 $max_num_tab = $_->{tab};
544 if($max_num_tab >= 9){
547 # loop through each tab 0 through 9
548 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
549 my @loop_data = (); #innerloop in the template.
551 foreach my $tag (@tab_data) {
554 my ($indicator1, $indicator2);
555 my $index_tag = CreateKey;
557 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
558 # if MARC::Record is empty => use tab as master loop.
559 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
561 if ( $tag ne '000' ) {
562 @fields = $record->field($tag);
565 push @fields, $record->leader(); # if tag == 000
567 # loop through each field
568 foreach my $field (@fields) {
572 my ( $value, $subfield );
573 if ( $tag ne '000' ) {
574 $value = $field->data();
581 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
583 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
584 'biblio.biblionumber' );
588 $tag, $subfield, $value, $index_tag, $tabloop, $record,
589 $authorised_values_sth,$input
594 my @subfields = $field->subfields();
595 foreach my $subfieldcount ( 0 .. $#subfields ) {
596 my $subfield = $subfields[$subfieldcount][0];
597 my $value = $subfields[$subfieldcount][1];
598 next if ( length $subfield != 1 );
599 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
603 $tag, $subfield, $value, $index_tag, $tabloop,
604 $record, $authorised_values_sth,$input
610 # now, loop again to add parameter subfield that are not in the MARC::Record
611 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
613 next if ( length $subfield != 1 );
614 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
615 next if ( $tag < 10 );
617 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
618 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
619 and not ( $subfield eq "9" and
620 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
621 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
622 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
624 ; #check for visibility flag
625 # if subfield is $9 in a field whose $a is authority-controlled,
626 # always include in the form regardless of the hidden setting - bug 2206
627 next if ( defined( $field->subfield($subfield) ) );
631 $tag, $subfield, '', $index_tag, $tabloop, $record,
632 $authorised_values_sth,$input
636 if ( $#subfields_data >= 0 ) {
637 # build the tag entry.
638 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
639 # have twice the same "name" value, and cgi->param() will return only one, making
640 # all subfields to be merged in a single field.
644 tag_lib => $tagslib->{$tag}->{lib},
645 repeatable => $tagslib->{$tag}->{repeatable},
646 mandatory => $tagslib->{$tag}->{mandatory},
647 subfield_loop => \@subfields_data,
648 fixedfield => $tag < 10?1:0,
651 if ($tag >= 10){ # no indicator for 00x tags
652 $tag_data{indicator1} = format_indicator($field->indicator(1)),
653 $tag_data{indicator2} = format_indicator($field->indicator(2)),
655 push( @loop_data, \%tag_data );
657 } # foreach $field end
659 # if breeding is empty
663 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
664 next if ( length $subfield != 1 );
666 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
667 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
668 and not ( $subfield eq "9" and
669 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
670 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
671 $tagslib->{$tag}->{'a'}->{authtypecode} ne ""
673 ; #check for visibility flag
674 # if subfield is $9 in a field whose $a is authority-controlled,
675 # always include in the form regardless of the hidden setting - bug 2206
677 if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
681 $tag, $subfield, '', $index_tag, $tabloop, $record,
682 $authorised_values_sth,$input
686 if ( $#subfields_data >= 0 ) {
690 tag_lib => $tagslib->{$tag}->{lib},
691 repeatable => $tagslib->{$tag}->{repeatable},
692 mandatory => $tagslib->{$tag}->{mandatory},
693 indicator1 => $indicator1,
694 indicator2 => $indicator2,
695 subfield_loop => \@subfields_data,
696 tagfirstsubfield => $subfields_data[0],
697 fixedfield => $tag < 10?1:0,
700 push @loop_data, \%tag_data ;
704 if ( $#loop_data >= 0 ) {
707 innerloop => \@loop_data,
711 $authorised_values_sth->finish;
712 $template->param( BIG_LOOP => \@BIG_LOOP );
715 # ========================
717 #=========================
719 my $error = $input->param('error');
720 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
721 my $parentbiblio = $input->param('parentbiblionumber');
722 my $breedingid = $input->param('breedingid');
723 my $z3950 = $input->param('z3950');
724 my $op = $input->param('op');
725 my $mode = $input->param('mode');
726 my $frameworkcode = $input->param('frameworkcode');
727 my $redirect = $input->param('redirect');
728 my $searchid = $input->param('searchid');
729 my $dbh = C4::Context->dbh;
730 my $hostbiblionumber = $input->param('hostbiblionumber');
731 my $hostitemnumber = $input->param('hostitemnumber');
732 # fast cataloguing datas in transit
733 my $fa_circborrowernumber = $input->param('circborrowernumber');
734 my $fa_barcode = $input->param('barcode');
735 my $fa_branch = $input->param('branch');
736 my $fa_stickyduedate = $input->param('stickyduedate');
737 my $fa_duedatespec = $input->param('duedatespec');
739 my $userflags = 'edit_catalogue';
740 if ($frameworkcode eq 'FA'){
741 $userflags = 'fast_cataloging';
744 my $changed_framework = $input->param('changed_framework');
745 $frameworkcode = &GetFrameworkCode($biblionumber)
746 if ( $biblionumber and not($frameworkcode) and $op ne 'addbiblio' );
748 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
749 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
751 template_name => "cataloguing/addbiblio.tt",
754 authnotrequired => 0,
755 flagsrequired => { editcatalogue => $userflags },
759 if ($frameworkcode eq 'FA'){
760 # We need to grab and set some variables in the template for use on the additems screen
762 'circborrowernumber' => $fa_circborrowernumber,
763 'barcode' => $fa_barcode,
764 'branch' => $fa_branch,
765 'stickyduedate' => $fa_stickyduedate,
766 'duedatespec' => $fa_duedatespec,
770 # Getting the list of all frameworks
772 my $frameworks = getframeworks;
773 my @frameworkcodeloop;
774 foreach my $thisframeworkcode ( keys %$frameworks ) {
776 value => $thisframeworkcode,
777 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
779 if ($frameworkcode eq $thisframeworkcode){
780 $row{'selected'} = 1;
782 push @frameworkcodeloop, \%row;
784 $template->param( frameworkcodeloop => \@frameworkcodeloop,
785 breedingid => $breedingid );
788 $tagslib = &GetMarcStructure( 1, $frameworkcode );
789 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
790 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
796 $biblionumbertagfield,
797 $biblionumbertagsubfield,
798 $biblioitemnumtagfield,
799 $biblioitemnumtagsubfield,
804 if (($biblionumber) && !($breedingid)){
805 $record = GetMarcBiblio($biblionumber);
808 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
811 #populate hostfield if hostbiblionumber is available
812 if ($hostbiblionumber) {
813 my $marcflavour = C4::Context->preference("marcflavour");
814 $record = MARC::Record->new();
817 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
818 $record->append_fields($field);
821 # This is a child record
823 my $marcflavour = C4::Context->preference('marcflavour');
824 $record = MARC::Record->new();
825 SetMarcUnicodeFlag($record, $marcflavour);
826 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
828 $record->append_fields($hostfield);
836 $template->param( title => $record->title(), );
838 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
839 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
840 &GetMarcFromKohaField( "biblio.biblionumber", $frameworkcode );
841 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
842 &GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode );
844 # search biblioitems value
845 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
846 $sth->execute($biblionumber);
847 ($biblioitemnumber) = $sth->fetchrow;
850 #-------------------------------------------------------------------------------------
851 if ( $op eq "addbiblio" ) {
852 #-------------------------------------------------------------------------------------
854 biblionumberdata => $biblionumber,
857 my @params = $input->param();
858 $record = TransformHtmlToMarc( $input );
859 # check for a duplicate
860 my ( $duplicatebiblionumber, $duplicatetitle );
861 if ( !$is_a_modif ) {
862 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
864 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
865 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
866 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
869 if (C4::Context->preference("BiblioAddsAuthorities")){
870 BiblioAutoLink( $record, $frameworkcode );
873 ModBiblioframework( $biblionumber, $frameworkcode );
874 ModBiblio( $record, $biblionumber, $frameworkcode );
877 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
879 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
880 if ($frameworkcode eq 'FA'){
881 print $input->redirect(
882 '/cgi-bin/koha/cataloguing/additem.pl?'
883 .'biblionumber='.$biblionumber
884 .'&frameworkcode='.$frameworkcode
885 .'&circborrowernumber='.$fa_circborrowernumber
886 .'&branch='.$fa_branch
887 .'&barcode='.uri_escape($fa_barcode)
888 .'&stickyduedate='.$fa_stickyduedate
889 .'&duedatespec='.$fa_duedatespec
894 print $input->redirect(
895 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
900 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
901 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
902 my $views = { C4::Search::enabled_staff_search_views };
903 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
904 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
905 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
906 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
907 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
908 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
910 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
915 elsif ($redirect eq "just_save"){
916 my $tab = $input->param('current_tab');
917 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
921 biblionumber => $biblionumber,
925 $template->param( title => $record->subfield('200',"a") ) if ($record ne "-1" && C4::Context->preference('marcflavour') =~/unimarc/i);
926 $template->param( title => $record->title() ) if ($record ne "-1" && C4::Context->preference('marcflavour') eq "usmarc");
929 itemtype => $frameworkcode,
931 output_html_with_http_headers $input, $cookie, $template->output;
935 # it may be a duplicate, warn the user and do nothing
936 build_tabs ($template, $record, $dbh,$encoding,$input);
938 biblionumber => $biblionumber,
939 biblioitemnumber => $biblioitemnumber,
940 duplicatebiblionumber => $duplicatebiblionumber,
941 duplicatebibid => $duplicatebiblionumber,
942 duplicatetitle => $duplicatetitle,
946 elsif ( $op eq "delete" ) {
948 my $error = &DelBiblio($biblionumber);
950 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
951 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
955 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
959 #----------------------------------------------------------------------------
960 # If we're in a duplication case, we have to set to "" the biblionumber
961 # as we'll save the biblio as a new one.
963 biblionumberdata => $biblionumber,
966 if ( $op eq "duplicate" ) {
970 if($changed_framework eq "changed"){
971 $record = TransformHtmlToMarc( $input );
973 elsif( $record ne -1 ) {
974 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
976 my $uxml = $record->as_xml;
977 MARC::Record::default_record_format("UNIMARC")
978 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
979 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
983 build_tabs( $template, $record, $dbh, $encoding,$input );
985 biblionumber => $biblionumber,
986 biblionumbertagfield => $biblionumbertagfield,
987 biblionumbertagsubfield => $biblionumbertagsubfield,
988 biblioitemnumtagfield => $biblioitemnumtagfield,
989 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
990 biblioitemnumber => $biblioitemnumber,
991 hostbiblionumber => $hostbiblionumber,
992 hostitemnumber => $hostitemnumber
996 $template->param( title => $record->title() ) if ( $record ne "-1" );
999 frameworkcode => $frameworkcode,
1000 itemtype => $frameworkcode,
1001 borrowernumber => $loggedinuser,
1002 tab => $input->param('tab')
1004 $template->{'VARS'}->{'searchid'} = $searchid;
1006 output_html_with_http_headers $input, $cookie, $template->output;