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>.
23 #use warnings; FIXME - Bug 2505
29 use C4
::AuthoritiesMarc
;
37 use Koha
::BiblioFrameworks
;
42 use Date
::Calc
qw(Today);
43 use MARC
::File
::USMARC
;
47 if ( C4
::Context
->preference('marcflavour') eq 'UNIMARC' ) {
48 MARC
::File
::XML
->default_record_format('UNIMARC');
51 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
55 =head2 MARCfindbreeding
57 $record = MARCfindbreeding($breedingid);
59 Look up the import record repository for the record with
60 record with id $breedingid. If found, returns the decoded
61 MARC::Record; otherwise, -1 is returned (FIXME).
62 Returns as second parameter the character encoding.
66 sub MARCfindbreeding
{
68 my ($marc, $encoding) = GetImportRecordMarc
($id);
69 # remove the - in isbn, koha store isbn without any -
71 my $record = MARC
::Record
->new_from_usmarc($marc);
72 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField
('biblioitems.isbn','');
73 if ( $record->field($isbnfield) ) {
74 foreach my $field ( $record->field($isbnfield) ) {
75 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
76 my $newisbn = $field->subfield($isbnsubfield);
78 $field->update( $isbnsubfield => $newisbn );
82 # fix the unimarc 100 coded field (with unicode information)
83 if (C4
::Context
->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
84 my $f100a=$record->subfield(100,'a');
85 my $f100 = $record->field(100);
86 my $f100temp = $f100->as_string;
87 $record->delete_field($f100);
88 if ( length($f100temp) > 28 ) {
89 substr( $f100temp, 26, 2, "50" );
90 $f100->update( 'a' => $f100temp );
91 my $f100 = MARC
::Field
->new( '100', '', '', 'a' => $f100temp );
92 $record->insert_fields_ordered($f100);
96 if ( !defined(ref($record)) ) {
100 # normalize author : UNIMARC specific...
101 if ( C4
::Context
->preference("z3950NormalizeAuthor")
102 and C4
::Context
->preference("z3950AuthorAuthFields")
103 and C4
::Context
->preference("marcflavour") eq 'UNIMARC' )
105 my ( $tag, $subfield ) = GetMarcFromKohaField
("biblio.author", '');
107 # my $summary = C4::Context->preference("z3950authortemplate");
109 C4
::Context
->preference("z3950AuthorAuthFields");
110 my @auth_fields = split /,/, $auth_fields;
113 if ( $record->field($tag) ) {
114 foreach my $tmpfield ( $record->field($tag)->subfields ) {
116 # foreach my $subfieldcode ($tmpfield->subfields){
117 my $subfieldcode = shift @
$tmpfield;
118 my $subfieldvalue = shift @
$tmpfield;
120 $field->add_subfields(
121 "$subfieldcode" => $subfieldvalue )
122 if ( $subfieldcode ne $subfield );
126 MARC
::Field
->new( $tag, "", "",
127 $subfieldcode => $subfieldvalue )
128 if ( $subfieldcode ne $subfield );
132 $record->delete_field( $record->field($tag) );
133 foreach my $fieldtag (@auth_fields) {
134 next unless ( $record->field($fieldtag) );
135 my $lastname = $record->field($fieldtag)->subfield('a');
136 my $firstname = $record->field($fieldtag)->subfield('b');
137 my $title = $record->field($fieldtag)->subfield('c');
138 my $number = $record->field($fieldtag)->subfield('d');
141 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
142 $field->add_subfields(
143 "$subfield" => ucfirst($title) . " "
144 . ucfirst($firstname) . " "
149 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
150 $field->add_subfields(
151 "$subfield" => ucfirst($firstname) . ", "
152 . ucfirst($lastname) );
155 $record->insert_fields_ordered($field);
157 return $record, $encoding;
163 =head2 build_authorized_values_list
167 sub build_authorized_values_list
{
168 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
170 my @authorised_values;
173 # builds list, depending on authorised value...
176 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
177 my $libraries = Koha
::Libraries
->search_filtered({}, {order_by
=> ['branchname']});
178 while ( my $l = $libraries->next ) {
179 push @authorised_values, $l->branchcode;;
180 $authorised_lib{$l->branchcode} = $l->branchname;
183 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value
} eq "itemtypes" ) {
184 push @authorised_values, ""
185 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
}
186 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
189 my $itemtypes = GetItemTypes
( style
=> 'array' );
190 for my $itemtype ( @
$itemtypes ) {
191 push @authorised_values, $itemtype->{itemtype
};
192 $authorised_lib{$itemtype->{itemtype
}} = $itemtype->{translated_description
};
194 $value = $itemtype unless ($value);
196 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value
} eq "cn_source" ) {
197 push @authorised_values, ""
198 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
} );
200 my $class_sources = GetClassSources
();
202 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
204 foreach my $class_source (sort keys %$class_sources) {
205 next unless $class_sources->{$class_source}->{'used'} or
206 ($value and $class_source eq $value) or
207 ($class_source eq $default_source);
208 push @authorised_values, $class_source;
209 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
211 $value = $default_source unless $value;
214 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
215 $authorised_values_sth->execute(
216 $tagslib->{$tag}->{$subfield}->{authorised_value
},
217 $branch_limit ?
$branch_limit : (),
220 push @authorised_values, ""
221 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
}
222 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
224 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
225 push @authorised_values, $value;
226 $authorised_lib{$value} = $lib;
229 $authorised_values_sth->finish;
232 id
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
233 name
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
235 values => \
@authorised_values,
236 labels
=> \
%authorised_lib,
243 Create a random value to set it into the input name
248 return int(rand(1000000));
251 =head2 GetMandatoryFieldZ3950
253 This function return an hashref which containts all mandatory field
254 to search with z3950 server.
258 sub GetMandatoryFieldZ3950
{
259 my $frameworkcode = shift;
260 my @isbn = GetMarcFromKohaField
('biblioitems.isbn',$frameworkcode);
261 my @title = GetMarcFromKohaField
('biblio.title',$frameworkcode);
262 my @author = GetMarcFromKohaField
('biblio.author',$frameworkcode);
263 my @issn = GetMarcFromKohaField
('biblioitems.issn',$frameworkcode);
264 my @lccn = GetMarcFromKohaField
('biblioitems.lccn',$frameworkcode);
267 $isbn[0].$isbn[1] => 'isbn',
268 $title[0].$title[1] => 'title',
269 $author[0].$author[1] => 'author',
270 $issn[0].$issn[1] => 'issn',
271 $lccn[0].$lccn[1] => 'lccn',
277 builds the <input ...> entry for a subfield.
282 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
284 my $index_subfield = CreateKey
(); # create a specifique key for each subfield
286 $value =~ s/"/"/g;
288 # if there is no value provided but a default value in parameters, get it
289 if ( $value eq '' ) {
290 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue
};
292 # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
293 my $today_dt = dt_from_string
;
294 my $year = $today_dt->year;
295 my $month = $today_dt->month;
296 my $day = $today_dt->day;
297 $value =~ s/<<YYYY>>/$year/g;
298 $value =~ s/<<MM>>/$month/g;
299 $value =~ s/<<DD>>/$day/g;
300 # And <<USER>> with surname (?)
301 my $username=(C4
::Context
->userenv?C4
::Context
->userenv->{'surname'}:"superlibrarian");
302 $value=~s/<<USER>>/$username/g;
305 my $dbh = C4
::Context
->dbh;
307 # map '@' as "subfield" label for fixed fields
308 # to something that's allowed in a div id.
309 my $id_subfield = $subfield;
310 $id_subfield = "00" if $id_subfield eq "@";
312 my %subfield_data = (
314 subfield
=> $id_subfield,
315 marc_lib
=> $tagslib->{$tag}->{$subfield}->{lib
},
316 tag_mandatory
=> $tagslib->{$tag}->{mandatory
},
317 mandatory
=> $tagslib->{$tag}->{$subfield}->{mandatory
},
318 repeatable
=> $tagslib->{$tag}->{$subfield}->{repeatable
},
319 kohafield
=> $tagslib->{$tag}->{$subfield}->{kohafield
},
321 id
=> "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
323 maxlength
=> $tagslib->{$tag}->{$subfield}->{maxlength
},
324 random
=> CreateKey
(),
327 if(exists $mandatory_z3950->{$tag.$subfield}){
328 $subfield_data{z3950_mandatory
} = $mandatory_z3950->{$tag.$subfield};
330 # Subfield is hidden depending of hidden and mandatory flag, and is always
331 # shown if it contains anything or if its field is mandatory.
332 my $tdef = $tagslib->{$tag};
333 $subfield_data{visibility
} = "display:none;"
334 if $tdef->{$subfield}->{hidden
} % 2 == 1 &&
336 !$tdef->{$subfield}->{mandatory
} &&
338 # expand all subfields of 773 if there is a host item provided in the input
339 $subfield_data{visibility
} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
342 # it's an authorised field
343 if ( $tagslib->{$tag}->{$subfield}->{authorised_value
} ) {
344 $subfield_data{marc_value
} =
345 build_authorized_values_list
( $tag, $subfield, $value, $dbh,
346 $authorised_values_sth,$index_tag,$index_subfield );
348 # it's a subfield $9 linking to an authority record - see bug 2206
350 elsif ($subfield eq "9" and
351 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
352 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
353 $tagslib->{$tag}->{'a'}->{authtypecode
} ne '') {
355 $subfield_data{marc_value
} = {
357 id
=> $subfield_data{id
},
358 name
=> $subfield_data{id
},
361 maxlength
=> $subfield_data{maxlength
},
365 # it's a thesaurus / authority field
367 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode
} ) {
368 # when authorities auto-creation is allowed, do not set readonly
369 my $is_readonly = !C4
::Context
->preference("BiblioAddsAuthorities");
371 $subfield_data{marc_value
} = {
373 id
=> $subfield_data{id
},
374 name
=> $subfield_data{id
},
377 maxlength
=> $subfield_data{maxlength
},
378 readonly
=> ($is_readonly) ?
1 : 0,
379 authtype
=> $tagslib->{$tag}->{$subfield}->{authtypecode
},
382 # it's a plugin field
383 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
384 require Koha
::FrameworkPlugin
;
385 my $plugin = Koha
::FrameworkPlugin
->new( {
386 name
=> $tagslib->{$tag}->{$subfield}->{'value_builder'},
388 my $pars= { dbh
=> $dbh, record
=> $rec, tagslib
=> $tagslib,
389 id
=> $subfield_data{id
}, tabloop
=> $tabloop };
390 $plugin->build( $pars );
391 if( !$plugin->errstr ) {
392 $subfield_data{marc_value
} = {
393 type
=> 'text_complex',
394 id
=> $subfield_data{id
},
395 name
=> $subfield_data{id
},
398 maxlength
=> $subfield_data{maxlength
},
399 javascript
=> $plugin->javascript,
400 noclick
=> $plugin->noclick,
403 warn $plugin->errstr;
404 # supply default input form
405 $subfield_data{marc_value
} = {
407 id
=> $subfield_data{id
},
408 name
=> $subfield_data{id
},
411 maxlength
=> $subfield_data{maxlength
},
416 # it's an hidden field
417 } elsif ( $tag eq '' ) {
418 $subfield_data{marc_value
} = {
420 id
=> $subfield_data{id
},
421 name
=> $subfield_data{id
},
424 maxlength
=> $subfield_data{maxlength
},
429 # it's a standard field
433 ( C4
::Context
->preference("marcflavour") eq "UNIMARC" && $tag >= 300
434 and $tag < 400 && $subfield eq 'a' )
437 && C4
::Context
->preference("marcflavour") eq "MARC21" )
440 $subfield_data{marc_value
} = {
442 id
=> $subfield_data{id
},
443 name
=> $subfield_data{id
},
449 $subfield_data{marc_value
} = {
451 id
=> $subfield_data{id
},
452 name
=> $subfield_data{id
},
455 maxlength
=> $subfield_data{maxlength
},
461 $subfield_data{'index_subfield'} = $index_subfield;
462 return \
%subfield_data;
466 =head2 format_indicator
468 Translate indicator value for output form - specifically, map
469 indicator = ' ' to ''. This is for the convenience of a cataloger
470 using a mouse to select an indicator input.
474 sub format_indicator
{
475 my $ind_value = shift;
476 return '' if not defined $ind_value;
477 return '' if $ind_value eq ' ';
482 my ( $template, $record, $dbh, $encoding,$input ) = @_;
488 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
489 my $query = "SELECT authorised_value, lib
490 FROM authorised_values";
491 $query .= qq{ LEFT JOIN authorised_values_branches ON
( id
= av_id
)} if $branch_limit;
492 $query .= " WHERE category = ?";
493 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
494 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
495 my $authorised_values_sth = $dbh->prepare( $query );
497 # in this array, we will push all the 10 tabs
498 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
501 my @tab_data; # all tags to display
503 foreach my $used ( @
$usedTagsLib ){
504 push @tab_data,$used->{tagfield
} if not $seen{$used->{tagfield
}};
505 $seen{$used->{tagfield
}}++;
509 foreach(@
$usedTagsLib){
510 if($_->{tab
} > -1 && $_->{tab
} >= $max_num_tab && $_->{tagfield
} != '995'){ # FIXME : MARC21 ?
511 $max_num_tab = $_->{tab
};
514 if($max_num_tab >= 9){
517 # loop through each tab 0 through 9
518 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
519 my @loop_data = (); #innerloop in the template.
521 foreach my $tag (@tab_data) {
524 my ($indicator1, $indicator2);
525 my $index_tag = CreateKey
;
527 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
528 # if MARC::Record is empty => use tab as master loop.
529 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
531 if ( $tag ne '000' ) {
532 @fields = $record->field($tag);
535 push @fields, $record->leader(); # if tag == 000
537 # loop through each field
538 foreach my $field (@fields) {
542 my ( $value, $subfield );
543 if ( $tag ne '000' ) {
544 $value = $field->data();
551 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
553 if ( $tagslib->{$tag}->{$subfield}->{kohafield
} eq
554 'biblio.biblionumber' );
558 $tag, $subfield, $value, $index_tag, $tabloop, $record,
559 $authorised_values_sth,$input
564 my @subfields = $field->subfields();
565 foreach my $subfieldcount ( 0 .. $#subfields ) {
566 my $subfield = $subfields[$subfieldcount][0];
567 my $value = $subfields[$subfieldcount][1];
568 next if ( length $subfield != 1 );
569 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
573 $tag, $subfield, $value, $index_tag, $tabloop,
574 $record, $authorised_values_sth,$input
580 # now, loop again to add parameter subfield that are not in the MARC::Record
581 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
583 next if ( length $subfield != 1 );
584 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
585 next if ( $tag < 10 );
587 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
588 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
589 and not ( $subfield eq "9" and
590 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
591 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
592 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
594 ; #check for visibility flag
595 # if subfield is $9 in a field whose $a is authority-controlled,
596 # always include in the form regardless of the hidden setting - bug 2206
597 next if ( defined( $field->subfield($subfield) ) );
601 $tag, $subfield, '', $index_tag, $tabloop, $record,
602 $authorised_values_sth,$input
606 if ( $#subfields_data >= 0 ) {
607 # build the tag entry.
608 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
609 # have twice the same "name" value, and cgi->param() will return only one, making
610 # all subfields to be merged in a single field.
614 tag_lib
=> $tagslib->{$tag}->{lib
},
615 repeatable
=> $tagslib->{$tag}->{repeatable
},
616 mandatory
=> $tagslib->{$tag}->{mandatory
},
617 subfield_loop
=> \
@subfields_data,
618 fixedfield
=> $tag < 10?
1:0,
621 if ($tag >= 10){ # no indicator for 00x tags
622 $tag_data{indicator1
} = format_indicator
($field->indicator(1)),
623 $tag_data{indicator2
} = format_indicator
($field->indicator(2)),
625 push( @loop_data, \
%tag_data );
627 } # foreach $field end
629 # if breeding is empty
633 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
634 next if ( length $subfield != 1 );
636 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
637 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
638 and not ( $subfield eq "9" and
639 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
640 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
641 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
643 ; #check for visibility flag
644 # if subfield is $9 in a field whose $a is authority-controlled,
645 # always include in the form regardless of the hidden setting - bug 2206
647 if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
651 $tag, $subfield, '', $index_tag, $tabloop, $record,
652 $authorised_values_sth,$input
656 if ( $#subfields_data >= 0 ) {
660 tag_lib
=> $tagslib->{$tag}->{lib
},
661 repeatable
=> $tagslib->{$tag}->{repeatable
},
662 mandatory
=> $tagslib->{$tag}->{mandatory
},
663 indicator1
=> $indicator1,
664 indicator2
=> $indicator2,
665 subfield_loop
=> \
@subfields_data,
666 tagfirstsubfield
=> $subfields_data[0],
667 fixedfield
=> $tag < 10?
1:0,
670 push @loop_data, \
%tag_data ;
674 if ( $#loop_data >= 0 ) {
677 innerloop
=> \
@loop_data,
681 $authorised_values_sth->finish;
682 $template->param( BIG_LOOP
=> \
@BIG_LOOP );
685 # ========================
687 #=========================
689 my $error = $input->param('error');
690 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
691 my $parentbiblio = $input->param('parentbiblionumber');
692 my $breedingid = $input->param('breedingid');
693 my $z3950 = $input->param('z3950');
694 my $op = $input->param('op');
695 my $mode = $input->param('mode');
696 my $frameworkcode = $input->param('frameworkcode');
697 my $redirect = $input->param('redirect');
698 my $searchid = $input->param('searchid');
699 my $dbh = C4
::Context
->dbh;
700 my $hostbiblionumber = $input->param('hostbiblionumber');
701 my $hostitemnumber = $input->param('hostitemnumber');
702 # fast cataloguing datas in transit
703 my $fa_circborrowernumber = $input->param('circborrowernumber');
704 my $fa_barcode = $input->param('barcode');
705 my $fa_branch = $input->param('branch');
706 my $fa_stickyduedate = $input->param('stickyduedate');
707 my $fa_duedatespec = $input->param('duedatespec');
709 my $userflags = 'edit_catalogue';
711 my $changed_framework = $input->param('changed_framework');
712 $frameworkcode = &GetFrameworkCode
($biblionumber)
713 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
715 if ($frameworkcode eq 'FA'){
716 $userflags = 'fast_cataloging';
719 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
720 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
722 template_name
=> "cataloguing/addbiblio.tt",
725 authnotrequired
=> 0,
726 flagsrequired
=> { editcatalogue
=> $userflags },
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 $frameworkcodeloop = Koha
::BiblioFrameworks
->search({}, { order_by
=> ['frameworktext'] });
748 $template->param( frameworkcodeloop
=> $frameworkcodeloop ,
749 breedingid
=> $breedingid );
752 $tagslib = &GetMarcStructure
( 1, $frameworkcode );
753 $usedTagsLib = &GetUsedMarcStructure
( $frameworkcode );
754 $mandatory_z3950 = GetMandatoryFieldZ3950
($frameworkcode);
760 $biblionumbertagfield,
761 $biblionumbertagsubfield,
762 $biblioitemnumtagfield,
763 $biblioitemnumtagsubfield,
767 if (($biblionumber) && !($breedingid)){
768 $record = GetMarcBiblio
($biblionumber);
771 ( $record, $encoding ) = MARCfindbreeding
( $breedingid ) ;
774 #populate hostfield if hostbiblionumber is available
775 if ($hostbiblionumber) {
776 my $marcflavour = C4
::Context
->preference("marcflavour");
777 $record = MARC
::Record
->new();
780 PrepHostMarcField
( $hostbiblionumber, $hostitemnumber, $marcflavour );
781 $record->append_fields($field);
784 # This is a child record
786 my $marcflavour = C4
::Context
->preference('marcflavour');
787 $record = MARC
::Record
->new();
788 SetMarcUnicodeFlag
($record, $marcflavour);
789 my $hostfield = prepare_host_field
($parentbiblio,$marcflavour);
791 $record->append_fields($hostfield);
799 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
800 $template->param( title
=> $title );
802 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
803 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
804 &GetMarcFromKohaField
( "biblio.biblionumber", $frameworkcode );
805 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
806 &GetMarcFromKohaField
( "biblioitems.biblioitemnumber", $frameworkcode );
808 # search biblioitems value
809 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
810 $sth->execute($biblionumber);
811 ($biblioitemnumber) = $sth->fetchrow;
814 #-------------------------------------------------------------------------------------
815 if ( $op eq "addbiblio" ) {
816 #-------------------------------------------------------------------------------------
818 biblionumberdata
=> $biblionumber,
821 my @params = $input->multi_param();
822 $record = TransformHtmlToMarc
( $input, 1 );
823 # check for a duplicate
824 my ( $duplicatebiblionumber, $duplicatetitle );
825 if ( !$is_a_modif ) {
826 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate
($record);
828 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
829 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
830 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
832 if (C4
::Context
->preference("BiblioAddsAuthorities")){
833 BiblioAutoLink
( $record, $frameworkcode );
836 ModBiblioframework
( $biblionumber, $frameworkcode );
837 ModBiblio
( $record, $biblionumber, $frameworkcode );
840 ( $biblionumber, $oldbibitemnum ) = AddBiblio
( $record, $frameworkcode );
842 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
843 if ($frameworkcode eq 'FA'){
844 print $input->redirect(
845 '/cgi-bin/koha/cataloguing/additem.pl?'
846 .'biblionumber='.$biblionumber
847 .'&frameworkcode='.$frameworkcode
848 .'&circborrowernumber='.$fa_circborrowernumber
849 .'&branch='.$fa_branch
850 .'&barcode='.uri_escape_utf8
($fa_barcode)
851 .'&stickyduedate='.$fa_stickyduedate
852 .'&duedatespec='.$fa_duedatespec
857 print $input->redirect(
858 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
863 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
864 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
865 my $views = { C4
::Search
::enabled_staff_search_views
};
866 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
867 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
868 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
869 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
870 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
871 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
873 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
878 elsif ($redirect eq "just_save"){
879 my $tab = $input->param('current_tab');
880 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
884 biblionumber
=> $biblionumber,
888 if ( $record ne '-1' ) {
889 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
890 $template->param( title
=> $title );
894 itemtype
=> $frameworkcode,
896 output_html_with_http_headers
$input, $cookie, $template->output;
900 # it may be a duplicate, warn the user and do nothing
901 build_tabs
($template, $record, $dbh,$encoding,$input);
903 biblionumber
=> $biblionumber,
904 biblioitemnumber
=> $biblioitemnumber,
905 duplicatebiblionumber
=> $duplicatebiblionumber,
906 duplicatebibid
=> $duplicatebiblionumber,
907 duplicatetitle
=> $duplicatetitle,
911 elsif ( $op eq "delete" ) {
913 my $error = &DelBiblio
($biblionumber);
915 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
916 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
920 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
924 #----------------------------------------------------------------------------
925 # If we're in a duplication case, we have to set to "" the biblionumber
926 # as we'll save the biblio as a new one.
928 biblionumberdata
=> $biblionumber,
931 if ( $op eq "duplicate" ) {
935 if($changed_framework eq "changed"){
936 $record = TransformHtmlToMarc
( $input, 1 );
938 elsif( $record ne -1 ) {
939 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
941 my $uxml = $record->as_xml;
942 MARC
::Record
::default_record_format
("UNIMARC")
943 if ( C4
::Context
->preference("marcflavour") eq "UNIMARC" );
944 my $urecord = MARC
::Record
::new_from_xml
( $uxml, 'UTF-8' );
948 build_tabs
( $template, $record, $dbh, $encoding,$input );
950 biblionumber
=> $biblionumber,
951 biblionumbertagfield
=> $biblionumbertagfield,
952 biblionumbertagsubfield
=> $biblionumbertagsubfield,
953 biblioitemnumtagfield
=> $biblioitemnumtagfield,
954 biblioitemnumtagsubfield
=> $biblioitemnumtagsubfield,
955 biblioitemnumber
=> $biblioitemnumber,
956 hostbiblionumber
=> $hostbiblionumber,
957 hostitemnumber
=> $hostitemnumber
961 if ( $record ne '-1' ) {
962 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
963 $template->param( title
=> $title );
967 frameworkcode
=> $frameworkcode,
968 itemtype
=> $frameworkcode,
969 borrowernumber
=> $loggedinuser,
970 tab
=> scalar $input->param('tab')
972 $template->{'VARS'}->{'searchid'} = $searchid;
974 output_html_with_http_headers
$input, $cookie, $template->output;