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

(-)a/C4/Biblio.pm (-8 / +132 lines)
Lines 475-481 sub BiblioAutoLink { Link Here
475
475
476
=head2 LinkBibHeadingsToAuthorities
476
=head2 LinkBibHeadingsToAuthorities
477
477
478
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
478
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
479
479
480
Links bib headings to authority records by checking
480
Links bib headings to authority records by checking
481
each authority-controlled field in the C<MARC::Record>
481
each authority-controlled field in the C<MARC::Record>
Lines 497-502 sub LinkBibHeadingsToAuthorities { Link Here
497
    my $bib           = shift;
497
    my $bib           = shift;
498
    my $frameworkcode = shift;
498
    my $frameworkcode = shift;
499
    my $allowrelink = shift;
499
    my $allowrelink = shift;
500
    my $verbose = shift;
500
    my %results;
501
    my %results;
501
    if (!$bib) {
502
    if (!$bib) {
502
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
503
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 504-510 sub LinkBibHeadingsToAuthorities { Link Here
504
    }
505
    }
505
    require C4::Heading;
506
    require C4::Heading;
506
    require C4::AuthoritiesMarc;
507
    require C4::AuthoritiesMarc;
507
508
    $allowrelink = 1 unless defined $allowrelink;
508
    $allowrelink = 1 unless defined $allowrelink;
509
    my $num_headings_changed = 0;
509
    my $num_headings_changed = 0;
510
    foreach my $field ( $bib->fields() ) {
510
    foreach my $field ( $bib->fields() ) {
Lines 517-547 sub LinkBibHeadingsToAuthorities { Link Here
517
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
517
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
518
        {
518
        {
519
            $results{'linked'}->{ $heading->display_form() }++;
519
            $results{'linked'}->{ $heading->display_form() }++;
520
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
520
            next;
521
            next;
521
        }
522
        }
522
523
523
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
524
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
524
        if ($authid) {
525
        if ($authid) {
525
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
526
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
526
              ->{ $heading->display_form() }++;
527
              ->{ $heading->display_form() }++;
527
            next if defined $current_link and $current_link == $authid;
528
            if(defined $current_link and $current_link == $authid) {
529
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
530
                next;
531
            }
528
532
529
            $field->delete_subfield( code => '9' ) if defined $current_link;
533
            $field->delete_subfield( code => '9' ) if defined $current_link;
530
            $field->add_subfields( '9', $authid );
534
            $field->add_subfields( '9', $authid );
531
            $num_headings_changed++;
535
            $num_headings_changed++;
536
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
532
        }
537
        }
533
        else {
538
        else {
539
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
534
            if ( defined $current_link
540
            if ( defined $current_link
535
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
541
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
536
            {
542
            {
537
                $results{'fuzzy'}->{ $heading->display_form() }++;
543
                $results{'fuzzy'}->{ $heading->display_form() }++;
544
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
538
            }
545
            }
539
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
546
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
540
                if ( _check_valid_auth_link( $current_link, $field ) ) {
547
                if ( _check_valid_auth_link( $current_link, $field ) ) {
541
                    $results{'linked'}->{ $heading->display_form() }++;
548
                    $results{'linked'}->{ $heading->display_form() }++;
542
                }
549
                }
543
                else {
550
                else {
544
                    my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
545
                    my $marcrecordauth = MARC::Record->new();
551
                    my $marcrecordauth = MARC::Record->new();
546
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
552
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
547
                        $marcrecordauth->leader('     nz  a22     o  4500');
553
                        $marcrecordauth->leader('     nz  a22     o  4500');
Lines 593-624 sub LinkBibHeadingsToAuthorities { Link Here
593
                    }
599
                    }
594
600
595
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
601
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
602
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
596
603
597
                    $authid =
598
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
599
                        $heading->auth_type() );
600
                    $field->add_subfields( '9', $authid );
604
                    $field->add_subfields( '9', $authid );
601
                    $num_headings_changed++;
605
                    $num_headings_changed++;
602
                    $linker->update_cache($heading, $authid);
606
                    $linker->update_cache($heading, $authid);
603
                    $results{'added'}->{ $heading->display_form() }++;
607
                    $results{'added'}->{ $heading->display_form() }++;
608
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
604
                }
609
                }
605
            }
610
            }
606
            elsif ( defined $current_link ) {
611
            elsif ( defined $current_link ) {
607
                if ( _check_valid_auth_link( $current_link, $field ) ) {
612
                if ( _check_valid_auth_link( $current_link, $field ) ) {
608
                    $results{'linked'}->{ $heading->display_form() }++;
613
                    $results{'linked'}->{ $heading->display_form() }++;
614
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
609
                }
615
                }
610
                else {
616
                else {
611
                    $field->delete_subfield( code => '9' );
617
                    $field->delete_subfield( code => '9' );
612
                    $num_headings_changed++;
618
                    $num_headings_changed++;
613
                    $results{'unlinked'}->{ $heading->display_form() }++;
619
                    $results{'unlinked'}->{ $heading->display_form() }++;
620
                    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;
614
                }
621
                }
615
            }
622
            }
616
            else {
623
            else {
617
                $results{'unlinked'}->{ $heading->display_form() }++;
624
                $results{'unlinked'}->{ $heading->display_form() }++;
625
                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;
618
            }
626
            }
619
        }
627
        }
620
628
621
    }
629
    }
630
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
622
    return $num_headings_changed, \%results;
631
    return $num_headings_changed, \%results;
623
}
632
}
624
633
Lines 646-651 sub _check_valid_auth_link { Link Here
646
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
655
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
647
}
656
}
648
657
658
=head2 AddAuthorityFromHeading
659
660
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
661
662
Creates a new authority from an heading and its associated field.
663
664
Returns the id of the newly created authority.
665
666
=cut
667
668
sub AddAuthorityFromHeading {
669
    my $heading = shift;
670
    my $field = shift;
671
    my $bib = shift;
672
673
    if(!defined $heading || !defined $field || !defined $bib){
674
       return 0;
675
    }
676
    my $authtypedata =
677
      Koha::Authority::Types->find( $heading->auth_type() );
678
    my $marcrecordauth = MARC::Record->new();
679
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
680
        $marcrecordauth->leader('     nz  a22     o  4500');
681
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
682
    }
