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

(-)a/C4/AuthoritiesMarc.pm (+64 lines)
Lines 47-52 BEGIN { Link Here
47
    	&GetAuthMARCFromKohaField 
47
    	&GetAuthMARCFromKohaField 
48
48
49
    	&AddAuthority
49
    	&AddAuthority
50
        &AddAuthorityFromHeading
50
    	&ModAuthority
51
    	&ModAuthority
51
    	&DelAuthority
52
    	&DelAuthority
52
    	&GetAuthority
53
    	&GetAuthority
Lines 1570-1575 sub get_auth_type_location { Link Here
1570
    }
1571
    }
1571
}
1572
}
1572
1573
1574
=head2 AddAuthorityFromHeading
1575
1576
  my $authid = AddAuthorityFromHeading($marcrecordauth, $heading);
1577
1578
Creates a new authority from an heading and its associated field.
1579
1580
Returns the id of the newly created authority.
1581
1582
=cut
1583
1584
sub AddAuthorityFromHeading {
1585
    my $marcrecordauth = shift;
1586
    my $heading = shift;
1587
1588
    if(!defined $heading || !defined $marcrecordauth){
1589
       return 0;
1590
    }
1591
    # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
1592
    my $date=POSIX::strftime("%y%m%d",localtime);
1593
    my @heading_use = qw(b b b);
1594
    my $thesaurus = '|';
1595
1596
    if ($heading->{'subject_added_entry'}) {
1597
        $heading_use[1] = 'a';
1598
        # Thesaurus treatment
1599
        my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
1600
        $thesaurus = 'z';
1601
        $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
1602
        if($thesaurus eq 'z')
1603
        {
1604
            $marcrecordauth->insert_fields_ordered(
1605
                    MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
1606
            );
1607
        }
1608
    }
1609
    if (not $heading->{'subject_added_entry'} ) {
1610
        $heading_use[0] = 'a';
1611
    }
1612
1613
    # Get a valid default value for field 008
1614
    my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
1615
    if(!$default_008 or length($default_008)<34) {
1616
        $default_008 = '|| aca||aabn           | a|a     d';
1617
    }
1618
    else {
1619
        $default_008 = substr($default_008,0,34)
1620
    }
1621
1622
    # Insert the date, thesaurus and heading_use into field 008
1623
    my $f008 = $date . $default_008;
1624
    substr($f008, 11, 1) = $thesaurus;
1625
    substr($f008, 14, 3) = join('', @heading_use);
1626
1627
    $marcrecordauth->insert_fields_ordered(
1628
        MARC::Field->new('008',$f008)
1629
    );
1630
1631
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
1632
    return $authid;
1633
}
1634
1635
1636
1573
END { }       # module clean-up code here (global destructor)
1637
END { }       # module clean-up code here (global destructor)
1574
1638
1575
1;
1639
1;
(-)a/C4/Biblio.pm (-3 / +15 lines)
Lines 460-466 sub BiblioAutoLink { Link Here
460
460
461
=head2 LinkBibHeadingsToAuthorities
461
=head2 LinkBibHeadingsToAuthorities
462
462
463
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
463
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
464
464
465
Links bib headings to authority records by checking
465
Links bib headings to authority records by checking
466
each authority-controlled field in the C<MARC::Record>
466
each authority-controlled field in the C<MARC::Record>
Lines 482-487 sub LinkBibHeadingsToAuthorities { Link Here
482
    my $bib           = shift;
482
    my $bib           = shift;
483
    my $frameworkcode = shift;
483
    my $frameworkcode = shift;
484
    my $allowrelink = shift;
484
    my $allowrelink = shift;
485
    my $verbose = shift;
485
    my %results;
486
    my %results;
486
    if (!$bib) {
487
    if (!$bib) {
487
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
488
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 489-495 sub LinkBibHeadingsToAuthorities { Link Here
489
    }
490
    }
490
    require C4::Heading;
491
    require C4::Heading;
491
    require C4::AuthoritiesMarc;
492
    require C4::AuthoritiesMarc;
492
493
    $allowrelink = 1 unless defined $allowrelink;
493
    $allowrelink = 1 unless defined $allowrelink;
494
    my $num_headings_changed = 0;
494
    my $num_headings_changed = 0;
495
    foreach my $field ( $bib->fields() ) {
495
    foreach my $field ( $bib->fields() ) {
Lines 502-507 sub LinkBibHeadingsToAuthorities { Link Here
502
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
502
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
503
        {
503
        {
504
            $results{'linked'}->{ $heading->display_form() }++;
504
            $results{'linked'}->{ $heading->display_form() }++;
505
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
505
            next;
506
            next;
506
        }
507
        }
507
508
Lines 509-525 sub LinkBibHeadingsToAuthorities { Link Here
509
        if ($authid) {
510
        if ($authid) {
510
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
511
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
511
              ->{ $heading->display_form() }++;
512
              ->{ $heading->display_form() }++;
512
            next if defined $current_link and $current_link == $authid;
513
            if(defined $current_link and $current_link == $authid) {
514
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
515
                next;
516
            }
513
517
514
            $field->delete_subfield( code => '9' ) if defined $current_link;
518
            $field->delete_subfield( code => '9' ) if defined $current_link;
515
            $field->add_subfields( '9', $authid );
519
            $field->add_subfields( '9', $authid );
516
            $num_headings_changed++;
520
            $num_headings_changed++;
521
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'LOCAL_FOUND'}) if $verbose;
517
        }
522
        }
518
        else {
523
        else {
524
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
519
            if ( defined $current_link
525
            if ( defined $current_link
520
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
526
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
521
            {
527
            {
522
                $results{'fuzzy'}->{ $heading->display_form() }++;
528
                $results{'fuzzy'}->{ $heading->display_form() }++;
529
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
523
            }
530
            }
524
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
531
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
525
                if ( _check_valid_auth_link( $current_link, $field ) ) {
532
                if ( _check_valid_auth_link( $current_link, $field ) ) {
Lines 595-618 sub LinkBibHeadingsToAuthorities { Link Here
595
                    $num_headings_changed++;
602
                    $num_headings_changed++;
596
                    $linker->update_cache($heading, $authid);
603
                    $linker->update_cache($heading, $authid);
597
                    $results{'added'}->{ $heading->display_form() }++;
604
                    $results{'added'}->{ $heading->display_form() }++;
605
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
598
                }
606
                }
599
            }
607
            }
600
            elsif ( defined $current_link ) {
608
            elsif ( defined $current_link ) {
601
                if ( _check_valid_auth_link( $current_link, $field ) ) {
609
                if ( _check_valid_auth_link( $current_link, $field ) ) {
602
                    $results{'linked'}->{ $heading->display_form() }++;
610
                    $results{'linked'}->{ $heading->display_form() }++;
611
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
603
                }
612
                }
604
                else {
613
                else {
605
                    $field->delete_subfield( code => '9' );
614
                    $field->delete_subfield( code => '9' );
606
                    $num_headings_changed++;
615
                    $num_headings_changed++;
607
                    $results{'unlinked'}->{ $heading->display_form() }++;
616
                    $results{'unlinked'}->{ $heading->display_form() }++;
617
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
608
                }
618
                }
609
            }
619
            }
610
            else {
620
            else {
611
                $results{'unlinked'}->{ $heading->display_form() }++;
621
                $results{'unlinked'}->{ $heading->display_form() }++;
622
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
612
            }
623
            }
613
        }
624
        }
614
625
615
    }
626
    }
627
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
616
    return $num_headings_changed, \%results;
628
    return $num_headings_changed, \%results;
617
}
629
}
618
630
(-)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/authorities/authorities.pl (-1 / +5 lines)
Lines 33-38 use MARC::File::XML; Link Here
33
use C4::Biblio;
33
use C4::Biblio;
34
use Koha::Authority::Types;
34
use Koha::Authority::Types;
35
use Koha::ItemTypes;
35
use Koha::ItemTypes;
36
use C4::Heading;
36
use vars qw( $tagslib);
37
use vars qw( $tagslib);
37
use vars qw( $authorised_values_sth);
38
use vars qw( $authorised_values_sth);
38
use vars qw( $is_a_modif );
39
use vars qw( $is_a_modif );
Lines 287-292 sub create_input { Link Here
287
288
288
        }
289
        }
289
    }
