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>.
24 use POSIX qw( strftime );
25 use Try::Tiny qw(catch try);
27 use C4::Output qw( output_html_with_http_headers );
28 use C4::Auth qw( get_template_and_user haspermission );
42 use C4::Search qw( FindDuplicate enabled_staff_search_views );
43 use C4::Auth qw( get_template_and_user haspermission );
46 use C4::ClassSource qw( GetClassSources );
47 use C4::ImportBatch qw( GetImportRecordMarc );
48 use C4::Charset qw( SetMarcUnicodeFlag );
49 use Koha::BiblioFrameworks;
50 use Koha::DateUtils qw( dt_from_string );
52 use Koha::Acquisition::Orders;
57 use Koha::BiblioFrameworks;
59 use Koha::UI::Form::Builder::Biblio;
61 use MARC::File::USMARC;
63 use URI::Escape qw( uri_escape_utf8 );
65 if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
66 MARC::File::XML->default_record_format('UNIMARC');
69 our($tagslib,$authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950,$op,$changed_framework);
73 =head2 MARCfindbreeding
75 $record = MARCfindbreeding($breedingid);
77 Look up the import record repository for the record with
78 record with id $breedingid. If found, returns the decoded
79 MARC::Record; otherwise, -1 is returned (FIXME).
80 Returns as second parameter the character encoding.
84 sub MARCfindbreeding {
86 my ($marc, $encoding) = GetImportRecordMarc($id);
87 # remove the - in isbn, koha store isbn without any -
89 my $record = MARC::Record->new_from_usmarc($marc);
90 if(C4::Context->preference('autoControlNumber') eq 'biblionumber'){
91 my @control_num = $record->field('001');
92 $record->delete_fields(@control_num);
94 my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField( 'biblioitems.isbn' );
95 if ( $record->field($isbnfield) ) {
96 foreach my $field ( $record->field($isbnfield) ) {
97 foreach my $subfield ( $field->subfield($isbnsubfield) ) {
98 my $newisbn = $field->subfield($isbnsubfield);
100 $field->update( $isbnsubfield => $newisbn );
104 # fix the unimarc 100 coded field (with unicode information)
105 if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
106 my $f100a=$record->subfield(100,'a');
107 my $f100 = $record->field(100);
108 my $f100temp = $f100->as_string;
109 $record->delete_field($f100);
110 if ( length($f100temp) > 28 ) {
111 substr( $f100temp, 26, 2, "50" );
112 $f100->update( 'a' => $f100temp );
113 my $f100 = MARC::Field->new( '100', '', '', 'a' => $f100temp );
114 $record->insert_fields_ordered($f100);
118 if ( !defined(ref($record)) ) {
122 # normalize author : UNIMARC specific...
123 if ( C4::Context->preference("z3950NormalizeAuthor")
124 and C4::Context->preference("z3950AuthorAuthFields")
125 and C4::Context->preference("marcflavour") eq 'UNIMARC' )
127 my ( $tag, $subfield ) = GetMarcFromKohaField( "biblio.author" );
130 C4::Context->preference("z3950AuthorAuthFields");
131 my @auth_fields = split /,/, $auth_fields;
134 if ( $record->field($tag) ) {
135 foreach my $tmpfield ( $record->field($tag)->subfields ) {
137 my $subfieldcode = shift @$tmpfield;
138 my $subfieldvalue = shift @$tmpfield;
140 $field->add_subfields(
141 "$subfieldcode" => $subfieldvalue )
142 if ( $subfieldcode ne $subfield );
146 MARC::Field->new( $tag, "", "",
147 $subfieldcode => $subfieldvalue )
148 if ( $subfieldcode ne $subfield );
152 $record->delete_field( $record->field($tag) );
153 foreach my $fieldtag (@auth_fields) {
154 next unless ( $record->field($fieldtag) );
155 my $lastname = $record->field($fieldtag)->subfield('a');
156 my $firstname = $record->field($fieldtag)->subfield('b');
157 my $title = $record->field($fieldtag)->subfield('c');
158 my $number = $record->field($fieldtag)->subfield('d');
160 $field->add_subfields(
161 "$subfield" => ucfirst($title) . " "
162 . ucfirst($firstname) . " "
166 $field->add_subfields(
167 "$subfield" => ucfirst($firstname) . ", "
168 . ucfirst($lastname) );
171 $record->insert_fields_ordered($field);
173 return $record, $encoding;
181 Create a random value to set it into the input name
186 return int(rand(1000000));
189 =head2 GetMandatoryFieldZ3950
191 This function returns a hashref which contains all mandatory field
192 to search with z3950 server.
196 sub GetMandatoryFieldZ3950 {
197 my $frameworkcode = shift;
198 my @isbn = GetMarcFromKohaField( 'biblioitems.isbn' );
199 my @title = GetMarcFromKohaField( 'biblio.title' );
200 my @author = GetMarcFromKohaField( 'biblio.author' );
201 my @issn = GetMarcFromKohaField( 'biblioitems.issn' );
202 my @lccn = GetMarcFromKohaField( 'biblioitems.lccn' );
205 $isbn[0].$isbn[1] => 'isbn',
206 $title[0].$title[1] => 'title',
207 $author[0].$author[1] => 'author',
208 $issn[0].$issn[1] => 'issn',
209 $lccn[0].$lccn[1] => 'lccn',
213 =head2 format_indicator
215 Translate indicator value for output form - specifically, map
216 indicator = ' ' to ''. This is for the convenience of a cataloger
217 using a mouse to select an indicator input.
221 sub format_indicator {
222 my $ind_value = shift;
223 return '' if not defined $ind_value;
224 return '' if $ind_value eq ' ';
229 my ( $template, $record, $dbh, $encoding,$input ) = @_;
235 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
236 my $query = "SELECT authorised_value, lib
237 FROM authorised_values";
238 $query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit;
239 $query .= " WHERE category = ?";
240 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
241 $query .= " GROUP BY authorised_value,lib ORDER BY lib, lib_opac";
242 my $authorised_values_sth = $dbh->prepare( $query );
244 # in this array, we will push all the 10 tabs
245 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
248 my @tab_data; # all tags to display
251 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
252 foreach my $used ( @$usedTagsLib ){
254 push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}};
255 $seen{$used->{tagfield}}++;
257 if ( $used->{tab} > -1
258 && $used->{tab} >= $max_num_tab
259 && $used->{tagfield} ne $itemtag )
261 $max_num_tab = $used->{tab};
264 if($max_num_tab >= 9){
268 my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new(
270 biblionumber => scalar $input->param('biblionumber'),
274 # loop through each tab 0 through 9
275 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
276 my @loop_data = (); #innerloop in the template.
278 foreach my $tag (sort @tab_data) {
281 my ($indicator1, $indicator2);
282 my $index_tag = CreateKey;
284 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
285 # if MARC::Record is empty => use tab as master loop.
286 if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
288 if ( $tag ne '000' ) {
289 @fields = $record->field($tag);
292 push @fields, $record->leader(); # if tag == 000
294 # loop through each field
295 foreach my $field (@fields) {
299 my ( $value, $subfield );
300 if ( $tag ne '000' ) {
301 $value = $field->data();
308 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
310 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
311 'biblio.biblionumber' );
314 $biblio_form_builder->generate_subfield_form(
317 subfield => $subfield,
319 index_tag => $index_tag,
321 hostitemnumber => scalar $input->param('hostitemnumber'),
323 changed_framework => $changed_framework,
324 breedingid => scalar $input->param('breedingid'),
326 mandatory_z3950 => $mandatory_z3950,
332 my @subfields = $field->subfields();
333 foreach my $subfieldcount ( 0 .. $#subfields ) {
334 my $subfield = $subfields[$subfieldcount][0];
335 my $value = $subfields[$subfieldcount][1];
336 next if ( length $subfield != 1 );
337 next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
340 $biblio_form_builder->generate_subfield_form(
343 subfield => $subfield,
345 index_tag => $index_tag,
347 hostitemnumber => scalar $input->param('hostitemnumber'),
349 changed_framework => $changed_framework,
350 breedingid => scalar $input->param('breedingid'),
352 mandatory_z3950 => $mandatory_z3950,
359 # now, loop again to add parameter subfield that are not in the MARC::Record
360 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
362 next if ( length $subfield != 1 );
363 next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
364 next if ( $tag < 10 );
366 if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
367 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) )
368 and not ( $subfield eq "9" and
369 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
370 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
371 $tagslib->{$tag}->{'a'}->{authtypecode} ne "" and
372 $tagslib->{$tag}->{'a'}->{hidden} > -4 and
373 $tagslib->{$tag}->{'a'}->{hidden} < 5
375 ; #check for visibility flag
376 # if subfield is $9 in a field whose $a is authority-controlled,
377 # always include in the form regardless of the hidden setting - bug 2206 and 28022
378 next if ( defined( $field->subfield($subfield) ) );
381 $biblio_form_builder->generate_subfield_form(
384 subfield => $subfield,
386 index_tag => $index_tag,
388 hostitemnumber => scalar $input->param('hostitemnumber'),
390 changed_framework => $changed_framework,
391 breedingid => scalar $input->param('breedingid'),
393 mandatory_z3950 => $mandatory_z3950,
398 if ( $#subfields_data >= 0 ) {
399 # build the tag entry.
400 # note that the random() field is mandatory. Otherwise, on repeated fields, you'll
401 # have twice the same "name" value, and cgi->param() will return only one, making
402 # all subfields to be merged in a single field.
406 tag_lib => $tagslib->{$tag}->{lib},
407 repeatable => $tagslib->{$tag}->{repeatable},
408 mandatory => $tagslib->{$tag}->{mandatory},
409 important => $tagslib->{$tag}->{important},
410 subfield_loop => \@subfields_data,
411 fixedfield => $tag < 10?1:0,
414 if ($tag >= 10){ # no indicator for 00x tags
415 $tag_data{indicator1} = format_indicator($field->indicator(1)),
416 $tag_data{indicator2} = format_indicator($field->indicator(2)),
418 push( @loop_data, \%tag_data );
420 } # foreach $field end
422 # if breeding is empty
426 foreach my $subfield (
427 sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} }
428 grep { ref($_) && %$_ } # Not a subfield (values for "important", "lib", "mandatory", etc.) or empty
429 values %{ $tagslib->{$tag} } )
432 if ( ( $subfield->{hidden} <= -4 )
433 or ( $subfield->{hidden} >= 5 ) )
434 and not ( $subfield->{subfield} eq "9" and
435 exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
436 defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
437 $tagslib->{$tag}->{'a'}->{authtypecode} ne "" and
438 $tagslib->{$tag}->{'a'}->{hidden} > -4 and
439 $tagslib->{$tag}->{'a'}->{hidden} < 5
441 ; #check for visibility flag
442 # if subfield is $9 in a field whose $a is authority-controlled,
443 # always include in the form regardless of the hidden setting - bug 2206 and 28022
445 if ( $subfield->{tab} ne $tabloop );
448 $biblio_form_builder->generate_subfield_form(
451 subfield => $subfield->{subfield},
453 index_tag => $index_tag,
455 hostitemnumber => scalar $input->param('hostitemnumber'),
457 changed_framework => $changed_framework,
458 breedingid => scalar $input->param('breedingid'),
460 mandatory_z3950 => $mandatory_z3950,
465 if ( $#subfields_data >= 0 ) {
469 tag_lib => $tagslib->{$tag}->{lib},
470 repeatable => $tagslib->{$tag}->{repeatable},
471 mandatory => $tagslib->{$tag}->{mandatory},
472 important => $tagslib->{$tag}->{important},
473 indicator1 => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value
474 indicator2 => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency
475 subfield_loop => \@subfields_data,
476 tagfirstsubfield => $subfields_data[0],
477 fixedfield => $tag < 10?1:0,
480 push @loop_data, \%tag_data ;
484 if ( $#loop_data >= 0 ) {
487 innerloop => \@loop_data,
491 $authorised_values_sth->finish;
492 $template->param( BIG_LOOP => \@BIG_LOOP );
495 # ========================
497 #=========================
498 my $input = CGI->new;
499 my $error = $input->param('error');
500 my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio.
501 my $parentbiblio = $input->param('parentbiblionumber');
502 my $breedingid = $input->param('breedingid');
503 my $z3950 = $input->param('z3950');
504 $op = $input->param('op') // q{};
505 my $mode = $input->param('mode') // q{};
506 my $frameworkcode = $input->param('frameworkcode');
507 my $redirect = $input->param('redirect');
508 my $searchid = $input->param('searchid') // "";
509 my $dbh = C4::Context->dbh;
510 my $hostbiblionumber = $input->param('hostbiblionumber');
511 my $hostitemnumber = $input->param('hostitemnumber');
512 # fast cataloguing datas in transit
513 my $fa_circborrowernumber = $input->param('circborrowernumber');
514 my $fa_barcode = $input->param('barcode');
515 my $fa_branch = $input->param('branch');
516 my $fa_stickyduedate = $input->param('stickyduedate');
517 my $fa_duedatespec = $input->param('duedatespec');
519 my $userflags = 'edit_catalogue';
521 if ( $op eq 'cud-change-framework' ) {
522 $op = $input->param('original_op');
523 $changed_framework = 1;
526 $frameworkcode = &GetFrameworkCode($biblionumber)
527 if ( $biblionumber and not( defined $frameworkcode) and $op ne 'cud-addbiblio' );
529 if ($frameworkcode eq 'FA'){
530 $userflags = 'fast_cataloging';
533 $frameworkcode = '' if ( $frameworkcode eq 'Default' );
534 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
536 template_name => "cataloguing/addbiblio.tt",
539 flagsrequired => { editcatalogue => $userflags },
543 my $logged_in_patron = Koha::Patrons->find($loggedinuser);
548 $biblio = Koha::Biblios->find($biblionumber);
550 # just in case $biblionumber obtained from CGI contains weird characters like spaces
551 $biblionumber = $biblio->biblionumber if $biblio;
553 unless ( $biblio->can_be_edited($logged_in_patron) ) {
554 print $input->redirect("/cgi-bin/koha/errors/403.pl"); # escape early
558 $biblionumber = undef;
559 $template->param( bib_doesnt_exist => 1 );
563 if ($frameworkcode eq 'FA'){
564 # We need to grab and set some variables in the template for use on the additems screen
566 'circborrowernumber' => $fa_circborrowernumber,
567 'barcode' => $fa_barcode,
568 'branch' => $fa_branch,
569 'stickyduedate' => $fa_stickyduedate,
570 'duedatespec' => $fa_duedatespec,
572 } elsif ( $op ne "cud-delete" &&
573 C4::Context->preference('EnableAdvancedCatalogingEditor') &&
574 C4::Auth::haspermission(C4::Context->userenv->{id},{'editcatalogue'=>'advanced_editor'}) &&
575 $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' &&
577 # Only use the advanced editor for non-fast-cataloging.
578 # breedingid is not handled because those would only come off a Z39.50
579 # search initiated by the basic editor.
580 print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( ($op eq 'duplicate'?'#duplicate/':'#catalog/') . $biblionumber ) : '' ) );
584 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
586 frameworks => $frameworks,
587 breedingid => $breedingid,
591 $tagslib = &GetMarcStructure( 1, $frameworkcode );
592 $usedTagsLib = &GetUsedMarcStructure( $frameworkcode );
593 $mandatory_z3950 = GetMandatoryFieldZ3950($frameworkcode);
599 $biblionumbertagfield,
600 $biblionumbertagsubfield,
601 $biblioitemnumtagfield,
602 $biblioitemnumtagsubfield,
606 if ( $biblio && !$breedingid ) {
607 eval { $record = $biblio->metadata->record };
610 $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
611 $record = $biblio->metadata->record_strip_nonxml;
612 $template->param( INVALID_METADATA => $exception );
616 ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ;
618 if ( $record && $op eq 'duplicate' &&
619 C4::Context->preference('autoControlNumber') eq 'biblionumber' ){
620 my @control_num = $record->field('001');
621 $record->delete_fields(@control_num);
623 if ( $record && $op eq 'duplicate' ) {
624 if ( C4::Context->preference('marcflavour') eq 'MARC21' && $record->field('008') ) {
625 my $s008 = $record->field('008')->data;
626 my $date = POSIX::strftime( "%y%m%d", localtime );
627 substr( $s008, 0, 6, $date );
628 $record->field('008')->update($s008);
629 } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield( '100', 'a' ) ) {
630 my $s100a = $record->subfield( '100', 'a' );
631 my $date = POSIX::strftime( "%Y%m%d", localtime );
632 substr( $s100a, 0, 8, $date );
633 $record->field('100')->update( a => $s100a );
636 #populate hostfield if hostbiblionumber is available
637 if ($hostbiblionumber) {
638 my $marcflavour = C4::Context->preference("marcflavour");
639 $record = MARC::Record->new();
642 PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
643 $record->append_fields($field);
646 # This is a child record
648 my $marcflavour = C4::Context->preference('marcflavour');
649 $record = MARC::Record->new();
650 SetMarcUnicodeFlag($record, $marcflavour);
651 my $hostfield = prepare_host_field($parentbiblio,$marcflavour);
653 $record->append_fields($hostfield);
661 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
662 $template->param( title => $title );
664 # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB.
665 ( $biblionumbertagfield, $biblionumbertagsubfield ) =
666 &GetMarcFromKohaField( "biblio.biblionumber" );
667 ( $biblioitemnumtagfield, $biblioitemnumtagsubfield ) =
668 &GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
670 # search biblioitems value
671 my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
672 $sth->execute($biblionumber);
673 ($biblioitemnumber) = $sth->fetchrow;
674 if (C4::Context->preference('MARCOverlayRules')) {
675 $record = ApplyMarcOverlayRules(
677 biblionumber => $biblionumber,
680 source => $z3950 ? 'z3950' : 'intranet',
681 categorycode => $logged_in_patron->categorycode,
682 userid => $logged_in_patron->userid,
689 #-------------------------------------------------------------------------------------
690 if ( $op eq "cud-addbiblio" ) {
691 #-------------------------------------------------------------------------------------
693 biblionumberdata => $biblionumber,
696 my @params = $input->multi_param();
697 $record = TransformHtmlToMarc( $input, 1 );
698 # check for a duplicate
699 my ( $duplicatebiblionumber, $duplicatetitle );
700 if ( !$is_a_modif ) {
701 ( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record);
703 my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
704 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
705 if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
714 source => $z3950 ? 'z3950' : 'intranet',
715 categorycode => $logged_in_patron->categorycode,
716 userid => $logged_in_patron->userid,
722 ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
724 if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){
725 if ($frameworkcode eq 'FA'){
726 print $input->redirect(
727 '/cgi-bin/koha/cataloguing/additem.pl?'
728 .'biblionumber='.$biblionumber
729 .'&frameworkcode='.$frameworkcode
730 .'&circborrowernumber='.$fa_circborrowernumber
731 .'&branch='.$fa_branch
732 .'&barcode='.uri_escape_utf8($fa_barcode)
733 .'&stickyduedate='.$fa_stickyduedate
734 .'&duedatespec='.$fa_duedatespec
739 print $input->redirect(
740 "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"
745 elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){
746 my $defaultview = C4::Context->preference('IntranetBiblioDefaultView');
747 my $views = { C4::Search::enabled_staff_search_views };
748 if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) {
749 print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
750 } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) {
751 print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid");
752 } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) {
753 print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid");
755 print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid");
760 elsif ($redirect eq "just_save"){
761 my $tab = $input->param('current_tab');
762 print $input->redirect("/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid");
766 biblionumber => $biblionumber,
770 if ( $record ne '-1' ) {
771 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
772 $template->param( title => $title );
776 itemtype => $frameworkcode,
778 output_html_with_http_headers $input, $cookie, $template->output;
782 # it may be a duplicate, warn the user and do nothing
783 build_tabs ($template, $record, $dbh,$encoding,$input);
785 biblionumber => $biblionumber,
786 biblioitemnumber => $biblioitemnumber,
787 duplicatebiblionumber => $duplicatebiblionumber,
788 duplicatebibid => $duplicatebiblionumber,
789 duplicatetitle => $duplicatetitle,
794 elsif ( $op eq "cud-delete" ) {
796 # Cancel attached order lines first before deleting biblio !
799 my @result = Koha::Acquisition::Orders->search( { biblionumber => $biblionumber } )->cancel;
800 my $warns = @{ $result[1] };
801 if ($warns) { # warnings about order lines not cancelled
802 warn sprintf( "%d order lines were cancelled, but %d lines gave a warning\n", $result[0], $warns );
804 $error = &DelBiblio($biblionumber);
806 $error = ref($_) ? 'Exception raised - ' . $_->error : $_;
810 #FIXME This should be handled in template alert
811 warn "ERROR when DELETING BIBLIO $biblionumber : $error";
812 print "Content-Type: text/html\n\n<html><body><h1>ERROR when DELETING BIBLIO $biblionumber : $error</h1></body></html>";
816 print $input->redirect('/cgi-bin/koha/catalogue/search.pl' . ($searchid ? "?searchid=$searchid" : ""));
820 #----------------------------------------------------------------------------
821 # If we're in a duplication case, we have to set to "" the biblionumber
822 # as we'll save the biblio as a new one.
824 biblionumberdata => $biblionumber,
828 if ( $op eq "duplicate" ) {
832 if($changed_framework){
833 $record = TransformHtmlToMarc( $input, 1 );
835 elsif( $record ne -1 ) {
836 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
838 my $uxml = $record->as_xml;
839 MARC::Record::default_record_format("UNIMARC")
840 if ( C4::Context->preference("marcflavour") eq "UNIMARC" );
841 my $urecord = MARC::Record::new_from_xml( $uxml, 'UTF-8' );
845 build_tabs( $template, $record, $dbh, $encoding,$input );
847 biblionumber => $biblionumber,
848 biblionumbertagfield => $biblionumbertagfield,
849 biblionumbertagsubfield => $biblionumbertagsubfield,
850 biblioitemnumtagfield => $biblioitemnumtagfield,
851 biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
852 biblioitemnumber => $biblioitemnumber,
853 hostbiblionumber => $hostbiblionumber,
854 hostitemnumber => $hostitemnumber
858 if ( $record ne '-1' ) {
859 my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
860 $template->param( title => $title );
864 frameworkcode => $frameworkcode,
865 itemtype => $frameworkcode,
866 borrowernumber => $loggedinuser,
867 tab => scalar $input->param('tab')
869 $template->{'VARS'}->{'searchid'} = $searchid;
871 output_html_with_http_headers $input, $cookie, $template->output;