683
    my $authfield =
684
      MARC::Field->new( $authtypedata->auth_tag_to_report,
685
        '', '', "a" => "" . $field->subfield('a') );
686
    map {
687
        $authfield->add_subfields( $_->[0] => $_->[1] )
688
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
689
    } $field->subfields();
690
    $marcrecordauth->insert_fields_ordered($authfield);
691
692
# bug 2317: ensure new authority knows it's using UTF-8; currently
693
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
694
# automatically for UNIMARC (by not transcoding)
695
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
696
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
697
# of change to a core API just before the 3.0 release.
698
699
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
700
        $marcrecordauth->insert_fields_ordered(
701
            MARC::Field->new(
702
                '667', '', '',
703
                'a' => "Machine generated authority record."
704
            )
705
        );
706
        if(defined $bib) {
707
            my $cite =
708
                $bib->author() . ", "
709
              . $bib->title_proper() . ", "
710
              . $bib->publication_date() . " ";
711
            $cite =~ s/^[\s\,]*//;
712
            $cite =~ s/[\s\,]*$//;
713
            $cite =
714
                "Work cat.: ("
715
              . C4::Context->preference('MARCOrgCode') . ")"
716
              . $bib->subfield( '999', 'c' ) . ": "
717
              . $cite;
718
            $marcrecordauth->insert_fields_ordered(
719
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
720
        }
721
722
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
723
        my $date=POSIX::strftime("%y%m%d",localtime);
724
        my @heading_use = qw(b b b);
725
        my $thesaurus = '|';
726
727
        if ($heading->{'subject_added_entry'}) {
728
            $heading_use[1] = 'a';
729
            # Thesaurus treatment
730
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
731
            $thesaurus = 'z';
732
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
733
            if($thesaurus eq 'z')
734
            {
735
                $marcrecordauth->insert_fields_ordered(
736
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
737
                );
738
            }
739
        }
740
        if ($heading->{'series_added_entry'}) {
741
            $heading_use[2] = 'a';
742
        }
743
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
744
            $heading_use[0] = 'a';
745
        }
