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

(-)a/C4/Biblio.pm (-7 / +131 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-540 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 {
534
            if ( defined $current_link
539
            if ( defined $current_link
535
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
540
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
536
            {
541
            {
537
                $results{'fuzzy'}->{ $heading->display_form() }++;
542
                $results{'fuzzy'}->{ $heading->display_form() }++;
543
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
538
            }
544
            }
539
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
545
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
540
                if ( _check_valid_auth_link( $current_link, $field ) ) {
546
                if ( _check_valid_auth_link( $current_link, $field ) ) {
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'}) 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'}) 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 / +20 lines)
Lines 563-568 my $myindex = $input->param('index'); Link Here
563
my $linkid=$input->param('linkid');
563
my $linkid=$input->param('linkid');
564
my $authtypecode = $input->param('authtypecode');
564
my $authtypecode = $input->param('authtypecode');
565
my $breedingid    = $input->param('breedingid');
565
my $breedingid    = $input->param('breedingid');
566
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new autority infos to the parent biblio
567
568
if($biblioindex and !$authid){
569
    require C4::Heading;
570
571
    my $record = TransformHtmlToMarc( $input );
572
573
    # Get the first heading found in the biblio informations
574
    foreach my $field ( $record->fields() ) {
575
        my $heading = C4::Heading->new_from_bib_field($field);
576
        next unless defined $heading;
577
578
        # Create a new authority using the heading informations
579
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
580
    }
581
}
566
582
567
my $dbh = C4::Context->dbh;
583
my $dbh = C4::Context->dbh;
568
if(!$authtypecode) {
584
if(!$authtypecode) {
Lines 577-583 my ($template, $loggedinuser, $cookie) Link Here
577
                            flagsrequired => {editauthorities => 1},
593
                            flagsrequired => {editauthorities => 1},
578
                            debug => 1,
594
                            debug => 1,
579
                            });
595
                            });
580
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
596
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
581
597
582
$tagslib = GetTagsLabels(1,$authtypecode);
598
$tagslib = GetTagsLabels(1,$authtypecode);
583
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
599
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 622-628 if ($op eq "add") { Link Here
622
        } else {
638
        } else {
623
            ($authid) = AddAuthority($record,$authid,$authtypecode);
639
            ($authid) = AddAuthority($record,$authid,$authtypecode);
624
        }
640
        }
