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

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

Return to bug 11299