View | Details | Raw Unified | Return to bug 11299
Collapse All | Expand All

(-)a/C4/Biblio.pm (-8 / +170 lines)
Lines 469-475 sub BiblioAutoLink { Link Here
469
469
470
=head2 LinkBibHeadingsToAuthorities
470
=head2 LinkBibHeadingsToAuthorities
471
471
472
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
472
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
473
473
474
Links bib headings to authority records by checking
474
Links bib headings to authority records by checking
475
each authority-controlled field in the C<MARC::Record>
475
each authority-controlled field in the C<MARC::Record>
Lines 491-496 sub LinkBibHeadingsToAuthorities { Link Here
491
    my $bib           = shift;
491
    my $bib           = shift;
492
    my $frameworkcode = shift;
492
    my $frameworkcode = shift;
493
    my $allowrelink = shift;
493
    my $allowrelink = shift;
494
    my $verbose = shift;
494
    my %results;
495
    my %results;
495
    if (!$bib) {
496
    if (!$bib) {
496
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
497
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 498-504 sub LinkBibHeadingsToAuthorities { Link Here
498
    }
499
    }
499
    require C4::Heading;
500
    require C4::Heading;
500
    require C4::AuthoritiesMarc;
501
    require C4::AuthoritiesMarc;
501
502
    $allowrelink = 1 unless defined $allowrelink;
502
    $allowrelink = 1 unless defined $allowrelink;
503
    my $num_headings_changed = 0;
503
    my $num_headings_changed = 0;
504
    foreach my $field ( $bib->fields() ) {
504
    foreach my $field ( $bib->fields() ) {
Lines 511-541 sub LinkBibHeadingsToAuthorities { Link Here
511
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
511
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
512
        {
512
        {
513
            $results{'linked'}->{ $heading->display_form() }++;
513
            $results{'linked'}->{ $heading->display_form() }++;
514
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
514
            next;
515
            next;
515
        }
516
        }
516
517
517
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
518
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
518
        if ($authid) {
519
        if ($authid) {
519
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
520
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
520
              ->{ $heading->display_form() }++;
521
              ->{ $heading->display_form() }++;
521
            next if defined $current_link and $current_link == $authid;
522
            if(defined $current_link and $current_link == $authid) {
523
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
524
                next;
525
            }
522
526
523
            $field->delete_subfield( code => '9' ) if defined $current_link;
527
            $field->delete_subfield( code => '9' ) if defined $current_link;
524
            $field->add_subfields( '9', $authid );
528
            $field->add_subfields( '9', $authid );
525
            $num_headings_changed++;
529
            $num_headings_changed++;
530
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
526
        }
531
        }
527
        else {
532
        else {
533
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
528
            if ( defined $current_link
534
            if ( defined $current_link
529
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
535
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
530
            {
536
            {
531
                $results{'fuzzy'}->{ $heading->display_form() }++;
537
                $results{'fuzzy'}->{ $heading->display_form() }++;
538
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
532
            }
539
            }
533
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
540
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
534
                if ( _check_valid_auth_link( $current_link, $field ) ) {
541
                if ( _check_valid_auth_link( $current_link, $field ) ) {
535
                    $results{'linked'}->{ $heading->display_form() }++;
542
                    $results{'linked'}->{ $heading->display_form() }++;
536
                }
543
                }
537
                else {
544
                else {
538
                    my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
539
                    my $marcrecordauth = MARC::Record->new();
545
                    my $marcrecordauth = MARC::Record->new();
540
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
546
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
541
                        $marcrecordauth->leader('     nz  a22     o  4500');
547
                        $marcrecordauth->leader('     nz  a22     o  4500');
Lines 590-621 sub LinkBibHeadingsToAuthorities { Link Here
590
                    }
596
                    }
591
597
592
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
598
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
599
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
593
600
594
                    $authid =
595
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
596
                        $heading->auth_type() );
597
                    $field->add_subfields( '9', $authid );
601
                    $field->add_subfields( '9', $authid );
598
                    $num_headings_changed++;
602
                    $num_headings_changed++;
599
                    $linker->update_cache($heading, $authid);
603
                    $linker->update_cache($heading, $authid);
600
                    $results{'added'}->{ $heading->display_form() }++;
604
                    $results{'added'}->{ $heading->display_form() }++;
605
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
601
                }
606
                }
602
            }
607
            }
603
            elsif ( defined $current_link ) {
608
            elsif ( defined $current_link ) {
604
                if ( _check_valid_auth_link( $current_link, $field ) ) {
609
                if ( _check_valid_auth_link( $current_link, $field ) ) {
605
                    $results{'linked'}->{ $heading->display_form() }++;
610
                    $results{'linked'}->{ $heading->display_form() }++;
611
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
606
                }
612
                }
607
                else {
613
                else {
608
                    $field->delete_subfield( code => '9' );
614
                    $field->delete_subfield( code => '9' );
609
                    $num_headings_changed++;
615
                    $num_headings_changed++;
610
                    $results{'unlinked'}->{ $heading->display_form() }++;
616
                    $results{'unlinked'}->{ $heading->display_form() }++;
617
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
611
                }
618
                }
612
            }
619
            }
613
            else {
620
            else {
614
                $results{'unlinked'}->{ $heading->display_form() }++;
621
                $results{'unlinked'}->{ $heading->display_form() }++;
622
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
615
            }
623
            }
616
        }
624
        }
617
625
618
    }
626
    }
627
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
619
    return $num_headings_changed, \%results;
628
    return $num_headings_changed, \%results;
620
}
629
}
621
630
Lines 641-646 sub _check_valid_auth_link { Link Here
641
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
650
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
642
}
651
}
643
652
653
=head2 AddAuthorityFromHeading
654
655
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
656
657
Creates a new authority from an heading and its associated field.
658
659
Returns the id of the newly created authority.
660
661
=cut
662
663
sub AddAuthorityFromHeading {
664
    my $heading = shift;
665
    my $field = shift;
666
    my $bib = shift;
667
668
    if(!defined $heading || !defined $field || !defined $bib){
669
       return 0;
670
    }
671
    my $authtypedata =
672
      Koha::Authority::Types->find( $heading->auth_type() );
673
    my $marcrecordauth = MARC::Record->new();
674
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
675
        $marcrecordauth->leader('     nz  a22     o  4500');
676
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
677
    }
