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 571-576 my $myindex = $input->param('index'); Link Here
571
my $linkid=$input->param('linkid');
571
my $linkid=$input->param('linkid');
572
my $authtypecode = $input->param('authtypecode');
572
my $authtypecode = $input->param('authtypecode');
573
my $breedingid    = $input->param('breedingid');
573
my $breedingid    = $input->param('breedingid');
574
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new autority infos to the parent biblio
575
576
if($biblioindex and !$authid){
577
    require C4::Heading;
578
579
    my $record = TransformHtmlToMarc( $input );
580
581
    # Get the first heading found in the biblio informations
582
    foreach my $field ( $record->fields() ) {
583
        my $heading = C4::Heading->new_from_bib_field($field);
584
        next unless defined $heading;
585
586
        # Create a new authority using the heading informations
587
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
588
    }
589
}
574
590
575
my $dbh = C4::Context->dbh;
591
my $dbh = C4::Context->dbh;
576
if(!$authtypecode) {
592
if(!$authtypecode) {
Lines 585-591 my ($template, $loggedinuser, $cookie) Link Here
585
                            flagsrequired => {editauthorities => 1},
601
                            flagsrequired => {editauthorities => 1},
586
                            debug => 1,
602
                            debug => 1,
587
                            });
603
                            });
588
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
604
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
589
605
590
$tagslib = GetTagsLabels(1,$authtypecode);
606
$tagslib = GetTagsLabels(1,$authtypecode);
591
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
607
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 630-636 if ($op eq "add") { Link Here
630
        } else {
646
        } else {
631
            ($authid) = AddAuthority($record,$authid,$authtypecode);
647
            ($authid) = AddAuthority($record,$authid,$authtypecode);
632
        }
648
        }
633
        if ($myindex) {
649
        if ($biblioindex) {
650
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
651
        } elsif ($myindex) {
634
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
652
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
635
        } else {
653
        } else {
636
            print $input->redirect("detail.pl?authid=$authid");
654
            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 201-206 function confirmnotdup(redirect){ Link Here
201
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
201
    <input type="hidden" name="authtypecode" value="[% authtypecode %]" />
202
    <input type="hidden" name="authid" value="[% authid %]" />
202
    <input type="hidden" name="authid" value="[% authid %]" />
203
    <input type="hidden" name="index" value="[% index %]" />
203
    <input type="hidden" name="index" value="[% index %]" />
204
    [% IF ( biblioindex ) %]
205
    <input type="hidden" name="biblioindex" value="[% biblioindex %]" />
206
    [% END %]
204
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
207
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
205
208
206
    <div id="toolbar" class="btn-toolbar">
209
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (-4 / +20 lines)
Lines 5-13 Link Here
5
//<![CDATA[
5
//<![CDATA[
6
    $(document).ready(function(){
6
    $(document).ready(function(){
7
        var index_start = "[% index %]";
7
        var index_start = "[% index %]";
8
        var whichfield;
8
        var whichfield = null;
9
10
        // Loop through opener windows and try to find the basewindow and the form field we need to fill
11
        var basewindow = window;
12
        var parents_to_close = [];
9
        try {
13
        try {
10
            whichfield = opener.opener.document.getElementById(index_start);
14
            while(whichfield === null) {
15
                basewindow = basewindow.opener;
16
                whichfield = basewindow.document.getElementById(index_start);
17
                if(whichfield === null) {
18
                    parents_to_close.unshift(basewindow);
19
                }
20
            }
11
        } catch(e) {
21
        } catch(e) {
12
            return;
22
            return;
13
        }
23
        }
Lines 99-111 Link Here
99
            [% ELSE %]
109
            [% ELSE %]
100
                if(code.value=='9'){
110
                if(code.value=='9'){
101
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
111
                    subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
102
                    break;
112
                    // Clean the field if it was modified by the automatic linker
113
                    $(subfield).siblings('.subfield_status').remove();
114
                    $(subfield).css({backgroundColor:''});
103
                }
115
                }
104
            [% END %]
116
            [% END %]
105
            }
117
            }
106
        }
118
        }
107
119
108
      	opener.close();
120
        // Close all parent windows, but not the basewindow
121
        while(parents_to_close.length != 0) {
122
            parents_to_close.shift().close();
123
        }
124
109
       	window.close();
125
       	window.close();
110
            
126
            
111
       	return false;
127
       	return false;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-1 / +185 lines)
Lines 80-85 Link Here
80
            [% END %]
80
            [% END %]
81
        });
81
        });
82
82
83
        $("#linkerbutton").click(function(){
84
            AutomaticLinker();
85
        });
