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>.
25 use C4::Output qw( output_html_with_http_headers );
26 use C4::Auth qw( get_template_and_user haspermission );
40 use C4::Search qw( FindDuplicate enabled_staff_search_views );
41 use C4::Auth qw( get_template_and_user haspermission );
44 use C4::ClassSource qw( GetClassSources );
45 use C4::ImportBatch qw( GetImportRecordMarc );
46 use C4::Charset qw( SetMarcUnicodeFlag );
47 use Koha::BiblioFrameworks;
48 use Koha::DateUtils qw( dt_from_string );
53 use Koha::BiblioFrameworks;
56 use MARC::File::USMARC;
58 use URI::Escape qw( uri_escape_utf8 );
60 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
61 MARC::File::XML->default_record_format('UNIMARC');
64 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
68 =head2 MARCfindbreeding
70 $record = MARCfindbreeding($breedingid);
72 Look up the import record repository for the record with
73 record with id $breedingid. If found, returns the decoded
74 MARC::Record; otherwise, -1 is returned (FIXME).
75 Returns as second parameter the character encoding.
79 sub MARCfindbreeding {
81 my ($marc, $encoding) = GetImportRecordMarc($id);
82 # remove the - in isbn, koha store isbn without any -
84 my $record = MARC::Record->new_from_usmarc($marc);
85 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField( 'biblioitems.isbn' );
86 if ( $record->field($isbnfield) ) {
87 foreach my $field ( $record->field($isbnfield) ) {
88 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
89 my $newisbn = $field->subfield($isbnsubfield);
91 $field->update( $isbnsubfield => $newisbn );
95 # fix the unimarc 100 coded field (with unicode information)
96 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
97 my $f100a=$record->subfield(100,'a');
98 my $f100 = $record->field(100);
99 my $f100temp = $f100->as_string;
100 $record->delete_field($f100);
101 if ( length($f100temp) > 28 ) {
102 substr( $f100temp, 26, 2, "50" );
103 $f100->update( 'a' => $f100temp );
104 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
105 $record->insert_fields_ordered($f100);
109 if ( !defined(ref($record)) ) {
113 # normalize author : UNIMARC specific...
114 if ( C4::Context->preference("z3950NormalizeAuthor")
115 and C4::Context->preference("z3950AuthorAuthFields")
116 and C4::Context->preference("marcflavour") eq 'UNIMARC' )
118 my ( $tag, $subfield ) = GetMarcFromKohaField( "biblio.author" );
121 C4::Context->preference("z3950AuthorAuthFields");
122 my @auth_fields = split /,/, $auth_fields;
125 if ( $record->field($tag) ) {
126 foreach my $tmpfield ( $record->field($tag)->subfields ) {
128 my $subfieldcode = shift @$tmpfield;
129 my $subfieldvalue = shift @$tmpfield;
131 $field->add_subfields(
132 "$subfieldcode" => $subfieldvalue )
133 if ( $subfieldcode ne $subfield );
137 MARC::Field->new( $tag, "", "",
138 $subfieldcode => $subfieldvalue )
139 if ( $subfieldcode ne $subfield );
143 $record->delete_field( $record->field($tag) );
144 foreach my $fieldtag (@auth_fields) {
145 next unless ( $record->field($fieldtag) );
146 my $lastname = $record->field($fieldtag)->subfield('a');
147 my $firstname = $record->field($fieldtag)->subfield('b');
148 my $title = $record->field($fieldtag)->subfield('c');
149 my $number = $record->field($fieldtag)->subfield('d');
151 $field->add_subfields(
152 "$subfield" => ucfirst($title) . " "
153 . ucfirst($firstname) . " "
157 $field->add_subfields(
158 "$subfield" => ucfirst($firstname) . ", "
159 . ucfirst($lastname) );
162 $record->insert_fields_ordered($field);
164 return $record, $encoding;
170 =head2 build_authorized_values_list
174 sub build_authorized_values_list {
175 my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
177 my @authorised_values;
180 # builds list, depending on authorised value...
183 my $category = $tagslib->{$tag}->{$subfield}->{authorised_value};
184 if ( $category eq "branches" ) {
185 my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
186 while ( my $l = $libraries->next ) {
187 push @authorised_values, $l->branchcode;;
188 $authorised_lib{$l->branchcode} = $l->branchname;
191 elsif ( $category eq "itemtypes" ) {
192 push @authorised_values, "";
195 my $itemtypes = Koha::ItemTypes->search_with_localization;
196 while ( $itemtype = $itemtypes->next ) {
197 push @authorised_values, $itemtype->itemtype;
198 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
200 $value = $itemtype unless ($value);
202 elsif ( $category eq "cn_source" ) {
203 push @authorised_values, "";
205 my $class_sources = GetClassSources();
207 my $default_source = C4::Context->preference("DefaultClassificationSource");
209 foreach my $class_source (sort keys %$class_sources) {
210 next unless $class_sources->{$class_source}->{'used'} or
211 ($value and $class_source eq $value) or
212 ($class_source eq $default_source);
213 push @authorised_values, $class_source;
214 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
216 $value = $default_source unless $value;
219 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
220 $authorised_values_sth->execute(
221 $tagslib->{$tag}->{$subfield}->{authorised_value},
222 $branch_limit ? $branch_limit : (),
225 push @authorised_values, "";
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;
236 id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
237 name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
239 values => \@authorised_values,
240 labels => \%authorised_lib,
241 ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ),
248 Create a random value to set it into the input name
253 return int(rand(1000000));
256 =head2 GetMandatoryFieldZ3950
258 This function returns a hashref which contains all mandatory field
259 to search with z3950 server.
263 sub GetMandatoryFieldZ3950 {
264 my $frameworkcode = shift;
265 my @isbn = GetMarcFromKohaField( 'biblioitems.isbn' );
266 my @title = GetMarcFromKohaField( 'biblio.title' );
267 my @author = GetMarcFromKohaField( 'biblio.author' );
268 my @issn = GetMarcFromKohaField( 'biblioitems.issn' );
269 my @lccn = GetMarcFromKohaField( 'biblioitems.lccn' );
272 $isbn[0].$isbn[1] => 'isbn',
273 $title[0].$title[1] => 'title',
274 $author[0].$author[1] => 'author',
275 $issn[0].$issn[1] => 'issn',
276 $lccn[0].$lccn[1] => 'lccn',
282 builds the <input ...> entry for a subfield.
287 my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth,$cgi ) = @_;
289 my $index_subfield = CreateKey(); # create a specifique key for each subfield
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} // q{};
295 # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
296 my $today_dt = dt_from_string;
297 my $year = $today_dt->strftime('%Y');
298 my $shortyear = $today_dt->strftime('%y');
299 my $month = $today_dt->strftime('%m');
300 my $day = $today_dt->strftime('%d');
301 $value =~ s/<<YYYY>>/$year/g;
302 $value =~ s/<<YY>>/$shortyear/g;
303 $value =~ s/<<MM>>/$month/g;
304 $value =~ s/<<DD>>/$day/g;
305 # And <<USER>> with surname (?)
306 my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
307 $value=~s/<<USER>>/$username/g;
310 my $dbh = C4::Context->dbh;
312 # map '@' as "subfield" label for fixed fields
313 # to something that's allowed in a div id.
314 my $id_subfield = $subfield;
315 $id_subfield = "00" if $id_subfield eq "@";
317 my %subfield_data = (
319 subfield => $id_subfield,
320 marc_lib => $tagslib->{$tag}->{$subfield}->{lib},
321 tag_mandatory => $tagslib->{$tag}->{mandatory},
322 mandatory => $tagslib->{$tag}->{$subfield}->{mandatory},
323 important => $tagslib->{$tag}->{$subfield}->{important},
324 repeatable => $tagslib->{$tag}->{$subfield}->{repeatable},
325 kohafield => $tagslib->{$tag}->{$subfield}->{kohafield},
327 id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
329 maxlength => $tagslib->{$tag}->{$subfield}->{maxlength},
330 random => CreateKey(),
333 if(exists $mandatory_z3950->{$tag.$subfield}){
334 $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
336 # Subfield is hidden depending of hidden and mandatory flag, and is always
337 # shown if it contains anything or if its field is mandatory or important.
338 my $tdef = $tagslib->{$tag};
339 $subfield_data{visibility} = "display:none;"
340 if $tdef->{$subfield}->{hidden} % 2 == 1 &&
342 !$tdef->{$subfield}->{mandatory} &&
343 !$tdef->{mandatory} &&
344 !$tdef->{$subfield}->{important} &&
346 # expand all subfields of 773 if there is a host item provided in the input
347 $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
350 # it's an authorised field
351 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
352 $subfield_data{marc_value} =
353 build_authorized_values_list( $tag, $subfield, $value, $dbh,
354 $authorised_values_sth,$index_tag,$index_subfield );
356 # it's a subfield $9 linking to an authority record - see bug 2206 and 28022
358 elsif ($subfield eq "9" and
359 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
360 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
361 $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and
362 $tagslib->{$tag}->{'a'}->{hidden} > -4 and
363 $tagslib->{$tag}->{'a'}->{hidden} < 5) {
364 $subfield_data{marc_value} = {
366 id => $subfield_data{id},
367 name => $subfield_data{id},
370 maxlength => $subfield_data{maxlength},
374 # it's a thesaurus / authority field
376 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
377 # when authorities auto-creation is allowed, do not set readonly
378 my $is_readonly = !C4::Context->preference("BiblioAddsAuthorities");
380 $subfield_data{marc_value} = {
382 id => $subfield_data{id},
383 name => $subfield_data{id},
386 maxlength => $subfield_data{maxlength},
387 readonly => ($is_readonly) ? 1 : 0,
388 authtype => $tagslib->{$tag}->{$subfield}->{authtypecode},
391 # it's a plugin field
392 } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
393 require Koha::FrameworkPlugin;
394 my $plugin = Koha::FrameworkPlugin->new( {
395 name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
397 my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
398 id => $subfield_data{id} };
399 $plugin->build( $pars );
400 if( !$plugin->errstr ) {
401 $subfield_data{marc_value} = {
402 type => 'text_complex',
403 id => $subfield_data{id},
404 name => $subfield_data{id},
407 maxlength => $subfield_data{maxlength},
408 javascript => $plugin->javascript,
409 plugin => $plugin->name,
410 noclick => $plugin->noclick,
413 warn $plugin->errstr;
414 # supply default input form
415 $subfield_data{marc_value} = {
417 id => $subfield_data{id},
418 name => $subfield_data{id},
421 maxlength => $subfield_data{maxlength},
426 # it's an hidden field
427 } elsif ( $tag eq '' ) {
428 $subfield_data{marc_value} = {
430 id => $subfield_data{id},
431 name => $subfield_data{id},
434 maxlength => $subfield_data{maxlength},
439 # it's a standard field
443 ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
444 and $tag < 400 && $subfield eq 'a' )
447 && C4::Context->preference("marcflavour") eq "MARC21" )
450 $subfield_data{marc_value} = {
452 id => $subfield_data{id},
453 name => $subfield_data{id},
459 $subfield_data{marc_value} = {
461 id => $subfield_data{id},
462 name => $subfield_data{id},
465 maxlength => $subfield_data{maxlength},
471 $subfield_data{'index_subfield'} = $index_subfield;
472 return \%subfield_data;
476 =head2 format_indicator
478 Translate indicator value for output form - specifically, map
479 indicator = ' ' to ''. This is for the convenience of a cataloger
480 using a mouse to select an indicator input.
484 sub format_indicator {
485 my $ind_value = shift;
486 return '' if not defined $ind_value;
487 return '' if $ind_value eq ' ';
492 my ( $template, $record, $dbh, $encoding,$input ) = @_;
498 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
499 my $query = "SELECT authorised_value, lib
500 FROM authorised_values";
501 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
502 $query .= " WHERE category = ?";
503 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
504 $query .= " GROUP BY authorised_value,lib ORDER BY lib, lib_opac";
505 my $authorised_values_sth = $dbh->prepare( $query );
507 # in this array, we will push all the 10 tabs
508 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
511 my @tab_data; # all tags to display
514 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
515 foreach my $used ( @$usedTagsLib ){
517 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
518 $seen{$used->{tagfield}}++;
520 if ( $used->{tab} > -1
521 && $used->{tab} >= $max_num_tab
522 && $used->{tagfield} ne $itemtag )
524 $max_num_tab = $used->{tab};
527 if($max_num_tab >= 9){
530 # loop through each tab 0 through 9
531 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
532 my @loop_data = (); #innerloop in the template.
534 foreach my $tag (sort @tab_data) {
537 my ($indicator1, $indicator2);
538 my $index_tag = CreateKey;
540 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
541 # if MARC::Record is empty => use tab as master loop.
542 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
544 if ( $tag ne '000' ) {
545 @fields = $record->field($tag);
548 push @fields, $record->leader(); # if tag == 000
550 # loop through each field
551 foreach my $field (@fields) {
555 my ( $value, $subfield );
556 if ( $tag ne '000' ) {
557 $value = $field->data();
564 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
566 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
567 'biblio.biblionumber' );
571 $tag, $subfield, $value, $index_tag, $record,
572 $authorised_values_sth,$input
577 my @subfields = $field->subfields();
578 foreach my $subfieldcount ( 0 .. $#subfields ) {
579 my $subfield = $subfields[$subfieldcount][0];
580 my $value = $subfields[$subfieldcount][1];
581 next if ( length $subfield != 1 );
582 next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
586 $tag, $subfield, $value, $index_tag,
587 $record, $authorised_values_sth,$input
593 # now, loop again to add parameter subfield that are not in the MARC::Record
594 foreach my $subfield ( keys %{ $tagslib->{$tag} } )
596 next if ( length $subfield != 1 );
597 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
598 next if ( $tag < 10 );
600 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
601 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
602 and not ( $subfield eq "9" and
603 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
604 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
605 $tagslib->{$tag}->{'a'}->{authtypecode} ne "" and
606 $tagslib->{$tag}->{'a'}->{hidden} > -4 and
607 $tagslib->{$tag}->{'a'}->{hidden} < 5
609 ; #check for visibility flag
610 # if subfield is $9 in a field whose $a is authority-controlled,
611 # always include in the form regardless of the hidden setting - bug 2206 and 28022
612 next if ( defined( $field->subfield($subfield) ) );
616 $tag, $subfield, '', $index_tag, $record,
617 $authorised_values_sth,$input
621 if ( $#subfields_data >= 0 ) {
622 # build the tag entry.
623 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
624 # have twice the same "name" value, and cgi->param() will return only one, making
625 # all subfields to be merged in a single field.
629 tag_lib => $tagslib->{$tag}->{lib},
630 repeatable => $tagslib->{$tag}->{repeatable},
631 mandatory => $tagslib->{$tag}->{mandatory},
632 important => $tagslib->{$tag}->{important},
633 subfield_loop => \@subfields_data,
634 fixedfield => $tag < 10?1:0,
637 if ($tag >= 10){ # no indicator for 00x tags
638 $tag_data{indicator1} = format_indicator($field->indicator(1)),
639 $tag_data{indicator2} = format_indicator($field->indicator(2)),
641 push( @loop_data, \%tag_data );
643 } # foreach $field end
645 # if breeding is empty
649 foreach my $subfield (
650 sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} }
651 grep { ref($_) && %$_ } # Not a subfield (values for "important", "lib", "mandatory", etc.) or empty
652 values %{ $tagslib->{$tag} } )
655 if ( ( $subfield->{hidden} <= -4 )
656 or ( $subfield->{hidden} >= 5 ) )
657 and not ( $subfield->{subfield} eq "9" and
658 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
659 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
660 $tagslib->{$tag}->{'a'}->{authtypecode} ne "" and
661 $tagslib->{$tag}->{'a'}->{hidden} > -4 and
662 $tagslib->{$tag}->{'a'}->{hidden} < 5
664 ; #check for visibility flag
665 # if subfield is $9 in a field whose $a is authority-controlled,
666 # always include in the form regardless of the hidden setting - bug 2206 and 28022
668 if ( $subfield->{tab} ne $tabloop );
672 $tag, $subfield->{subfield}, '', $index_tag, $record,
673 $authorised_values_sth,$input
677 if ( $#subfields_data >= 0 ) {
681 tag_lib => $tagslib->{$tag}->{lib},
682 repeatable => $tagslib->{$tag}->{repeatable},
683 mandatory => $tagslib->{$tag}->{mandatory},
684 important => $tagslib->{$tag}->{important},
685 indicator1 => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value
686 indicator2 => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency
687 subfield_loop => \@subfields_data,
688 tagfirstsubfield => $subfields_data[0],
689 fixedfield => $tag < 10?1:0,
692 push @loop_data, \%tag_data ;
696 if ( $#loop_data >= 0 ) {
699 innerloop => \@loop_data,
703 $authorised_values_sth->finish;
704 $template->param( BIG_LOOP => \@BIG_LOOP );
707 # ========================
709 #=========================
710 my $input = CGI->new;
711 my $error = $input->param('error');
712 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
713 my $parentbiblio = $input->param('parentbiblionumber');
714 my $breedingid = $input->param('breedingid');
715 my $z3950 = $input->param('z3950');
716 my $op = $input->param('op') // q{};
717 my $mode = $input->param('mode');
718 my $frameworkcode = $input->param('frameworkcode');
719 my $redirect = $input->param('redirect');
720 my $searchid = $input->param('searchid') // "";
721 my $dbh = C4::Context->dbh;
722 my $hostbiblionumber = $input->param('hostbiblionumber');
723 my $hostitemnumber = $input->param('hostitemnumber');
724 # fast cataloguing datas in transit
725 my $fa_circborrowernumber = $input->param('circborrowernumber');
726 my $fa_barcode = $input->param('barcode');
727 my $fa_branch = $input->param('branch');
728 my $fa_stickyduedate = $input->param('stickyduedate');
729 my $fa_duedatespec = $input->param('duedatespec');
731 my $userflags = 'edit_catalogue';
733 my $changed_framework = $input->param('changed_framework') // q{};
734 $frameworkcode = &GetFrameworkCode($biblionumber)
735 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'addbiblio' );
737 if ($frameworkcode eq 'FA'){
738 $userflags = 'fast_cataloging';
741 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
742 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
744 template_name => "cataloguing/addbiblio.tt",
747 flagsrequired => { editcatalogue => $userflags },
752 my $does_bib_exist = Koha::Biblios->find($biblionumber);
753 if (!defined $does_bib_exist){
754 $biblionumber = undef;
755 $template->param( bib_doesnt_exist => 1 );
759 if ($frameworkcode eq 'FA'){
760 # We need to grab and set some variables in the template for use on the additems screen
762 'circborrowernumber' => $fa_circborrowernumber,
763 'barcode' => $fa_barcode,
764 'branch' => $fa_branch,
765 'stickyduedate' => $fa_stickyduedate,
766 'duedatespec' => $fa_duedatespec,
768 } elsif ( $op ne "delete" &&
769 C4::Context->preference('EnableAdvancedCatalogingEditor') &&
770 C4::Auth::haspermission(C4::Context->userenv->{id},{'editcatalogue'=>'advanced_editor'}) &&
771 $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' &&
773 # Only use the advanced editor for non-fast-cataloging.
774 # breedingid is not handled because those would only come off a Z39.50
775 # search initiated by the basic editor.
776 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( ($op eq 'duplicate'?'#duplicate/':'#catalog/') . $biblionumber ) : '' ) );
780 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
782 frameworks => $frameworks,
783 breedingid => $breedingid,
787 $tagslib = &GetMarcStructure( 1, $frameworkcode );
788 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
789 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
795 $biblionumbertagfield,
796 $biblionumbertagsubfield,
797 $biblioitemnumtagfield,
798 $biblioitemnumtagsubfield,
802 if (($biblionumber) && !($breedingid)){
803 $record = GetMarcBiblio({ biblionumber => $biblionumber });
806 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
809 #populate hostfield if hostbiblionumber is available
810 if ($hostbiblionumber) {
811 my $marcflavour = C4::Context->preference("marcflavour");
812 $record = MARC::Record->new();
815 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
816 $record->append_fields($field);
819 # This is a child record
821 my $marcflavour = C4::Context->preference('marcflavour');
822 $record = MARC::Record->new();
823 SetMarcUnicodeFlag($record, $marcflavour);
824 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
826 $record->append_fields($hostfield);
834 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
835 $template->param( title => $title );
837 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
838 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
839 &GetMarcFromKohaField( "biblio.biblionumber" );
840 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
841 &GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
843 # search biblioitems value
844 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
845 $sth->execute($biblionumber);
846 ($biblioitemnumber) = $sth->fetchrow;
849 #-------------------------------------------------------------------------------------
850 if ( $op eq "addbiblio" ) {
851 #-------------------------------------------------------------------------------------
853 biblionumberdata => $biblionumber,
856 my @params = $input->multi_param();
857 $record = TransformHtmlToMarc( $input, 1 );
858 # check for a duplicate
859 my ( $duplicatebiblionumber, $duplicatetitle );
860 if ( !$is_a_modif ) {
861 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
863 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
864 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
865 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
868 my $member = Koha::Patrons->find($loggedinuser);
875 source => $z3950 ? 'z39.50' : 'intranet',
876 categorycode => $member->categorycode,
877 userid => $member->userid
883 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
885 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
886 if ($frameworkcode eq 'FA'){
887 print $input->redirect(
888 '/cgi-bin/koha/cataloguing/additem.pl?'
889 .'biblionumber='.$biblionumber
890 .'&frameworkcode='.$frameworkcode
891 .'&circborrowernumber='.$fa_circborrowernumber
892 .'&branch='.$fa_branch
893 .'&barcode='.uri_escape_utf8($fa_barcode)
894 .'&stickyduedate='.$fa_stickyduedate
895 .'&duedatespec='.$fa_duedatespec
900 print $input->redirect(
901 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
906 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
907 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
908 my $views = { C4::Search::enabled_staff_search_views };
909 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
910 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
911 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
912 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
913 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
914 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
916 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
921 elsif ($redirect eq "just_save"){
922 my $tab = $input->param('current_tab');
923 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
927 biblionumber => $biblionumber,
931 if ( $record ne '-1' ) {
932 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
933 $template->param( title => $title );
937 itemtype => $frameworkcode,
939 output_html_with_http_headers $input, $cookie, $template->output;
943 # it may be a duplicate, warn the user and do nothing
944 build_tabs ($template, $record, $dbh,$encoding,$input);
946 biblionumber => $biblionumber,
947 biblioitemnumber => $biblioitemnumber,
948 duplicatebiblionumber => $duplicatebiblionumber,
949 duplicatebibid => $duplicatebiblionumber,
950 duplicatetitle => $duplicatetitle,
954 elsif ( $op eq "delete" ) {
956 my $error = &DelBiblio($biblionumber);
958 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
959 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
963 print $input->redirect('/cgi-bin/koha/catalogue/search.pl' . ($searchid ? "?searchid=$searchid" : ""));
967 #----------------------------------------------------------------------------
968 # If we're in a duplication case, we have to set to "" the biblionumber
969 # as we'll save the biblio as a new one.
971 biblionumberdata => $biblionumber,
975 if ( $op eq "duplicate" ) {
979 if($changed_framework eq "changed"){
980 $record = TransformHtmlToMarc( $input, 1 );
982 elsif( $record ne -1 ) {
983 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
985 my $uxml = $record->as_xml;
986 MARC::Record::default_record_format("UNIMARC")
987 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
988 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
992 build_tabs( $template, $record, $dbh, $encoding,$input );
994 biblionumber => $biblionumber,
995 biblionumbertagfield => $biblionumbertagfield,
996 biblionumbertagsubfield => $biblionumbertagsubfield,
997 biblioitemnumtagfield => $biblioitemnumtagfield,
998 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
999 biblioitemnumber => $biblioitemnumber,
1000 hostbiblionumber => $hostbiblionumber,
1001 hostitemnumber => $hostitemnumber
1005 if ( $record ne '-1' ) {
1006 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
1007 $template->param( title => $title );
1011 frameworkcode => $frameworkcode,
1012 itemtype => $frameworkcode,
1013 borrowernumber => $loggedinuser,
1014 tab => scalar $input->param('tab')
1016 $template->{'VARS'}->{'searchid'} = $searchid;
1018 output_html_with_http_headers $input, $cookie, $template->output;