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
;
43 use Koha
::BiblioFrameworks
;
45 use Date
::Calc
qw(Today);
46 use MARC
::File
::USMARC
;
50 if ( C4
::Context
->preference('marcflavour') eq 'UNIMARC' ) {
51 MARC
::File
::XML
->default_record_format('UNIMARC');
54 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
58 =head2 MARCfindbreeding
60 $record = MARCfindbreeding($breedingid);
62 Look up the import record repository for the record with
63 record with id $breedingid. If found, returns the decoded
64 MARC::Record; otherwise, -1 is returned (FIXME).
65 Returns as second parameter the character encoding.
69 sub MARCfindbreeding
{
71 my ($marc, $encoding) = GetImportRecordMarc
($id);
72 # remove the - in isbn, koha store isbn without any -
74 my $record = MARC
::Record
->new_from_usmarc($marc);
75 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField
('biblioitems.isbn','');
76 if ( $record->field($isbnfield) ) {
77 foreach my $field ( $record->field($isbnfield) ) {
78 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
79 my $newisbn = $field->subfield($isbnsubfield);
81 $field->update( $isbnsubfield => $newisbn );
85 # fix the unimarc 100 coded field (with unicode information)
86 if (C4
::Context
->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
87 my $f100a=$record->subfield(100,'a');
88 my $f100 = $record->field(100);
89 my $f100temp = $f100->as_string;
90 $record->delete_field($f100);
91 if ( length($f100temp) > 28 ) {
92 substr( $f100temp, 26, 2, "50" );
93 $f100->update( 'a' => $f100temp );
94 my $f100 = MARC
::Field
->new( '100', '', '', 'a' => $f100temp );
95 $record->insert_fields_ordered($f100);
99 if ( !defined(ref($record)) ) {
103 # normalize author : UNIMARC specific...
104 if ( C4
::Context
->preference("z3950NormalizeAuthor")
105 and C4
::Context
->preference("z3950AuthorAuthFields")
106 and C4
::Context
->preference("marcflavour") eq 'UNIMARC' )
108 my ( $tag, $subfield ) = GetMarcFromKohaField
("biblio.author", '');
110 # my $summary = C4::Context->preference("z3950authortemplate");
112 C4
::Context
->preference("z3950AuthorAuthFields");
113 my @auth_fields = split /,/, $auth_fields;
116 if ( $record->field($tag) ) {
117 foreach my $tmpfield ( $record->field($tag)->subfields ) {
119 # foreach my $subfieldcode ($tmpfield->subfields){
120 my $subfieldcode = shift @
$tmpfield;
121 my $subfieldvalue = shift @
$tmpfield;
123 $field->add_subfields(
124 "$subfieldcode" => $subfieldvalue )
125 if ( $subfieldcode ne $subfield );
129 MARC
::Field
->new( $tag, "", "",
130 $subfieldcode => $subfieldvalue )
131 if ( $subfieldcode ne $subfield );
135 $record->delete_field( $record->field($tag) );
136 foreach my $fieldtag (@auth_fields) {
137 next unless ( $record->field($fieldtag) );
138 my $lastname = $record->field($fieldtag)->subfield('a');
139 my $firstname = $record->field($fieldtag)->subfield('b');
140 my $title = $record->field($fieldtag)->subfield('c');
141 my $number = $record->field($fieldtag)->subfield('d');
144 # $field->add_subfields("$subfield"=>"[ ".ucfirst($title).ucfirst($firstname)." ".$number." ]");
145 $field->add_subfields(
146 "$subfield" => ucfirst($title) . " "
147 . ucfirst($firstname) . " "
152 # $field->add_subfields("$subfield"=>"[ ".ucfirst($firstname).", ".ucfirst($lastname)." ]");
153 $field->add_subfields(
154 "$subfield" => ucfirst($firstname) . ", "
155 . ucfirst($lastname) );
158 $record->insert_fields_ordered($field);
160 return $record, $encoding;
166 =head2 build_authorized_values_list
170 sub build_authorized_values_list
{
171 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
173 my @authorised_values;
176 # builds list, depending on authorised value...
179 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
180 my $libraries = Koha
::Libraries
->search_filtered({}, {order_by
=> ['branchname']});
181 while ( my $l = $libraries->next ) {
182 push @authorised_values, $l->branchcode;;
183 $authorised_lib{$l->branchcode} = $l->branchname;
186 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value
} eq "itemtypes" ) {
187 push @authorised_values, ""
188 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
}
189 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
192 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
193 while ( $itemtype = $itemtypes->next ) {
194 push @authorised_values, $itemtype->itemtype;
195 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
197 $value = $itemtype unless ($value);
199 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value
} eq "cn_source" ) {
200 push @authorised_values, ""
201 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
} );
203 my $class_sources = GetClassSources
();
205 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
207 foreach my $class_source (sort keys %$class_sources) {
208 next unless $class_sources->{$class_source}->{'used'} or
209 ($value and $class_source eq $value) or
210 ($class_source eq $default_source);
211 push @authorised_values, $class_source;
212 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
214 $value = $default_source unless $value;
217 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
218 $authorised_values_sth->execute(
219 $tagslib->{$tag}->{$subfield}->{authorised_value
},
220 $branch_limit ?
$branch_limit : (),
223 push @authorised_values, ""
224 unless ( $tagslib->{$tag}->{$subfield}->{mandatory
}
225 && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue
} ) );
227 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
228 push @authorised_values, $value;
229 $authorised_lib{$value} = $lib;
232 $authorised_values_sth->finish;
235 id
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
236 name
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
238 values => \
@authorised_values,
239 labels
=> \
%authorised_lib,
246 Create a random value to set it into the input name
251 return int(rand(1000000));
254 =head2 GetMandatoryFieldZ3950
256 This function returns a hashref which contains all mandatory field
257 to search with z3950 server.
261 sub GetMandatoryFieldZ3950
{
262 my $frameworkcode = shift;
263 my @isbn = GetMarcFromKohaField
('biblioitems.isbn',$frameworkcode);
264 my @title = GetMarcFromKohaField
('biblio.title',$frameworkcode);
265 my @author = GetMarcFromKohaField
('biblio.author',$frameworkcode);
266 my @issn = GetMarcFromKohaField
('biblioitems.issn',$frameworkcode);
267 my @lccn = GetMarcFromKohaField
('biblioitems.lccn',$frameworkcode);
270 $isbn[0].$isbn[1] => 'isbn',
271 $title[0].$title[1] => 'title',
272 $author[0].$author[1] => 'author',
273 $issn[0].$issn[1] => 'issn',
274 $lccn[0].$lccn[1] => 'lccn',
280 builds the <input ...> entry for a subfield.
285 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
287 my $index_subfield = CreateKey
(); # create a specifique key for each subfield
289 $value =~ s/"/"/g;
291 # if there is no value provided but a default value in parameters, get it
292 if ( $value eq '' ) {
293 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue
};
295 # get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value
296 my $today_dt = dt_from_string
;
297 my $year = $today_dt->strftime('%Y');
298 my $month = $today_dt->strftime('%m');
299 my $day = $today_dt->strftime('%d');
300 $value =~ s/<<YYYY>>/$year/g;
301 $value =~ s/<<MM>>/$month/g;
302 $value =~ s/<<DD>>/$day/g;
303 # And <<USER>> with surname (?)
304 my $username=(C4
::Context
->userenv?C4
::Context
->userenv->{'surname'}:"superlibrarian");
305 $value=~s/<<USER>>/$username/g;
308 my $dbh = C4
::Context
->dbh;
310 # map '@' as "subfield" label for fixed fields
311 # to something that's allowed in a div id.
312 my $id_subfield = $subfield;
313 $id_subfield = "00" if $id_subfield eq "@";
315 my %subfield_data = (
317 subfield
=> $id_subfield,
318 marc_lib
=> $tagslib->{$tag}->{$subfield}->{lib
},
319 tag_mandatory
=> $tagslib->{$tag}->{mandatory
},
320 mandatory
=> $tagslib->{$tag}->{$subfield}->{mandatory
},
321 repeatable
=> $tagslib->{$tag}->{$subfield}->{repeatable
},
322 kohafield
=> $tagslib->{$tag}->{$subfield}->{kohafield
},
324 id
=> "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
326 maxlength
=> $tagslib->{$tag}->{$subfield}->{maxlength
},
327 random
=> CreateKey
(),
330 if(exists $mandatory_z3950->{$tag.$subfield}){
331 $subfield_data{z3950_mandatory
} = $mandatory_z3950->{$tag.$subfield};
333 # Subfield is hidden depending of hidden and mandatory flag, and is always
334 # shown if it contains anything or if its field is mandatory.
335 my $tdef = $tagslib->{$tag};
336 $subfield_data{visibility
} = "display:none;"
337 if $tdef->{$subfield}->{hidden
} % 2 == 1 &&
339 !$tdef->{$subfield}->{mandatory
} &&
341 # expand all subfields of 773 if there is a host item provided in the input
342 $subfield_data{visibility
} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
345 # it's an authorised field
346 if ( $tagslib->{$tag}->{$subfield}->{authorised_value
} ) {
347 $subfield_data{marc_value
} =
348 build_authorized_values_list
( $tag, $subfield, $value, $dbh,
349 $authorised_values_sth,$index_tag,$index_subfield );
351 # it's a subfield $9 linking to an authority record - see bug 2206
353 elsif ($subfield eq "9" and
354 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
355 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
356 $tagslib->{$tag}->{'a'}->{authtypecode
} ne '') {
358 $subfield_data{marc_value
} = {
360 id
=> $subfield_data{id
},
361 name
=> $subfield_data{id
},
364 maxlength
=> $subfield_data{maxlength
},
368 # it's a thesaurus / authority field
370 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode
} ) {
371 # when authorities auto-creation is allowed, do not set readonly
372 my $is_readonly = !C4
::Context
->preference("BiblioAddsAuthorities");
374 $subfield_data{marc_value
} = {
376 id
=> $subfield_data{id
},
377 name
=> $subfield_data{id
},
380 maxlength
=> $subfield_data{maxlength
},
381 readonly
=> ($is_readonly) ?
1 : 0,
382 authtype
=> $tagslib->{$tag}->{$subfield}->{authtypecode
},
385 # it's a plugin field
386 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
387 require Koha
::FrameworkPlugin
;
388 my $plugin = Koha
::FrameworkPlugin
->new( {
389 name
=> $tagslib->{$tag}->{$subfield}->{'value_builder'},
391 my $pars= { dbh
=> $dbh, record
=> $rec, tagslib
=> $tagslib,
392 id
=> $subfield_data{id
}, tabloop
=> $tabloop };
393 $plugin->build( $pars );
394 if( !$plugin->errstr ) {
395 $subfield_data{marc_value
} = {
396 type
=> 'text_complex',
397 id
=> $subfield_data{id
},
398 name
=> $subfield_data{id
},
401 maxlength
=> $subfield_data{maxlength
},
402 javascript
=> $plugin->javascript,
403 noclick
=> $plugin->noclick,
406 warn $plugin->errstr;
407 # supply default input form
408 $subfield_data{marc_value
} = {
410 id
=> $subfield_data{id
},
411 name
=> $subfield_data{id
},
414 maxlength
=> $subfield_data{maxlength
},
419 # it's an hidden field
420 } elsif ( $tag eq '' ) {
421 $subfield_data{marc_value
} = {
423 id
=> $subfield_data{id
},
424 name
=> $subfield_data{id
},
427 maxlength
=> $subfield_data{maxlength
},
432 # it's a standard field
436 ( C4
::Context
->preference("marcflavour") eq "UNIMARC" && $tag >= 300
437 and $tag < 400 && $subfield eq 'a' )
440 && C4
::Context
->preference("marcflavour") eq "MARC21" )
443 $subfield_data{marc_value
} = {
445 id
=> $subfield_data{id
},
446 name
=> $subfield_data{id
},
452 $subfield_data{marc_value
} = {
454 id
=> $subfield_data{id
},
455 name
=> $subfield_data{id
},
458 maxlength
=> $subfield_data{maxlength
},
464 $subfield_data{'index_subfield'} = $index_subfield;
465 return \
%subfield_data;
469 =head2 format_indicator
471 Translate indicator value for output form - specifically, map
472 indicator = ' ' to ''. This is for the convenience of a cataloger
473 using a mouse to select an indicator input.
477 sub format_indicator
{
478 my $ind_value = shift;
479 return '' if not defined $ind_value;
480 return '' if $ind_value eq ' ';
485 my ( $template, $record, $dbh, $encoding,$input ) = @_;
491 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
492 my $query = "SELECT authorised_value, lib
493 FROM authorised_values";
494 $query .= qq{ LEFT JOIN authorised_values_branches ON
( id
= av_id
)} if $branch_limit;
495 $query .= " WHERE category = ?";
496 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
497 $query .= " GROUP BY lib ORDER BY lib, lib_opac";
498 my $authorised_values_sth = $dbh->prepare( $query );
500 # in this array, we will push all the 10 tabs
501 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
504 my @tab_data; # all tags to display
506 foreach my $used ( @
$usedTagsLib ){
507 push @tab_data,$used->{tagfield
} if not $seen{$used->{tagfield
}};
508 $seen{$used->{tagfield
}}++;
512 foreach(@
$usedTagsLib){
513 if($_->{tab
} > -1 && $_->{tab
} >= $max_num_tab && $_->{tagfield
} != '995'){ # FIXME : MARC21 ?
514 $max_num_tab = $_->{tab
};
517 if($max_num_tab >= 9){
520 # loop through each tab 0 through 9
521 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
522 my @loop_data = (); #innerloop in the template.
524 foreach my $tag (@tab_data) {
527 my ($indicator1, $indicator2);
528 my $index_tag = CreateKey
;
530 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
531 # if MARC::Record is empty => use tab as master loop.
532 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
534 if ( $tag ne '000' ) {
535 @fields = $record->field($tag);
538 push @fields, $record->leader(); # if tag == 000
540 # loop through each field
541 foreach my $field (@fields) {
545 my ( $value, $subfield );
546 if ( $tag ne '000' ) {
547 $value = $field->data();
554 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
556 if ( $tagslib->{$tag}->{$subfield}->{kohafield
} eq
557 'biblio.biblionumber' );
561 $tag, $subfield, $value, $index_tag, $tabloop, $record,
562 $authorised_values_sth,$input
567 my @subfields = $field->subfields();
568 foreach my $subfieldcount ( 0 .. $#subfields ) {
569 my $subfield = $subfields[$subfieldcount][0];
570 my $value = $subfields[$subfieldcount][1];
571 next if ( length $subfield != 1 );
572 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
576 $tag, $subfield, $value, $index_tag, $tabloop,
577 $record, $authorised_values_sth,$input
583 # now, loop again to add parameter subfield that are not in the MARC::Record
584 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
586 next if ( length $subfield != 1 );
587 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
588 next if ( $tag < 10 );
590 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
591 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
592 and not ( $subfield eq "9" and
593 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
594 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
595 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
597 ; #check for visibility flag
598 # if subfield is $9 in a field whose $a is authority-controlled,
599 # always include in the form regardless of the hidden setting - bug 2206
600 next if ( defined( $field->subfield($subfield) ) );
604 $tag, $subfield, '', $index_tag, $tabloop, $record,
605 $authorised_values_sth,$input
609 if ( $#subfields_data >= 0 ) {
610 # build the tag entry.
611 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
612 # have twice the same "name" value, and cgi->param() will return only one, making
613 # all subfields to be merged in a single field.
617 tag_lib
=> $tagslib->{$tag}->{lib
},
618 repeatable
=> $tagslib->{$tag}->{repeatable
},
619 mandatory
=> $tagslib->{$tag}->{mandatory
},
620 subfield_loop
=> \
@subfields_data,
621 fixedfield
=> $tag < 10?
1:0,
624 if ($tag >= 10){ # no indicator for 00x tags
625 $tag_data{indicator1
} = format_indicator
($field->indicator(1)),
626 $tag_data{indicator2
} = format_indicator
($field->indicator(2)),
628 push( @loop_data, \
%tag_data );
630 } # foreach $field end
632 # if breeding is empty
636 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
637 next if ( length $subfield != 1 );
639 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
640 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
641 and not ( $subfield eq "9" and
642 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
643 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
644 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
646 ; #check for visibility flag
647 # if subfield is $9 in a field whose $a is authority-controlled,
648 # always include in the form regardless of the hidden setting - bug 2206
650 if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
654 $tag, $subfield, '', $index_tag, $tabloop, $record,
655 $authorised_values_sth,$input
659 if ( $#subfields_data >= 0 ) {
663 tag_lib
=> $tagslib->{$tag}->{lib
},
664 repeatable
=> $tagslib->{$tag}->{repeatable
},
665 mandatory
=> $tagslib->{$tag}->{mandatory
},
666 indicator1
=> $indicator1,
667 indicator2
=> $indicator2,
668 subfield_loop
=> \
@subfields_data,
669 tagfirstsubfield
=> $subfields_data[0],
670 fixedfield
=> $tag < 10?
1:0,
673 push @loop_data, \
%tag_data ;
677 if ( $#loop_data >= 0 ) {
680 innerloop
=> \
@loop_data,
684 $authorised_values_sth->finish;
685 $template->param( BIG_LOOP
=> \
@BIG_LOOP );
688 # ========================
690 #=========================
692 my $error = $input->param('error');
693 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
694 my $parentbiblio = $input->param('parentbiblionumber');
695 my $breedingid = $input->param('breedingid');
696 my $z3950 = $input->param('z3950');
697 my $op = $input->param('op');
698 my $mode = $input->param('mode');
699 my $frameworkcode = $input->param('frameworkcode');
700 my $redirect = $input->param('redirect');
701 my $searchid = $input->param('searchid');
702 my $dbh = C4
::Context
->dbh;
703 my $hostbiblionumber = $input->param('hostbiblionumber');
704 my $hostitemnumber = $input->param('hostitemnumber');
705 # fast cataloguing datas in transit
706 my $fa_circborrowernumber = $input->param('circborrowernumber');
707 my $fa_barcode = $input->param('barcode');
708 my $fa_branch = $input->param('branch');
709 my $fa_stickyduedate = $input->param('stickyduedate');
710 my $fa_duedatespec = $input->param('duedatespec');
712 my $userflags = 'edit_catalogue';
714 my $changed_framework = $input->param('changed_framework');
715 $frameworkcode = &GetFrameworkCode
($biblionumber)
716 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
718 if ($frameworkcode eq 'FA'){
719 $userflags = 'fast_cataloging';
722 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
723 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
725 template_name
=> "cataloguing/addbiblio.tt",
728 authnotrequired
=> 0,
729 flagsrequired
=> { editcatalogue
=> $userflags },
734 my $does_bib_exist = Koha
::Biblios
->find($biblionumber);
735 if (!defined $does_bib_exist){
736 $biblionumber = undef;
737 $template->param( bib_doesnt_exist
=> 1 );
741 if ($frameworkcode eq 'FA'){
742 # We need to grab and set some variables in the template for use on the additems screen
744 'circborrowernumber' => $fa_circborrowernumber,
745 'barcode' => $fa_barcode,
746 'branch' => $fa_branch,
747 'stickyduedate' => $fa_stickyduedate,
748 'duedatespec' => $fa_duedatespec,
750 } elsif ( $op ne "delete" && C4
::Context
->preference('EnableAdvancedCatalogingEditor') && $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' && !$breedingid ) {
751 # Only use the advanced editor for non-fast-cataloging.
752 # breedingid is not handled because those would only come off a Z39.50
753 # search initiated by the basic editor.
754 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ?
( '#catalog/' . $biblionumber ) : '' ) );
758 my $frameworks = Koha
::BiblioFrameworks
->search({}, { order_by
=> ['frameworktext'] });
760 frameworks
=> $frameworks,
761 breedingid
=> $breedingid,
765 $tagslib = &GetMarcStructure
( 1, $frameworkcode );
766 $usedTagsLib = &GetUsedMarcStructure
( $frameworkcode );
767 $mandatory_z3950 = GetMandatoryFieldZ3950
($frameworkcode);
773 $biblionumbertagfield,
774 $biblionumbertagsubfield,
775 $biblioitemnumtagfield,
776 $biblioitemnumtagsubfield,
780 if (($biblionumber) && !($breedingid)){
781 $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
784 ( $record, $encoding ) = MARCfindbreeding
( $breedingid ) ;
787 #populate hostfield if hostbiblionumber is available
788 if ($hostbiblionumber) {
789 my $marcflavour = C4
::Context
->preference("marcflavour");
790 $record = MARC
::Record
->new();
793 PrepHostMarcField
( $hostbiblionumber, $hostitemnumber, $marcflavour );
794 $record->append_fields($field);
797 # This is a child record
799 my $marcflavour = C4
::Context
->preference('marcflavour');
800 $record = MARC
::Record
->new();
801 SetMarcUnicodeFlag
($record, $marcflavour);
802 my $hostfield = prepare_host_field
($parentbiblio,$marcflavour);
804 $record->append_fields($hostfield);
812 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
813 $template->param( title
=> $title );
815 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
816 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
817 &GetMarcFromKohaField
( "biblio.biblionumber", $frameworkcode );
818 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
819 &GetMarcFromKohaField
( "biblioitems.biblioitemnumber", $frameworkcode );
821 # search biblioitems value
822 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
823 $sth->execute($biblionumber);
824 ($biblioitemnumber) = $sth->fetchrow;
827 #-------------------------------------------------------------------------------------
828 if ( $op eq "addbiblio" ) {
829 #-------------------------------------------------------------------------------------
831 biblionumberdata
=> $biblionumber,
834 my @params = $input->multi_param();
835 $record = TransformHtmlToMarc
( $input, 1 );
836 # check for a duplicate
837 my ( $duplicatebiblionumber, $duplicatetitle );
838 if ( !$is_a_modif ) {
839 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate
($record);
841 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
842 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
843 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
845 if (C4
::Context
->preference("BiblioAddsAuthorities")){
846 BiblioAutoLink
( $record, $frameworkcode );
849 ModBiblio
( $record, $biblionumber, $frameworkcode );
852 ( $biblionumber, $oldbibitemnum ) = AddBiblio
( $record, $frameworkcode );
854 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
855 if ($frameworkcode eq 'FA'){
856 print $input->redirect(
857 '/cgi-bin/koha/cataloguing/additem.pl?'
858 .'biblionumber='.$biblionumber
859 .'&frameworkcode='.$frameworkcode
860 .'&circborrowernumber='.$fa_circborrowernumber
861 .'&branch='.$fa_branch
862 .'&barcode='.uri_escape_utf8
($fa_barcode)
863 .'&stickyduedate='.$fa_stickyduedate
864 .'&duedatespec='.$fa_duedatespec
869 print $input->redirect(
870 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
875 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
876 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
877 my $views = { C4
::Search
::enabled_staff_search_views
};
878 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
879 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
880 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
881 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
882 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
883 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
885 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
890 elsif ($redirect eq "just_save"){
891 my $tab = $input->param('current_tab');
892 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
896 biblionumber
=> $biblionumber,
900 if ( $record ne '-1' ) {
901 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
902 $template->param( title
=> $title );
906 itemtype
=> $frameworkcode,
908 output_html_with_http_headers
$input, $cookie, $template->output;
912 # it may be a duplicate, warn the user and do nothing
913 build_tabs
($template, $record, $dbh,$encoding,$input);
915 biblionumber
=> $biblionumber,
916 biblioitemnumber
=> $biblioitemnumber,
917 duplicatebiblionumber
=> $duplicatebiblionumber,
918 duplicatebibid
=> $duplicatebiblionumber,
919 duplicatetitle
=> $duplicatetitle,
923 elsif ( $op eq "delete" ) {
925 my $error = &DelBiblio
($biblionumber);
927 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
928 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
932 print $input->redirect('/cgi-bin/koha/catalogue/search.pl');
936 #----------------------------------------------------------------------------
937 # If we're in a duplication case, we have to set to "" the biblionumber
938 # as we'll save the biblio as a new one.
940 biblionumberdata
=> $biblionumber,
943 if ( $op eq "duplicate" ) {
947 if($changed_framework eq "changed"){
948 $record = TransformHtmlToMarc
( $input, 1 );
950 elsif( $record ne -1 ) {
951 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
953 my $uxml = $record->as_xml;
954 MARC
::Record
::default_record_format
("UNIMARC")
955 if ( C4
::Context
->preference("marcflavour") eq "UNIMARC" );
956 my $urecord = MARC
::Record
::new_from_xml
( $uxml, 'UTF-8' );
960 build_tabs
( $template, $record, $dbh, $encoding,$input );
962 biblionumber
=> $biblionumber,
963 biblionumbertagfield
=> $biblionumbertagfield,
964 biblionumbertagsubfield
=> $biblionumbertagsubfield,
965 biblioitemnumtagfield
=> $biblioitemnumtagfield,
966 biblioitemnumtagsubfield
=> $biblioitemnumtagsubfield,
967 biblioitemnumber
=> $biblioitemnumber,
968 hostbiblionumber
=> $hostbiblionumber,
969 hostitemnumber
=> $hostitemnumber
973 if ( $record ne '-1' ) {
974 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
975 $template->param( title
=> $title );
979 frameworkcode
=> $frameworkcode,
980 itemtype
=> $frameworkcode,
981 borrowernumber
=> $loggedinuser,
982 tab
=> scalar $input->param('tab')
984 $template->{'VARS'}->{'searchid'} = $searchid;
986 output_html_with_http_headers
$input, $cookie, $template->output;