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

(-)a/C4/Biblio.pm (-54 / +127 lines)
Lines 507-513 sub BiblioAutoLink { Link Here
507
507
508
=head2 LinkBibHeadingsToAuthorities
508
=head2 LinkBibHeadingsToAuthorities
509
509
510
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
510
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
511
511
512
Links bib headings to authority records by checking
512
Links bib headings to authority records by checking
513
each authority-controlled field in the C<MARC::Record>
513
each authority-controlled field in the C<MARC::Record>
Lines 529-534 sub LinkBibHeadingsToAuthorities { Link Here
529
    my $bib           = shift;
529
    my $bib           = shift;
530
    my $frameworkcode = shift;
530
    my $frameworkcode = shift;
531
    my $allowrelink = shift;
531
    my $allowrelink = shift;
532
    my $verbose = shift;
532
    my %results;
533
    my %results;
533
    if (!$bib) {
534
    if (!$bib) {
534
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
535
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 549-648 sub LinkBibHeadingsToAuthorities { Link Here
549
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
550
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
550
        {
551
        {
551
            $results{'linked'}->{ $heading->display_form() }++;
552
            $results{'linked'}->{ $heading->display_form() }++;
553
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
552
            next;
554
            next;
553
        }
555
        }
554
556
555
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
557
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
556
        if ($authid) {
558
        if ($authid) {
557
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
559
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
558
              ->{ $heading->display_form() }++;
560
              ->{ $heading->display_form() }++;
559
            next if defined $current_link and $current_link == $authid;
561
            if(defined $current_link and $current_link == $authid) {
562
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
563
                next;
564
            }
560
565
561
            $field->delete_subfield( code => '9' ) if defined $current_link;
566
            $field->delete_subfield( code => '9' ) if defined $current_link;
562
            $field->add_subfields( '9', $authid );
567
            $field->add_subfields( '9', $authid );
563
            $num_headings_changed++;
568
            $num_headings_changed++;
569
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
564
        }
570
        }
565
        else {
571
        else {
566
            if ( defined $current_link
572
            if ( defined $current_link
567
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
573
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
568
            {
574
            {
569
                $results{'fuzzy'}->{ $heading->display_form() }++;
575
                $results{'fuzzy'}->{ $heading->display_form() }++;
576
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
570
            }
577
            }
571
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
578
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
572
                if ( _check_valid_auth_link( $current_link, $field ) ) {
579
                if ( _check_valid_auth_link( $current_link, $field ) ) {
573
                    $results{'linked'}->{ $heading->display_form() }++;
580
                    $results{'linked'}->{ $heading->display_form() }++;
574
                }
581
                }
575
                else {
582
                else {
576
                    my $authtypedata =
583
                    $authid = AddAuthorityFromHeading($heading, $field, $bib);
577
                      C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() );
578
                    my $marcrecordauth = MARC::Record->new();
579
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
580
                        $marcrecordauth->leader('     nz  a22     o  4500');
581
                        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
582
                    }
583
                    $field->delete_subfield( code => '9' )
584
                      if defined $current_link;
585
                    my $authfield =
586
                      MARC::Field->new( $authtypedata->{auth_tag_to_report},
587
                        '', '', "a" => "" . $field->subfield('a') );
588
                    map {
589
                        $authfield->add_subfields( $_->[0] => $_->[1] )
590
                          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
591
                    } $field->subfields();
592
                    $marcrecordauth->insert_fields_ordered($authfield);
593
594
# bug 2317: ensure new authority knows it's using UTF-8; currently
595
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
596
# automatically for UNIMARC (by not transcoding)
597
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
598
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
599
# of change to a core API just before the 3.0 release.
600
601
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
602
                        $marcrecordauth->insert_fields_ordered(
603
                            MARC::Field->new(
604
                                '667', '', '',
605
                                'a' => "Machine generated authority record."
606
                            )
607
                        );
608
                        my $cite =
609
                            $bib->author() . ", "
610
                          . $bib->title_proper() . ", "
611
                          . $bib->publication_date() . " ";
612
                        $cite =~ s/^[\s\,]*//;
613
                        $cite =~ s/[\s\,]*$//;
614
                        $cite =
615
                            "Work cat.: ("
616
                          . C4::Context->preference('MARCOrgCode') . ")"
617
                          . $bib->subfield( '999', 'c' ) . ": "
618
                          . $cite;
619
                        $marcrecordauth->insert_fields_ordered(
620
                            MARC::Field->new( '670', '', '', 'a' => $cite ) );
621
                    }
622
623
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
624
584
625
                    $authid =
626
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
627
                        $heading->auth_type() );
628
                    $field->add_subfields( '9', $authid );
585
                    $field->add_subfields( '9', $authid );
629
                    $num_headings_changed++;
586
                    $num_headings_changed++;
630
                    $linker->update_cache($heading, $authid);
587
                    $linker->update_cache($heading, $authid);
631
                    $results{'added'}->{ $heading->display_form() }++;
588
                    $results{'added'}->{ $heading->display_form() }++;
589
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
632
                }
590
                }
633
            }
591
            }
634
            elsif ( defined $current_link ) {
592
            elsif ( defined $current_link ) {
635
                if ( _check_valid_auth_link( $current_link, $field ) ) {
593
                if ( _check_valid_auth_link( $current_link, $field ) ) {
636
                    $results{'linked'}->{ $heading->display_form() }++;
594
                    $results{'linked'}->{ $heading->display_form() }++;
595
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
637
                }
596
                }
638
                else {
597
                else {
639
                    $field->delete_subfield( code => '9' );
598
                    $field->delete_subfield( code => '9' );
640
                    $num_headings_changed++;
599
                    $num_headings_changed++;
641
                    $results{'unlinked'}->{ $heading->display_form() }++;
600
                    $results{'unlinked'}->{ $heading->display_form() }++;
601
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
642
                }
602
                }
643
            }
603
            }
644
            else {
604
            else {
645
                $results{'unlinked'}->{ $heading->display_form() }++;
605
                $results{'unlinked'}->{ $heading->display_form() }++;
606
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND'}) if $verbose;
646
            }
607
            }
647
        }
608
        }
648
609
Lines 674-679 sub _check_valid_auth_link { Link Here
674
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
635
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
675
}
636
}
676
637
638
=head2 AddAuthorityFromHeading
639
640
  my $authid = AddAuthorityFromHeading($heading, $field, [$bib]);