625
        if ($myindex) {
641
        if ($biblioindex) {
642
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
643
        } elsif ($myindex) {
626
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
644
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
627
        } else {
645
        } else {
628
            print $input->redirect("detail.pl?authid=$authid");
646
            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/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-3 / +6 lines)
Lines 206-214 function confirmnotdup(redirect){ Link Here
206
    <input type="hidden" name="op" value="add" />
206
    <input type="hidden" name="op" value="add" />
207
    <input type="hidden" name="addfield_field" value="" />
207
    <input type="hidden" name="addfield_field" value="" />
208
    <input type="hidden" name="repeat_field" value="" />
208
    <input type="hidden" name="repeat_field" value="" />
209
    <input type="hidden" name="authtypecode" value="[% authtypecode | html %]" />
209
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
210
    <input type="hidden" name="authid" value="[% authid | html %]" />
210
    <input type="hidden" name="authid" value="[% authid %]" />
211
    <input type="hidden" name="index" value="[% index | html %]" />
211
    <input type="hidden" name="index" value="[% index %]" />
212
    [% IF ( biblioindex ) %]
213
    <input type="hidden" name="biblioindex" value="[% biblioindex %]" />
214
    [% END %]
212
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
215
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
213
216
214
    <div id="toolbar" class="btn-toolbar">
217
    <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 / +199 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
function addCreateAuthorityButton(tag_subfield_line, tag, index) {
171
    var title = _("Create authority");
172
    var elem = $('<a class="subfield_status" href="#"><img src="[% interface %]/[% theme %]/img/edit-tag.png" title="' + title + '" /></a>');
173
    tag_subfield_line.append(elem);
174
175
    elem.click(function() {
176
        var biblioindex = $(this).parents('.subfield_line').find('input').eq(1).attr('id');
177
        var popup = window.open("", "new_auth_popup",'width=700,height=550,toolbar=false,scrollbars=yes');
178
179
    if(popup !== null) {
180
        // Create a new form that will be POSTed in the new window
181
        var form = $('<form>').attr({
182
        method: 'post',
183
        action: "../authorities/authorities.pl",
184
        target: "new_auth_popup"
185
        });
186
187
        // Add the biblioindex
188
        form.append($('<input>').attr({
189
        type: 'hidden',
190
        name: 'biblioindex',
191
        value: biblioindex
192
        }));
193
        //add the authtypecode
194
        form.append($('<input>').attr({
195
        type: 'hidden',
196
        name: 'authtypecode',
197
        value: $("#authtypecode").val()
198
        }));
199
200
201
    // Get all form datas for the current heading field
202
        $('.tag[id^=tag_' + tag + '_]').eq(index).find(':input').each(function(){
203
        form.append($('<input>').attr({
204
            type: 'hidden',
205
            name: this.name,
206
            value: $(this).val()
207
        }));
208
        });
209
210
        // We need to add the temporary form to the body so we can submit it
211
        $('body').append(form);
212
        form.submit();
213
        form.remove();
214
    }
215
216
    return false;
217
    });
218
}
219
220
/**
221
 * Updates the authid for every heading field
222
 * Adds visual feedback for the changes made on the form.
223
 */
224
function updateHeadingLinks(links) {
225
    var current_tag = '';
226
    var tag_index = 0;
227
228
    // Delete the old message dialog and create a new one
229
    $('#autolinker_dialog').remove();
230
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
231
    var message_dialog_ul = message_dialog.find('ul');
232
233
    $.each(links, function(index, heading) {
234
        if(current_tag == heading.tag) {
235
            tag_index++;
236
        }
237
        else {
238
            current_tag = heading.tag;
239
            tag_index = 0;
240
        }
241
242
        // Find the $9 field to update
243
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
244
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
245
246
        // Delete the old status if one exists
247
        tag_subfield_line.children('.subfield_status').remove();
248
        subfield.css({backgroundColor:''});
249
250
        // If the field wasn't modified. Skip it.
251
        if(heading.status == 'UNCHANGED') {
252
            return;
253
        }
254
255
256
        // Make the subfield line visible and update its value
257
        tag_subfield_line.show();
258
        subfield.val(heading.authid);
259
260
        // Add the new status
261
        var image = 'deny.gif';
262
        var message = '';
263
        var field_color = '#FFAAAA';
264
        switch(heading.status) {
265
            case 'LOCAL_FOUND':
266
                image = 'approve.gif';
267
                message = _("A matching authority was found in the local database.");
268
                field_color = '#99FF99';
269
                break;
270
            case 'CREATED':
271
                image = 'approve.gif';
272
                message = _("No matching authority found. A new authority was created automatically.");
273
                field_color = '#99FF99';
274
                break;
275
            case 'MULTIPLE_MATCH':
276
                message = _("More than one local match found. Possibly a duplicate authority!");
277
                break;
278
            case 'NONE_FOUND':
279
                message = _("No matching authority found.");
280
                break;
281
            default:
282
                message = heading.status;
283
                break;
284
        }
285
286
        subfield.css({backgroundColor:field_color});
287
        tag_subfield_line.append('<img class="subfield_status" src="[% interface %]/[% theme %]/img/' + image + '" title="' + message + '" />');
288
289
        // Add the message to the dialog
290
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
291
292
        // Add a link to create a new authority if none was found
293
        if(heading.status == 'NONE_FOUND') {
294
            addCreateAuthorityButton(tag_subfield_line, heading.tag, tag_index);
295
        }
296
    });
297
298
    if(message_dialog.find('li').length == 0) {
299
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
300
    }
301
    $('#addbibliotabs').before(message_dialog);
302
}
303
304
/**
305
 * Use an ajax request to automatically find authority links for the current record
306
 */
307
function AutomaticLinker() {
308
    // Show the Loading overlay
309
    $("#loading").show();
310
311
    // Remove fields that are completely empty
312
    $('#f').find('.tag').each(function() {
313
        var empty = true;
314
        $(this).find('.input_marceditor').each(function() {
315
            if($(this).val() != '') {
316
                empty = false;
317
                return false;
318
            }
319
        });
320
        if(empty) {
321
            UnCloneField($(this).attr('id'));
322
        }
323
    });
324
325
    // Get all the form values to post via AJAX
326
    var form_data = {};
327
    $('#f').find(':input').each(function(){
328
        form_data[this.name] = $(this).val();
329
    });
330
    delete form_data[''];
331
332
    // Send the data to automatic_linker.pl
333
    $.ajax({
334
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
335
        type:'post',
336
        data: form_data,
337
        dataType: 'json',
338
        error: function(xhr) {
339
            alert("Error : \n" + xhr.responseText);
340
        },
341
        success: function(json) {
342
            switch(json.status) {
343
                case 'UNAUTHORIZED':
344
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
345
                    break;
346
                case 'OK':
347
                    updateHeadingLinks(json.links);
348
                    break;
349
            }
350
        },
351
        complete: function() {
352
            $("#loading").hide();
353
        }
354
    });
355
}
356
357
166
function PopupMARCFieldDoc(field) {
358
function PopupMARCFieldDoc(field) {
167
    [% IF Koha.Preference('marcfielddocurl') %]
359
    [% IF Koha.Preference('marcfielddocurl') %]
168
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
360
        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>
675
        <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 %]
676
    [% END %]
485
677
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">
678
    <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>
679
        <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">
680
        <ul id="settings-menu" class="dropdown-menu">
Lines 527-532 function Changefwk() { Link Here
527
        </ul>
715
        </ul>
528
    </div>
716
    </div>
529
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
717
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
718
        <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>
719
        <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>
720
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
721
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
722
        [% END %]
530
        [% IF (biblionumber) %]
723
        [% IF (biblionumber) %]
531
            [% IF ( BiblioDefaultViewmarc ) %]
724
            [% IF ( BiblioDefaultViewmarc ) %]
532
                <div class="btn-group">
725
                <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 -%]" />
873
                    <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 %]
874
                    [% END %]
682
                    [% IF ( mv.authtype ) %]
875
                    [% 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>
876
                    <input type="hidden" name="authtypecode" id="authtypecode" value="[% mv.authtype %]" />
877
                    <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 %]
878
                    [% END %]
685
                [% ELSIF ( mv.type == 'text_complex' ) %]
879
                [% 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 -%]" />
880
                    <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/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/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