290
    }
291
    if ($cgi->param('tagreport') && $subfield_data{tag} == $cgi->param('tagreport')) {
292
        $subfield_data{marc_value}{value} = $cgi->param('tag'. $cgi->param('tagbiblio') . 'subfield' . $subfield_data{subfield});
293
    }
290
    $subfield_data{'index_subfield'} = $index_subfield;
294
    $subfield_data{'index_subfield'} = $index_subfield;
291
    return \%subfield_data;
295
    return \%subfield_data;
292
}
296
}
Lines 575-581 my ($template, $loggedinuser, $cookie) Link Here
575
                            flagsrequired => {editauthorities => 1},
579
                            flagsrequired => {editauthorities => 1},
576
                            debug => 1,
580
                            debug => 1,
577
                            });
581
                            });
578
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
582
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid);
579
583
580
$tagslib = GetTagsLabels(1,$authtypecode);
584
$tagslib = GetTagsLabels(1,$authtypecode);
581
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
585
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
(-)a/cataloguing/automatic_linker.pl (+75 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Frédérick Capovilla, 2011 - Libéo
4
# Bouzid Fergani, 2020   - inLibro
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 3 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
use Modern::Perl;
22
use CGI;
23
use CGI::Cookie;
24
use JSON;
25
use C4::Auth;
26
use C4::Biblio;
27
use C4::Context;
28
29
my $input = new CGI;
30
print $input->header('application/json');
31
32
# Check the user's permissions
33
my %cookies = CGI::Cookie->fetch;
34
my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
35
my ( $auth_status, $auth_sessid ) =
36
  C4::Auth::check_cookie_auth( $sessid, { editauthorities => 1, editcatalogue => 1 } );
37
if ( $auth_status ne "ok" ) {
38
    print to_json( { status => 'UNAUTHORIZED' } );
39
    exit 0;
40
}
41
42
# Link the biblio headings to authorities and return a json containing the status of all the links.
43
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
44
#
45
# tag = the tag number of the field
46
# authid = the value of the $9 subfield for this tag
47
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
48
49
my $json;
50
51
my $record = TransformHtmlToMarc($input,1);
52
53
my $linker_module =
54
  "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' );
55
eval { eval "require $linker_module"; };
56
if ($@) {
57
    $linker_module = 'C4::Linker::Default';
58
    eval "require $linker_module";
59
}
60
if ($@) {
61
    return 0, 0;
62
}
63
my $linker = $linker_module->new(
64
    { 'options' => C4::Context->preference("LinkerOptions") } );
65
66
my ( $headings_changed, $results ) = LinkBibHeadingsToAuthorities(
67
    $linker, $record,
68
    $input->param('frameworkcode'),
69
    C4::Context->preference("CatalogModuleRelink") || '', 1
70
);
71
72
$json->{status} = 'OK';
73
$json->{links} = $results->{details} || '';
74
75
print to_json($json);
(-)a/cataloguing/z3950_auth_search.pl (+3 lines)
Lines 42-47 my $subjectsubdiv = $input->param('subjectsubdiv'); Link Here
42
my $srchany       = $input->param('srchany');
42
my $srchany       = $input->param('srchany');
43
my $op            = $input->param('op')||'';
43
my $op            = $input->param('op')||'';
44
my $page            = $input->param('current_page') || 1;
44
my $page            = $input->param('current_page') || 1;
45
my $index =$input->param('index');
45
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
my $controlnumber    = $input->param('controlnumber');
47
my $controlnumber    = $input->param('controlnumber');
47
48
Lines 65-70 $template->param( Link Here
65
    srchany      => $srchany,
66
    srchany      => $srchany,
66
    authid => $authid,
67
    authid => $authid,
67
    controlnumber => $controlnumber,
68
    controlnumber => $controlnumber,
69
    index => $index,
68
);
70
);
69
71
70
if ( $op ne "do_search" ) {
72
if ( $op ne "do_search" ) {
Lines 74-79 if ( $op ne "do_search" ) { Link Here
74
    $template->param(
76
    $template->param(
75
        serverloop   => $serverloop,
77
        serverloop   => $serverloop,
76
        opsearch     => "search",
78
        opsearch     => "search",
79
        index        => $index,
77
    );
80
    );
78
    output_html_with_http_headers $input, $cookie, $template->output;
81
    output_html_with_http_headers $input, $cookie, $template->output;
79
    exit;
82
    exit;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-3 / +4 lines)
Lines 28-35 Link Here
28
		});
