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

(-)a/C4/Biblio.pm (-7 / +131 lines)
Lines 477-483 sub BiblioAutoLink { Link Here
477
477
478
=head2 LinkBibHeadingsToAuthorities
478
=head2 LinkBibHeadingsToAuthorities
479
479
480
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
480
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
481
481
482
Links bib headings to authority records by checking
482
Links bib headings to authority records by checking
483
each authority-controlled field in the C<MARC::Record>
483
each authority-controlled field in the C<MARC::Record>
Lines 499-504 sub LinkBibHeadingsToAuthorities { Link Here
499
    my $bib           = shift;
499
    my $bib           = shift;
500
    my $frameworkcode = shift;
500
    my $frameworkcode = shift;
501
    my $allowrelink = shift;
501
    my $allowrelink = shift;
502
    my $verbose = shift;
502
    my %results;
503
    my %results;
503
    if (!$bib) {
504
    if (!$bib) {
504
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
505
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 506-512 sub LinkBibHeadingsToAuthorities { Link Here
506
    }
507
    }
507
    require C4::Heading;
508
    require C4::Heading;
508
    require C4::AuthoritiesMarc;
509
    require C4::AuthoritiesMarc;
509
510
    $allowrelink = 1 unless defined $allowrelink;
510
    $allowrelink = 1 unless defined $allowrelink;
511
    my $num_headings_changed = 0;
511
    my $num_headings_changed = 0;
512
    foreach my $field ( $bib->fields() ) {
512
    foreach my $field ( $bib->fields() ) {
Lines 519-542 sub LinkBibHeadingsToAuthorities { Link Here
519
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
519
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
520
        {
520
        {
521
            $results{'linked'}->{ $heading->display_form() }++;
521
            $results{'linked'}->{ $heading->display_form() }++;
522
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
522
            next;
523
            next;
523
        }
524
        }
524
525
525
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
526
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
526
        if ($authid) {
527
        if ($authid) {
527
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
528
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
528
              ->{ $heading->display_form() }++;
529
              ->{ $heading->display_form() }++;
529
            next if defined $current_link and $current_link == $authid;
530
            if(defined $current_link and $current_link == $authid) {
531
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
532
                next;
533
            }
530
534
531
            $field->delete_subfield( code => '9' ) if defined $current_link;
535
            $field->delete_subfield( code => '9' ) if defined $current_link;
532
            $field->add_subfields( '9', $authid );
536
            $field->add_subfields( '9', $authid );
533
            $num_headings_changed++;
537
            $num_headings_changed++;
538
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
534
        }
539
        }
535
        else {
540
        else {
536
            if ( defined $current_link
541
            if ( defined $current_link
537
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
542
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
538
            {
543
            {
539
                $results{'fuzzy'}->{ $heading->display_form() }++;
544
                $results{'fuzzy'}->{ $heading->display_form() }++;
545
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
540
            }
546
            }
541
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
547
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
542
                if ( _check_valid_auth_link( $current_link, $field ) ) {
548
                if ( _check_valid_auth_link( $current_link, $field ) ) {
Lines 595-626 sub LinkBibHeadingsToAuthorities { Link Here
595
                    }
601
                    }
596
602
597
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
603
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
604
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
598
605
599
                    $authid =
600
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
601
                        $heading->auth_type() );
602
                    $field->add_subfields( '9', $authid );
606
                    $field->add_subfields( '9', $authid );
603
                    $num_headings_changed++;
607
                    $num_headings_changed++;
604
                    $linker->update_cache($heading, $authid);
608
                    $linker->update_cache($heading, $authid);
605
                    $results{'added'}->{ $heading->display_form() }++;
609
                    $results{'added'}->{ $heading->display_form() }++;
610
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
606
                }
611
                }
607
            }
612
            }
608
            elsif ( defined $current_link ) {
613
            elsif ( defined $current_link ) {
609
                if ( _check_valid_auth_link( $current_link, $field ) ) {
614
                if ( _check_valid_auth_link( $current_link, $field ) ) {
610
                    $results{'linked'}->{ $heading->display_form() }++;
615
                    $results{'linked'}->{ $heading->display_form() }++;
616
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
611
                }
617
                }
612
                else {
618
                else {
613
                    $field->delete_subfield( code => '9' );
619
                    $field->delete_subfield( code => '9' );
614
                    $num_headings_changed++;
620
                    $num_headings_changed++;
615
                    $results{'unlinked'}->{ $heading->display_form() }++;
621
                    $results{'unlinked'}->{ $heading->display_form() }++;
622
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
616
                }
623
                }
617
            }
624
            }
618
            else {
625
            else {
619
                $results{'unlinked'}->{ $heading->display_form() }++;
626
                $results{'unlinked'}->{ $heading->display_form() }++;
627
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
620
            }
628
            }
621
        }
629
        }
622
630
623
    }
631
    }
632
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
624
    return $num_headings_changed, \%results;
633
    return $num_headings_changed, \%results;
625
}
634
}
626
635
Lines 648-653 sub _check_valid_auth_link { Link Here
648
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
657
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
649
}
658
}
650
659
660
=head2 AddAuthorityFromHeading
661
662
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
663
664
Creates a new authority from an heading and its associated field.
665
666
Returns the id of the newly created authority.
667
668
=cut
669
670
sub AddAuthorityFromHeading {
671
    my $heading = shift;
672
    my $field = shift;
673
    my $bib = shift;
674
675
    if(!defined $heading || !defined $field || !defined $bib){
676
       return 0;
677
    }
678
    my $authtypedata =
679
      Koha::Authority::Types->find( $heading->auth_type() );
680
    my $marcrecordauth = MARC::Record->new();
681
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
682
        $marcrecordauth->leader('     nz  a22     o  4500');
683
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
684
    }