746
747
        # Get a valid default value for field 008
748
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
749
        if(!$default_008 or length($default_008)<34) {
750
            $default_008 = '|| aca||aabn           | a|a     d';
751
        }
752
        else {
753
            $default_008 = substr($default_008,0,34)
754
        }
755
756
        # Insert the date, thesaurus and heading_use into field 008
757
        my $f008 = $date . $default_008;
758
        substr($f008, 11, 1) = $thesaurus;
759
        substr($f008, 14, 3) = join('', @heading_use);
760
761
        $marcrecordauth->insert_fields_ordered(
762
            MARC::Field->new('008',$f008)
763
        );
764
    }
765
766
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
767
768
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
769
    return $authid;
770
}
771
772
649
=head2 GetRecordValue
773
=head2 GetRecordValue
650
774
651
  my $values = GetRecordValue($field, $record, $frameworkcode);
775
  my $values = GetRecordValue($field, $record, $frameworkcode);
(-)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 42-48 sub get_link { Link Here
42
        # look for matching authorities
42
        # look for matching authorities
43
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
43
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
44
44
45
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
45
        if ( $behavior eq 'default' && $#{$authorities} >= 0 ) {
46
            $authid = $authorities->[0]->{'authid'};
46
            $authid = $authorities->[0]->{'authid'};
47
        }
47
        }
48
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
48
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
(-)a/authorities/authorities.pl (-2 / +23 lines)
Lines 289-294 sub create_input { Link Here
289
289
290
        }
290
        }
291
    }
291
    }
292
    if ($cgi->param('tagreport') && $subfield_data{tag} == $cgi->param('tagreport')) {
293
        $subfield_data{marc_value}{value} = $cgi->param('tag'. $cgi->param('tagbiblio') . 'subfield' . $subfield_data{subfield});
294
    }
292
    $subfield_data{'index_subfield'} = $index_subfield;
295
    $subfield_data{'index_subfield'} = $index_subfield;
293
    return \%subfield_data;
296
    return \%subfield_data;
294
}
297
}
Lines 563-568 my $myindex = $input->param('index'); Link Here
563
my $linkid=$input->param('linkid');
566
my $linkid=$input->param('linkid');
564
my $authtypecode = $input->param('authtypecode');
567
my $authtypecode = $input->param('authtypecode');
565
my $breedingid    = $input->param('breedingid');
568
my $breedingid    = $input->param('breedingid');
569
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new authority infos to the parent biblio
570
571
if($biblioindex and !$authid){
572
    require C4::Heading;
573
574
    my $record = TransformHtmlToMarc( $input );
575
576
    # Get the first heading found in the biblio informations
577
    foreach my $field ( $record->fields() ) {
578
        my $heading = C4::Heading->new_from_bib_field($field);
579
        next unless defined $heading;
580
581
        # Create a new authority using the heading informations
582
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
583
    }
584
}
566
585
567
my $dbh = C4::Context->dbh;
586
my $dbh = C4::Context->dbh;
568
if(!$authtypecode) {
587
if(!$authtypecode) {
Lines 577-583 my ($template, $loggedinuser, $cookie) Link Here
577
                            flagsrequired => {editauthorities => 1},
596
                            flagsrequired => {editauthorities => 1},
578
                            debug => 1,
597
                            debug => 1,
579
                            });
598
                            });
580
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
599
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
581
600
582
$tagslib = GetTagsLabels(1,$authtypecode);
601
$tagslib = GetTagsLabels(1,$authtypecode);
583
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
602
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 622-628 if ($op eq "add") { Link Here
622
        } else {
641
        } else {
623
            ($authid) = AddAuthority($record,$authid,$authtypecode);
642
            ($authid) = AddAuthority($record,$authid,$authtypecode);
624
        }