28
		});
29
        $("#z3950submit").click(function(){
29
        $("#z3950submit").click(function(){
30
            var strQuery = GetZ3950Terms();
30
            var strQuery = GetZ3950Terms();
31
            var index = "&index=[% index | html %]";
31
            if(strQuery){
32
            if(strQuery){
32
                window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
33
                window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery+index,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
33
            }
34
            }
34
            return false;
35
            return false;
35
        });
36
        });
Lines 207-215 function confirmnotdup(redirect){ Link Here
207
    <input type="hidden" name="op" value="add" />
208
    <input type="hidden" name="op" value="add" />
208
    <input type="hidden" name="addfield_field" value="" />
209
    <input type="hidden" name="addfield_field" value="" />
209
    <input type="hidden" name="repeat_field" value="" />
210
    <input type="hidden" name="repeat_field" value="" />
210
    <input type="hidden" name="authtypecode" value="[% authtypecode | html %]" />
211
    <input type="hidden" name="authtypecode" value="[% authtypecode  | html%]" />
211
    <input type="hidden" name="authid" value="[% authid | html %]" />
212
    <input type="hidden" name="authid" value="[% authid | html %]" />
212
    <input type="hidden" name="index" value="[% index | html %]" />
213
    <input type="hidden" name="index" value="[% index | html  %]" />
213
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
214
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
214
215
215
    <div id="toolbar" class="btn-toolbar">
216
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (-2 / +10 lines)
Lines 44-54 Link Here
44
            var whichfield;
44
            var whichfield;
45
            try {
45
            try {
46
                whichfield = opener.opener.document.getElementById(index_start);
46
                whichfield = opener.opener.document.getElementById(index_start);
47
                autolinker_dialog = opener.opener.document.getElementById("autolinker_dialog");
47
            } catch(e) {
48
            } catch(e) {
48
                return;
49
                whichfield = opener.document.getElementById(index_start);
50
                autolinker_dialog = opener.document.getElementById("autolinker_dialog");
49
            }
51
            }
50
            var field_start = whichfield.parentNode.parentNode.parentNode;
52
            var field_start = whichfield.parentNode.parentNode.parentNode;
51
52
            // Sets the good number of form fields for the specified subfield
53
            // Sets the good number of form fields for the specified subfield
53
            // Returns false if the cloning failed
54
            // Returns false if the cloning failed
54
            function SetSubfieldNumber(subfield_name, nb) {
55
            function SetSubfieldNumber(subfield_name, nb) {
Lines 138-143 Link Here
138
                [% ELSE %]
139
                [% ELSE %]
139
                    if(code.value=='9'){
140
                    if(code.value=='9'){
140
                        subfield.value = "[% To.json(authid) | $raw %]";
141
                        subfield.value = "[% To.json(authid) | $raw %]";
142
                        subfield.style.backgroundColor = "#99FF99";
143
141
                        break;
144
                        break;
142
                    }
145
                    }
143
                [% END %]
146
                [% END %]
Lines 145-150 Link Here
145
            }
148
            }
146
            [% END %]
149
            [% END %]
147
150
151
            //Delete create authority button and status
152
            var linkinfos = field_start.getElementsByTagName('i');
153
            for (index = linkinfos.length - 1; index >= 0; index--) {
154
                linkinfos[index].parentNode.removeChild(linkinfos[index]);
155
            }
148
            opener.close();
156
            opener.close();
149
            window.close();
157
            window.close();
150
            return false;
158
            return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-1 / +241 lines)
