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}->{mandatory
}
196 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
200 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
201 push @authorised_values, $itemtype;
202 $authorised_lib{$itemtype} = $description;
204 $value = $itemtype unless ($value);
208 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value
} eq "cn_source" ) {
209 push @authorised_values, ""
210 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
} );
212 my $class_sources = GetClassSources
();
214 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
216 foreach my $class_source (sort keys %$class_sources) {
217 next unless $class_sources->{$class_source}->{'used'} or
218 ($value and $class_source eq $value) or
219 ($class_source eq $default_source);
220 push @authorised_values, $class_source;
221 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
223 $value = $default_source unless $value;
226 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
227 $authorised_values_sth->execute(
228 $tagslib->{$tag}->{$subfield}->{authorised_value
},
229 $branch_limit ?
$branch_limit : (),
232 push @authorised_values, ""
233 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
}
234 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
236 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
237 push @authorised_values, $value;
238 $authorised_lib{$value} = $lib;
241 $authorised_values_sth->finish;
242 return CGI
::scrolling_list
(
243 -name
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
244 -values => \
@authorised_values,
246 -labels
=> \
%authorised_lib,
251 -id
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
252 -class => "input_marceditor",
258 Create a random value to set it into the input name
263 return int(rand(1000000));
266 =head2 GetMandatoryFieldZ3950
268 This function return an hashref which containts all mandatory field
269 to search with z3950 server.
273 sub GetMandatoryFieldZ3950
{
274 my $frameworkcode = shift;
275 my @isbn = GetMarcFromKohaField
('biblioitems.isbn',$frameworkcode);
276 my @title = GetMarcFromKohaField
('biblio.title',$frameworkcode);
277 my @author = GetMarcFromKohaField
('biblio.author',$frameworkcode);
278 my @issn = GetMarcFromKohaField
('biblioitems.issn',$frameworkcode);
279 my @lccn = GetMarcFromKohaField
('biblioitems.lccn',$frameworkcode);
282 $isbn[0].$isbn[1] => 'isbn',
283 $title[0].$title[1] => 'title',
284 $author[0].$author[1] => 'author',
285 $issn[0].$issn[1] => 'issn',
286 $lccn[0].$lccn[1] => 'lccn',
292 builds the <input ...> entry for a subfield.
297 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
299 my $index_subfield = CreateKey
(); # create a specifique key for each subfield
301 $value =~ s/"/"/g;
303 # if there is no value provided but a default value in parameters, get it
304 if ( $value eq '' ) {
305 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue
};
307 # get today date & replace YYYY, MM, DD if provided in the default value
308 my ( $year, $month, $day ) = Today
();
309 $month = sprintf( "%02d", $month );
310 $day = sprintf( "%02d", $day );
311 $value =~ s/YYYY/$year/g;
312 $value =~ s/MM/$month/g;
313 $value =~ s/DD/$day/g;
314 my $username=(C4
::Context
->userenv?C4
::Context
->userenv->{'surname'}:"superlibrarian");
315 $value=~s/user/$username/g;
318 my $dbh = C4
::Context
->dbh;
320 # map '@' as "subfield" label for fixed fields
321 # to something that's allowed in a div id.
322 my $id_subfield = $subfield;
323 $id_subfield = "00" if $id_subfield eq "@";
325 my %subfield_data = (
327 subfield
=> $id_subfield,
328 marc_lib
=> substr( $tagslib->{$tag}->{$subfield}->{lib
}, 0, 22 ),
329 marc_lib_plain
=> $tagslib->{$tag}->{$subfield}->{lib
},
330 tag_mandatory
=> $tagslib->{$tag}->{mandatory
},
331 mandatory
=> $tagslib->{$tag}->{$subfield}->{mandatory
},
332 repeatable
=> $tagslib->{$tag}->{$subfield}->{repeatable
},
333 kohafield
=> $tagslib->{$tag}->{$subfield}->{kohafield
},
335 id
=> "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
337 maxlength
=> $tagslib->{$tag}->{$subfield}->{maxlength
},
338 random
=> CreateKey
(),
341 if(exists $mandatory_z3950->{$tag.$subfield}){
342 $subfield_data{z3950_mandatory
} = $mandatory_z3950->{$tag.$subfield};
344 # Subfield is hidden depending of hidden and mandatory flag, and is always
345 # shown if it contains anything or if its field is mandatory.
346 my $tdef = $tagslib->{$tag};
347 $subfield_data{visibility
} = "display:none;"
348 if $tdef->{$subfield}->{hidden
} % 2 == 1 &&
350 !$tdef->{$subfield}->{mandatory
} &&
352 # expand all subfields of 773 if there is a host item provided in the input
353 $subfield_data{visibility
} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
356 # it's an authorised field
357 if ( $tagslib->{$tag}->{$subfield}->{authorised_value
} ) {
358 $subfield_data{marc_value
} =
359 build_authorized_values_list
( $tag, $subfield, $value, $dbh,
360 $authorised_values_sth,$index_tag,$index_subfield );
362 # it's a subfield $9 linking to an authority record - see bug 2206
364 elsif ($subfield eq "9" and
365 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
366 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
367 $tagslib->{$tag}->{'a'}->{authtypecode
} ne '') {
369 $subfield_data{marc_value
} =
370 "<input type=\"text\"
371 id=\"".$subfield_data{id
}."\"
372 name=\"".$subfield_data{id
}."\"
374 class=\"input_marceditor readonly\"
377 maxlength=\"".$subfield_data{maxlength
}."\"
378 readonly=\"readonly\"
381 # it's a thesaurus / authority field
383 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode
} ) {
384 # when authorities auto-creation is allowed, do not set readonly
385 my $is_readonly = !C4
::Context
->preference("BiblioAddsAuthorities");
386 $subfield_data{marc_value
} =
387 "<input type=\"text\"
388 id=\"".$subfield_data{id
}."\"
389 name=\"".$subfield_data{id
}."\"
391 class=\"input_marceditor readonly\"
394 maxlength=\"".$subfield_data{maxlength
}."\"".
395 ($is_readonly ?
"readonly=\"readonly\"" : "").
397 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\"
398 onclick=\"openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'".$tagslib->{$tag}->{$subfield}->{authtypecode
}."','biblio'); return false;\" tabindex=\"1\" title=\"Tag editor\">Tag editor</a></span>
400 # it's a plugin field
402 elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
404 # opening plugin. Just check whether we are on a developer computer on a production one
405 # (the cgidir differs)
406 my $cgidir = C4
::Context
->intranetdir . "/cgi-bin/cataloguing/value_builder";
407 unless ( opendir( DIR
, "$cgidir" ) ) {
408 $cgidir = C4
::Context
->intranetdir . "/cataloguing/value_builder";
411 my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
413 my $extended_param = plugin_parameters
( $dbh, $rec, $tagslib, $subfield_data{id
}, $tabloop );
414 my ( $function_name, $javascript ) = plugin_javascript
( $dbh, $rec, $tagslib, $subfield_data{id
}, $tabloop );
416 $subfield_data{marc_value
} =
417 "<input tabindex=\"1\"
419 id=\"".$subfield_data{id
}."\"
420 name=\"".$subfield_data{id
}."\"
422 class=\"input_marceditor\"
423 onfocus=\"Focus$function_name($index_tag)\"
425 maxlength=\"".$subfield_data{maxlength
}."\"
426 onblur=\"Blur$function_name($index_tag); \" \/>
427 <span class=\"subfield_controls\"><a href=\"#\" class=\"buttonDot tag_editor\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" tabindex=\"1\" title=\"Tag editor\">Tag editor</a></span>
430 warn "Plugin Failed: $plugin";
431 # supply default input form
432 $subfield_data{marc_value
} =
433 "<input type=\"text\"
434 id=\"".$subfield_data{id
}."\"
435 name=\"".$subfield_data{id
}."\"
439 maxlength=\"".$subfield_data{maxlength
}."\"
440 class=\"input_marceditor\"
444 # it's an hidden field
446 elsif ( $tag eq '' ) {
447 $subfield_data{marc_value
} =
448 "<input tabindex=\"1\"
450 id=\"".$subfield_data{id
}."\"
451 name=\"".$subfield_data{id
}."\"
453 maxlength=\"".$subfield_data{maxlength
}."\"
458 # it's a standard field
462 ( C4
::Context
->preference("marcflavour") eq "UNIMARC" && $tag >= 300
463 and $tag < 400 && $subfield eq 'a' )
466 && C4
::Context
->preference("marcflavour") eq "MARC21" )
469 $subfield_data{marc_value
} =
470 "<textarea cols=\"70\"
472 id=\"".$subfield_data{id
}."\"
473 name=\"".$subfield_data{id
}."\"
474 class=\"input_marceditor\"
480 $subfield_data{marc_value
} =
481 "<input type=\"text\"
482 id=\"".$subfield_data{id
}."\"
483 name=\"".$subfield_data{id
}."\"
487 maxlength=\"".$subfield_data{maxlength
}."\"
488 class=\"input_marceditor\"
493 $subfield_data{'index_subfield'} = $index_subfield;
494 return \
%subfield_data;
498 =head2 format_indicator
500 Translate indicator value for output form - specifically, map
501 indicator = ' ' to ''. This is for the convenience of a cataloger
502 using a mouse to select an indicator input.
506 sub format_indicator
{
507 my $ind_value = shift;
508 return '' if not defined $ind_value;
509 return '' if $ind_value eq ' ';
514 my ( $template, $record, $dbh, $encoding,$input ) = @_;
520 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
521 my $query = "SELECT authorised_value, lib
522 FROM authorised_values";
523 $query .= qq{ LEFT JOIN authorised_values_branches ON
( id
= av_id
)} if $branch_limit;
524 $query .= " WHERE category = ?";
525 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
526 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
527 my $authorised_values_sth = $dbh->prepare( $query );
529 # in this array, we will push all the 10 tabs
530 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
533 my @tab_data; # all tags to display
535 foreach my $used ( @
$usedTagsLib ){
536 push @tab_data,$used->{tagfield
} if not $seen{$used->{tagfield
}};
537 $seen{$used->{tagfield
}}++;
541 foreach(@
$usedTagsLib){
542 if($_->{tab
} > -1 && $_->{tab
} >= $max_num_tab && $_->{tagfield
} != '995'){ # FIXME : MARC21 ?
543 $max_num_tab = $_->{tab
};
546 if($max_num_tab >= 9){
549 # loop through each tab 0 through 9
550 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
551 my @loop_data = (); #innerloop in the template.
553 foreach my $tag (@tab_data) {
556 my ($indicator1, $indicator2);
557 my $index_tag = CreateKey
;
559 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
560 # if MARC::Record is empty => use tab as master loop.
561 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
563 if ( $tag ne '000' ) {
564 @fields = $record->field($tag);
567 push @fields, $record->leader(); # if tag == 000
569 # loop through each field
570 foreach my $field (@fields) {
574 my ( $value, $subfield );
575 if ( $tag ne '000' ) {
576 $value = $field->data();
583 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
585 if ( $tagslib->{$tag}->{$subfield}->{kohafield
} eq
586 'biblio.biblionumber' );
590 $tag, $subfield, $value, $index_tag, $tabloop, $record,
591 $authorised_values_sth,$input
596 my @subfields = $field->subfields();
597 foreach my $subfieldcount ( 0 .. $#subfields ) {
598 my $subfield = $subfields[$subfieldcount][0];
599 my $value = $subfields[$subfieldcount][1];
600 next if ( length $subfield != 1 );
601 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
605 $tag, $subfield, $value, $index_tag, $tabloop,
606 $record, $authorised_values_sth,$input
612 # now, loop again to add parameter subfield that are not in the MARC::Record
613 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
615 next if ( length $subfield != 1 );
616 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
617 next if ( $tag < 10 );
619 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
620 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
621 and not ( $subfield eq "9" and
622 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
623 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
624 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
626 ; #check for visibility flag
627 # if subfield is $9 in a field whose $a is authority-controlled,
628 # always include in the form regardless of the hidden setting - bug 2206
629 next if ( defined( $field->subfield($subfield) ) );
633 $tag, $subfield, '', $index_tag, $tabloop, $record,
634 $authorised_values_sth,$input
638 if ( $#subfields_data >= 0 ) {
639 # build the tag entry.
640 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
641 # have twice the same "name" value, and cgi->param() will return only one, making
642 # all subfields to be merged in a single field.
646 tag_lib
=> $tagslib->{$tag}->{lib
},
647 repeatable
=> $tagslib->{$tag}->{repeatable
},
648 mandatory
=> $tagslib->{$tag}->{mandatory
},
649 subfield_loop
=> \
@subfields_data,
650 fixedfield
=> $tag < 10?
1:0,
653 if ($tag >= 10){ # no indicator for 00x tags
654 $tag_data{indicator1
} = format_indicator
($field->indicator(1)),
655 $tag_data{indicator2
} = format_indicator
($field->indicator(2)),
657 push( @loop_data, \
%tag_data );
659 } # foreach $field end
661 # if breeding is empty
665 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
666 next if ( length $subfield != 1 );
668 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -5 )
669 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 4 ) )
670 and not ( $subfield eq "9" and
671 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
672 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
673 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
675 ; #check for visibility flag
676 # if subfield is $9 in a field whose $a is authority-controlled,
677 # always include in the form regardless of the hidden setting - bug 2206
679 if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
683 $tag, $subfield, '', $index_tag, $tabloop, $record,
684 $authorised_values_sth,$input
688 if ( $#subfields_data >= 0 ) {
692 tag_lib
=> $tagslib->{$tag}->{lib
},
693 repeatable
=> $tagslib->{$tag}->{repeatable
},
694 mandatory
=> $tagslib->{$tag}->{mandatory
},
695 indicator1
=> $indicator1,
696 indicator2
=> $indicator2,
697 subfield_loop
=> \
@subfields_data,
698 tagfirstsubfield
=> $subfields_data[0],
699 fixedfield
=> $tag < 10?
1:0,
702 push @loop_data, \
%tag_data ;
706 if ( $#loop_data >= 0 ) {
709 innerloop
=> \
@loop_data,
713 $authorised_values_sth->finish;
714 $template->param( BIG_LOOP
=> \
@BIG_LOOP );
717 # ========================
719 #=========================
721 my $error = $input->param('error');
722 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
723 my $parentbiblio = $input->param('parentbiblionumber');
724 my $breedingid = $input->param('breedingid');
725 my $z3950 = $input->param('z3950');
726 my $op = $input->param('op');
727 my $mode = $input->param('mode');
728 my $frameworkcode = $input->param('frameworkcode');
729 my $redirect = $input->param('redirect');
730 my $searchid = $input->param('searchid');
731 my $dbh = C4
::Context
->dbh;
732 my $hostbiblionumber = $input->param('hostbiblionumber');
733 my $hostitemnumber = $input->param('hostitemnumber');
734 # fast cataloguing datas in transit
735 my $fa_circborrowernumber = $input->param('circborrowernumber');
736 my $fa_barcode = $input->param('barcode');
737 my $fa_branch = $input->param('branch');
738 my $fa_stickyduedate = $input->param('stickyduedate');
739 my $fa_duedatespec = $input->param('duedatespec');
741 my $userflags = 'edit_catalogue';
742 if ($frameworkcode eq 'FA'){
743 $userflags = 'fast_cataloging';
746 my $changed_framework = $input->param('changed_framework');
747 $frameworkcode = &GetFrameworkCode
($biblionumber)
748 if ( $biblionumber and not($frameworkcode) and $op ne 'addbiblio' );
750 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
751 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
753 template_name
=> "cataloguing/addbiblio.tt",
756 authnotrequired
=> 0,
757 flagsrequired
=> { editcatalogue
=> $userflags },
761 if ($frameworkcode eq 'FA'){
762 # We need to grab and set some variables in the template for use on the additems screen
764 'circborrowernumber' => $fa_circborrowernumber,
765 'barcode' => $fa_barcode,
766 'branch' => $fa_branch,
767 'stickyduedate' => $fa_stickyduedate,
768 'duedatespec' => $fa_duedatespec,
772 # Getting the list of all frameworks
774 my $frameworks = getframeworks
;
775 my @frameworkcodeloop;
776 foreach my $thisframeworkcode ( keys %$frameworks ) {
778 value
=> $thisframeworkcode,
779 frameworktext
=> $frameworks->{$thisframeworkcode}->{'frameworktext'},
781 if ($frameworkcode eq $thisframeworkcode){
782 $row{'selected'} = 1;
784 push @frameworkcodeloop, \
%row;
786 $template->param( frameworkcodeloop
=> \
@frameworkcodeloop,
787 breedingid
=> $breedingid );
790 $tagslib = &GetMarcStructure
( 1, $frameworkcode );
791 $usedTagsLib = &GetUsedMarcStructure
( $frameworkcode );
792 $mandatory_z3950 = GetMandatoryFieldZ3950
($frameworkcode);
798 $biblionumbertagfield,
799 $biblionumbertagsubfield,
800 $biblioitemnumtagfield,
801 $biblioitemnumtagsubfield,
806 if (($biblionumber) && !($breedingid)){
807 $record = GetMarcBiblio
($biblionumber);
810 ( $record, $encoding ) = MARCfindbreeding
( $breedingid ) ;
813 #populate hostfield if hostbiblionumber is available
814 if ($hostbiblionumber) {
815 my $marcflavour = C4
::Context
->preference("marcflavour");
816 $record = MARC
::Record
->new();
819 PrepHostMarcField
( $hostbiblionumber, $hostitemnumber, $marcflavour );
820 $record->append_fields($field);
823 # This is a child record
825 my $marcflavour = C4
::Context
->preference('marcflavour');
826 $record = MARC
::Record
->new();
827 SetMarcUnicodeFlag
($record, $marcflavour);
828 my $hostfield = prepare_host_field
($parentbiblio,$marcflavour);
830 $record->append_fields($hostfield);
838 $template->param( title
=> $record->title(), );
840 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
841 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
842 &GetMarcFromKohaField
( "biblio.biblionumber", $frameworkcode );
843 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
844 &GetMarcFromKohaField
( "biblioitems.biblioitemnumber", $frameworkcode );
846 # search biblioitems value
847 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
848 $sth->execute($biblionumber);
849 ($biblioitemnumber) = $sth->fetchrow;
852 #-------------------------------------------------------------------------------------
853 if ( $op eq "addbiblio" ) {
854 #-------------------------------------------------------------------------------------
856 biblionumberdata
=> $biblionumber,
859 my @params = $input->param();
860 $record = TransformHtmlToMarc
( $input );
861 # check for a duplicate
862 my ( $duplicatebiblionumber, $duplicatetitle );
863 if ( !$is_a_modif ) {
864 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate
($record);
866 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
867 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
868 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
871 if (C4
::Context
->preference("BiblioAddsAuthorities")){
872 BiblioAutoLink
( $record, $frameworkcode );
875 ModBiblioframework
( $biblionumber, $frameworkcode );
876 ModBiblio
( $record, $biblionumber, $frameworkcode );
879 ( $biblionumber, $oldbibitemnum ) = AddBiblio
( $record, $frameworkcode );
881 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
882 if ($frameworkcode eq 'FA'){
883 print $input->redirect(
884 '/cgi-bin/koha/cataloguing/additem.pl?'
885 .'biblionumber='.$biblionumber
886 .'&frameworkcode='.$frameworkcode
887 .'&circborrowernumber='.$fa_circborrowernumber
888 .'&branch='.$fa_branch
889 .'&barcode='.uri_escape
($fa_barcode)
890 .'&stickyduedate='.$fa_stickyduedate
891 .'&duedatespec='.$fa_duedatespec
896 print $input->redirect(
897 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
902 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
903 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
904 my $views = { C4
::Search
::enabled_staff_search_views
};
905 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
906 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
907 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
908 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
909 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
910 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
912 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
917 elsif ($redirect eq "just_save"){
918 my $tab = $input->param('current_tab');
919 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
923 biblionumber
=> $biblionumber,
927 $template->param( title
=> $record->subfield('200',"a") ) if ($record ne "-1" && C4
::Context
->preference('marcflavour') =~/unimarc/i);
928 $template->param( title
=> $record->title() ) if ($record ne "-1" && C4
::Context
->preference('marcflavour') eq "usmarc");
931 itemtype
=> $frameworkcode,
933 output_html_with_http_headers
$input, $cookie, $template->output;
937 # it may be a duplicate, warn the user and do nothing
938 build_tabs
($template, $record, $dbh,$encoding,$input);
940 biblionumber
=> $biblionumber,
941 biblioitemnumber
=> $biblioitemnumber,
942 duplicatebiblionumber
=> $duplicatebiblionumber,
943 duplicatebibid
=> $duplicatebiblionumber,
944 duplicatetitle
=> $duplicatetitle,
948 elsif ( $op eq "delete" ) {
950 my $error = &DelBiblio
($biblionumber);
952 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
953 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
957 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
961 #----------------------------------------------------------------------------
962 # If we're in a duplication case, we have to set to "" the biblionumber
963 # as we'll save the biblio as a new one.
965 biblionumberdata
=> $biblionumber,
968 if ( $op eq "duplicate" ) {
972 if($changed_framework eq "changed"){
973 $record = TransformHtmlToMarc
( $input );
975 elsif( $record ne -1 ) {
976 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
978 my $uxml = $record->as_xml;
979 MARC
::Record
::default_record_format
("UNIMARC")
980 if ( C4
::Context
->preference("marcflavour") eq "UNIMARC" );
981 my $urecord = MARC
::Record
::new_from_xml
( $uxml, 'UTF-8' );
985 build_tabs
( $template, $record, $dbh, $encoding,$input );
987 biblionumber
=> $biblionumber,
988 biblionumbertagfield
=> $biblionumbertagfield,
989 biblionumbertagsubfield
=> $biblionumbertagsubfield,
990 biblioitemnumtagfield
=> $biblioitemnumtagfield,
991 biblioitemnumtagsubfield
=> $biblioitemnumtagsubfield,
992 biblioitemnumber
=> $biblioitemnumber,
993 hostbiblionumber
=> $hostbiblionumber,
994 hostitemnumber
=> $hostitemnumber
998 $template->param( title
=> $record->title() ) if ( $record ne "-1" );
1001 frameworkcode
=> $frameworkcode,
1002 itemtype
=> $frameworkcode,
1003 borrowernumber
=> $loggedinuser,
1004 tab
=> $input->param('tab')
1006 $template->{'VARS'}->{'searchid'} = $searchid;
1008 output_html_with_http_headers
$input, $cookie, $template->output;