643
        }
625
        if ($myindex) {
644
        if ($biblioindex) {
645
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
646
        } elsif ($myindex) {
626
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
647
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
627
        } else {
648
        } else {
628
            print $input->redirect("detail.pl?authid=$authid");
649
            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
47
47
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
48
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
Lines 63-68 $template->param( Link Here
63
    subjectsubdiv   => $subjectsubdiv,
64
    subjectsubdiv   => $subjectsubdiv,
64
    srchany      => $srchany,
65
    srchany      => $srchany,
65
    authid => $authid,
66
    authid => $authid,
67
    index => $index,
66
);
68
);
67
69
68
if ( $op ne "do_search" ) {
70
if ( $op ne "do_search" ) {
Lines 72-77 if ( $op ne "do_search" ) { Link Here
72
    $template->param(
74
    $template->param(
73
        serverloop   => $serverloop,
75
        serverloop   => $serverloop,
74
        opsearch     => "search",
76
        opsearch     => "search",
77
        index        => $index,
75
    );
78
    );
76
    output_html_with_http_headers $input, $cookie, $template->output;
79
    output_html_with_http_headers $input, $cookie, $template->output;
77
    exit;
80
    exit;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-4 / +8 lines)
Lines 22-29 Link Here
22
        $("#z3950submit").click(function(){
22
        $("#z3950submit").click(function(){
23
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
23
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
24
                var strQuery = GetZ3950Terms();
24
                var strQuery = GetZ3950Terms();
25
                var index = "&index=[% index %]";
25
                if(strQuery){
26
                if(strQuery){
26
                    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');
27
                    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');
27
                }
28
                }
28
            }
29
            }
29
            return false;
30
            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 (-1 / +4 lines)
Lines 42-48 Link Here
42
            var index_start = "[% index | html %]";
42
            var index_start = "[% index | html %]";
43
            var whichfield;
43
            var whichfield;
44
            try {
44
            try {
45
                whichfield = opener.opener.document.getElementById(index_start);
45
                whichfield = window.opener.document.getElementById(index_start);
46
            } catch(e) {
46
            } catch(e) {
47
                return;
47
                return;
48
            }
48
            }
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 (-5 / +207 lines)
Lines 81-86 Link Here
81
            [% END %]
81
            [% END %]
82
        });
82
        });
83
83
84
        $("#linkerbutton").click(function(){
85
            AutomaticLinker();
86
        });
87
84
        $("#saverecord").click(function(){
88
        $("#saverecord").click(function(){
85
            $(".btn-group").removeClass("open");
89
            $(".btn-group").removeClass("open");
86
            onOption();
90
            onOption();
Lines 163-168 function PopupZ3950() { Link Here
163
    } 
167
    } 
164
}
168
}
165
169
170
/**
171
* this function append button for create new authority if not found
172
*/
173
174
function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
175
    var title = _("Create authority");
176
    var elem = $('<a class="subfield_status" href="#"><img src="[% interface %]/[% theme %]/img/create.png" title="' + title + '" /></a>');
177
    tag_subfield_line.append(elem);
178
    var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
179
    var subfield_a = tag_subfield_line_a.children('.input_marceditor').eq(0);
180
    var index = subfield_a.attr('id');
181
    elem.click(function() {
182
        var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
183
        if(popup !== null) {
184
            // Create a new form that will be POSTed in the new window
185
            var form = $('<form>').attr({
186
            method: 'post',
187
            action: "../authorities/authorities.pl",
188
            target: "new_auth_popup"
189
            });
190
            //add the authtypecode
191
            form.append($('<input>').attr({
192
                type: 'hidden',
193
                name: 'authtypecode',
194
                value: heading.auth_type
195
            }));
196
            form.append($('<input>').attr({
197
                type: 'hidden',
198
                name: 'tagreport',
199
                value: heading.tag_to_report
200
            }));
201
            form.append($('<input>').attr({
202
                type: 'hidden',
203
                name: 'tagbiblio',
204
                value: heading.tag
205
            }));
206
            form.append($('<input>').attr({
207
                type: 'hidden',
208
                name: 'index',
209
                value: index
210
            }));
211
            $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
212
                form.append($('<input>').attr({
213
                    type: 'hidden',
214
                    name: this.name.split('_',4).join(''),
215
                    value: $(this).val()
216
                }));
217
            });
218
219
            $('body').append(form);
220
            form.submit();
221
            form.remove();
222
        }
223
        return false;
224
    });
