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

(-)a/C4/Biblio.pm (-6 / +130 lines)
Lines 511-517 sub BiblioAutoLink { Link Here
511
511
512
=head2 LinkBibHeadingsToAuthorities
512
=head2 LinkBibHeadingsToAuthorities
513
513
514
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
514
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
515
515
516
Links bib headings to authority records by checking
516
Links bib headings to authority records by checking
517
each authority-controlled field in the C<MARC::Record>
517
each authority-controlled field in the C<MARC::Record>
Lines 533-538 sub LinkBibHeadingsToAuthorities { Link Here
533
    my $bib           = shift;
533
    my $bib           = shift;
534
    my $frameworkcode = shift;
534
    my $frameworkcode = shift;
535
    my $allowrelink = shift;
535
    my $allowrelink = shift;
536
    my $verbose = shift;
536
    my %results;
537
    my %results;
537
    if (!$bib) {
538
    if (!$bib) {
538
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
539
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 553-576 sub LinkBibHeadingsToAuthorities { Link Here
553
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
554
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
554
        {
555
        {
555
            $results{'linked'}->{ $heading->display_form() }++;
556
            $results{'linked'}->{ $heading->display_form() }++;
557
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
556
            next;
558
            next;
557
        }
559
        }
558
560
559
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
561
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
560
        if ($authid) {
562
        if ($authid) {
561
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
563
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
562
              ->{ $heading->display_form() }++;
564
              ->{ $heading->display_form() }++;
563
            next if defined $current_link and $current_link == $authid;
565
            if(defined $current_link and $current_link == $authid) {
566
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
567
                next;
568
            }
564
569
565
            $field->delete_subfield( code => '9' ) if defined $current_link;
570
            $field->delete_subfield( code => '9' ) if defined $current_link;
566
            $field->add_subfields( '9', $authid );
571
            $field->add_subfields( '9', $authid );
567
            $num_headings_changed++;
572
            $num_headings_changed++;
573
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
568
        }
574
        }
569
        else {
575
        else {
570
            if ( defined $current_link
576
            if ( defined $current_link
571
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
577
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
572
            {
578
            {
573
                $results{'fuzzy'}->{ $heading->display_form() }++;
579
                $results{'fuzzy'}->{ $heading->display_form() }++;
580
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
574
            }
581
            }
575
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
582
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
576
                if ( _check_valid_auth_link( $current_link, $field ) ) {
583
                if ( _check_valid_auth_link( $current_link, $field ) ) {
Lines 624-651 sub LinkBibHeadingsToAuthorities { Link Here
624
                    }
631
                    }
625
632
626
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
633
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
634
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
627
635
628
                    $authid =
629
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
630
                        $heading->auth_type() );
631
                    $field->add_subfields( '9', $authid );
636
                    $field->add_subfields( '9', $authid );
632
                    $num_headings_changed++;
637
                    $num_headings_changed++;
633
                    $linker->update_cache($heading, $authid);
638
                    $linker->update_cache($heading, $authid);
634
                    $results{'added'}->{ $heading->display_form() }++;
639
                    $results{'added'}->{ $heading->display_form() }++;
640
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
635
                }
641
                }
636
            }
642
            }
637
            elsif ( defined $current_link ) {
643
            elsif ( defined $current_link ) {
638
                if ( _check_valid_auth_link( $current_link, $field ) ) {
644
                if ( _check_valid_auth_link( $current_link, $field ) ) {
639
                    $results{'linked'}->{ $heading->display_form() }++;
645
                    $results{'linked'}->{ $heading->display_form() }++;
646
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
640
                }
647
                }
641
                else {
648
                else {
642
                    $field->delete_subfield( code => '9' );
649
                    $field->delete_subfield( code => '9' );
643
                    $num_headings_changed++;
650
                    $num_headings_changed++;
644
                    $results{'unlinked'}->{ $heading->display_form() }++;
651
                    $results{'unlinked'}->{ $heading->display_form() }++;
652
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
645
                }
653
                }
646
            }
654
            }
647
            else {
655
            else {
648
                $results{'unlinked'}->{ $heading->display_form() }++;
656
                $results{'unlinked'}->{ $heading->display_form() }++;
657
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
649
            }
658
            }
650
        }
659
        }
651
660
Lines 677-682 sub _check_valid_auth_link { Link Here
677
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
686
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
678
}
687
}
679
688
689
=head2 AddAuthorityFromHeading
690
691
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
692
693
Creates a new authority from an heading and its associated field.
694
695
Returns the id of the newly created authority.
696
697
=cut
698
699
sub AddAuthorityFromHeading {
700
    my $heading = shift;
701
    my $field = shift;
702
    my $bib = shift;
703
704
    if(!defined $heading || !defined $field || !defined $bib){
705
       return 0;
706
    }
707
    my $authtypedata =
708
      C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() );
709
    my $marcrecordauth = MARC::Record->new();
710
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
711
        $marcrecordauth->leader('     nz  a22     o  4500');
712
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
713
    }
714
    my $authfield =
715
      MARC::Field->new( $authtypedata->{auth_tag_to_report},
716
        '', '', "a" => "" . $field->subfield('a') );
717
    map {
718
        $authfield->add_subfields( $_->[0] => $_->[1] )
719
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
720
    } $field->subfields();
721
    $marcrecordauth->insert_fields_ordered($authfield);
722
723
# bug 2317: ensure new authority knows it's using UTF-8; currently
724
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
725
# automatically for UNIMARC (by not transcoding)
726
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
727
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
728
# of change to a core API just before the 3.0 release.
729
730
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
731
        $marcrecordauth->insert_fields_ordered(
732
            MARC::Field->new(
733
                '667', '', '',
734
                'a' => "Machine generated authority record."
735
            )
736
        );
737
        if(defined $bib) {
738
            my $cite =
739
                $bib->author() . ", "
740
              . $bib->title_proper() . ", "
741
              . $bib->publication_date() . " ";
742
            $cite =~ s/^[\s\,]*//;
743
            $cite =~ s/[\s\,]*$//;
744
            $cite =
745
                "Work cat.: ("
746
              . C4::Context->preference('MARCOrgCode') . ")"
747
              . $bib->subfield( '999', 'c' ) . ": "
748
              . $cite;
749
            $marcrecordauth->insert_fields_ordered(
750
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
751
        }
752
753
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
754
        my $date=POSIX::strftime("%y%m%d",localtime);
755
        my @heading_use = qw(b b b);
756
        my $thesaurus = '|';
757
758
        if ($heading->{'subject_added_entry'}) {
759
            $heading_use[1] = 'a';
760
            # Thesaurus treatment
761
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
762
            $thesaurus = 'z';
763
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
764
            if($thesaurus eq 'z')
765
            {
766
                $marcrecordauth->insert_fields_ordered(
767
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
768
                );
769
            }
770
        }
771
        if ($heading->{'series_added_entry'}) {
772
            $heading_use[2] = 'a';
773
        }
774
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
775
            $heading_use[0] = 'a';
776
        }
777
778
        # Get a valid default value for field 008
779
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
780
        if(!$default_008 or length($default_008)<34) {
781
            $default_008 = '|| aca||aabn           | a|a     d';
782
        }
783
        else {
784
            $default_008 = substr($default_008,0,34)
785
        }
786
787
        # Insert the date, thesaurus and heading_use into field 008
788
        my $f008 = $date . $default_008;
789
        substr($f008, 11, 1) = $thesaurus;
790
        substr($f008, 14, 3) = join('', @heading_use);
791
792
        $marcrecordauth->insert_fields_ordered(
793
            MARC::Field->new('008',$f008)
794
        );
795
    }