685
    my $authfield =
686
      MARC::Field->new( $authtypedata->auth_tag_to_report,
687
        '', '', "a" => "" . $field->subfield('a') );
688
    map {
689
        $authfield->add_subfields( $_->[0] => $_->[1] )
690
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
691
    } $field->subfields();
692
    $marcrecordauth->insert_fields_ordered($authfield);
693
694
# bug 2317: ensure new authority knows it's using UTF-8; currently
695
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
696
# automatically for UNIMARC (by not transcoding)
697
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
698
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
699
# of change to a core API just before the 3.0 release.
700
701
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
702
        $marcrecordauth->insert_fields_ordered(
703
            MARC::Field->new(
704
                '667', '', '',
705
                'a' => "Machine generated authority record."
706
            )
707
        );
708
        if(defined $bib) {
709
            my $cite =
710
                $bib->author() . ", "
711
              . $bib->title_proper() . ", "
712
              . $bib->publication_date() . " ";
713
            $cite =~ s/^[\s\,]*//;
714
            $cite =~ s/[\s\,]*$//;
715
            $cite =
716
                "Work cat.: ("
717
              . C4::Context->preference('MARCOrgCode') . ")"
718
              . $bib->subfield( '999', 'c' ) . ": "
719
              . $cite;
720
            $marcrecordauth->insert_fields_ordered(
721
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
722
        }
723
724
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
725
        my $date=POSIX::strftime("%y%m%d",localtime);
726
        my @heading_use = qw(b b b);
727
        my $thesaurus = '|';
728
729
        if ($heading->{'subject_added_entry'}) {
730
            $heading_use[1] = 'a';
731
            # Thesaurus treatment
732
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
733
            $thesaurus = 'z';
734
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
735
            if($thesaurus eq 'z')
736
            {
737
                $marcrecordauth->insert_fields_ordered(
738
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
739
                );
740
            }
741
        }
742
        if ($heading->{'series_added_entry'}) {
743
            $heading_use[2] = 'a';
744
        }
745
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
746
            $heading_use[0] = 'a';
747
        }
748
749
        # Get a valid default value for field 008
750
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
751
        if(!$default_008 or length($default_008)<34) {
752
            $default_008 = '|| aca||aabn           | a|a     d';
753
        }
754
        else {
755
            $default_008 = substr($default_008,0,34)
756
        }
757
758
        # Insert the date, thesaurus and heading_use into field 008
759
        my $f008 = $date . $default_008;
760
        substr($f008, 11, 1) = $thesaurus;
761
        substr($f008, 14, 3) = join('', @heading_use);
762
763
        $marcrecordauth->insert_fields_ordered(
764
            MARC::Field->new('008',$f008)
765
        );
766
    }
767
768
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
769
770
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
771
    return $authid;
772
}
773
774
651
=head2 GetRecordValue
775
=head2 GetRecordValue
652
776
653
  my $values = GetRecordValue($field, $record, $frameworkcode);
777
  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 lines)