225
226
}
227
228
/**
229
 * Updates the authid for every heading field
230
 * Adds visual feedback for the changes made on the form.
231
 */
232
function updateHeadingLinks(links) {
233
    var current_tag = '';
234
    var tag_index = 0;
235
236
    // Delete the old message dialog and create a new one
237
    $('#autolinker_dialog').remove();
238
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
239
    var message_dialog_ul = message_dialog.find('ul');
240
241
    $.each(links, function(index, heading) {
242
        if(current_tag == heading.tag) {
243
            tag_index++;
244
        }
245
        else {
246
            current_tag = heading.tag;
247
            tag_index = 0;
248
        }
249
250
        // Find the $9 field to update
251
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
252
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
253
254
        // Delete the old status if one exists
255
        tag_subfield_line.children('.subfield_status').remove();
256
        subfield.css({backgroundColor:''});
257
258
        // If the field wasn't modified. Skip it.
259
        if(heading.status == 'UNCHANGED') {
260
            return;
261
        }
262
263
264
        // Make the subfield line visible and update its value
265
        tag_subfield_line.show();
266
        subfield.val(heading.authid);
267
268
        // Add the new status
269
        var image = 'deny.gif';
270
        var message = '';
271
        var field_color = '#FFAAAA';
272
        switch(heading.status) {
273
            case 'LOCAL_FOUND':
274
                image = 'approve.gif';
275
                message = _("A matching authority was found in the local database.");
276
                field_color = '#99FF99';
277
                break;
278
            case 'CREATED':
279
                image = 'approve.gif';
280
                message = _("No matching authority found. A new authority was created automatically.");
281
                field_color = '#99FF99';
282
                break;
283
            case 'MULTIPLE_MATCH':
284
                message = _("More than one local match found. Possibly a duplicate authority!");
285
                break;
286
            case 'NONE_FOUND':
287
                message = _("No matching authority found.");
288
                break;
289
            default:
290
                message = heading.status;
291
                break;
292
        }
293
294
        subfield.css({backgroundColor:field_color});
295
        tag_subfield_line.append('<img class="subfield_status" src="[% interface %]/[% theme %]/img/' + image + '" title="' + message + '" />');
296
297
        // Add the message to the dialog
298
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
299
300
        // Add a link to create a new authority if none was found
301
        if(heading.status == 'NONE_FOUND') {
302
            addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
303
        }
304
    });
305
306
    if(message_dialog.find('li').length == 0) {
307
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
308
    }
309
    $('#addbibliotabs').before(message_dialog);
310
}
311
312
/**
313
 * Use an ajax request to automatically find authority links for the current record
314
 */