86
83
        $("#saverecord").click(function(){
87
        $("#saverecord").click(function(){
84
            $(".btn-group").removeClass("open");
88
            $(".btn-group").removeClass("open");
85
            onOption();
89
            onOption();
Lines 139-144 function PopupZ3950() { Link Here
139
    } 
143
    } 
140
}
144
}
141
145
146
function addCreateAuthorityButton(tag_subfield_line, tag, index) {
147
	var title = _("Create authority");
148
	var elem = $('<a class="subfield_status" href="#"><img src="/intranet-tmpl/[% theme %]/img/edit-tag.png" title="' + title + '" /></a>');
149
	tag_subfield_line.append(elem);
150
151
	elem.click(function() {
152
        var biblioindex = $(this).parents('.subfield_line').find('input').eq(1).attr('id');
153
		var popup = window.open("", "new_auth_popup",'width=700,height=550,toolbar=false,scrollbars=yes');
154
155
		if(popup !== null) {
156
			// Create a new form that will be POSTed in the new window
157
			var form = $('<form>').attr({
158
				method: 'post',
159
				action: "../authorities/authorities.pl",
160
				target: "new_auth_popup"
161
			});
162
163
			// Add the biblioindex
164
			form.append($('<input>').attr({
165
				type: 'hidden',
166
				name: 'biblioindex',
167
				value: biblioindex
168
			}));
169
170
			// Get all form datas for the current heading field
171
			$('.tag[id^=tag_' + tag + '_]').eq(index).find(':input').each(function(){
172
				form.append($('<input>').attr({
173
					type: 'hidden',
174
					name: this.name,
175
					value: $(this).val()
176
				}));
177
			});
178
179
			// We need to add the temporary form to the body so we can submit it
180
			$('body').append(form);
181
			form.submit();
182
			form.remove();
183
		}
184
185
		return false;
186
	});
187
}
188
189
/**
190
 * Updates the authid for every heading field
191
 * Adds visual feedback for the changes made on the form.
192
 */
193
function updateHeadingLinks(links) {
194
    var current_tag = '';
195
    var tag_index = 0;
196
197
    // Delete the old message dialog and create a new one
198
    $('#autolinker_dialog').remove();
199
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
200
    var message_dialog_ul = message_dialog.find('ul');
201
202
    $.each(links, function(index, heading) {
203
        if(current_tag == heading.tag) {
204
            tag_index++;
205
        }
206
        else {
207
            current_tag = heading.tag;
208
            tag_index = 0;
209
        }
210
211
        // Find the $9 field to update
212
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
213
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
214
215
        // Delete the old status if one exists
216
        tag_subfield_line.children('.subfield_status').remove();
217
        subfield.css({backgroundColor:''});
218
219
        // If the field wasn't modified. Skip it.
220
        if(heading.status == 'UNCHANGED') {
221
            return;
222
        }
223
224
225
        // Make the subfield line visible and update its value
226
        tag_subfield_line.show();
227
        subfield.val(heading.authid);
228
229
        // Add the new status
230
        var image = 'deny.gif';
231
        var message = '';
232
        var field_color = '#FFAAAA';
233
        switch(heading.status) {
234
            case 'LOCAL_FOUND':
235
                image = 'approve.gif';
236
                message = _("A matching authority was found in the local database.");
237
                field_color = '#99FF99';
238
                break;
239
            case 'CREATED':
240
                image = 'approve.gif';
241
                message = _("No matching authority found. A new authority was created automatically.");
242
                field_color = '#99FF99';
243
                break;
244
            case 'MULTIPLE_MATCH':
245
                message = _("More than one local match found. Possibly a duplicate authority!");
246
                break;
247
            case 'NONE_FOUND':
248
                message = _("No matching authority found.");
249
                break;
250
            default:
251
                message = heading.status;
252
                break;
253
        }
254
255
        subfield.css({backgroundColor:field_color});
256
        tag_subfield_line.append('<img class="subfield_status" src="/intranet-tmpl/[% theme %]/img/' + image + '" title="' + message + '" />');
257
258
        // Add the message to the dialog
259
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
260
261
        // Add a link to create a new authority if none was found
262
        if(heading.status == 'NONE_FOUND') {
263
			addCreateAuthorityButton(tag_subfield_line, heading.tag, tag_index);
264
        }
265
    });
266
267
    if(message_dialog.find('li').length == 0) {
268
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
269
    }
270
    $('#addbibliotabs').before(message_dialog);
271
}
272
273
/**
274
 * Use an ajax request to automatically find authority links for the current record
275
 */
276
function AutomaticLinker() {
277
    // Show the Loading overlay
278
    $("#loading").show();
279
280
    // Remove fields that are completely empty
281
    $('#f').find('.tag').each(function() {
282
        var empty = true;
283
        $(this).find('.input_marceditor').each(function() {
284
            if($(this).val() != '') {
285
                empty = false;
286
                return false;
287
            }
288
        });
289
        if(empty) {
290
            UnCloneField($(this).attr('id'));
291
        }
292
    });
293
294
    // Get all the form values to post via AJAX
295
    var form_data = {};
296
    $('#f').find(':input').each(function(){
297
        form_data[this.name] = $(this).val();
298
    });
299
    delete form_data[''];
300
301
    // Send the data to automatic_linker.pl
302
    $.ajax({
303
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
304
        type:'post',
305
        data: form_data,
306
        dataType: 'json',
307
        error: function(xhr) {
308
            alert("Error : \n" + xhr.responseText);
309
        },
310
        success: function(json) {
311
            switch(json.status) {
312
                case 'UNAUTHORIZED':
313
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
314
                    break;
315
                case 'OK':
316
                    updateHeadingLinks(json.links);
317
                    break;
318
            }
319
        },
320
        complete: function() {
321
            $("#loading").hide();
322
        }
323
    });
324
}
325
326
142
function PopupMARCFieldDoc(field) {
327
function PopupMARCFieldDoc(field) {
143
    [% IF ( marcflavour == 'MARC21' ) %]
328
    [% IF ( marcflavour == 'MARC21' ) %]
144
        _MARC21FieldDoc(field);
329
        _MARC21FieldDoc(field);
145
- 

Return to bug 11299