678
    my $authfield =
679
      MARC::Field->new( $authtypedata->auth_tag_to_report,
680
        '', '', "a" => "" . $field->subfield('a') );
681
    map {
682
        $authfield->add_subfields( $_->[0] => $_->[1] )
683
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
684
    } $field->subfields();
685
    $marcrecordauth->insert_fields_ordered($authfield);
686
687
# bug 2317: ensure new authority knows it's using UTF-8; currently
688
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
689
# automatically for UNIMARC (by not transcoding)
690
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
691
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
692
# of change to a core API just before the 3.0 release.
693
694
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
695
        $marcrecordauth->insert_fields_ordered(
696
            MARC::Field->new(
697
                '667', '', '',
698
                'a' => "Machine generated authority record."
699
            )
700
        );
701
        if(defined $bib) {
702
            my $cite =
703
                $bib->author() . ", "
704
              . $bib->title_proper() . ", "
705
              . $bib->publication_date() . " ";
706
            $cite =~ s/^[\s\,]*//;
707
            $cite =~ s/[\s\,]*$//;
708
            $cite =
709
                "Work cat.: ("
710
              . C4::Context->preference('MARCOrgCode') . ")"
711
              . $bib->subfield( '999', 'c' ) . ": "
712
              . $cite;
713
            $marcrecordauth->insert_fields_ordered(
714
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
715
        }
716
717
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
718
        my $date=POSIX::strftime("%y%m%d",localtime);
719
        my @heading_use = qw(b b b);
720
        my $thesaurus = '|';
721
722
        if ($heading->{'subject_added_entry'}) {
723
            $heading_use[1] = 'a';
724
            # Thesaurus treatment
725
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
726
            $thesaurus = 'z';
727
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
728
            if($thesaurus eq 'z')
729
            {
730
                $marcrecordauth->insert_fields_ordered(
731
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
732
                );
733
            }
734
        }
735
        if ($heading->{'series_added_entry'}) {
736
            $heading_use[2] = 'a';
737
        }
738
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
739
            $heading_use[0] = 'a';
740
        }
