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

(-)a/C4/Biblio.pm (-54 / +130 lines)
Lines 506-512 sub BiblioAutoLink { Link Here
506
506
507
=head2 LinkBibHeadingsToAuthorities
507
=head2 LinkBibHeadingsToAuthorities
508
508
509
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
509
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
510
510
511
Links bib headings to authority records by checking
511
Links bib headings to authority records by checking
512
each authority-controlled field in the C<MARC::Record>
512
each authority-controlled field in the C<MARC::Record>
Lines 528-533 sub LinkBibHeadingsToAuthorities { Link Here
528
    my $bib           = shift;
528
    my $bib           = shift;
529
    my $frameworkcode = shift;
529
    my $frameworkcode = shift;
530
    my $allowrelink = shift;
530
    my $allowrelink = shift;
531
    my $verbose = shift;
531
    my %results;
532
    my %results;
532
    if (!$bib) {
533
    if (!$bib) {
533
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
534
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 548-647 sub LinkBibHeadingsToAuthorities { Link Here
548
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
549
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
549
        {
550
        {
550
            $results{'linked'}->{ $heading->display_form() }++;
551
            $results{'linked'}->{ $heading->display_form() }++;
552
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
551
            next;
553
            next;
552
        }
554
        }
553
555
554
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
556
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
555
        if ($authid) {
557
        if ($authid) {
556
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
558
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
557
              ->{ $heading->display_form() }++;
559
              ->{ $heading->display_form() }++;
558
            next if defined $current_link and $current_link == $authid;
560
            if(defined $current_link and $current_link == $authid) {
561
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
562
                next;
563
            }
559
564
560
            $field->delete_subfield( code => '9' ) if defined $current_link;
565
            $field->delete_subfield( code => '9' ) if defined $current_link;
561
            $field->add_subfields( '9', $authid );
566
            $field->add_subfields( '9', $authid );
562
            $num_headings_changed++;
567
            $num_headings_changed++;
568
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
563
        }
569
        }
564
        else {
570
        else {
565
            if ( defined $current_link
571
            if ( defined $current_link
566
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
572
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
567
            {
573
            {
568
                $results{'fuzzy'}->{ $heading->display_form() }++;
574
                $results{'fuzzy'}->{ $heading->display_form() }++;
575
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
569
            }
576
            }
570
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
577
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
571
                if ( _check_valid_auth_link( $current_link, $field ) ) {
578
                if ( _check_valid_auth_link( $current_link, $field ) ) {
572
                    $results{'linked'}->{ $heading->display_form() }++;
579
                    $results{'linked'}->{ $heading->display_form() }++;
573
                }
580
                }
574
                else {
581
                else {
575
                    my $authtypedata =
582
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
576
                      C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() );
577
                    my $marcrecordauth = MARC::Record->new();
578
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
579
                        $marcrecordauth->leader('     nz  a22     o  4500');
580
                        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
581
                    }
582
                    $field->delete_subfield( code => '9' )
583
                      if defined $current_link;
584
                    my $authfield =
585
                      MARC::Field->new( $authtypedata->{auth_tag_to_report},
586
                        '', '', "a" => "" . $field->subfield('a') );
587
                    map {
588
                        $authfield->add_subfields( $_->[0] => $_->[1] )
589
                          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
590
                    } $field->subfields();
591
                    $marcrecordauth->insert_fields_ordered($authfield);
592
593
# bug 2317: ensure new authority knows it's using UTF-8; currently
594
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
595
# automatically for UNIMARC (by not transcoding)
596
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
597
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
598
# of change to a core API just before the 3.0 release.
599
600
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
601
                        $marcrecordauth->insert_fields_ordered(
602
                            MARC::Field->new(
603
                                '667', '', '',
604
                                'a' => "Machine generated authority record."
605
                            )
606
                        );
607
                        my $cite =
608
                            $bib->author() . ", "
609
                          . $bib->title_proper() . ", "
610
                          . $bib->publication_date() . " ";
611
                        $cite =~ s/^[\s\,]*//;
612
                        $cite =~ s/[\s\,]*$//;
613
                        $cite =
614
                            "Work cat.: ("
615
                          . C4::Context->preference('MARCOrgCode') . ")"
616
                          . $bib->subfield( '999', 'c' ) . ": "
617
                          . $cite;
618
                        $marcrecordauth->insert_fields_ordered(
619
                            MARC::Field->new( '670', '', '', 'a' => $cite ) );
620
                    }
621
622
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
623
583
624
                    $authid =
625
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
626
                        $heading->auth_type() );
627
                    $field->add_subfields( '9', $authid );
584
                    $field->add_subfields( '9', $authid );
628
                    $num_headings_changed++;
585
                    $num_headings_changed++;
629
                    $linker->update_cache($heading, $authid);
586
                    $linker->update_cache($heading, $authid);
630
                    $results{'added'}->{ $heading->display_form() }++;
587
                    $results{'added'}->{ $heading->display_form() }++;
588
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
631
                }
589
                }
632
            }
590
            }
633
            elsif ( defined $current_link ) {
591
            elsif ( defined $current_link ) {
634
                if ( _check_valid_auth_link( $current_link, $field ) ) {
592
                if ( _check_valid_auth_link( $current_link, $field ) ) {
635
                    $results{'linked'}->{ $heading->display_form() }++;
593
                    $results{'linked'}->{ $heading->display_form() }++;
594
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
636
                }
595
                }
637
                else {
596
                else {
638
                    $field->delete_subfield( code => '9' );
597
                    $field->delete_subfield( code => '9' );
639
                    $num_headings_changed++;
598
                    $num_headings_changed++;
640
                    $results{'unlinked'}->{ $heading->display_form() }++;
599
                    $results{'unlinked'}->{ $heading->display_form() }++;
600
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
641
                }
601
                }
642
            }
602
            }
643
            else {
603
            else {
644
                $results{'unlinked'}->{ $heading->display_form() }++;
604
                $results{'unlinked'}->{ $heading->display_form() }++;
605
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
645
            }
606
            }
646
        }
607
        }
647
608
Lines 673-678 sub _check_valid_auth_link { Link Here
673
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
634
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
674
}
635
}
675
636
637
=head2 AddAuthorityFromHeading
638
639
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
640
641
Creates a new authority from an heading and its associated field.
642
643
Returns the id of the newly created authority.
644
645
=cut
646
647
sub AddAuthorityFromHeading {
648
    my $heading = shift;
649
    my $field = shift;
650
    my $bib = shift;
651
652
    if(!defined $heading || !defined $field || !defined $bib){
653
       return 0;
654
    }
655
    my $authtypedata =
656
      C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() );
