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>.
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" );
111 C4
::Context
->preference("z3950AuthorAuthFields");
112 my @auth_fields = split /,/, $auth_fields;
115 if ( $record->field($tag) ) {
116 foreach my $tmpfield ( $record->field($tag)->subfields ) {
118 my $subfieldcode = shift @
$tmpfield;
119 my $subfieldvalue = shift @
$tmpfield;
121 $field->add_subfields(
122 "$subfieldcode" => $subfieldvalue )
123 if ( $subfieldcode ne $subfield );
127 MARC
::Field
->new( $tag, "", "",
128 $subfieldcode => $subfieldvalue )
129 if ( $subfieldcode ne $subfield );
133 $record->delete_field( $record->field($tag) );
134 foreach my $fieldtag (@auth_fields) {
135 next unless ( $record->field($fieldtag) );
136 my $lastname = $record->field($fieldtag)->subfield('a');
137 my $firstname = $record->field($fieldtag)->subfield('b');
138 my $title = $record->field($fieldtag)->subfield('c');
139 my $number = $record->field($fieldtag)->subfield('d');
141 $field->add_subfields(
142 "$subfield" => ucfirst($title) . " "
143 . ucfirst($firstname) . " "
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 my $category = $tagslib->{$tag}->{$subfield}->{authorised_value
};
174 if ( $category eq "branches" ) {
175 my $libraries = Koha
::Libraries
->search_filtered({}, {order_by
=> ['branchname']});
176 while ( my $l = $libraries->next ) {
177 push @authorised_values, $l->branchcode;;
178 $authorised_lib{$l->branchcode} = $l->branchname;
181 elsif ( $category eq "itemtypes" ) {
182 push @authorised_values, "";
185 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
186 while ( $itemtype = $itemtypes->next ) {
187 push @authorised_values, $itemtype->itemtype;
188 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
190 $value = $itemtype unless ($value);
192 elsif ( $category eq "cn_source" ) {
193 push @authorised_values, "";
195 my $class_sources = GetClassSources
();
197 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
199 foreach my $class_source (sort keys %$class_sources) {
200 next unless $class_sources->{$class_source}->{'used'} or
201 ($value and $class_source eq $value) or
202 ($class_source eq $default_source);
203 push @authorised_values, $class_source;
204 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
206 $value = $default_source unless $value;
209 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
210 $authorised_values_sth->execute(
211 $tagslib->{$tag}->{$subfield}->{authorised_value
},
212 $branch_limit ?
$branch_limit : (),
215 push @authorised_values, "";
217 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
218 push @authorised_values, $value;
219 $authorised_lib{$value} = $lib;
222 $authorised_values_sth->finish;
226 id
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
227 name
=> "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
229 values => \
@authorised_values,
230 labels
=> \
%authorised_lib,
231 ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ?
() : ( category
=> $category ) ),
238 Create a random value to set it into the input name
243 return int(rand(1000000));
246 =head2 GetMandatoryFieldZ3950
248 This function returns a hashref which contains all mandatory field
249 to search with z3950 server.
253 sub GetMandatoryFieldZ3950
{
254 my $frameworkcode = shift;
255 my @isbn = GetMarcFromKohaField
( 'biblioitems.isbn' );
256 my @title = GetMarcFromKohaField
( 'biblio.title' );
257 my @author = GetMarcFromKohaField
( 'biblio.author' );
258 my @issn = GetMarcFromKohaField
( 'biblioitems.issn' );
259 my @lccn = GetMarcFromKohaField
( 'biblioitems.lccn' );
262 $isbn[0].$isbn[1] => 'isbn',
263 $title[0].$title[1] => 'title',
264 $author[0].$author[1] => 'author',
265 $issn[0].$issn[1] => 'issn',
266 $lccn[0].$lccn[1] => 'lccn',
272 builds the <input ...> entry for a subfield.
277 my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
279 my $index_subfield = CreateKey
(); # create a specifique key for each subfield
281 # if there is no value provided but a default value in parameters, get it
282 if ( $value eq '' ) {
283 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue
} // q{};
285 # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
286 my $today_dt = dt_from_string
;
287 my $year = $today_dt->strftime('%Y');
288 my $shortyear = $today_dt->strftime('%y');
289 my $month = $today_dt->strftime('%m');
290 my $day = $today_dt->strftime('%d');
291 $value =~ s/<<YYYY>>/$year/g;
292 $value =~ s/<<YY>>/$shortyear/g;
293 $value =~ s/<<MM>>/$month/g;
294 $value =~ s/<<DD>>/$day/g;
295 # And <<USER>> with surname (?)
296 my $username=(C4
::Context
->userenv?C4
::Context
->userenv->{'surname'}:"superlibrarian");
297 $value=~s/<<USER>>/$username/g;
300 my $dbh = C4
::Context
->dbh;
302 # map '@' as "subfield" label for fixed fields
303 # to something that's allowed in a div id.
304 my $id_subfield = $subfield;
305 $id_subfield = "00" if $id_subfield eq "@";
307 my %subfield_data = (
309 subfield
=> $id_subfield,
310 marc_lib
=> $tagslib->{$tag}->{$subfield}->{lib
},
311 tag_mandatory
=> $tagslib->{$tag}->{mandatory
},
312 mandatory
=> $tagslib->{$tag}->{$subfield}->{mandatory
},
313 important
=> $tagslib->{$tag}->{$subfield}->{important
},
314 repeatable
=> $tagslib->{$tag}->{$subfield}->{repeatable
},
315 kohafield
=> $tagslib->{$tag}->{$subfield}->{kohafield
},
317 id
=> "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
319 maxlength
=> $tagslib->{$tag}->{$subfield}->{maxlength
},
320 random
=> CreateKey
(),
323 if(exists $mandatory_z3950->{$tag.$subfield}){
324 $subfield_data{z3950_mandatory
} = $mandatory_z3950->{$tag.$subfield};
326 # Subfield is hidden depending of hidden and mandatory flag, and is always
327 # shown if it contains anything or if its field is mandatory or important.
328 my $tdef = $tagslib->{$tag};
329 $subfield_data{visibility
} = "display:none;"
330 if $tdef->{$subfield}->{hidden
} % 2 == 1 &&
332 !$tdef->{$subfield}->{mandatory
} &&
333 !$tdef->{mandatory
} &&
334 !$tdef->{$subfield}->{important
} &&
336 # expand all subfields of 773 if there is a host item provided in the input
337 $subfield_data{visibility
} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
340 # it's an authorised field
341 if ( $tagslib->{$tag}->{$subfield}->{authorised_value
} ) {
342 $subfield_data{marc_value
} =
343 build_authorized_values_list
( $tag, $subfield, $value, $dbh,
344 $authorised_values_sth,$index_tag,$index_subfield );
346 # it's a subfield $9 linking to an authority record - see bug 2206
348 elsif ($subfield eq "9" and
349 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
350 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
351 $tagslib->{$tag}->{'a'}->{authtypecode
} ne '') {
353 $subfield_data{marc_value
} = {
355 id
=> $subfield_data{id
},
356 name
=> $subfield_data{id
},
359 maxlength
=> $subfield_data{maxlength
},
363 # it's a thesaurus / authority field
365 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode
} ) {
366 # when authorities auto-creation is allowed, do not set readonly
367 my $is_readonly = !C4
::Context
->preference("BiblioAddsAuthorities");
369 $subfield_data{marc_value
} = {
371 id
=> $subfield_data{id
},
372 name
=> $subfield_data{id
},
375 maxlength
=> $subfield_data{maxlength
},
376 readonly
=> ($is_readonly) ?
1 : 0,
377 authtype
=> $tagslib->{$tag}->{$subfield}->{authtypecode
},
380 # it's a plugin field
381 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
382 require Koha
::FrameworkPlugin
;
383 my $plugin = Koha
::FrameworkPlugin
->new( {
384 name
=> $tagslib->{$tag}->{$subfield}->{'value_builder'},
386 my $pars= { dbh
=> $dbh, record
=> $rec, tagslib
=> $tagslib,
387 id
=> $subfield_data{id
}, tabloop
=> $tabloop };
388 $plugin->build( $pars );
389 if( !$plugin->errstr ) {
390 $subfield_data{marc_value
} = {
391 type
=> 'text_complex',
392 id
=> $subfield_data{id
},
393 name
=> $subfield_data{id
},
396 maxlength
=> $subfield_data{maxlength
},
397 javascript
=> $plugin->javascript,
398 plugin
=> $plugin->name,
399 noclick
=> $plugin->noclick,
402 warn $plugin->errstr;
403 # supply default input form
404 $subfield_data{marc_value
} = {
406 id
=> $subfield_data{id
},
407 name
=> $subfield_data{id
},
410 maxlength
=> $subfield_data{maxlength
},
415 # it's an hidden field
416 } elsif ( $tag eq '' ) {
417 $subfield_data{marc_value
} = {
419 id
=> $subfield_data{id
},
420 name
=> $subfield_data{id
},
423 maxlength
=> $subfield_data{maxlength
},
428 # it's a standard field
432 ( C4
::Context
->preference("marcflavour") eq "UNIMARC" && $tag >= 300
433 and $tag < 400 && $subfield eq 'a' )
436 && C4
::Context
->preference("marcflavour") eq "MARC21" )
439 $subfield_data{marc_value
} = {
441 id
=> $subfield_data{id
},
442 name
=> $subfield_data{id
},
448 $subfield_data{marc_value
} = {
450 id
=> $subfield_data{id
},
451 name
=> $subfield_data{id
},
454 maxlength
=> $subfield_data{maxlength
},
460 $subfield_data{'index_subfield'} = $index_subfield;
461 return \
%subfield_data;
465 =head2 format_indicator
467 Translate indicator value for output form - specifically, map
468 indicator = ' ' to ''. This is for the convenience of a cataloger
469 using a mouse to select an indicator input.
473 sub format_indicator
{
474 my $ind_value = shift;
475 return '' if not defined $ind_value;
476 return '' if $ind_value eq ' ';
481 my ( $template, $record, $dbh, $encoding,$input ) = @_;
487 my $branch_limit = C4
::Context
->userenv ? C4
::Context
->userenv->{"branch"} : "";
488 my $query = "SELECT authorised_value, lib
489 FROM authorised_values";
490 $query .= qq{ LEFT JOIN authorised_values_branches ON
( id
= av_id
)} if $branch_limit;
491 $query .= " WHERE category = ?";
492 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
493 $query .= " GROUP BY authorised_value,lib ORDER BY lib, lib_opac";
494 my $authorised_values_sth = $dbh->prepare( $query );
496 # in this array, we will push all the 10 tabs
497 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
500 my @tab_data; # all tags to display
503 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField
( "items.itemnumber" );
504 foreach my $used ( @
$usedTagsLib ){
506 push @tab_data,$used->{tagfield
} if not $seen{$used->{tagfield
}};
507 $seen{$used->{tagfield
}}++;
509 if ( $used->{tab
} > -1
510 && $used->{tab
} >= $max_num_tab
511 && $used->{tagfield
} ne $itemtag )
513 $max_num_tab = $used->{tab
};
516 if($max_num_tab >= 9){
519 # loop through each tab 0 through 9
520 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
521 my @loop_data = (); #innerloop in the template.
523 foreach my $tag (sort @tab_data) {
526 my ($indicator1, $indicator2);
527 my $index_tag = CreateKey
;
529 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
530 # if MARC::Record is empty => use tab as master loop.
531 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
533 if ( $tag ne '000' ) {
534 @fields = $record->field($tag);
537 push @fields, $record->leader(); # if tag == 000
539 # loop through each field
540 foreach my $field (@fields) {
544 my ( $value, $subfield );
545 if ( $tag ne '000' ) {
546 $value = $field->data();
553 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
555 if ( $tagslib->{$tag}->{$subfield}->{kohafield
} eq
556 'biblio.biblionumber' );
560 $tag, $subfield, $value, $index_tag, $tabloop, $record,
561 $authorised_values_sth,$input
566 my @subfields = $field->subfields();
567 foreach my $subfieldcount ( 0 .. $#subfields ) {
568 my $subfield = $subfields[$subfieldcount][0];
569 my $value = $subfields[$subfieldcount][1];
570 next if ( length $subfield != 1 );
571 next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
575 $tag, $subfield, $value, $index_tag, $tabloop,
576 $record, $authorised_values_sth,$input
582 # now, loop again to add parameter subfield that are not in the MARC::Record
583 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
585 next if ( length $subfield != 1 );
586 next if ( $tagslib->{$tag}->{$subfield}->{tab
} ne $tabloop );
587 next if ( $tag < 10 );
589 if ( ( $tagslib->{$tag}->{$subfield}->{hidden
} <= -4 )
590 or ( $tagslib->{$tag}->{$subfield}->{hidden
} >= 5 ) )
591 and not ( $subfield eq "9" and
592 exists($tagslib->{$tag}->{'a'}->{authtypecode
}) and
593 defined($tagslib->{$tag}->{'a'}->{authtypecode
}) and
594 $tagslib->{$tag}->{'a'}->{authtypecode
} ne ""
596 ; #check for visibility flag
597 # if subfield is $9 in a field whose $a is authority-controlled,
598 # always include in the form regardless of the hidden setting - bug 2206
599 next if ( defined( $field->subfield($subfield) ) );
603 $tag, $subfield, '', $index_tag, $tabloop, $record,
604 $authorised_values_sth,$input
608 if ( $#subfields_data >= 0 ) {
609 # build the tag entry.
610 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
611 # have twice the same "name" value, and cgi->param() will return only one, making
612 # all subfields to be merged in a single field.
616 tag_lib
=> $tagslib->{$tag}->{lib
},
617 repeatable
=> $tagslib->{$tag}->{repeatable
},
618 mandatory
=> $tagslib->{$tag}->{mandatory
},
619 important
=> $tagslib->{$tag}->{important
},
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 important
=> $tagslib->{$tag}->{important
},
667 indicator1
=> ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue
} ), #if not set, try to load the default value
668 indicator2
=> ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue
} ), #use short-circuit operator for efficiency
669 subfield_loop
=> \
@subfields_data,
670 tagfirstsubfield
=> $subfields_data[0],
671 fixedfield
=> $tag < 10?
1:0,
674 push @loop_data, \
%tag_data ;
678 if ( $#loop_data >= 0 ) {
681 innerloop
=> \
@loop_data,
685 $authorised_values_sth->finish;
686 $template->param( BIG_LOOP
=> \
@BIG_LOOP );
689 # ========================
691 #=========================
693 my $error = $input->param('error');
694 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
695 my $parentbiblio = $input->param('parentbiblionumber');
696 my $breedingid = $input->param('breedingid');
697 my $z3950 = $input->param('z3950');
698 my $op = $input->param('op') // q{};
699 my $mode = $input->param('mode');
700 my $frameworkcode = $input->param('frameworkcode');
701 my $redirect = $input->param('redirect');
702 my $searchid = $input->param('searchid');
703 my $dbh = C4
::Context
->dbh;
704 my $hostbiblionumber = $input->param('hostbiblionumber');
705 my $hostitemnumber = $input->param('hostitemnumber');
706 # fast cataloguing datas in transit
707 my $fa_circborrowernumber = $input->param('circborrowernumber');
708 my $fa_barcode = $input->param('barcode');
709 my $fa_branch = $input->param('branch');
710 my $fa_stickyduedate = $input->param('stickyduedate');
711 my $fa_duedatespec = $input->param('duedatespec');
713 my $userflags = 'edit_catalogue';
715 my $changed_framework = $input->param('changed_framework') // q{};
716 $frameworkcode = &GetFrameworkCode
($biblionumber)
717 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
719 if ($frameworkcode eq 'FA'){
720 $userflags = 'fast_cataloging';
723 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
724 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
726 template_name
=> "cataloguing/addbiblio.tt",
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" &&
751 C4
::Context
->preference('EnableAdvancedCatalogingEditor') &&
752 C4
::Auth
::haspermission
(C4
::Context
->userenv->{id
},{'editcatalogue'=>'advanced_editor'}) &&
753 $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' &&
755 # Only use the advanced editor for non-fast-cataloging.
756 # breedingid is not handled because those would only come off a Z39.50
757 # search initiated by the basic editor.
758 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ?
( ($op eq 'duplicate'?
'#duplicate/':'#catalog/') . $biblionumber ) : '' ) );
762 my $frameworks = Koha
::BiblioFrameworks
->search({}, { order_by
=> ['frameworktext'] });
764 frameworks
=> $frameworks,
765 breedingid
=> $breedingid,
769 $tagslib = &GetMarcStructure
( 1, $frameworkcode );
770 $usedTagsLib = &GetUsedMarcStructure
( $frameworkcode );
771 $mandatory_z3950 = GetMandatoryFieldZ3950
($frameworkcode);
777 $biblionumbertagfield,
778 $biblionumbertagsubfield,
779 $biblioitemnumtagfield,
780 $biblioitemnumtagsubfield,
784 if (($biblionumber) && !($breedingid)){
785 $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
788 ( $record, $encoding ) = MARCfindbreeding
( $breedingid ) ;
791 #populate hostfield if hostbiblionumber is available
792 if ($hostbiblionumber) {
793 my $marcflavour = C4
::Context
->preference("marcflavour");
794 $record = MARC
::Record
->new();
797 PrepHostMarcField
( $hostbiblionumber, $hostitemnumber, $marcflavour );
798 $record->append_fields($field);
801 # This is a child record
803 my $marcflavour = C4
::Context
->preference('marcflavour');
804 $record = MARC
::Record
->new();
805 SetMarcUnicodeFlag
($record, $marcflavour);
806 my $hostfield = prepare_host_field
($parentbiblio,$marcflavour);
808 $record->append_fields($hostfield);
816 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
817 $template->param( title
=> $title );
819 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
820 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
821 &GetMarcFromKohaField
( "biblio.biblionumber" );
822 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
823 &GetMarcFromKohaField
( "biblioitems.biblioitemnumber" );
825 # search biblioitems value
826 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
827 $sth->execute($biblionumber);
828 ($biblioitemnumber) = $sth->fetchrow;
831 #-------------------------------------------------------------------------------------
832 if ( $op eq "addbiblio" ) {
833 #-------------------------------------------------------------------------------------
835 biblionumberdata
=> $biblionumber,
838 my @params = $input->multi_param();
839 $record = TransformHtmlToMarc
( $input, 1 );
840 # check for a duplicate
841 my ( $duplicatebiblionumber, $duplicatetitle );
842 if ( !$is_a_modif ) {
843 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate
($record);
845 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
846 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
847 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
850 ModBiblio
( $record, $biblionumber, $frameworkcode );
853 ( $biblionumber, $oldbibitemnum ) = AddBiblio
( $record, $frameworkcode );
855 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
856 if ($frameworkcode eq 'FA'){
857 print $input->redirect(
858 '/cgi-bin/koha/cataloguing/additem.pl?'
859 .'biblionumber='.$biblionumber
860 .'&frameworkcode='.$frameworkcode
861 .'&circborrowernumber='.$fa_circborrowernumber
862 .'&branch='.$fa_branch
863 .'&barcode='.uri_escape_utf8
($fa_barcode)
864 .'&stickyduedate='.$fa_stickyduedate
865 .'&duedatespec='.$fa_duedatespec
870 print $input->redirect(
871 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
876 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
877 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
878 my $views = { C4
::Search
::enabled_staff_search_views
};
879 if ($defaultview eq 'isbd' && $views->{can_view_ISBD
}) {
880 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
881 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC
}) {
882 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
883 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC
}) {
884 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
886 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
891 elsif ($redirect eq "just_save"){
892 my $tab = $input->param('current_tab');
893 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
897 biblionumber
=> $biblionumber,
901 if ( $record ne '-1' ) {
902 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
903 $template->param( title
=> $title );
907 itemtype
=> $frameworkcode,
909 output_html_with_http_headers
$input, $cookie, $template->output;
913 # it may be a duplicate, warn the user and do nothing
914 build_tabs
($template, $record, $dbh,$encoding,$input);
916 biblionumber
=> $biblionumber,
917 biblioitemnumber
=> $biblioitemnumber,
918 duplicatebiblionumber
=> $duplicatebiblionumber,
919 duplicatebibid
=> $duplicatebiblionumber,
920 duplicatetitle
=> $duplicatetitle,
924 elsif ( $op eq "delete" ) {
926 my $error = &DelBiblio
($biblionumber);
928 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
929 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
933 print $input->redirect('/cgi-bin/koha/catalogue/search.pl' . ($searchid ?
"?searchid=$searchid" : ""));
937 #----------------------------------------------------------------------------
938 # If we're in a duplication case, we have to set to "" the biblionumber
939 # as we'll save the biblio as a new one.
941 biblionumberdata
=> $biblionumber,
944 if ( $op eq "duplicate" ) {
948 if($changed_framework eq "changed"){
949 $record = TransformHtmlToMarc
( $input, 1 );
951 elsif( $record ne -1 ) {
952 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
954 my $uxml = $record->as_xml;
955 MARC
::Record
::default_record_format
("UNIMARC")
956 if ( C4
::Context
->preference("marcflavour") eq "UNIMARC" );
957 my $urecord = MARC
::Record
::new_from_xml
( $uxml, 'UTF-8' );
961 build_tabs
( $template, $record, $dbh, $encoding,$input );
963 biblionumber
=> $biblionumber,
964 biblionumbertagfield
=> $biblionumbertagfield,
965 biblionumbertagsubfield
=> $biblionumbertagsubfield,
966 biblioitemnumtagfield
=> $biblioitemnumtagfield,
967 biblioitemnumtagsubfield
=> $biblioitemnumtagsubfield,
968 biblioitemnumber
=> $biblioitemnumber,
969 hostbiblionumber
=> $hostbiblionumber,
970 hostitemnumber
=> $hostitemnumber
974 if ( $record ne '-1' ) {
975 my $title = C4
::Context
->preference('marcflavour') eq "UNIMARC" ?
$record->subfield('200', 'a') : $record->title;
976 $template->param( title
=> $title );
980 frameworkcode
=> $frameworkcode,
981 itemtype
=> $frameworkcode,
982 borrowernumber
=> $loggedinuser,
983 tab
=> scalar $input->param('tab')
985 $template->{'VARS'}->{'searchid'} = $searchid;
987 output_html_with_http_headers
$input, $cookie, $template->output;