741
742
        # Get a valid default value for field 008
743
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
744
        if(!$default_008 or length($default_008)<34) {
745
            $default_008 = '|| aca||aabn           | a|a     d';
746
        }
747
        else {
748
            $default_008 = substr($default_008,0,34)
749
        }
750
751
        # Insert the date, thesaurus and heading_use into field 008
752
        my $f008 = $date . $default_008;
753
        substr($f008, 11, 1) = $thesaurus;
754
        substr($f008, 14, 3) = join('', @heading_use);
755
756
        $marcrecordauth->insert_fields_ordered(
757
            MARC::Field->new('008',$f008)
758
        );
759
    }
760
761
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
762
763
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
764
    return $authid;
765
}
766
767
768
=head2 GetRecordValue
769
770
  my $values = GetRecordValue($field, $record, $frameworkcode);
771
772
Get MARC fields from a keyword defined in fieldmapping table.
773
774
=cut
775
776
sub GetRecordValue {
777
    my ( $field, $record, $frameworkcode ) = @_;
778
779
    if (!$record) {
780
        carp 'GetRecordValue called with undefined record';
781
        return;
782
    }
783
    my $dbh = C4::Context->dbh;
784
785
    my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?');
786
    $sth->execute( $frameworkcode, $field );
787
788
    my @result = ();
789
790
    while ( my $row = $sth->fetchrow_hashref ) {
791
        foreach my $field ( $record->field( $row->{fieldcode} ) ) {
792
            if ( ( $row->{subfieldcode} ne "" && $field->subfield( $row->{subfieldcode} ) ) ) {
793
                foreach my $subfield ( $field->subfield( $row->{subfieldcode} ) ) {
794
                    push @result, { 'subfield' => $subfield };
795
                }
796
797
            } elsif ( $row->{subfieldcode} eq "" ) {
798
                push @result, { 'subfield' => $field->as_string() };
799
            }
800
        }
801
    }
802
803
    return \@result;
804
}
805
644
=head2 GetBiblioData
806
=head2 GetBiblioData
645
807
646
  $data = &GetBiblioData($biblionumber);
808
  $data = &GetBiblioData($biblionumber);
(-)a/C4/Linker.pm (-2 / +3 lines)
Lines 30-37 C4::Linker - Base class for linking authorities to bibliographic records Link Here
30
Base class for C4::Linker::X. Subclasses need to provide the following methods
30
Base class for C4::Linker::X. Subclasses need to provide the following methods
31
31
32
B<get_link ($field)> - return the authid for the authority that should be
32
B<get_link ($field)> - return the authid for the authority that should be
33
linked to the provided MARC::Field object, and a boolean to indicate whether
33
linked to the provided MARC::Field object, a boolean to indicate whether
34
the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin).
34
the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin),
35
and an optional 'status' string giving more informations on the link status.
35
In order to handle authority limits, get_link should always end with:
36
In order to handle authority limits, get_link should always end with:
36
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
37
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
37
38
(-)a/C4/Linker/Default.pm (-1 / +1 lines)
Lines 43-49 sub get_link { Link Here
43
        # look for matching authorities
43
        # look for matching authorities
44
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
44
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
45
45
46
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46
        if ( $behavior eq 'default' && $#{$authorities} >= 0 ) {
47
            $authid = $authorities->[0]->{'authid'};
47
            $authid = $authorities->[0]->{'authid'};
48
        }
48
        }
49
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
49
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
(-)a/authorities/authorities.pl (-2 / +23 lines)
Lines 287-292 sub create_input { Link Here
287
287
288
        }
288
        }
289
    }
289
    }
290
    if ($cgi->param('tagreport') && $subfield_data{tag} == $cgi->param('tagreport')) {
291
        $subfield_data{marc_value}{value} = $cgi->param('tag'. $cgi->param('tagbiblio') . 'subfield' . $subfield_data{subfield});
292
    }