657
    my $marcrecordauth = MARC::Record->new();
658
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
659
        $marcrecordauth->leader('     nz  a22     o  4500');
660
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
661
    }
662
    my $authfield =
663
      MARC::Field->new( $authtypedata->{auth_tag_to_report},
664
        '', '', "a" => "" . $field->subfield('a') );
665
    map {
666
        $authfield->add_subfields( $_->[0] => $_->[1] )
667
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
668
    } $field->subfields();
669
    $marcrecordauth->insert_fields_ordered($authfield);
670
671
# bug 2317: ensure new authority knows it's using UTF-8; currently
672
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
673
# automatically for UNIMARC (by not transcoding)
674
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
675
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
676
# of change to a core API just before the 3.0 release.
677
678
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
679
        $marcrecordauth->insert_fields_ordered(
680
            MARC::Field->new(
681
                '667', '', '',
682
                'a' => "Machine generated authority record."
683
            )
684
        );
685
        if(defined $bib) {
686
            my $cite =
687
                $bib->author() . ", "
688
              . $bib->title_proper() . ", "
689
              . $bib->publication_date() . " ";
690
            $cite =~ s/^[\s\,]*//;
691
            $cite =~ s/[\s\,]*$//;
692
            $cite =
693
                "Work cat.: ("
694
              . C4::Context->preference('MARCOrgCode') . ")"
695
              . $bib->subfield( '999', 'c' ) . ": "
696
              . $cite;
697
            $marcrecordauth->insert_fields_ordered(
698
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
699
        }
700
701
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
702
        my $date=POSIX::strftime("%y%m%d",localtime);
703
        my @heading_use = qw(b b b);
704
        my $thesaurus = '|';
705
706
        if ($heading->{'subject_added_entry'}) {
707
            $heading_use[1] = 'a';
708
            # Thesaurus treatment
709
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
710
            $thesaurus = 'z';
711
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
712
            if($thesaurus eq 'z')
713
            {
714
                $marcrecordauth->insert_fields_ordered(
715
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
716
                );
717
            }
718
        }
719
        if ($heading->{'series_added_entry'}) {
720
            $heading_use[2] = 'a';
721
        }
722
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
723
            $heading_use[0] = 'a';
724
        }