641
642
Creates a new authority from an heading and its associated field.
643
644
Returns the id of the newly created authority.
645
646
=cut
647
648
sub AddAuthorityFromHeading {
649
    my $heading = shift;
650
    my $field = shift;
651
    my $bib = shift;
652
653
    my $authtypedata =
654
      C4::AuthoritiesMarc::GetAuthType( $heading->auth_type() );
655
    my $marcrecordauth = MARC::Record->new();
656
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
657
        $marcrecordauth->leader('     nz  a22     o  4500');
658
        SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' );
659
    }
660
    my $authfield =
661
      MARC::Field->new( $authtypedata->{auth_tag_to_report},
662
        '', '', "a" => "" . $field->subfield('a') );
663
    map {
664
        $authfield->add_subfields( $_->[0] => $_->[1] )
665
          if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" )
666
    } $field->subfields();
667
    $marcrecordauth->insert_fields_ordered($authfield);
668
669
# bug 2317: ensure new authority knows it's using UTF-8; currently
670
# only need to do this for MARC21, as MARC::Record->as_xml_record() handles
671
# automatically for UNIMARC (by not transcoding)
672
# FIXME: AddAuthority() instead should simply explicitly require that the MARC::Record
673
# use UTF-8, but as of 2008-08-05, did not want to introduce that kind
674
# of change to a core API just before the 3.0 release.
675
676
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
677
        $marcrecordauth->insert_fields_ordered(
678
            MARC::Field->new(
679
                '667', '', '',
680
                'a' => "Machine generated authority record."
681
            )
682
        );
683
        if(defined $bib) {
684
            my $cite =
685
                $bib->author() . ", "
686
              . $bib->title_proper() . ", "
687
              . $bib->publication_date() . " ";
688
            $cite =~ s/^[\s\,]*//;
689
            $cite =~ s/[\s\,]*$//;
690
            $cite =
691
                "Work cat.: ("
692
              . C4::Context->preference('MARCOrgCode') . ")"
693
              . $bib->subfield( '999', 'c' ) . ": "
694
              . $cite;
695
            $marcrecordauth->insert_fields_ordered(
696
                MARC::Field->new( '670', '', '', 'a' => $cite ) );
697
        }
698
699
        # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
700
        my $date=POSIX::strftime("%y%m%d",localtime);
701
        my @heading_use = qw(b b b);
702
        my $thesaurus = '|';
703
704
        if ($heading->{'subject_added_entry'}) {
705
            $heading_use[1] = 'a';
706
            # Thesaurus treatment
707
            my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
708
            $thesaurus = 'z';
709
            $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
710
            if($thesaurus eq 'z')
711
            {
712
                $marcrecordauth->insert_fields_ordered(
713
                        MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
714
                );
715
            }
716
        }