290
    $subfield_data{'index_subfield'} = $index_subfield;
293
    $subfield_data{'index_subfield'} = $index_subfield;
291
    return \%subfield_data;
294
    return \%subfield_data;
292
}
295
}
Lines 561-566 my $myindex = $input->param('index'); Link Here
561
my $linkid=$input->param('linkid');
564
my $linkid=$input->param('linkid');
562
my $authtypecode = $input->param('authtypecode');
565
my $authtypecode = $input->param('authtypecode');
563
my $breedingid    = $input->param('breedingid');
566
my $breedingid    = $input->param('breedingid');
567
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new authority infos to the parent biblio
568
569
if($biblioindex and !$authid){
570
    require C4::Heading;
571
572
    my $record = TransformHtmlToMarc( $input );
573
574
    # Get the first heading found in the biblio informations
575
    foreach my $field ( $record->fields() ) {
576
        my $heading = C4::Heading->new_from_bib_field($field);
577
        next unless defined $heading;
578
579
        # Create a new authority using the heading informations
580
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
581
    }
582
}
564
583
565
my $dbh = C4::Context->dbh;
584
my $dbh = C4::Context->dbh;
566
if(!$authtypecode) {
585
if(!$authtypecode) {
Lines 575-581 my ($template, $loggedinuser, $cookie) Link Here
575
                            flagsrequired => {editauthorities => 1},
594
                            flagsrequired => {editauthorities => 1},
576
                            debug => 1,
595
                            debug => 1,
577
                            });
596
                            });
578
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
597
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
579
598
580
$tagslib = GetTagsLabels(1,$authtypecode);
599
$tagslib = GetTagsLabels(1,$authtypecode);
581
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
600
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 620-626 if ($op eq "add") { Link Here
620
        } else {
639
        } else {
621
            ($authid) = AddAuthority($record,$authid,$authtypecode);
640
            ($authid) = AddAuthority($record,$authid,$authtypecode);
622
        }
641
        }
