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

(-)a/C4/Biblio.pm (-7 / +131 lines)
Lines 481-487 sub BiblioAutoLink { Link Here
481
481
482
=head2 LinkBibHeadingsToAuthorities
482
=head2 LinkBibHeadingsToAuthorities
483
483
484
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
484
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
485
485
486
Links bib headings to authority records by checking
486
Links bib headings to authority records by checking
487
each authority-controlled field in the C<MARC::Record>
487
each authority-controlled field in the C<MARC::Record>
Lines 503-508 sub LinkBibHeadingsToAuthorities { Link Here
503
    my $bib           = shift;
503
    my $bib           = shift;
504
    my $frameworkcode = shift;
504
    my $frameworkcode = shift;
505
    my $allowrelink = shift;
505
    my $allowrelink = shift;
506
    my $verbose = shift;
506
    my %results;
507
    my %results;
507
    if (!$bib) {
508
    if (!$bib) {
508
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
509
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 510-516 sub LinkBibHeadingsToAuthorities { Link Here
510
    }
511
    }
511
    require C4::Heading;
512
    require C4::Heading;
512
    require C4::AuthoritiesMarc;
513
    require C4::AuthoritiesMarc;
513
514
    $allowrelink = 1 unless defined $allowrelink;
514
    $allowrelink = 1 unless defined $allowrelink;
515
    my $num_headings_changed = 0;
515
    my $num_headings_changed = 0;
516
    foreach my $field ( $bib->fields() ) {
516
    foreach my $field ( $bib->fields() ) {
Lines 523-546 sub LinkBibHeadingsToAuthorities { Link Here
523
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
523
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
524
        {
524
        {
525
            $results{'linked'}->{ $heading->display_form() }++;
525
            $results{'linked'}->{ $heading->display_form() }++;
526
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
526
            next;
527
            next;
527
        }
528
        }
528
529
529
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
530
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
530
        if ($authid) {
531
        if ($authid) {
531
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
532
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
532
              ->{ $heading->display_form() }++;
533
              ->{ $heading->display_form() }++;
533
            next if defined $current_link and $current_link == $authid;
534
            if(defined $current_link and $current_link == $authid) {
535
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
536
                next;
537
            }
534
538
535
            $field->delete_subfield( code => '9' ) if defined $current_link;
539
            $field->delete_subfield( code => '9' ) if defined $current_link;
536
            $field->add_subfields( '9', $authid );
540
            $field->add_subfields( '9', $authid );
537
            $num_headings_changed++;
541
            $num_headings_changed++;
542
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
538
        }
543
        }
539
        else {
544
        else {
540
            if ( defined $current_link
545
            if ( defined $current_link
541
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
546
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
542
            {
547
            {
543
                $results{'fuzzy'}->{ $heading->display_form() }++;
548
                $results{'fuzzy'}->{ $heading->display_form() }++;
549
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
544
            }
550
            }
545
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
551
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
546
                if ( _check_valid_auth_link( $current_link, $field ) ) {
552
                if ( _check_valid_auth_link( $current_link, $field ) ) {
Lines 594-625 sub LinkBibHeadingsToAuthorities { Link Here
594
                    }
600
                    }
595
601
596
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
602
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
603
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
597
604
598
                    $authid =
599
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
600
                        $heading->auth_type() );
601
                    $field->add_subfields( '9', $authid );
605
                    $field->add_subfields( '9', $authid );
602
                    $num_headings_changed++;
606
                    $num_headings_changed++;
603
                    $linker->update_cache($heading, $authid);
607
                    $linker->update_cache($heading, $authid);
604
                    $results{'added'}->{ $heading->display_form() }++;
608
                    $results{'added'}->{ $heading->display_form() }++;
609
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
605
                }
610
                }
606
            }
611
            }
607
            elsif ( defined $current_link ) {
612
            elsif ( defined $current_link ) {
608
                if ( _check_valid_auth_link( $current_link, $field ) ) {
613
                if ( _check_valid_auth_link( $current_link, $field ) ) {
609
                    $results{'linked'}->{ $heading->display_form() }++;
614
                    $results{'linked'}->{ $heading->display_form() }++;
615
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
610
                }
616
                }
611
                else {
617
                else {
612
                    $field->delete_subfield( code => '9' );
618
                    $field->delete_subfield( code => '9' );
613
                    $num_headings_changed++;
619
                    $num_headings_changed++;
614
                    $results{'unlinked'}->{ $heading->display_form() }++;
620
                    $results{'unlinked'}->{ $heading->display_form() }++;
621
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
615
                }
622
                }
616
            }
623
            }
617
            else {
624
            else {
618
                $results{'unlinked'}->{ $heading->display_form() }++;
625
                $results{'unlinked'}->{ $heading->display_form() }++;
626
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
619
            }
627
            }
620
        }
628
        }
621
629
622
    }
630
    }
631
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
623
    return $num_headings_changed, \%results;
632
    return $num_headings_changed, \%results;
624
}
633
}
625
634
Lines 647-652 sub _check_valid_auth_link { Link Here
647
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
656
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
648
}
657
}
649
658
659
=head2 AddAuthorityFromHeading
660
661
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
662
663
Creates a new authority from an heading and its associated field.
664
665
Returns the id of the newly created authority.
666
667
=cut
668
669
sub AddAuthorityFromHeading {
670
    my $heading = shift;
671
    my $field = shift;
672
    my $bib = shift;
673
674
    if(!defined $heading || !defined $field || !defined $bib){
675
       return 0;
676
    }
677
    my $authtypedata =
678
      Koha::Authority::Types->find( $heading->auth_type() );
679
    my $marcrecordauth = MARC::Record->new();
680
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
681
        $marcrecordauth->leader('     nz  a22     o  4500');
682
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
683
    }