315
function AutomaticLinker() {
316
    // Show the Loading overlay
317
    $("#loading").show();
318
319
    // Remove fields that are completely empty
320
    $('#f').find('.tag').each(function() {
321
        var empty = true;
322
        $(this).find('.input_marceditor').each(function() {
323
            if($(this).val() != '') {
324
                empty = false;
325
                return false;
326
            }
327
        });
328
        if(empty) {
329
            UnCloneField($(this).attr('id'));
330
        }
331
    });
332
333
    // Get all the form values to post via AJAX
334
    var form_data = {};
335
    $('#f').find(':input').each(function(){
336
        form_data[this.name] = $(this).val();
337
    });
338
    delete form_data[''];
339
340
    // Send the data to automatic_linker.pl
341
    $.ajax({
342
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
343
        type:'post',
344
        data: form_data,
345
        dataType: 'json',
346
        error: function(xhr) {
347
            alert("Error : \n" + xhr.responseText);
348
        },
349
        success: function(json) {
350
            switch(json.status) {
351
                case 'UNAUTHORIZED':
352
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
353
                    break;
354
                case 'OK':
355
                    updateHeadingLinks(json.links);
356
                    break;
357
            }
358
        },
359
        complete: function() {
360
            $("#loading").hide();
361
        }
362
    });
363
}
364
365
166
function PopupMARCFieldDoc(field) {
366
function PopupMARCFieldDoc(field) {
167
    [% IF Koha.Preference('marcfielddocurl') %]
367
    [% IF Koha.Preference('marcfielddocurl') %]
168
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
368
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
Lines 483-492 function Changefwk() { Link Here
483
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
683
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
484
    [% END %]
684
    [% END %]
485
685
486
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
487
        <div class="btn-group"><a class="btn btn-default btn-sm" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
488
    [% END %]
489
490
    <div class="btn-group">
686
    <div class="btn-group">
491
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
687
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
492
        <ul id="settings-menu" class="dropdown-menu">
688
        <ul id="settings-menu" class="dropdown-menu">
Lines 527-532 function Changefwk() { Link Here
527
        </ul>
723
        </ul>
528
    </div>
724
    </div>
529
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
725
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
726
        <div class="btn-group"><a class="btn btn-default btn-sm" href="#" id="linkerbutton"><i class="fa fa-refresh"></i> Link authorities automatically</a></div>
727
        <div class="btn-group"><a class="btn btn-default btn-sm" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
728
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
729
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-default btn-sm">Switch to advanced editor</a></div>
730
        [% END %]
530
        [% IF (biblionumber) %]
731
        [% IF (biblionumber) %]
531
            [% IF ( BiblioDefaultViewmarc ) %]
732
            [% IF ( BiblioDefaultViewmarc ) %]
532
                <div class="btn-group">
733
                <div class="btn-group">
Lines 680-686 function Changefwk() { Link Here
680
                    <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
881
                    <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
681
                    [% END %]
882
                    [% END %]
682
                    [% IF ( mv.authtype ) %]
883
                    [% IF ( mv.authtype ) %]
683
                    <span class="subfield_controls"><a href="#" class="buttonDot tag_editor" onclick="openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'[%- mv.authtype | html -%]','biblio'); return false;" tabindex="1" title="Tag editor">Tag editor</a></span>
884
                    <input type="hidden" name="authtypecode" id="authtypecode" value="[% mv.authtype %]" />
885
                    <span class="subfield_controls"><a href="#" class="buttonDot tag_editor" onclick="openAuth(this.parentNode.parentNode.getElementsByTagName('input')[1].id,'[%- mv.authtype -%]','biblio'); return false;" tabindex="1" title="Tag editor">Tag editor</a></span>
684
                    [% END %]
886
                    [% END %]
685
                [% ELSIF ( mv.type == 'text_complex' ) %]
887
                [% ELSIF ( mv.type == 'text_complex' ) %]
686
                    <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
888
                    <input type="text" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt (-1 / +2 lines)
Lines 21-26 Link Here
21
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
21
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
22
        <input type="hidden" name="op" id="op" value="do_search" />
22
        <input type="hidden" name="op" id="op" value="do_search" />
23
        <input type="hidden" name="authid" value="[% authid | html %]" />
23
        <input type="hidden" name="authid" value="[% authid | html %]" />
24
        <input type="hidden" name="index" value="[% index %]" />
24
            <div class="row">
25
            <div class="row">
25
            <div class="col-xs-6">
26
            <div class="col-xs-6">
26
                <fieldset class="rows">
27
                <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 | html %]" 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 | html %]" 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 176-178 warnings_like { $ret = UpdateTotalIssues() } Link Here
176
176
177
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
177
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
178
178
179
- 
179
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
180
1;

Return to bug 11299