Lines 87-92 Link Here
87
            PopupZ3950();
87
            PopupZ3950();
88
        });
88
        });
89
89
90
        $("#linkerbutton").click(function(){
91
            AutomaticLinker();
92
        });
93
90
        $("#saverecord").click(function(){
94
        $("#saverecord").click(function(){
91
            $(".btn-group").removeClass("open");
95
            $(".btn-group").removeClass("open");
92
            onOption();
96
            onOption();
Lines 173-180 Link Here
173
        var onOption = function () {
177
        var onOption = function () {
174
            return Check();
178
            return Check();
175
        }
179
        }
176
    [% END %]
180
[% END %]
181
182
function confirmnotdup(redirect){
183
    $("#confirm_not_duplicate").attr("value","1");
184
    $("#redirect").attr("value",redirect);
185
    Check();
186
}
187
188
function Dopop(link,i) {
189
    defaultvalue = document.getElementById(i).value;
190
    window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
191
}
192
193
/**
194
 * this function open a popup to search on z3950 server.
195
 */
196
function PopupZ3950() {
197
    var strQuery = GetZ3950Terms();
198
    if(strQuery){
199
        window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
200
    }
201
}
202
203
/**
204
* this function append button for create new authority if not found
205
*/
206
207
function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
208
    var title = _("Create authority");
209
    var elem = $('<a href="#" title="' + title + '"><i class="fa fa-plus-circle"></i></a>');
210
    tag_subfield_line.append(elem);
211
    var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
212
    var subfield_a = tag_subfield_line_a.children('.input_marceditor').eq(0);
213
    var index = subfield_a.attr('id');
214
    elem.click(function() {
215
        var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
216
        if(popup !== null) {
217
            // Create a new form that will be POSTed in the new window
218
            var form = $('<form>').attr({
219
            method: 'post',
220
            action: "../authorities/authorities.pl",
221
            target: "new_auth_popup"
222
            });
223
            //add the authtypecode
224
            form.append($('<input>').attr({
225
                type: 'hidden',
226
                name: 'authtypecode',
227
                value: heading.auth_type
228
            }));
229
            form.append($('<input>').attr({
230
                type: 'hidden',
231
                name: 'tagreport',
232
                value: heading.tag_to_report
233
            }));
234
            form.append($('<input>').attr({
235
                type: 'hidden',
236
                name: 'tagbiblio',
237
                value: heading.tag
238
            }));
239
            form.append($('<input>').attr({
240
                type: 'hidden',
241
                name: 'index',
242
                value: index
243
            }));
244
            $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
245
                form.append($('<input>').attr({
246
                    type: 'hidden',
247
                    name: this.name.split('_',4).join(''),
248
                    value: $(this).val()
249
                }));
250
            });
251
252
            $('body').append(form);
253
            form.submit();
254
            form.remove();
255
        }
256
        return false;
257
    });
258
259
}
260
261
/**
262
 * Updates the authid for every heading field
263
 * Adds visual feedback for the changes made on the form.
264
 */
265
function updateHeadingLinks(links) {
266
    var current_tag = '';
267
    var tag_index = 0;
268
269
    // Delete the old message dialog and create a new one
270
    $('#autolinker_dialog').remove();
271
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
272
    var message_dialog_ul = message_dialog.find('ul');
273
274
    $.each(links, function(index, heading) {
275
        if(current_tag == heading.tag) {
276
            tag_index++;
277
        }
278
        else {
279
            current_tag = heading.tag;
280
            tag_index = 0;
281
        }
282
283
        // Find the $9 field to update
284
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
285
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
286
287
        // Delete the old status if one exists
288
        tag_subfield_line.children('.subfield_status').remove();
289
        subfield.css({backgroundColor:''});
290
291
        // If the field wasn't modified. Skip it.
292
        if(heading.status == 'UNCHANGED') {
293
            return;
294
        }
295
296
297
        // Make the subfield line visible and update its value
298
        tag_subfield_line.show();
299
        subfield.val(heading.authid);
300
301
        // Add the new status
302
        var image = '<i class="fa fa-close" style="color: #FFAAAA"></i> ';
303
        var message = '';
304
        var field_color = '#FFAAAA';
305
        switch(heading.status) {
306
            case 'LOCAL_FOUND':
307
                image = '<i class="fa fa-check" style="color: #99FF99"></i> ';
308
                message = _("A matching authority was found in the local database.");
309
                field_color = '#99FF99';
310
                break;
311
            case 'CREATED':
312
                image = '<i class="fa fa-check" style="color: #99FF99"></i> ';
313
                message = _("No matching authority found. A new authority was created automatically.");
314
                field_color = '#99FF99';
315
                break;
316
            case 'MULTIPLE_MATCH':
317
                message = _("More than one local match found. Possibly a duplicate authority!");
318
                break;
319
            case 'NONE_FOUND':
320
                message = _("No matching authority found.");
321
                break;
322
            default:
323
                message = heading.status;
324
                break;
325
        }
177
326
327
        subfield.css({backgroundColor:field_color});
328
        tag_subfield_line.find('i').each(function() {
329
            this.remove();
330
        });
331
        tag_subfield_line.append(image);
332
333
        // Add the message to the dialog
334
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
335
336
        // Add a link to create a new authority if none was found
337
        if(heading.status == 'NONE_FOUND' && tag_subfield_line.find('i').length == 1) {
338
            addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
339
        }
340
    });
341
342
    if(message_dialog.find('li').length == 0) {
343
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
344
    }
345
    $('#addbibliotabs').before(message_dialog);
346
}
347
348
/**
349
 * Use an ajax request to automatically find authority links for the current record
350
 */
351
function AutomaticLinker() {
352
    // Show the Loading overlay
353
    $("#loading").show();
354
355
    // Remove fields that are completely empty
356
    $('#f').find('.tag').each(function() {
357
        var empty = true;
358
        $(this).find('.input_marceditor').each(function() {
359
            if($(this).val() != '') {
360
                empty = false;
361
                return false;
362
            }
363
        });
364
        if(empty) {
365
            UnCloneField($(this).attr('id'));
366
        }
367
    });
368
369
    // Get all the form values to post via AJAX
370
    var form_data = {};
371
    $('#f').find(':input').each(function(){
372
        form_data[this.name] = $(this).val();
373
    });
374
    delete form_data[''];
375
376
    // Send the data to automatic_linker.pl
377
    $.ajax({
378
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
379
        type:'post',
380
        data: form_data,
381
        dataType: 'json',
382
        error: function(xhr) {
383
            alert("Error : \n" + xhr.responseText);
384
        },
385
        success: function(json) {
386
            switch(json.status) {
387
                case 'UNAUTHORIZED':
388
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
389
                    break;
390
                case 'OK':
391
                    updateHeadingLinks(json.links);
392
                    break;
393
            }
394
        },
395
        complete: function() {
396
            $("#loading").hide();
397
        }
398
    });
399
}
400
401
402
function PopupMARCFieldDoc(field) {
403
    [% IF Koha.Preference('marcfielddocurl') %]
404
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
405
        docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
406
        docurl = docurl.replace("{FIELD}", ""+field);
407
        docurl = docurl.replace("{LANG}", "[% lang | html %]");
408
        window.open(docurl);
409
    [% ELSIF ( marcflavour == 'MARC21' ) %]
410
        _MARC21FieldDoc(field);
411
    [% ELSIF ( marcflavour == 'UNIMARC' ) %]
412
        _UNIMARCFieldDoc(field);
413
    [% END %]
414
}
178
    function confirmnotdup(redirect){
415
    function confirmnotdup(redirect){
179
        $("#confirm_not_duplicate").attr("value","1");
416
        $("#confirm_not_duplicate").attr("value","1");
180
        $("#redirect").attr("value",redirect);
417
        $("#redirect").attr("value",redirect);
Lines 585-590 Link Here
585
                        [% ELSE %]
822
                        [% ELSE %]
586
                            <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
823
                            <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
587
                        [% END %]
824
                        [% END %]
825
                        [% IF ( CAN_user_editauthorities ) %]
826
                            <div class="btn-group"><a class="btn btn-default" href="#" id="linkerbutton"><i class="fa fa-refresh"></i> Link authorities automatically</a></div>
827
                        [% END %]
588
                    [% END %]
828
                    [% END %]
589
829
590
                    <div class="btn-group">
830
                    <div class="btn-group">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt (-1 / +2 lines)
Lines 20-25 Link Here
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
21
        <input type="hidden" name="op" id="op" value="do_search" />
21
        <input type="hidden" name="op" id="op" value="do_search" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
23
        <input type="hidden" name="index" value="[% index | html %]" />
23
            <div class="row">
24
            <div class="row">
24
            <div class="col-xs-6">
25
            <div class="col-xs-6">
25
                <fieldset class="rows">
26
                <fieldset class="rows">
Lines 94-100 Link Here
94
                    </a>
95
                    </a>
95
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]"><i class="fa fa-download"></i> Import</a></li>
98
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]" data-index="[% index | html %]" ><i class="fa fa-download"></i> Import</a></li>
98
                    </ul>
99
                    </ul>
99
                </div>
100
                </div>
100
            </td>
101
            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (+6 lines)
Lines 137-142 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
137
            for( j = 0 ; j < inputs.length ; j++ ) {
137
            for( j = 0 ; j < inputs.length ; j++ ) {
138
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
138
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
139
                    inputs[j].value = "";
139
                    inputs[j].value = "";
140
141
                    //Remove the color added by the automatic linker
142
                    $(inputs[j]).css({backgroundColor:""});
140
                }
143
                }
141
            }