623
        if ($myindex) {
642
        if ($biblioindex) {
643
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
644
        } elsif ($myindex) {
624
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
645
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
625
        } else {
646
        } else {
626
            print $input->redirect("detail.pl?authid=$authid");
647
            print $input->redirect("detail.pl?authid=$authid");
(-)a/cataloguing/automatic_linker.pl (+74 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Frédérick Capovilla, 2011 - Libéo
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use CGI;
22
use CGI::Cookie;
23
use JSON;
24
use C4::Auth;
25
use C4::Biblio;
26
use C4::Context;
27
28
my $input = new CGI;
29
print $input->header('application/json');
30
31
# Check the user's permissions
32
my %cookies = CGI::Cookie->fetch;
33
my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
34
my ( $auth_status, $auth_sessid ) =
35
  C4::Auth::check_cookie_auth( $sessid, { editauthorities => 1 } );
36
if ( $auth_status ne "ok" ) {
37
    print to_json( { status => 'UNAUTHORIZED' } );
38
    exit 0;
39
}
40
41
# Link the biblio headings to authorities and return a json containing the status of all the links.
42
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
43
#
44
# tag = the tag number of the field
45
# authid = the value of the $9 subfield for this tag
46
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
47
48
my $json;
49
50
my $record = TransformHtmlToMarc($input,1);
51
52
my $linker_module =
53
  "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' );
54
eval { eval "require $linker_module"; };
55
if ($@) {
56
    $linker_module = 'C4::Linker::Default';
57
    eval "require $linker_module";
58
}
59
if ($@) {
60
    return 0, 0;
61
}
62
my $linker = $linker_module->new(
63
    { 'options' => C4::Context->preference("LinkerOptions") } );
64
65
my ( $headings_changed, $results ) = LinkBibHeadingsToAuthorities(
66
    $linker, $record,
67
    $input->param('frameworkcode'),
68
    C4::Context->preference("CatalogModuleRelink") || '', 1
69
);
70
71
$json->{status} = 'OK';
72
$json->{links} = $results->{details} || '';
73
74
print to_json($json);
(-)a/cataloguing/z3950_auth_search.pl (+3 lines)
Lines 42-47 my $subjectsubdiv = $input->param('subjectsubdiv'); Link Here
42
my $srchany       = $input->param('srchany');
42
my $srchany       = $input->param('srchany');
43
my $op            = $input->param('op')||'';
43
my $op            = $input->param('op')||'';
44
my $page            = $input->param('current_page') || 1;
44
my $page            = $input->param('current_page') || 1;
45
my $index =$input->param('index');
45
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
my $controlnumber    = $input->param('controlnumber');
47
my $controlnumber    = $input->param('controlnumber');
47
48
Lines 65-70 $template->param( Link Here
65
    srchany      => $srchany,
66
    srchany      => $srchany,
66
    authid => $authid,
67
    authid => $authid,
67
    controlnumber => $controlnumber,
68
    controlnumber => $controlnumber,
69
    index => $index,
68
);
70
);
69
71
70
if ( $op ne "do_search" ) {
72
if ( $op ne "do_search" ) {
Lines 74-79 if ( $op ne "do_search" ) { Link Here
74
    $template->param(
76
    $template->param(
75
        serverloop   => $serverloop,
77
        serverloop   => $serverloop,
76
        opsearch     => "search",
78
        opsearch     => "search",
79
        index        => $index,
77
    );
80
    );
78
    output_html_with_http_headers $input, $cookie, $template->output;
81
    output_html_with_http_headers $input, $cookie, $template->output;
79
    exit;
82
    exit;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-4 / +8 lines)
Lines 26-33 Link Here
26
        $("#z3950submit").click(function(){
26
        $("#z3950submit").click(function(){
27
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
27
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
28
                var strQuery = GetZ3950Terms();
28
                var strQuery = GetZ3950Terms();
29
                var index = "&index=[% index %]";
29
                if(strQuery){
30
                if(strQuery){
30
                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
31
                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery+index,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
31
                }
32
                }
32
            }
33
            }
33
            return false;
34
            return false;
Lines 206-214 function confirmnotdup(redirect){ Link Here
206
    <input type="hidden" name="op" value="add" />
207
    <input type="hidden" name="op" value="add" />
207
    <input type="hidden" name="addfield_field" value="" />
208
    <input type="hidden" name="addfield_field" value="" />
208
    <input type="hidden" name="repeat_field" value="" />
209
    <input type="hidden" name="repeat_field" value="" />
209
    <input type="hidden" name="authtypecode" value="[% authtypecode | html %]" />
210
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
210
    <input type="hidden" name="authid" value="[% authid | html %]" />
211
    <input type="hidden" name="authid" value="[% authid %]" />
211
    <input type="hidden" name="index" value="[% index | html %]" />
212
    <input type="hidden" name="index" value="[% index %]" />
213
    [% IF ( biblioindex ) %]
214
    <input type="hidden" name="biblioindex" value="[% biblioindex %]" />
215
    [% END %]
212
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
216
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
213
217
214
    <div id="toolbar" class="btn-toolbar">
218
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (+3 lines)
Lines 137-142 Link Here
137
                [% ELSE %]
137
                [% ELSE %]
138
                    if(code.value=='9'){
138
                    if(code.value=='9'){
139
                        subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
139
                        subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
140
                        // Clean the field if it was modified by the automatic linker
141
                        $(subfield).siblings('.subfield_status').remove();
142
                        $(subfield).css({backgroundColor:''});
140
                        break;
143
                        break;
141
                    }
144
                    }
142
                [% END %]
145
                [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-2 / +237 lines)
Lines 86-91 Link Here
86
            [% END %]
86
            [% END %]
87
        });
87
        });
88
88
89
        $("#linkerbutton").click(function(){
90
            AutomaticLinker();
91
        });
92
89
        $("#saverecord").click(function(){
93
        $("#saverecord").click(function(){
90
            $(".btn-group").removeClass("open");
94
            $(".btn-group").removeClass("open");
91
            onOption();
95
            onOption();
Lines 172-179 Link Here
172
        var onOption = function () {
176
        var onOption = function () {
173
            return Check();
177
            return Check();
174
        }
178
        }
175
    [% END %]
179
[% END %]
180
181
function confirmnotdup(redirect){
182
	$("#confirm_not_duplicate").attr("value","1");
183
    $("#redirect").attr("value",redirect);
184
	Check();
185
}
186
187
function Dopop(link,i) {
188
    defaultvalue = document.getElementById(i).value;
189
    window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
190
}
191
192
/**
193
 * this function open a popup to search on z3950 server.
194
 */
195
function PopupZ3950() {
196
    var strQuery = GetZ3950Terms();
197
	if(strQuery){
198
        window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
199
    } 
200
}
201
202
/**
203
* this function append button for create new authority if not found
204
*/
205
206
function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
207
    var title = _("Create authority");
208
    var elem = $('<a class="subfield_status" href="#"><img src="[% interface %]/[% theme %]/img/create.png" title="' + title + '" /></a>');
209
    tag_subfield_line.append(elem);
210
    var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
211
    var subfield_a = tag_subfield_line_a.children('.input_marceditor').eq(0);
212
    var index = subfield_a.attr('id');
213
    elem.click(function() {
214
        var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
215
        if(popup !== null) {
216
            // Create a new form that will be POSTed in the new window
217
            var form = $('<form>').attr({
218
            method: 'post',
219
            action: "../authorities/authorities.pl",
220
            target: "new_auth_popup"
221
            });
222
            //add the authtypecode
223
            form.append($('<input>').attr({
224
                type: 'hidden',
225
                name: 'authtypecode',
226
                value: heading.auth_type
227
            }));
228
            form.append($('<input>').attr({
229
                type: 'hidden',
230
                name: 'tagreport',
231
                value: heading.tag_to_report
232
            }));
233
            form.append($('<input>').attr({
234
                type: 'hidden',
235
                name: 'tagbiblio',
236
                value: heading.tag
237
            }));
238
            form.append($('<input>').attr({
239
                type: 'hidden',
240
                name: 'index',
241
                value: index
242
            }));
243
            $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
244
                form.append($('<input>').attr({
245
                    type: 'hidden',
246
                    name: this.name.split('_',4).join(''),
247
                    value: $(this).val()
248
                }));
249
            });
250
251
            $('body').append(form);
252
            form.submit();
253
            form.remove();
254
        }
255
        return false;
256
    });
257
258
}
259
260
/**
261
 * Updates the authid for every heading field
262
 * Adds visual feedback for the changes made on the form.
263
 */
264
function updateHeadingLinks(links) {
265
    var current_tag = '';
266
    var tag_index = 0;
267
268
    // Delete the old message dialog and create a new one
269
    $('#autolinker_dialog').remove();
270
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
271
    var message_dialog_ul = message_dialog.find('ul');
272
273
    $.each(links, function(index, heading) {
274
        if(current_tag == heading.tag) {
275
            tag_index++;
276
        }
277
        else {
278
            current_tag = heading.tag;
279
            tag_index = 0;
280
        }
281
282
        // Find the $9 field to update
283
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
284
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
285
286
        // Delete the old status if one exists
287
        tag_subfield_line.children('.subfield_status').remove();
288
        subfield.css({backgroundColor:''});
289
290
        // If the field wasn't modified. Skip it.
291
        if(heading.status == 'UNCHANGED') {
292
            return;
293
        }
294
295
296
        // Make the subfield line visible and update its value
297
        tag_subfield_line.show();
298
        subfield.val(heading.authid);
299
300
        // Add the new status
301
        var image = 'deny.gif';
302
        var message = '';
303
        var field_color = '#FFAAAA';
304
        switch(heading.status) {
305
            case 'LOCAL_FOUND':
306
                image = 'approve.gif';
307
                message = _("A matching authority was found in the local database.");
308
                field_color = '#99FF99';
309
                break;
310
            case 'CREATED':
311
                image = 'approve.gif';
312
                message = _("No matching authority found. A new authority was created automatically.");
313
                field_color = '#99FF99';
314
                break;
315
            case 'MULTIPLE_MATCH':
316
                message = _("More than one local match found. Possibly a duplicate authority!");
317
                break;
318
            case 'NONE_FOUND':
319
                message = _("No matching authority found.");
320
                break;
321
            default:
322
                message = heading.status;
323
                break;
324
        }
176
325
326
        subfield.css({backgroundColor:field_color});
327
        tag_subfield_line.append('<img class="subfield_status" src="[% interface %]/[% theme %]/img/' + image + '" title="' + message + '" />');
328
329
        // Add the message to the dialog
330
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
331
332
        // Add a link to create a new authority if none was found
333
        if(heading.status == 'NONE_FOUND') {
334
            addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
335
        }
336
    });
337
338
    if(message_dialog.find('li').length == 0) {
339
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
340
    }
341
    $('#addbibliotabs').before(message_dialog);
342
}
343
344
/**
345
 * Use an ajax request to automatically find authority links for the current record
346
 */
347
function AutomaticLinker() {
348
    // Show the Loading overlay
349
    $("#loading").show();
350
351
    // Remove fields that are completely empty
352
    $('#f').find('.tag').each(function() {
353
        var empty = true;
354
        $(this).find('.input_marceditor').each(function() {
355
            if($(this).val() != '') {
356
                empty = false;
357
                return false;
358
            }
359
        });
360
        if(empty) {
361
            UnCloneField($(this).attr('id'));
362
        }
363
    });
364
365
    // Get all the form values to post via AJAX
366
    var form_data = {};
367
    $('#f').find(':input').each(function(){
368
        form_data[this.name] = $(this).val();
369
    });
370
    delete form_data[''];
371
372
    // Send the data to automatic_linker.pl
373
    $.ajax({
374
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
375
        type:'post',
376
        data: form_data,
377
        dataType: 'json',
378
        error: function(xhr) {
379
            alert("Error : \n" + xhr.responseText);
380
        },
381
        success: function(json) {
382
            switch(json.status) {
383
                case 'UNAUTHORIZED':
384
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
385
                    break;
386
                case 'OK':
387
                    updateHeadingLinks(json.links);
388
                    break;
389
            }
390
        },
391
        complete: function() {
392
            $("#loading").hide();
393
        }
394
    });
395
}
396
397
398
function PopupMARCFieldDoc(field) {
399
    [% IF Koha.Preference('marcfielddocurl') %]
400
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
401
        docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
402
        docurl = docurl.replace("{FIELD}", ""+field);
403
        docurl = docurl.replace("{LANG}", "[% lang | html %]");
404
        window.open(docurl);
405
    [% ELSIF ( marcflavour == 'MARC21' ) %]
406
        _MARC21FieldDoc(field);
407
    [% ELSIF ( marcflavour == 'UNIMARC' ) %]
408
        _UNIMARCFieldDoc(field);
409
    [% END %]
410
}
177
    function confirmnotdup(redirect){
411
    function confirmnotdup(redirect){
178
        $("#confirm_not_duplicate").attr("value","1");
412
        $("#confirm_not_duplicate").attr("value","1");
179
        $("#redirect").attr("value",redirect);
413
        $("#redirect").attr("value",redirect);
Lines 301-307 Link Here
301
            if (tabflag[tag+subfield+tagnumber] ==  null) {
535
            if (tabflag[tag+subfield+tagnumber] ==  null) {
302
            tabflag[tag+subfield+tagnumber]=new Array();
536
            tabflag[tag+subfield+tagnumber]=new Array();
303
                tabflag[tag+subfield+tagnumber][0]=0;
537
                tabflag[tag+subfield+tagnumber][0]=0;
304
        }
538
            }
305
            if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(mandatories[i]) != null && ! document.getElementById(mandatories[i]).value || document.getElementById(mandatories[i]) == null)){
539
            if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(mandatories[i]) != null && ! document.getElementById(mandatories[i]).value || document.getElementById(mandatories[i]) == null)){
306
                tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
540
                tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
307
                document.getElementById(mandatories[i]).setAttribute('class','input_marceditor noEnterSubmit subfield_not_filled');
541
                document.getElementById(mandatories[i]).setAttribute('class','input_marceditor noEnterSubmit subfield_not_filled');
Lines 536-541 Link Here
536
                    [% END # /IF CAN_user_editcatalogue_edit_items %]
770
                    [% END # /IF CAN_user_editcatalogue_edit_items %]
537
771
538
                    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
772
                    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
773
                        <div class="btn-group"><a class="btn btn-default" href="#" id="linkerbutton"><i class="fa fa-refresh"></i> Link authorities automatically</a></div>
539
                        <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
774
                        <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
540
                    [% END %]
775
                    [% END %]
541
776
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt (-1 / +2 lines)
Lines 20-25 Link Here
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
21
        <input type="hidden" name="op" id="op" value="do_search" />
21
        <input type="hidden" name="op" id="op" value="do_search" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
23
        <input type="hidden" name="index" value="[% index %]" />
23
            <div class="row">
24
            <div class="row">
24
            <div class="col-xs-6">
25
            <div class="col-xs-6">
25
                <fieldset class="rows">
26
                <fieldset class="rows">
Lines 94-100 Link Here
94
                    </a>
95
                    </a>
95
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]"><i class="fa fa-download"></i> Import</a></li>
98
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]" data-index="[% index %]" ><i class="fa fa-download"></i> Import</a></li>
98
                    </ul>
99
                    </ul>
99
                </div>
100
                </div>
100
            </td>
101
            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (+6 lines)
Lines 132-137 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
132
            for( j = 0 ; j < inputs.length ; j++ ) {
132
            for( j = 0 ; j < inputs.length ; j++ ) {
133
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
133
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
134
                    inputs[j].value = "";
134
                    inputs[j].value = "";
135
136
                    //Remove the color added by the automatic linker
137
                    $(inputs[j]).css({backgroundColor:""});
135
                }
138
                }
136
            }
139
            }
137
            var textareas = divs[i].getElementsByTagName('textarea');
140
            var textareas = divs[i].getElementsByTagName('textarea');
Lines 141-146 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
141
                }
144
                }