Lines 209-214 function confirmnotdup(redirect){ Link Here
209
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
209
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
210
    <input type="hidden" name="authid" value="[% authid %]" />
210
    <input type="hidden" name="authid" value="[% authid %]" />
211
    <input type="hidden" name="index" value="[% index %]" />
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 (-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 100-112 Link Here
100
            [% ELSE %]
110
            [% ELSE %]
101
                if(code.value=='9'){
111
                if(code.value=='9'){
102
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
112
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
103
                    break;
113
                    // Clean the field if it was modified by the automatic linker
114
                    $(subfield).siblings('.subfield_status').remove();
115
                    $(subfield).css({backgroundColor:''});
104
                }
116
                }
105
            [% END %]
117
            [% END %]
106
            }
118
            }
107
        }
119
        }
108
120
109
      	opener.close();
121
        // Close all parent windows, but not the basewindow
122
        while(parents_to_close.length != 0) {
123
            parents_to_close.shift().close();
124
        }
125
110
       	window.close();
126
       	window.close();
111
            
127
            
112
       	return false;
128
       	return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-4 / +198 lines)
Lines 82-87 Link Here
82
            [% END %]
82
            [% END %]
83
        });
83
        });
84
84
85
        $("#linkerbutton").click(function(){
86
            AutomaticLinker();
87
        });