144
            }
142
            var textareas = divs[i].getElementsByTagName('textarea');
145
            var textareas = divs[i].getElementsByTagName('textarea');
Lines 146-151 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
146
                }
149
                }
147
            }
150
            }
148
151
152
            // Remove the status icons added by the automatic linker
153
            $(divs[i]).find('.subfield_status').remove();
154
149
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
155
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
150
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
156
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
151
157
(-)a/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js (-3 / +4 lines)
Lines 1-10 Link Here
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
2
function Import(Breeding, recordid, AuthType, FrameworkCode) {
2
function Import(Breeding, recordid, AuthType, FrameworkCode, index) {
3
3
4
    if ( AuthType == false ) {
4
    if ( AuthType == false ) {
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
6
    } else {
6
    } else {
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid;
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid+"&index="+index;
8
    }
8
    }
9
    window.close();
9
    window.close();
10
    return false;
10
    return false;
Lines 127-136 $( document ).ready( function() { Link Here
127
        var data_authid = $( this ).data( "authid" );
127
        var data_authid = $( this ).data( "authid" );
128
        var data_biblionumber = $( this ).data( "biblionumber" );
128
        var data_biblionumber = $( this ).data( "biblionumber" );
129
        var data_frameworkcode = $( this ).data( "frameworkcode" );
129
        var data_frameworkcode = $( this ).data( "frameworkcode" );
130
        var data_index = $( this ).data( "index" );
130
        if ( data_headingcode == undefined ) {
131
        if ( data_headingcode == undefined ) {
131
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
132
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
132
        } else {
133
        } else {
133
            Import( data_breedingid, data_authid, data_headingcode );
134
            Import( data_breedingid, data_authid, data_headingcode, "", data_index );
134
        }
135
        }
135
        return false;
136
        return false;
136
    });
137
    });
(-)a/t/Biblio.t (-1 / +2 lines)
Lines 158-160 warnings_like { $ret = UpdateTotalIssues() } Link Here
158
158
159
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
159
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
160
160
161
- 
161
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
162
1;

Return to bug 11299