142
            }
145
            }
143
146
147
            // Remove the status icons added by the automatic linker
148
            $(divs[i]).find('.subfield_status').remove();
149
144
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
150
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
145
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
151
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
146
            var id_input;
152
            var id_input;
(-)a/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js (-3 / +4 lines)
Lines 1-10 Link Here
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
2
function Import(Breeding, recordid, AuthType, FrameworkCode) {
2
function Import(Breeding, recordid, AuthType, FrameworkCode, index) {
3
3
4
    if ( AuthType == false ) {
4
    if ( AuthType == false ) {
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
6
    } else {
6
    } else {
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid;
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid+"&index="+index;
8
    }
8
    }
9
    window.close();
9
    window.close();
10
    return false;
10
    return false;
Lines 87-96 $( document ).ready( function() { Link Here
87
        var data_authid = $( this ).data( "authid" );
87
        var data_authid = $( this ).data( "authid" );
88
        var data_biblionumber = $( this ).data( "biblionumber" );
88
        var data_biblionumber = $( this ).data( "biblionumber" );
89
        var data_frameworkcode = $( this ).data( "frameworkcode" );
89
        var data_frameworkcode = $( this ).data( "frameworkcode" );
90
        var data_index = $( this ).data( "index" );
90
        if ( data_headingcode == undefined ) {
91
        if ( data_headingcode == undefined ) {
91
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
92
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
92
        } else {
93
        } else {
93
            Import( data_breedingid, data_authid, data_headingcode );
94
            Import( data_breedingid, data_authid, data_headingcodei, "", data_index );
94
        }
95
        }
95
        return false;
96
        return false;
96
    });
97
    });
(-)a/t/Biblio.t (-1 / +2 lines)
Lines 164-166 warnings_like { $ret = UpdateTotalIssues() } Link Here
164
164
165
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
165
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
166
166
167
- 
167
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
168
1;

Return to bug 11299