725
726
        # Get a valid default value for field 008
727
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
728
        if(!$default_008 or length($default_008)<34) {
729
            $default_008 = '|| aca||aabn           | a|a     d';
730
        }
731
        else {
732
            $default_008 = substr($default_008,0,34)
733
        }
734
735
        # Insert the date, thesaurus and heading_use into field 008
736
        my $f008 = $date . $default_008;
737
        substr($f008, 11, 1) = $thesaurus;
738
        substr($f008, 14, 3) = join('', @heading_use);
739
740
        $marcrecordauth->insert_fields_ordered(
741
            MARC::Field->new('008',$f008)
742
        );
743
    }
744
745
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
746
747
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
748
    return $authid;
749
}
750
751
676
=head2 GetRecordValue
752
=head2 GetRecordValue
677
753
678
  my $values = GetRecordValue($field, $record, $frameworkcode);
754
  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 / +20 lines)
Lines 564-569 my $myindex = $input->param('index'); Link Here
564
my $linkid=$input->param('linkid');
564
my $linkid=$input->param('linkid');
565
my $authtypecode = $input->param('authtypecode');
565
my $authtypecode = $input->param('authtypecode');
566
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 autority 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
}
567
583
568
my $dbh = C4::Context->dbh;
584
my $dbh = C4::Context->dbh;
569
if(!$authtypecode) {
585
if(!$authtypecode) {
Lines 578-584 my ($template, $loggedinuser, $cookie) Link Here
578
                            flagsrequired => {editauthorities => 1},
594
                            flagsrequired => {editauthorities => 1},
579
                            debug => 1,
595
                            debug => 1,
580
                            });
596
                            });
581
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
597
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
582
598
583
$tagslib = GetTagsLabels(1,$authtypecode);
599
$tagslib = GetTagsLabels(1,$authtypecode);
584
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
600
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 623-629 if ($op eq "add") { Link Here
623
        } else {
639
        } else {
624
            ($authid) = AddAuthority($record,$authid,$authtypecode);
640
            ($authid) = AddAuthority($record,$authid,$authtypecode);
625
        }
641
        }
626
        if ($myindex) {
642
        if ($biblioindex) {
643
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
644
        } elsif ($myindex) {
627
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
645
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
628
        } else {
646
        } else {
629
            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);
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/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js (+6 lines)
Lines 108-116 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
108
            for( j = 0 ; j < inputs.length ; j++ ) {
108
            for( j = 0 ; j < inputs.length ; j++ ) {
109
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
109
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
110
                    inputs[j].value = "";
110
                    inputs[j].value = "";
111
112
                    //Remove the color added by the automatic linker
113
                    $(inputs[j]).css({backgroundColor:""});
111
                }
114
                }
112
            }
115
            }
113
116
117
            // Remove the status icons added by the automatic linker
118
            $(divs[i]).find('.subfield_status').remove();
119
114
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
120
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
115
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
121
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
116
            var id_input;
122
            var id_input;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (+3 lines)
Lines 201-206 function confirmnotdup(redirect){ Link Here
201
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
201
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
202
    <input type="hidden" name="authid" value="[% authid %]" />
202
    <input type="hidden" name="authid" value="[% authid %]" />
203
    <input type="hidden" name="index" value="[% index %]" />
203
    <input type="hidden" name="index" value="[% index %]" />
204
    [% IF ( biblioindex ) %]
205
    <input type="hidden" name="biblioindex" value="[% biblioindex %]" />
206
    [% END %]
204
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
207
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
205
208
206
    <div id="toolbar" class="btn-toolbar">
209
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (-4 / +20 lines)
Lines 5-13 Link Here
5
//<![CDATA[
5
//<![CDATA[
6
    $(document).ready(function(){
6
    $(document).ready(function(){
7
        var index_start = "[% index %]";
7
        var index_start = "[% index %]";
8
        var whichfield;
8
        var whichfield = null;
9
10
        // Loop through opener windows and try to find the basewindow and the form field we need to fill
11
        var basewindow = window;
12
        var parents_to_close = [];
9
        try {
13
        try {
10
            whichfield = opener.opener.document.getElementById(index_start);
14
            while(whichfield === null) {
15
                basewindow = basewindow.opener;
16
                whichfield = basewindow.document.getElementById(index_start);
17
                if(whichfield === null) {
18
                    parents_to_close.unshift(basewindow);
19
                }
20
            }
11
        } catch(e) {
21
        } catch(e) {
12
            return;
22
            return;
13
        }
23
        }
Lines 99-111 Link Here
99
            [% ELSE %]
109
            [% ELSE %]
100
                if(code.value=='9'){
110
                if(code.value=='9'){
101
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
111
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
102
                    break;
112
                    // Clean the field if it was modified by the automatic linker
113
                    $(subfield).siblings('.subfield_status').remove();
114
                    $(subfield).css({backgroundColor:''});
103
                }
115
                }
104
            [% END %]
116
            [% END %]
105
            }
117
            }
106
        }
118
        }
107
119
108
      	opener.close();
120
        // Close all parent windows, but not the basewindow
121
        while(parents_to_close.length != 0) {
122
            parents_to_close.shift().close();
123
        }
124
109
       	window.close();
125
       	window.close();
110
            
126
            
111
       	return false;
127
       	return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-1 / +195 lines)