684
    my $authfield =
685
      MARC::Field->new( $authtypedata->auth_tag_to_report,
686
        '', '', "a" => "" . $field->subfield('a') );
687
    map {
688
        $authfield->add_subfields( $_->[0] => $_->[1] )
689
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
690
    } $field->subfields();
691
    $marcrecordauth->insert_fields_ordered($authfield);
692
693
# bug 2317: ensure new authority knows it's using UTF-8; currently
694
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
695
# automatically for UNIMARC (by not transcoding)
696
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
697
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
698
# of change to a core API just before the 3.0 release.
699
700
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
701
        $marcrecordauth->insert_fields_ordered(
702
            MARC::Field->new(
703
                '667', '', '',
704
                'a' => "Machine generated authority record."
705
            )
706
        );
707
        if(defined $bib) {
708
            my $cite =
709
                $bib->author() . ", "
710
              . $bib->title_proper() . ", "
711
              . $bib->publication_date() . " ";
712
            $cite =~ s/^[\s\,]*//;
713
            $cite =~ s/[\s\,]*$//;
714
            $cite =
715
                "Work cat.: ("
716
              . C4::Context->preference('MARCOrgCode') . ")"
717
              . $bib->subfield( '999', 'c' ) . ": "
718
              . $cite;
719
            $marcrecordauth->insert_fields_ordered(
720
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
721
        }
722
723
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
724
        my $date=POSIX::strftime("%y%m%d",localtime);
725
        my @heading_use = qw(b b b);
726
        my $thesaurus = '|';
727
728
        if ($heading->{'subject_added_entry'}) {
729
            $heading_use[1] = 'a';
730
            # Thesaurus treatment
731
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
732
            $thesaurus = 'z';
733
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
734
            if($thesaurus eq 'z')
735
            {
736
                $marcrecordauth->insert_fields_ordered(
737
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
738
                );
739
            }
740
        }
741
        if ($heading->{'series_added_entry'}) {
742
            $heading_use[2] = 'a';
743
        }
744
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
745
            $heading_use[0] = 'a';
746
        }
747
748
        # Get a valid default value for field 008
749
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
750
        if(!$default_008 or length($default_008)<34) {
751
            $default_008 = '|| aca||aabn           | a|a     d';
752
        }
753
        else {
754
            $default_008 = substr($default_008,0,34)
755
        }
756
757
        # Insert the date, thesaurus and heading_use into field 008
758
        my $f008 = $date . $default_008;
759
        substr($f008, 11, 1) = $thesaurus;
760
        substr($f008, 14, 3) = join('', @heading_use);
761
762
        $marcrecordauth->insert_fields_ordered(
763
            MARC::Field->new('008',$f008)
764
        );
765
    }
766
767
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
768
769
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
770
    return $authid;
771
}
772
773
650
=head2 GetRecordValue
774
=head2 GetRecordValue
651
775
652
  my $values = GetRecordValue($field, $record, $frameworkcode);
776
  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,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 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 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 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 472-481 function Changefwk() { Link Here
472
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
664
        <div class="btn-group"><a href="#" id="saveandview" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a></div>
473
    [% END %]
665
    [% END %]
474
666
475
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
476
        <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>
477
    [% END %]
478
479
    <div class="btn-group">
667
    <div class="btn-group">
480
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
668
        <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> Settings <span class="caret"></span></button>
481
        <ul id="settings-menu" class="dropdown-menu">
669
        <ul id="settings-menu" class="dropdown-menu">
Lines 516-521 function Changefwk() { Link Here
516
        </ul>
704
        </ul>
517
    </div>
705
    </div>
518
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
706
    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
707
        <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>
708
        <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>
709
        [% IF Koha.Preference( 'EnableAdvancedCatalogingEditor' ) == 1 %]
710
            <div class="btn-group"><a href="#" id="switcheditor" class="btn btn-small">Switch to advanced editor</a></div>
711
        [% END %]
519
        [% IF (biblionumber) %]
712
        [% IF (biblionumber) %]
520
            [% IF ( BiblioDefaultViewmarc ) %]
713
            [% IF ( BiblioDefaultViewmarc ) %]
521
                <div class="btn-group">
714
                <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 -%]" />
855
                    <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 %]
856
                    [% END %]
664
                    [% IF ( mv.authtype ) %]
857
                    [% IF ( mv.authtype ) %]
858
                    <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>
859
                    <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 %]
860
                    [% END %]
667
                [% ELSIF ( mv.type == 'text_complex' ) %]
861
                [% ELSIF ( mv.type == 'text_complex' ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (+6 lines)
Lines 128-133 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
128
            for( j = 0 ; j < inputs.length ; j++ ) {
128
            for( j = 0 ; j < inputs.length ; j++ ) {
129
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
129
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
130
                    inputs[j].value = "";
130
                    inputs[j].value = "";
131
132
                    //Remove the color added by the automatic linker
133
                    $(inputs[j]).css({backgroundColor:""});
131
                }
134
                }
132
            }
135
            }
133
            var textareas = divs[i].getElementsByTagName('textarea');
136
            var textareas = divs[i].getElementsByTagName('textarea');
Lines 137-142 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
137
                }
140
                }
138
            }
141
            }
139
142
143
            // Remove the status icons added by the automatic linker
144
            $(divs[i]).find('.subfield_status').remove();
145
140
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
146
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
141
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
147
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
142
            var id_input;
148
            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