796
797
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
798
799
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
800
    return $authid;
801
}
802
803
680
=head2 GetRecordValue
804
=head2 GetRecordValue
681
805
682
  my $values = GetRecordValue($field, $record, $frameworkcode);
806
  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 565-570 my $myindex = $input->param('index'); Link Here
565
my $linkid=$input->param('linkid');
565
my $linkid=$input->param('linkid');
566
my $authtypecode = $input->param('authtypecode');
566
my $authtypecode = $input->param('authtypecode');
567
my $breedingid    = $input->param('breedingid');
567
my $breedingid    = $input->param('breedingid');
568
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new autority infos to the parent biblio
569
570
if($biblioindex and !$authid){
571
    require C4::Heading;
572
573
    my $record = TransformHtmlToMarc( $input );
574
575
    # Get the first heading found in the biblio informations
576
    foreach my $field ( $record->fields() ) {
577
        my $heading = C4::Heading->new_from_bib_field($field);
578
        next unless defined $heading;
579
580
        # Create a new authority using the heading informations
581
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
582
    }
583
}
568
584
569
my $dbh = C4::Context->dbh;
585
my $dbh = C4::Context->dbh;
570
if(!$authtypecode) {
586
if(!$authtypecode) {
Lines 579-585 my ($template, $loggedinuser, $cookie) Link Here
579
                            flagsrequired => {editauthorities => 1},
595
                            flagsrequired => {editauthorities => 1},
580
                            debug => 1,
596
                            debug => 1,
581
                            });