717
        if ($heading->{'series_added_entry'}) {
718
            $heading_use[2] = 'a';
719
        }
720
        if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
721
            $heading_use[0] = 'a';
722
        }
723
724
        # Get a valid default value for field 008
725
        my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
726
        if(!$default_008 or length($default_008)<34) {
727
            $default_008 = '|| aca||aabn           | a|a     d';
728
        }
729
        else {
730
            $default_008 = substr($default_008,0,34)
731
        }
732
733
        # Insert the date, thesaurus and heading_use into field 008
734
        my $f008 = $date . $default_008;
735
        substr($f008, 11, 1) = $thesaurus;
736
        substr($f008, 14, 3) = join('', @heading_use);
737
738
        $marcrecordauth->insert_fields_ordered(
739
            MARC::Field->new('008',$f008)
740
        );
741
    }
742
743
#          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
744
745
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
746
    return $authid;
747
}
748
749
677
=head2 GetRecordValue
750
=head2 GetRecordValue
678
751
679
  my $values = GetRecordValue($field, $record, $frameworkcode);
752
  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/authorities/authorities.pl (-2 / +20 lines)
Lines 545-550 my $myindex = $input->param('index'); Link Here
545
my $linkid=$input->param('linkid');
545
my $linkid=$input->param('linkid');
546
my $authtypecode = $input->param('authtypecode');
546
my $authtypecode = $input->param('authtypecode');
547
my $breedingid    = $input->param('breedingid');
547
my $breedingid    = $input->param('breedingid');
548
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new autority infos to the parent biblio
549
550
if($biblioindex and !$authid){
551
    require C4::Heading;
552
553
    my $record = TransformHtmlToMarc( $input );
554
555
    # Get the first heading found in the biblio informations
556
    foreach my $field ( $record->fields() ) {
557
        my $heading = C4::Heading->new_from_bib_field($field);
558
        next unless defined $heading;
559
560
        # Create a new authority using the heading informations
561
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
562
    }
563
}
548
564
549
my $dbh = C4::Context->dbh;
565
my $dbh = C4::Context->dbh;
550
if(!$authtypecode) {
566
if(!$authtypecode) {
Lines 559-565 my ($template, $loggedinuser, $cookie) Link Here
559
                            flagsrequired => {editauthorities => 1},
575
                            flagsrequired => {editauthorities => 1},
560
                            debug => 1,
576
                            debug => 1,
561
                            });
577
                            });
562
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
578
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
563
579
564
$tagslib = GetTagsLabels(1,$authtypecode);
580
$tagslib = GetTagsLabels(1,$authtypecode);
565
my $record=-1;
581
my $record=-1;
Lines 602-608 if ($op eq "add") { Link Here
602
        } else {
618
        } else {
603
            ($authid) = AddAuthority($record,$authid,$authtypecode);
619
            ($authid) = AddAuthority($record,$authid,$authtypecode);
604
        }
620
        }