88
85
        $("#saverecord").click(function(){
89
        $("#saverecord").click(function(){
86
            $(".btn-group").removeClass("open");
90
            $(".btn-group").removeClass("open");
87
            onOption();
91
            onOption();
Lines 164-169 function PopupZ3950() { Link Here
164
    } 
168
    } 
165
}
169
}
166
170
171
function addCreateAuthorityButton(tag_subfield_line, tag, index) {
172
    var title = _("Create authority");
173
    var elem = $('<a class="subfield_status" href="#"><img src="[% interface %]/[% theme %]/img/edit-tag.png" title="' + title + '" /></a>');
174
    tag_subfield_line.append(elem);
175
176
    elem.click(function() {
177
        var biblioindex = $(this).parents('.subfield_line').find('input').eq(1).attr('id');
178
        var popup = window.open("", "new_auth_popup",'width=700,height=550,toolbar=false,scrollbars=yes');
179
180
    if(popup !== null) {
181
        // Create a new form that will be POSTed in the new window
182
        var form = $('<form>').attr({
183
        method: 'post',
184
        action: "../authorities/authorities.pl",
185
        target: "new_auth_popup"
186
        });
187
188
        // Add the biblioindex
189
        form.append($('<input>').attr({
190
        type: 'hidden',
191
        name: 'biblioindex',
192
        value: biblioindex
193
        }));
194
        //add the authtypecode
195
        form.append($('<input>').attr({
196
        type: 'hidden',
197
        name: 'authtypecode',
198
        value: $("#authtypecode").val()
199
        }));
200
201
202
    // Get all form datas for the current heading field
203
        $('.tag[id^=tag_' + tag + '_]').eq(index).find(':input').each(function(){
204
        form.append($('<input>').attr({
205
            type: 'hidden',
206
            name: this.name,
207
            value: $(this).val()
208
        }));
209
        });
210
211
        // We need to add the temporary form to the body so we can submit it
212
        $('body').append(form);
213
        form.submit();
214
        form.remove();
215
    }
216
217
    return false;
218
    });
219
}
220
221
/**
222
 * Updates the authid for every heading field
223
 * Adds visual feedback for the changes made on the form.
224
 */
225
function updateHeadingLinks(links) {
226
    var current_tag = '';
227
    var tag_index = 0;
228
229
    // Delete the old message dialog and create a new one
230
    $('#autolinker_dialog').remove();
231
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
232
    var message_dialog_ul = message_dialog.find('ul');
233
234
    $.each(links, function(index, heading) {
235
        if(current_tag == heading.tag) {
236
            tag_index++;
237
        }
238
        else {
239
            current_tag = heading.tag;
240
            tag_index = 0;
241
        }
242
243
        // Find the $9 field to update
244
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
245
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
246
247
        // Delete the old status if one exists
248
        tag_subfield_line.children('.subfield_status').remove();
249
        subfield.css({backgroundColor:''});
250
251
        // If the field wasn't modified. Skip it.
252
        if(heading.status == 'UNCHANGED') {
253
            return;
254
        }
255
256
257
        // Make the subfield line visible and update its value
258
        tag_subfield_line.show();
259
        subfield.val(heading.authid);
260
261
        // Add the new status
262
        var image = 'deny.gif';
263
        var message = '';
264
        var field_color = '#FFAAAA';
265
        switch(heading.status) {
266
            case 'LOCAL_FOUND':
267
                image = 'approve.gif';
268
                message = _("A matching authority was found in the local database.");
269
                field_color = '#99FF99';
270
                break;
271
            case 'CREATED':
272
                image = 'approve.gif';
273
                message = _("No matching authority found. A new authority was created automatically.");
274
                field_color = '#99FF99';
275
                break;
276
            case 'MULTIPLE_MATCH':
277
                message = _("More than one local match found. Possibly a duplicate authority!");
278
                break;
279
            case 'NONE_FOUND':
280
                message = _("No matching authority found.");
281
                break;
282
            default:
283
                message = heading.status;
284
                break;
285
        }
286
287
        subfield.css({backgroundColor:field_color});
288
        tag_subfield_line.append('<img class="subfield_status" src="[% interface %]/[% theme %]/img/' + image + '" title="' + message + '" />');
289
290
        // Add the message to the dialog
291
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
292
293
        // Add a link to create a new authority if none was found
294
        if(heading.status == 'NONE_FOUND') {
295
            addCreateAuthorityButton(tag_subfield_line, heading.tag, tag_index);
296
        }
297
    });
298
299
    if(message_dialog.find('li').length == 0) {
300
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
301
    }
302
    $('#addbibliotabs').before(message_dialog);
303
}
304
305
/**
306
 * Use an ajax request to automatically find authority links for the current record
307
 */
308
function AutomaticLinker() {
309
    // Show the Loading overlay
310
    $("#loading").show();
311
312
    // Remove fields that are completely empty
313
    $('#f').find('.tag').each(function() {
314
        var empty = true;
315
        $(this).find('.input_marceditor').each(function() {
316
            if($(this).val() != '') {
317
                empty = false;
318
                return false;
319
            }
320
        });
321
        if(empty) {
322
            UnCloneField($(this).attr('id'));
323
        }
324
    });
325
326
    // Get all the form values to post via AJAX
327
    var form_data = {};
328
    $('#f').find(':input').each(function(){
329
        form_data[this.name] = $(this).val();
330
    });
331
    delete form_data[''];
332
333
    // Send the data to automatic_linker.pl
334
    $.ajax({
335
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
336
        type:'post',
337
        data: form_data,
338
        dataType: 'json',
339
        error: function(xhr) {
340
            alert("Error : \n" + xhr.responseText);
341
        },
342
        success: function(json) {
343
            switch(json.status) {
344
                case 'UNAUTHORIZED':
345
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
346
                    break;
347
                case 'OK':
348
                    updateHeadingLinks(json.links);
349
                    break;
350
            }
351
        },
352
        complete: function() {
353
            $("#loading").hide();
354
        }
355
    });
356
}
357
358
167
function PopupMARCFieldDoc(field) {
359
function PopupMARCFieldDoc(field) {
168
    [% IF ( marcflavour == 'MARC21' ) %]
360
    [% IF ( marcflavour == 'MARC21' ) %]
169
        _MARC21FieldDoc(field);
361
        _MARC21FieldDoc(field);
Lines 478-487 function Changefwk() { Link Here
478
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
670
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
479
    [% END %]
671
    [% END %]
480
672
481
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
482
        <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>
483
    [% END %]
484
485
    <div class="btn-group">
673
    <div class="btn-group">
486
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
674
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
487
        <ul id="settings-menu" class="dropdown-menu">
675
        <ul id="settings-menu" class="dropdown-menu">
Lines 522-527 function Changefwk() { Link Here
522
        </ul>
710
        </ul>
523
    </div>
711
    </div>
524
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
712
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
713
        <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>
714
        <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>
715
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
716
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
717
        [% END %]
525
        [% IF (biblionumber) %]
718
        [% IF (biblionumber) %]
526
            [% IF ( BiblioDefaultViewmarc ) %]
719
            [% IF ( BiblioDefaultViewmarc ) %]
527
                <div class="btn-group">
720
                <div class="btn-group">
Lines 675-680 function Changefwk() { Link Here
675
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
868
                    <input type="text" id="[%- mv.id -%]" name="[%- mv.name -%]" value="[%- mv.value -%]" class="input_marceditor" tabindex="1" size="[%- mv.size -%]" maxlength="[%- mv.maxlength -%]" />
676
                    [% END %]
869
                    [% END %]
677
                    [% IF ( mv.authtype ) %]
870
                    [% IF ( mv.authtype ) %]
871
                    <input type="hidden" name="authtypecode" id="authtypecode" value="[% mv.authtype %]" />
678
                    <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>
872
                    <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>
679
                    [% END %]
873
                    [% END %]
680
                [% ELSIF ( mv.type == 'text_complex' ) %]
874
                [% ELSIF ( mv.type == 'text_complex' ) %]
(-)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 197-199 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
- 
200
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
201
1;

Return to bug 11299