597
                            });
582
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
598
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
583
599
584
$tagslib = GetTagsLabels(1,$authtypecode);
600
$tagslib = GetTagsLabels(1,$authtypecode);
585
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
601
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 624-630 if ($op eq "add") { Link Here
624
        } else {
640
        } else {
625
            ($authid) = AddAuthority($record,$authid,$authtypecode);
641
            ($authid) = AddAuthority($record,$authid,$authtypecode);
626
        }
642
        }
627
        if ($myindex) {
643
        if ($biblioindex) {
644
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
645
        } elsif ($myindex) {
628
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
646
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
629
        } else {
647
        } else {
630
            print $input->redirect("detail.pl?authid=$authid");
648
            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/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 (+198 lines)
Lines 76-81 Link Here
76
            [% END %]
76
            [% END %]
77
        });
77
        });
78
78
79
        $("#linkerbutton").click(function(){
80
            AutomaticLinker();
81
        });
82
79
        $("#saverecord").click(function(){
83
        $("#saverecord").click(function(){
80
            $(".btn-group").removeClass("open");
84
            $(".btn-group").removeClass("open");
81
            onOption();
85
            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 516-521 function Changefwk() { Link Here
516
        </ul>
708
        </ul>
517
    </div>
709
    </div>
518
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
710
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
711
        <div class="btn-group"><a class="btn btn-small" href="#" id="linkerbutton"><i class="icon-ok"></i> Link authorities automatically</a></div>
712
        <div class="btn-group"><a class="btn btn-small" href="#" id="z3950search"><i class="icon-search"></i> Z39.50/SRU search</a></div>
713
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
714
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
715
        [% END %]
519
        [% IF (biblionumber) %]
716
        [% IF (biblionumber) %]
520
            [% IF ( BiblioDefaultViewmarc ) %]
717
            [% IF ( BiblioDefaultViewmarc ) %]
521
                <div class="btn-group">
718
                <div class="btn-group">
Lines 662-667 function Changefwk() { Link Here
662
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
859
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
663
                    [% END %]
860
                    [% END %]
664
                    [% IF ( mv.authtype ) %]
861
                    [% IF ( mv.authtype ) %]
862
                    <input type="hidden" name="authtypecode" id="authtypecode" value="[% mv.authtype %]" />
665
                    <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>
863
                    <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>
666
                    [% END %]
864
                    [% END %]
667
                [% ELSIF ( mv.type == 'text_complex' ) %]
865
                [% ELSIF ( mv.type == 'text_complex' ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/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/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