605
        if ($myindex) {
621
        if ($biblioindex) {
622
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
623
        } elsif ($myindex) {
606
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
624
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
607
        } else {
625
        } else {
608
            print $input->redirect("detail.pl?authid=$authid");
626
            print $input->redirect("detail.pl?authid=$authid");
(-)a/cataloguing/automatic_linker.pl (+70 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 2 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 strict;
21
use warnings;
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 = fetch CGI::Cookie;
34
my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
35
my ($auth_status, $auth_sessid) = C4::Auth::check_cookie_auth($sessid, {"catalogue"});
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 @params = $input->param();
51
my $record = TransformHtmlToMarc( $input );
52
53
54
my $linker_module = "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( { 'options' => C4::Context->preference("LinkerOptions") } );
64
65
my ( $headings_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $record, $params['frameworkcode'], C4::Context->preference("CatalogModuleRelink") || '', 1 );
66
67
$json->{status} = 'OK';
68
$json->{links} = $results->{details} || '';
69
70
print to_json($json);
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js (+6 lines)
Lines 107-115 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
107
            for( j = 0 ; j < inputs.length ; j++ ) {
107
            for( j = 0 ; j < inputs.length ; j++ ) {
108
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
108
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
109
                    inputs[j].value = "";
109
                    inputs[j].value = "";
110
111
                    //Remove the color added by the automatic linker
112
                    $(inputs[j]).css({backgroundColor:""});
110
                }
113
                }
111
            }
114
            }
112
115
116
            // Remove the status icons added by the automatic linker
117
            $(divs[i]).find('.subfield_status').remove();
118
113
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
119
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
114
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
120
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
115
            var id_input;
121
            var id_input;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (+3 lines)
Lines 173-178 function confirmnotdup(redirect){ Link Here
173
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
173
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
174
    <input type="hidden" name="authid" value="[% authid %]" />
174
    <input type="hidden" name="authid" value="[% authid %]" />
175
    <input type="hidden" name="index" value="[% index %]" />
175
    <input type="hidden" name="index" value="[% index %]" />
176
    [% IF ( biblioindex ) %]
177
    <input type="hidden" name="biblioindex" value="[% biblioindex %]" />
178
    [% END %]
176
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
179
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
177
180
178
    <div id="toolbar" class="btn-toolbar">
181
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (-4 / +20 lines)
Lines 5-13 Link Here
5
//<![CDATA[
5
//<![CDATA[
6
    $(document).ready(function(){
6
    $(document).ready(function(){
7
        var index_start = "[% index %]";
7
        var index_start = "[% index %]";
8
        var whichfield;
8
        var whichfield = null;
9
10
        // Loop through opener windows and try to find the basewindow and the form field we need to fill
11
        var basewindow = window;
12
        var parents_to_close = [];
9
        try {
13
        try {
10
            whichfield = opener.opener.document.getElementById(index_start);
14
            while(whichfield === null) {
15
                basewindow = basewindow.opener;
16
                whichfield = basewindow.document.getElementById(index_start);
17
                if(whichfield === null) {
18
                    parents_to_close.unshift(basewindow);
19
                }
20
            }
11
        } catch(e) {
21
        } catch(e) {
12
            return;
22
            return;
13
        }
23
        }
Lines 99-111 Link Here
99
            [% ELSE %]
109
            [% ELSE %]
100
                if(code.value=='9'){
110
                if(code.value=='9'){
101
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
111
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
102
                    break;
112
                    // Clean the field if it was modified by the automatic linker
113
                    $(subfield).siblings('.subfield_status').remove();
114
                    $(subfield).css({backgroundColor:''});
103
                }
115
                }
104
            [% END %]
116
            [% END %]
105
            }
117
            }
106
        }
118
        }
107
119
108
      	opener.close();
120
        // Close all parent windows, but not the basewindow
121
        while(parents_to_close.length != 0) {
122
            parents_to_close.shift().close();
123
        }
124
109
       	window.close();
125
       	window.close();
110
            
126
            
111
       	return false;
127
       	return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-1 / +185 lines)
Lines 75-80 Link Here
75
            }
75
            }
76
        });
76
        });
77
77
78
        $("#linkerbutton").click(function(){
79
            AutomaticLinker();
80
        });