Lines 80-85 Link Here
80
            [% END %]
80
            [% END %]
81
        });
81
        });
82
82
83
        $("#linkerbutton").click(function(){
84
            AutomaticLinker();
85
        });
86
83
        $("#saverecord").click(function(){
87
        $("#saverecord").click(function(){
84
            $(".btn-group").removeClass("open");
88
            $(".btn-group").removeClass("open");
85
            onOption();
89
            onOption();
Lines 158-163 function PopupZ3950() { Link Here
158
    } 
162
    } 
159
}
163
}
160
164
165
function addCreateAuthorityButton(tag_subfield_line, tag, index) {
166
    var title = _("Create authority");
167
    var elem = $('<a class="subfield_status" href="#"><img src="[% interface %]/[% theme %]/img/edit-tag.png" title="' + title + '" /></a>');
168
    tag_subfield_line.append(elem);
169
170
    elem.click(function() {
171
        var biblioindex = $(this).parents('.subfield_line').find('input').eq(1).attr('id');
172
        var popup = window.open("", "new_auth_popup",'width=700,height=550,toolbar=false,scrollbars=yes');
173
174
    if(popup !== null) {
175
        // Create a new form that will be POSTed in the new window
176
        var form = $('<form>').attr({
177
        method: 'post',
178
        action: "../authorities/authorities.pl",
179
        target: "new_auth_popup"
180
        });
181
182
        // Add the biblioindex
183
        form.append($('<input>').attr({
184
        type: 'hidden',
185
        name: 'biblioindex',
186
        value: biblioindex
187
        }));
188
        //add the authtypecode
189
        form.append($('<input>').attr({
190
        type: 'hidden',
191
        name: 'authtypecode',
192
        value: $("#authtypecode").val()
193
        }));
194
195
196
    // Get all form datas for the current heading field
197
        $('.tag[id^=tag_' + tag + '_]').eq(index).find(':input').each(function(){
198
        form.append($('<input>').attr({
199
            type: 'hidden',
200
            name: this.name,
201
            value: $(this).val()
202
        }));
203
        });
204
205
        // We need to add the temporary form to the body so we can submit it
206
        $('body').append(form);
207
        form.submit();
208
        form.remove();
209
    }
210
211
    return false;
212
    });
213
}
214
215
/**
216
 * Updates the authid for every heading field
217
 * Adds visual feedback for the changes made on the form.
218
 */
219
function updateHeadingLinks(links) {
220
    var current_tag = '';
221
    var tag_index = 0;
222
223
    // Delete the old message dialog and create a new one
224
    $('#autolinker_dialog').remove();
225
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
226
    var message_dialog_ul = message_dialog.find('ul');
227
228
    $.each(links, function(index, heading) {
229
        if(current_tag == heading.tag) {
230
            tag_index++;
231
        }
232
        else {
233
            current_tag = heading.tag;
234
            tag_index = 0;
235
        }
236
237
        // Find the $9 field to update
238
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
239
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
240
241
        // Delete the old status if one exists
242
        tag_subfield_line.children('.subfield_status').remove();
243
        subfield.css({backgroundColor:''});
244
245
        // If the field wasn't modified. Skip it.
246
        if(heading.status == 'UNCHANGED') {
247
            return;
248
        }
249
250
251
        // Make the subfield line visible and update its value
252
        tag_subfield_line.show();
253
        subfield.val(heading.authid);
254
255
        // Add the new status
256
        var image = 'deny.gif';
257
        var message = '';
258
        var field_color = '#FFAAAA';
259
        switch(heading.status) {
260
            case 'LOCAL_FOUND':
261
                image = 'approve.gif';
262
                message = _("A matching authority was found in the local database.");
263
                field_color = '#99FF99';
264
                break;
265
            case 'CREATED':
266
                image = 'approve.gif';
267
                message = _("No matching authority found. A new authority was created automatically.");
268
                field_color = '#99FF99';
269
                break;
270
            case 'MULTIPLE_MATCH':
271
                message = _("More than one local match found. Possibly a duplicate authority!");
272
                break;
273
            case 'NONE_FOUND':
274
                message = _("No matching authority found.");
275
                break;
276
            default:
277
                message = heading.status;
278
                break;
279
        }
280
281
        subfield.css({backgroundColor:field_color});
282
        tag_subfield_line.append('<img class="subfield_status" src="[% interface %]/[% theme %]/img/' + image + '" title="' + message + '" />');
283
284
        // Add the message to the dialog
285
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
286
287
        // Add a link to create a new authority if none was found
288
        if(heading.status == 'NONE_FOUND') {
289
            addCreateAuthorityButton(tag_subfield_line, heading.tag, tag_index);
290
        }
291
    });
292
293
    if(message_dialog.find('li').length == 0) {
294
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
295
    }
296
    $('#addbibliotabs').before(message_dialog);
297
}
298
299
/**
300
 * Use an ajax request to automatically find authority links for the current record
301
 */
302
function AutomaticLinker() {
303
    // Show the Loading overlay
304
    $("#loading").show();
305
306
    // Remove fields that are completely empty
307
    $('#f').find('.tag').each(function() {
308
        var empty = true;
309
        $(this).find('.input_marceditor').each(function() {
310
            if($(this).val() != '') {
311
                empty = false;
312
                return false;
313
            }
314
        });
315
        if(empty) {
316
            UnCloneField($(this).attr('id'));
317
        }
318
    });
319
320
    // Get all the form values to post via AJAX
321
    var form_data = {};
322
    $('#f').find(':input').each(function(){
323
        form_data[this.name] = $(this).val();
324
    });
325
    delete form_data[''];
326
327
    // Send the data to automatic_linker.pl
328
    $.ajax({
329
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
330
        type:'post',
331
        data: form_data,
332
        dataType: 'json',
333
        error: function(xhr) {
334
            alert("Error : \n" + xhr.responseText);
335
        },
336
        success: function(json) {
337
            switch(json.status) {
338
                case 'UNAUTHORIZED':
339
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
340
                    break;
341
                case 'OK':
342
                    updateHeadingLinks(json.links);
343
                    break;
344
            }
345
        },
346
        complete: function() {
347
            $("#loading").hide();
348
        }
349
    });
350
}
351
352
161
function PopupMARCFieldDoc(field) {
353
function PopupMARCFieldDoc(field) {
162
    [% IF ( marcflavour == 'MARC21' ) %]
354
    [% IF ( marcflavour == 'MARC21' ) %]
163
        _MARC21FieldDoc(field);
355
        _MARC21FieldDoc(field);
Lines 480-486 function Changefwk(FwkList) { Link Here
480
    [% END %]
672
    [% END %]
481
673
482
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
674
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
483
        <div class="btn-group"><a class="btn btn-small" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
675
        <div class="btn-group"><a class="btn btn-small" href="#" id="linkerbutton"><i class="icon-ok"></i> Link authorities automatically</a></div>
676
        <div class="btn-group"><a class="btn btn-small" href="#" id="z3950search"><i class="icon-search"></i> Z39.50/SRU search</a></div>
484
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
677
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
485
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
678
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
486
        [% END %]
679
        [% END %]
Lines 645-650 function Changefwk(FwkList) { Link Here
645
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
838
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
646
                    [% END %]
839
                    [% END %]
647
                    [% IF ( mv.authtype ) %]
840
                    [% IF ( mv.authtype ) %]
841
                    <input type="hidden" name="authtypecode" id="authtypecode" value="[% mv.authtype %]" />
648
                    <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>
842
                    <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>
649
                    [% END %]
843
                    [% END %]
650
                [% ELSIF ( mv.type == 'text_complex' ) %]
844
                [% ELSIF ( mv.type == 'text_complex' ) %]
(-)a/t/Biblio.t (-1 / +1 lines)
Lines 197-200 warnings_like { $ret = UpdateTotalIssues() } Link Here
197
197
198
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
198
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
199
199
200
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
200
1;
201
1;
201
- 

Return to bug 11299