81
78
        $("#saverecord").click(function(){
82
        $("#saverecord").click(function(){
79
            $(".btn-group").removeClass("open");
83
            $(".btn-group").removeClass("open");
80
            onOption();
84
            onOption();
Lines 134-139 function PopupZ3950() { Link Here
134
    } 
138
    } 
135
}
139
}
136
140
141
function addCreateAuthorityButton(tag_subfield_line, tag, index) {
142
	var title = _("Create authority");
143
	var elem = $('<a class="subfield_status" href="#"><img src="/intranet-tmpl/[% theme %]/img/edit-tag.png" title="' + title + '" /></a>');
144
	tag_subfield_line.append(elem);
145
146
	elem.click(function() {
147
        var biblioindex = $(this).parents('.subfield_line').find('input').eq(1).attr('id');
148
		var popup = window.open("", "new_auth_popup",'width=700,height=550,toolbar=false,scrollbars=yes');
149
150
		if(popup !== null) {
151
			// Create a new form that will be POSTed in the new window
152
			var form = $('<form>').attr({
153
				method: 'post',
154
				action: "../authorities/authorities.pl",
155
				target: "new_auth_popup"
156
			});
157
158
			// Add the biblioindex
159
			form.append($('<input>').attr({
160
				type: 'hidden',
161
				name: 'biblioindex',
162
				value: biblioindex
163
			}));
164
165
			// Get all form datas for the current heading field
166
			$('.tag[id^=tag_' + tag + '_]').eq(index).find(':input').each(function(){
167
				form.append($('<input>').attr({
168
					type: 'hidden',
169
					name: this.name,
170
					value: $(this).val()
171
				}));
172
			});
173
174
			// We need to add the temporary form to the body so we can submit it
175
			$('body').append(form);
176
			form.submit();
177
			form.remove();
178
		}
179
180
		return false;
181
	});
182
}
183
184
/**
185
 * Updates the authid for every heading field
186
 * Adds visual feedback for the changes made on the form.
187
 */
188
function updateHeadingLinks(links) {
189
    var current_tag = '';
190
    var tag_index = 0;
191
192
    // Delete the old message dialog and create a new one
193
    $('#autolinker_dialog').remove();
194
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
195
    var message_dialog_ul = message_dialog.find('ul');
196
197
    $.each(links, function(index, heading) {
198
        if(current_tag == heading.tag) {
199
            tag_index++;
200
        }
201
        else {
202
            current_tag = heading.tag;
203
            tag_index = 0;
204
        }
205
206
        // Find the $9 field to update
207
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
208
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
209
210
        // Delete the old status if one exists
211
        tag_subfield_line.children('.subfield_status').remove();
212
        subfield.css({backgroundColor:''});
213
214
        // If the field wasn't modified. Skip it.
215
        if(heading.status == 'UNCHANGED') {
216
            return;
217
        }
218
219
220
        // Make the subfield line visible and update its value
221
        tag_subfield_line.show();
222
        subfield.val(heading.authid);
223
224
        // Add the new status
225
        var image = 'deny.gif';
226
        var message = '';
227
        var field_color = '#FFAAAA';
228
        switch(heading.status) {
229
            case 'LOCAL_FOUND':
230
                image = 'approve.gif';
231
                message = _("A matching authority was found in the local database.");
232
                field_color = '#99FF99';
233
                break;
234
            case 'CREATED':
235
                image = 'approve.gif';
236
                message = _("No matching authority found. A new authority was created automatically.");
237
                field_color = '#99FF99';
238
                break;
239
            case 'MULTIPLE_MATCH':
240
                message = _("More than one local match found. Possibly a duplicate authority!");
241
                break;
242
            case 'NONE_FOUND':
243
                message = _("No matching authority found.");
244
                break;
245
            default:
246
                message = heading.status;
247
                break;
248
        }
249
250
        subfield.css({backgroundColor:field_color});
251
        tag_subfield_line.append('<img class="subfield_status" src="/intranet-tmpl/[% theme %]/img/' + image + '" title="' + message + '" />');
252
253
        // Add the message to the dialog
254
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
255
256
        // Add a link to create a new authority if none was found
257
        if(heading.status == 'NONE_FOUND') {
258
			addCreateAuthorityButton(tag_subfield_line, heading.tag, tag_index);
259
        }
260
    });
261
262
    if(message_dialog.find('li').length == 0) {
263
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
264
    }
265
    $('#addbibliotabs').before(message_dialog);
266
}
267
268
/**
269
 * Use an ajax request to automatically find authority links for the current record
270
 */
271
function AutomaticLinker() {
272
    // Show the Loading overlay
273
    $("#loading").show();
274
275
    // Remove fields that are completely empty
276
    $('#f').find('.tag').each(function() {
277
        var empty = true;
278
        $(this).find('.input_marceditor').each(function() {
279
            if($(this).val() != '') {
280
                empty = false;
281
                return false;
282
            }
283
        });
284
        if(empty) {
285
            UnCloneField($(this).attr('id'));
286
        }
287
    });
288
289
    // Get all the form values to post via AJAX
290
    var form_data = {};
291
    $('#f').find(':input').each(function(){
292
        form_data[this.name] = $(this).val();
293
    });
294
    delete form_data[''];
295
296
    // Send the data to automatic_linker.pl
297
    $.ajax({
298
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
299
        type:'post',
300
        data: form_data,
301
        dataType: 'json',
302
        error: function(xhr) {
303
            alert("Error : \n" + xhr.responseText);
304
        },
305
        success: function(json) {
306
            switch(json.status) {
307
                case 'UNAUTHORIZED':
308
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
309
                    break;
310
                case 'OK':
311
                    updateHeadingLinks(json.links);
312
                    break;
313
            }
314
        },
315
        complete: function() {
316
            $("#loading").hide();
317
        }
318
    });
319
}
320
321
137
function PopupMARCFieldDoc(field) {
322
function PopupMARCFieldDoc(field) {
138
    [% IF ( marcflavour == 'MARC21' ) %]
323
    [% IF ( marcflavour == 'MARC21' ) %]
139
        _MARC21FieldDoc(field);
324
        _MARC21FieldDoc(field);
140
- 

Return to bug 11299