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

(-)a/C4/Biblio.pm (-8 / +120 lines)
Lines 468-474 sub BiblioAutoLink { Link Here
468
468
469
=head2 LinkBibHeadingsToAuthorities
469
=head2 LinkBibHeadingsToAuthorities
470
470
471
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink]);
471
  my $num_headings_changed, %results = LinkBibHeadingsToAuthorities($linker, $marc, $frameworkcode, [$allowrelink, $verbose]);
472
472
473
Links bib headings to authority records by checking
473
Links bib headings to authority records by checking
474
each authority-controlled field in the C<MARC::Record>
474
each authority-controlled field in the C<MARC::Record>
Lines 490-495 sub LinkBibHeadingsToAuthorities { Link Here
490
    my $bib           = shift;
490
    my $bib           = shift;
491
    my $frameworkcode = shift;
491
    my $frameworkcode = shift;
492
    my $allowrelink = shift;
492
    my $allowrelink = shift;
493
    my $verbose = shift;
493
    my %results;
494
    my %results;
494
    if (!$bib) {
495
    if (!$bib) {
495
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
496
        carp 'LinkBibHeadingsToAuthorities called on undefined bib record';
Lines 497-503 sub LinkBibHeadingsToAuthorities { Link Here
497
    }
498
    }
498
    require C4::Heading;
499
    require C4::Heading;
499
    require C4::AuthoritiesMarc;
500
    require C4::AuthoritiesMarc;
500
501
    $allowrelink = 1 unless defined $allowrelink;
501
    $allowrelink = 1 unless defined $allowrelink;
502
    my $num_headings_changed = 0;
502
    my $num_headings_changed = 0;
503
    foreach my $field ( $bib->fields() ) {
503
    foreach my $field ( $bib->fields() ) {
Lines 510-540 sub LinkBibHeadingsToAuthorities { Link Here
510
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
510
        if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) )
511
        {
511
        {
512
            $results{'linked'}->{ $heading->display_form() }++;
512
            $results{'linked'}->{ $heading->display_form() }++;
513
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
513
            next;
514
            next;
514
        }
515
        }
515
516
516
        my ( $authid, $fuzzy ) = $linker->get_link($heading);
517
        my ( $authid, $fuzzy, $status ) = $linker->get_link($heading);
517
        if ($authid) {
518
        if ($authid) {
518
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
519
            $results{ $fuzzy ? 'fuzzy' : 'linked' }
519
              ->{ $heading->display_form() }++;
520
              ->{ $heading->display_form() }++;
520
            next if defined $current_link and $current_link == $authid;
521
            if(defined $current_link and $current_link == $authid) {
522
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
523
                next;
524
            }
521
525
522
            $field->delete_subfield( code => '9' ) if defined $current_link;
526
            $field->delete_subfield( code => '9' ) if defined $current_link;
523
            $field->add_subfields( '9', $authid );
527
            $field->add_subfields( '9', $authid );
524
            $num_headings_changed++;
528
            $num_headings_changed++;
529
            push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => $status || 'LOCAL_FOUND'}) if $verbose;
525
        }
530
        }
526
        else {
531
        else {
532
            my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
527
            if ( defined $current_link
533
            if ( defined $current_link
528
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
534
                && (!$allowrelink || C4::Context->preference('LinkerKeepStale')) )
529
            {
535
            {
530
                $results{'fuzzy'}->{ $heading->display_form() }++;
536
                $results{'fuzzy'}->{ $heading->display_form() }++;
537
                push(@{$results{'details'}}, { tag => $field->tag(), authid => $current_link, status => 'UNCHANGED'}) if $verbose;
531
            }
538
            }
532
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
539
            elsif ( C4::Context->preference('AutoCreateAuthorities') ) {
533
                if ( _check_valid_auth_link( $current_link, $field ) ) {
540
                if ( _check_valid_auth_link( $current_link, $field ) ) {
534
                    $results{'linked'}->{ $heading->display_form() }++;
541
                    $results{'linked'}->{ $heading->display_form() }++;
535
                }
542
                }
536
                else {
543
                else {
537
                    my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
538
                    my $marcrecordauth = MARC::Record->new();
544
                    my $marcrecordauth = MARC::Record->new();
539
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
545
                    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
540
                        $marcrecordauth->leader('     nz  a22     o  4500');
546
                        $marcrecordauth->leader('     nz  a22     o  4500');
Lines 595-626 sub LinkBibHeadingsToAuthorities { Link Here
595
                    }
601
                    }
596
602
597
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
603
           #          warn "AUTH RECORD ADDED : ".$marcrecordauth->as_formatted;
604
                    $authid = AddAuthorityFromHeading($marcrecordauth, $heading);
598
605
599
                    $authid =
600
                      C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '',
601
                        $heading->auth_type() );
602
                    $field->add_subfields( '9', $authid );
606
                    $field->add_subfields( '9', $authid );
603
                    $num_headings_changed++;
607
                    $num_headings_changed++;
604
                    $linker->update_cache($heading, $authid);
608
                    $linker->update_cache($heading, $authid);
605
                    $results{'added'}->{ $heading->display_form() }++;
609
                    $results{'added'}->{ $heading->display_form() }++;
610
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'CREATED'}) if $verbose;
606
                }
611
                }
607
            }
612
            }
608
            elsif ( defined $current_link ) {
613
            elsif ( defined $current_link ) {
609
                if ( _check_valid_auth_link( $current_link, $field ) ) {
614
                if ( _check_valid_auth_link( $current_link, $field ) ) {
610
                    $results{'linked'}->{ $heading->display_form() }++;
615
                    $results{'linked'}->{ $heading->display_form() }++;
616
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => $authid, status => 'UNCHANGED'}) if $verbose;
611
                }
617
                }
612
                else {
618
                else {
613
                    $field->delete_subfield( code => '9' );
619
                    $field->delete_subfield( code => '9' );
614
                    $num_headings_changed++;
620
                    $num_headings_changed++;
615
                    $results{'unlinked'}->{ $heading->display_form() }++;
621
                    $results{'unlinked'}->{ $heading->display_form() }++;
622
                    push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
616
                }
623
                }
617
            }
624
            }
618
            else {
625
            else {
619
                $results{'unlinked'}->{ $heading->display_form() }++;
626
                $results{'unlinked'}->{ $heading->display_form() }++;
627
                push(@{$results{'details'}}, { tag => $field->tag(), authid => undef, status => 'NONE_FOUND', auth_type => $heading->auth_type(), tag_to_report => $authority_type->auth_tag_to_report}) if $verbose;
620
            }
628
            }
621
        }
629
        }
622
630
623
    }
631
    }
632
    push(@{$results{'details'}}, { tag => '', authid => undef, status => 'UNCHANGED'}) unless %results;
624
    return $num_headings_changed, \%results;
633
    return $num_headings_changed, \%results;
625
}
634
}
626
635
Lines 646-651 sub _check_valid_auth_link { Link Here
646
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
655
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
647
}
656
}
648
657
658
=head2 AddAuthorityFromHeading
659
660
  my $authid = AddAuthorityFromHeading($marcrecordauth, $heading);
661
662
Creates a new authority from an heading and its associated field.
663
664
Returns the id of the newly created authority.
665
666
=cut
667
668
sub AddAuthorityFromHeading {
669
    my $marcrecordauth = shift;
670
    my $heading = shift;
671
672
    if(!defined $heading || !defined $marcrecordauth){
673
       return 0;
674
    }
675
    # Add correct informations in field 008 and 040 so the authority can be linked correctly in future linkings
676
    my $date=POSIX::strftime("%y%m%d",localtime);
677
    my @heading_use = qw(b b b);
678
    my $thesaurus = '|';
679
680
    if ($heading->{'subject_added_entry'}) {
681
        $heading_use[1] = 'a';
682
        # Thesaurus treatment
683
        my %thesaurus_conv = ('lcsh'=>'a','lcac'=>'b','mesh'=>'c','nal'=>'d','notspecified'=>'n','cash'=>'k','rvm'=>'v');
684
        $thesaurus = 'z';
685
        $thesaurus = $thesaurus_conv{$heading->{'thesaurus'}} if exists $thesaurus_conv{$heading->{'thesaurus'}};
686
        if($thesaurus eq 'z')
687
        {
688
            $marcrecordauth->insert_fields_ordered(
689
                    MARC::Field->new('040','','','f'=>$heading->{'thesaurus'})
690
            );
691
        }
692
    }
693
    if ($heading->{'series_added_entry'}) {
694
        $heading_use[2] = 'a';
695
    }
696
    if (not $heading->{'subject_added_entry'} and not $heading->{'series_added_entry'}) {
697
        $heading_use[0] = 'a';
698
    }
699
700
    # Get a valid default value for field 008
701
    my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
702
    if(!$default_008 or length($default_008)<34) {
703
        $default_008 = '|| aca||aabn           | a|a     d';
704
    }
705
    else {
706
        $default_008 = substr($default_008,0,34)
707
    }
708
709
    # Insert the date, thesaurus and heading_use into field 008
710
    my $f008 = $date . $default_008;
711
    substr($f008, 11, 1) = $thesaurus;
712
    substr($f008, 14, 3) = join('', @heading_use);
713
714
    $marcrecordauth->insert_fields_ordered(
715
        MARC::Field->new('008',$f008)
716
    );
717
718
    my $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() );
719
    return $authid;
720
}
721
722
723
=head2 GetRecordValue
724
725
  my $values = GetRecordValue($field, $record, $frameworkcode);
726
727
Get MARC fields from a keyword defined in fieldmapping table.
728
729
=cut
730
731
sub GetRecordValue {
732
    my ( $field, $record, $frameworkcode ) = @_;
733
734
    if (!$record) {
735
        carp 'GetRecordValue called with undefined record';
736
        return;
737
    }
738
    my $dbh = C4::Context->dbh;
739
740
    my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?');
741
    $sth->execute( $frameworkcode, $field );
742
743
    my @result = ();
744
745
    while ( my $row = $sth->fetchrow_hashref ) {
746
        foreach my $field ( $record->field( $row->{fieldcode} ) ) {
747
            if ( ( $row->{subfieldcode} ne "" && $field->subfield( $row->{subfieldcode} ) ) ) {
748
                foreach my $subfield ( $field->subfield( $row->{subfieldcode} ) ) {
749
                    push @result, { 'subfield' => $subfield };
750
                }
751
752
            } elsif ( $row->{subfieldcode} eq "" ) {
753
                push @result, { 'subfield' => $field->as_string() };
754
            }
755
        }
756
    }
757
758
    return \@result;
759
}
760
649
=head2 GetBiblioData
761
=head2 GetBiblioData
650
762
651
  $data = &GetBiblioData($biblionumber);
763
  $data = &GetBiblioData($biblionumber);
(-)a/C4/Linker.pm (-2 / +3 lines)
Lines 30-37 C4::Linker - Base class for linking authorities to bibliographic records Link Here
30
Base class for C4::Linker::X. Subclasses need to provide the following methods
30
Base class for C4::Linker::X. Subclasses need to provide the following methods
31
31
32
B<get_link ($field)> - return the authid for the authority that should be
32
B<get_link ($field)> - return the authid for the authority that should be
33
linked to the provided MARC::Field object, and a boolean to indicate whether
33
linked to the provided MARC::Field object, a boolean to indicate whether
34
the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin).
34
the match is "fuzzy" (the semantics of "fuzzy" are up to the individual plugin),
35
and an optional 'status' string giving more informations on the link status.
35
In order to handle authority limits, get_link should always end with:
36
In order to handle authority limits, get_link should always end with:
36
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
37
    return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
37
38
(-)a/C4/Linker/Default.pm (-1 / +1 lines)
Lines 43-49 sub get_link { Link Here
43
        # look for matching authorities
43
        # look for matching authorities
44
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
44
        my $authorities = $heading->authorities(1);    # $skipmetadata = true
45
45
46
        if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
46
        if ( $behavior eq 'default' && $#{$authorities} >= 0 ) {
47
            $authid = $authorities->[0]->{'authid'};
47
            $authid = $authorities->[0]->{'authid'};
48
        }
48
        }
49
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
49
        elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
(-)a/authorities/authorities.pl (-2 / +23 lines)
Lines 33-38 use MARC::File::XML; Link Here
33
use C4::Biblio;
33
use C4::Biblio;
34
use Koha::Authority::Types;
34
use Koha::Authority::Types;
35
use Koha::ItemTypes;
35
use Koha::ItemTypes;
36
use C4::Heading;
36
use vars qw( $tagslib);
37
use vars qw( $tagslib);
37
use vars qw( $authorised_values_sth);
38
use vars qw( $authorised_values_sth);
38
use vars qw( $is_a_modif );
39
use vars qw( $is_a_modif );
Lines 287-292 sub create_input { Link Here
287
288
288
        }
289
        }
289
    }
290
    }
291
    if ($cgi->param('tagreport') && $subfield_data{tag} == $cgi->param('tagreport')) {
292
        $subfield_data{marc_value}{value} = $cgi->param('tag'. $cgi->param('tagbiblio') . 'subfield' . $subfield_data{subfield});
293
    }
290
    $subfield_data{'index_subfield'} = $index_subfield;
294
    $subfield_data{'index_subfield'} = $index_subfield;
291
    return \%subfield_data;
295
    return \%subfield_data;
292
}
296
}
Lines 561-566 my $myindex = $input->param('index'); Link Here
561
my $linkid=$input->param('linkid');
565
my $linkid=$input->param('linkid');
562
my $authtypecode = $input->param('authtypecode');
566
my $authtypecode = $input->param('authtypecode');
563
my $breedingid    = $input->param('breedingid');
567
my $breedingid    = $input->param('breedingid');
568
my $biblioindex = $input->param('biblioindex'); # Used when in popup mode to send the new authority infos to the parent biblio
569
570
if($biblioindex and !$authid){
571
572
    my $record = TransformHtmlToMarc( $input );
573
574
    # Get the first heading found in the biblio informations
575
    foreach my $field ( $record->fields() ) {
576
        my $heading = C4::Heading->new_from_bib_field($field);
577
        next unless defined $heading;
578
579
        # Create a new authority using the heading informations
580
        $authid = C4::Biblio::AddAuthorityFromHeading($heading, $field);
581
    }
582
}
564
583
565
my $dbh = C4::Context->dbh;
584
my $dbh = C4::Context->dbh;
566
if(!$authtypecode) {
585
if(!$authtypecode) {
Lines 575-581 my ($template, $loggedinuser, $cookie) Link Here
575
                            flagsrequired => {editauthorities => 1},
594
                            flagsrequired => {editauthorities => 1},
576
                            debug => 1,
595
                            debug => 1,
577
                            });
596
                            });
578
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
597
$template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,biblioindex=>$biblioindex);
579
598
580
$tagslib = GetTagsLabels(1,$authtypecode);
599
$tagslib = GetTagsLabels(1,$authtypecode);
581
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
600
$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
Lines 620-626 if ($op eq "add") { Link Here
620
        } else {
639
        } else {
621
            ($authid) = AddAuthority($record,$authid,$authtypecode);
640
            ($authid) = AddAuthority($record,$authid,$authtypecode);
622
        }
641
        }
623
        if ($myindex) {
642
        if ($biblioindex) {
643
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$biblioindex");
644
        } elsif ($myindex) {
624
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
645
            print $input->redirect("blinddetail-biblio-search.pl?authid=$authid&index=$myindex");
625
        } else {
646
        } else {
626
            print $input->redirect("detail.pl?authid=$authid");
647
            print $input->redirect("detail.pl?authid=$authid");
(-)a/cataloguing/automatic_linker.pl (+74 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Frédérick Capovilla, 2011 - Libéo
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use CGI;
22
use CGI::Cookie;
23
use JSON;
24
use C4::Auth;
25
use C4::Biblio;
26
use C4::Context;
27
28
my $input = new CGI;
29
print $input->header('application/json');
30
31
# Check the user's permissions
32
my %cookies = CGI::Cookie->fetch;
33
my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
34
my ( $auth_status, $auth_sessid ) =
35
  C4::Auth::check_cookie_auth( $sessid, { editauthorities => 1, editcatalogue => 1 } );
36
if ( $auth_status ne "ok" ) {
37
    print to_json( { status => 'UNAUTHORIZED' } );
38
    exit 0;
39
}
40
41
# Link the biblio headings to authorities and return a json containing the status of all the links.
42
# Example : {"status":"OK","links":[{"authid":"123","status":"LINK_CHANGED","tag":"650"}]}
43
#
44
# tag = the tag number of the field
45
# authid = the value of the $9 subfield for this tag
46
# status = The status of the link (LOCAL_FOUND, NONE_FOUND, MULTIPLE_MATCH, UNCHANGED, CREATED)
47
48
my $json;
49
50
my $record = TransformHtmlToMarc($input,1);
51
52
my $linker_module =
53
  "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' );
54
eval { eval "require $linker_module"; };
55
if ($@) {
56
    $linker_module = 'C4::Linker::Default';
57
    eval "require $linker_module";
58
}
59
if ($@) {
60
    return 0, 0;
61
}
62
my $linker = $linker_module->new(
63
    { 'options' => C4::Context->preference("LinkerOptions") } );
64
65
my ( $headings_changed, $results ) = LinkBibHeadingsToAuthorities(
66
    $linker, $record,
67
    $input->param('frameworkcode'),
68
    C4::Context->preference("CatalogModuleRelink") || '', 1
69
);
70
71
$json->{status} = 'OK';
72
$json->{links} = $results->{details} || '';
73
74
print to_json($json);
(-)a/cataloguing/z3950_auth_search.pl (+3 lines)
Lines 42-47 my $subjectsubdiv = $input->param('subjectsubdiv'); Link Here
42
my $srchany       = $input->param('srchany');
42
my $srchany       = $input->param('srchany');
43
my $op            = $input->param('op')||'';
43
my $op            = $input->param('op')||'';
44
my $page            = $input->param('current_page') || 1;
44
my $page            = $input->param('current_page') || 1;
45
my $index =$input->param('index');
45
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
$page = $input->param('goto_page') if $input->param('changepage_goto');
46
my $controlnumber    = $input->param('controlnumber');
47
my $controlnumber    = $input->param('controlnumber');
47
48
Lines 65-70 $template->param( Link Here
65
    srchany      => $srchany,
66
    srchany      => $srchany,
66
    authid => $authid,
67
    authid => $authid,
67
    controlnumber => $controlnumber,
68
    controlnumber => $controlnumber,
69
    index => $index,
68
);
70
);
69
71
70
if ( $op ne "do_search" ) {
72
if ( $op ne "do_search" ) {
Lines 74-79 if ( $op ne "do_search" ) { Link Here
74
    $template->param(
76
    $template->param(
75
        serverloop   => $serverloop,
77
        serverloop   => $serverloop,
76
        opsearch     => "search",
78
        opsearch     => "search",
79
        index        => $index,
77
    );
80
    );
78
    output_html_with_http_headers $input, $cookie, $template->output;
81
    output_html_with_http_headers $input, $cookie, $template->output;
79
    exit;
82
    exit;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt (-3 / +7 lines)
Lines 28-35 Link Here
28
        $("#z3950submit").click(function(){
28
        $("#z3950submit").click(function(){
29
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
29
            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
30
                var strQuery = GetZ3950Terms();
30
                var strQuery = GetZ3950Terms();
31
                var index = "&index=[% index | html %]";
31
                if(strQuery){
32
                if(strQuery){
32
                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
33
                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid | html %]"+strQuery+index,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
33
                }
34
                }
34
            }
35
            }
35
            return false;
36
            return false;
Lines 208-216 function confirmnotdup(redirect){ Link Here
208
    <input type="hidden" name="op" value="add" />
209
    <input type="hidden" name="op" value="add" />
209
    <input type="hidden" name="addfield_field" value="" />
210
    <input type="hidden" name="addfield_field" value="" />
210
    <input type="hidden" name="repeat_field" value="" />
211
    <input type="hidden" name="repeat_field" value="" />
211
    <input type="hidden" name="authtypecode" value="[% authtypecode | html %]" />
212
    <input type="hidden" name="authtypecode" value="[% authtypecode  | html%]" />
212
    <input type="hidden" name="authid" value="[% authid | html %]" />
213
    <input type="hidden" name="authid" value="[% authid | html %]" />
213
    <input type="hidden" name="index" value="[% index | html %]" />
214
    <input type="hidden" name="index" value="[% index | html  %]" />
215
    [% IF ( biblioindex ) %]
216
    <input type="hidden" name="biblioindex" value="[% biblioindex | html %]" />
217
    [% END %]
214
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
218
    <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
215
219
216
    <div id="toolbar" class="btn-toolbar">
220
    <div id="toolbar" class="btn-toolbar">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt (+3 lines)
Lines 137-142 Link Here
137
                [% ELSE %]
137
                [% ELSE %]
138
                    if(code.value=='9'){
138
                    if(code.value=='9'){
139
                        subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
139
                        subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
140
                        // Clean the field if it was modified by the automatic linker
141
                        $(subfield).siblings('.subfield_status').remove();
142
                        $(subfield).css({backgroundColor:''});
140
                        break;
143
                        break;
141
                    }
144
                    }
142
                [% END %]
145
                [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-1 / +239 lines)
Lines 94-99 Link Here
94
            [% END %]
94
            [% END %]
95
        });
95
        });
96
96
97
        $("#linkerbutton").click(function(){
98
            AutomaticLinker();
99
        });
100
97
        $("#saverecord").click(function(){
101
        $("#saverecord").click(function(){
98
            $(".btn-group").removeClass("open");
102
            $(".btn-group").removeClass("open");
99
            onOption();
103
            onOption();
Lines 180-187 Link Here
180
        var onOption = function () {
184
        var onOption = function () {
181
            return Check();
185
            return Check();
182
        }
186
        }
183
    [% END %]
187
[% END %]
188
189
function confirmnotdup(redirect){
190
    $("#confirm_not_duplicate").attr("value","1");
191
    $("#redirect").attr("value",redirect);
192
    Check();
193
}
194
195
function Dopop(link,i) {
196
    defaultvalue = document.getElementById(i).value;
197
    window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
198
}
199
200
/**
201
 * this function open a popup to search on z3950 server.
202
 */
203
function PopupZ3950() {
204
    var strQuery = GetZ3950Terms();
205
    if(strQuery){
206
        window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=[% biblionumber | html %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
207
    }
208
}
209
210
/**
211
* this function append button for create new authority if not found
212
*/
213
214
function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
215
    var title = _("Create authority");
216
    var elem = $('<a href="#" title="' + title + '"><i class="fa fa-plus-circle"></i></a>');
217
    tag_subfield_line.append(elem);
218
    var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
219
    var subfield_a = tag_subfield_line_a.children('.input_marceditor').eq(0);
220
    var index = subfield_a.attr('id');
221
    elem.click(function() {
222
        var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
223
        if(popup !== null) {
224
            // Create a new form that will be POSTed in the new window
225
            var form = $('<form>').attr({
226
            method: 'post',
227
            action: "../authorities/authorities.pl",
228
            target: "new_auth_popup"
229
            });
230
            //add the authtypecode
231
            form.append($('<input>').attr({
232
                type: 'hidden',
233
                name: 'authtypecode',
234
                value: heading.auth_type
235
            }));
236
            form.append($('<input>').attr({
237
                type: 'hidden',
238
                name: 'tagreport',
239
                value: heading.tag_to_report
240
            }));
241
            form.append($('<input>').attr({
242
                type: 'hidden',
243
                name: 'tagbiblio',
244
                value: heading.tag
245
            }));
246
            form.append($('<input>').attr({
247
                type: 'hidden',
248
                name: 'index',
249
                value: index
250
            }));
251
            $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
252
                form.append($('<input>').attr({
253
                    type: 'hidden',
254
                    name: this.name.split('_',4).join(''),
255
                    value: $(this).val()
256
                }));
257
            });
258
259
            $('body').append(form);
260
            form.submit();
261
            form.remove();
262
        }
263
        return false;
264
    });
265
266
}
267
268
/**
269
 * Updates the authid for every heading field
270
 * Adds visual feedback for the changes made on the form.
271
 */
272
function updateHeadingLinks(links) {
273
    var current_tag = '';
274
    var tag_index = 0;
275
276
    // Delete the old message dialog and create a new one
277
    $('#autolinker_dialog').remove();
278
    var message_dialog = $('<div id="autolinker_dialog" class="dialog"><strong>' + _("Automatic authority link results:") + '</strong><ul></ul></div>');
279
    var message_dialog_ul = message_dialog.find('ul');
280
281
    $.each(links, function(index, heading) {
282
        if(current_tag == heading.tag) {
283
            tag_index++;
284
        }
285
        else {
286
            current_tag = heading.tag;
287
            tag_index = 0;
288
        }
289
290
        // Find the $9 field to update
291
        var tag_subfield_line = $('.subfield_line[id^=subfield' + heading.tag + '9]').eq(tag_index);
292
        var subfield = tag_subfield_line.children('.input_marceditor').eq(0);
293
294
        // Delete the old status if one exists
295
        tag_subfield_line.children('.subfield_status').remove();
296
        subfield.css({backgroundColor:''});
297
298
        // If the field wasn't modified. Skip it.
299
        if(heading.status == 'UNCHANGED') {
300
            return;
301
        }
302
303
304
        // Make the subfield line visible and update its value
305
        tag_subfield_line.show();
306
        subfield.val(heading.authid);
307
308
        // Add the new status
309
        var image = '<i class="fa fa-close" style="color: #FFAAAA"></i> ';
310
        var message = '';
311
        var field_color = '#FFAAAA';
312
        switch(heading.status) {
313
            case 'LOCAL_FOUND':
314
                image = '<i class="fa fa-check" style="color: #99FF99"></i> ';
315
                message = _("A matching authority was found in the local database.");
316
                field_color = '#99FF99';
317
                break;
318
            case 'CREATED':
319
                image = '<i class="fa fa-check" style="color: #99FF99"></i> ';
320
                message = _("No matching authority found. A new authority was created automatically.");
321
                field_color = '#99FF99';
322
                break;
323
            case 'MULTIPLE_MATCH':
324
                message = _("More than one local match found. Possibly a duplicate authority!");
325
                break;
326
            case 'NONE_FOUND':
327
                message = _("No matching authority found.");
328
                break;
329
            default:
330
                message = heading.status;
331
                break;
332
        }
333
334
        subfield.css({backgroundColor:field_color});
335
        tag_subfield_line.find('i').each(function() {
336
            this.remove();
337
        });
338
        tag_subfield_line.append(image);
339
340
        // Add the message to the dialog
341
        message_dialog_ul.append('<li><strong>' + heading.tag + '</strong> - ' + message + '</li>');
342
343
        // Add a link to create a new authority if none was found
344
        if(heading.status == 'NONE_FOUND' && tag_subfield_line.find('i').length == 1) {
345
            addCreateAuthorityButton(tag_subfield_line, heading , tag_index);
346
        }
347
    });
348
349
    if(message_dialog.find('li').length == 0) {
350
        message_dialog_ul.append("<li>" + _("No authority link was changed.") + "</li>");
351
    }
352
    $('#addbibliotabs').before(message_dialog);
353
}
354
355
/**
356
 * Use an ajax request to automatically find authority links for the current record
357
 */
358
function AutomaticLinker() {
359
    // Show the Loading overlay
360
    $("#loading").show();
361
362
    // Remove fields that are completely empty
363
    $('#f').find('.tag').each(function() {
364
        var empty = true;
365
        $(this).find('.input_marceditor').each(function() {
366
            if($(this).val() != '') {
367
                empty = false;
368
                return false;
369
            }
370
        });
371
        if(empty) {
372
            UnCloneField($(this).attr('id'));
373
        }
374
    });
184
375
376
    // Get all the form values to post via AJAX
377
    var form_data = {};
378
    $('#f').find(':input').each(function(){
379
        form_data[this.name] = $(this).val();
380
    });
381
    delete form_data[''];
382
383
    // Send the data to automatic_linker.pl
384
    $.ajax({
385
        url:'/cgi-bin/koha/cataloguing/automatic_linker.pl',
386
        type:'post',
387
        data: form_data,
388
        dataType: 'json',
389
        error: function(xhr) {
390
            alert("Error : \n" + xhr.responseText);
391
        },
392
        success: function(json) {
393
            switch(json.status) {
394
                case 'UNAUTHORIZED':
395
                    alert(_("Error : You do not have the permissions necessary to use this functionality."));
396
                    break;
397
                case 'OK':
398
                    updateHeadingLinks(json.links);
399
                    break;
400
            }
401
        },
402
        complete: function() {
403
            $("#loading").hide();
404
        }
405
    });
406
}
407
408
409
function PopupMARCFieldDoc(field) {
410
    [% IF Koha.Preference('marcfielddocurl') %]
411
        var docurl = "[% Koha.Preference('marcfielddocurl').replace('"','&quot;') | html %]";
412
        docurl = docurl.replace("{MARC}", "[% marcflavour | html %]");
413
        docurl = docurl.replace("{FIELD}", ""+field);
414
        docurl = docurl.replace("{LANG}", "[% lang | html %]");
415
        window.open(docurl);
416
    [% ELSIF ( marcflavour == 'MARC21' ) %]
417
        _MARC21FieldDoc(field);
418
    [% ELSIF ( marcflavour == 'UNIMARC' ) %]
419
        _UNIMARCFieldDoc(field);
420
    [% END %]
421
}
185
    function confirmnotdup(redirect){
422
    function confirmnotdup(redirect){
186
        $("#confirm_not_duplicate").attr("value","1");
423
        $("#confirm_not_duplicate").attr("value","1");
187
        $("#redirect").attr("value",redirect);
424
        $("#redirect").attr("value",redirect);
Lines 587-592 Link Here
587
                    [% END # /IF CAN_user_editcatalogue_edit_items %]
824
                    [% END # /IF CAN_user_editcatalogue_edit_items %]
588
825
589
                    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
826
                    [% UNLESS (circborrowernumber) %][%# Hide in fast cataloging %]
827
                        <div class="btn-group"><a class="btn btn-default" href="#" id="linkerbutton"><i class="fa fa-refresh"></i> Link authorities automatically</a></div>
590
                        <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
828
                        <div class="btn-group"><a class="btn btn-default" href="#" id="z3950search"><i class="fa fa-search"></i> Z39.50/SRU search</a></div>
591
                    [% END %]
829
                    [% END %]
592
830
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt (-1 / +2 lines)
Lines 20-25 Link Here
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
20
        <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
21
        <input type="hidden" name="op" id="op" value="do_search" />
21
        <input type="hidden" name="op" id="op" value="do_search" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
22
        <input type="hidden" name="authid" value="[% authid | html %]" />
23
        <input type="hidden" name="index" value="[% index | html %]" />
23
            <div class="row">
24
            <div class="row">
24
            <div class="col-xs-6">
25
            <div class="col-xs-6">
25
                <fieldset class="rows">
26
                <fieldset class="rows">
Lines 94-100 Link Here
94
                    </a>
95
                    </a>
95
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="cataloguesearchactions[% breeding_loo.breedingid | html %]">
96
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid | uri %]" class="previewMARC"><i class="fa fa-eye"></i> MARC preview</a></li>
97
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]"><i class="fa fa-download"></i> Import</a></li>
98
                        <li><a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid | html %]" data-heading_code="[% breeding_loo.heading_code | html %]" data-authid="[% breeding_loo.authid | html %]" data-index="[% index | html %]" ><i class="fa fa-download"></i> Import</a></li>
98
                    </ul>
99
                    </ul>
99
                </div>
100
                </div>
100
            </td>
101
            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (+6 lines)
Lines 137-142 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
137
            for( j = 0 ; j < inputs.length ; j++ ) {
137
            for( j = 0 ; j < inputs.length ; j++ ) {
138
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
138
                if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
139
                    inputs[j].value = "";
139
                    inputs[j].value = "";
140
141
                    //Remove the color added by the automatic linker
142
                    $(inputs[j]).css({backgroundColor:""});
140
                }
143
                }
141
            }
144
            }
142
            var textareas = divs[i].getElementsByTagName('textarea');
145
            var textareas = divs[i].getElementsByTagName('textarea');
Lines 146-151 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
146
                }
149
                }
147
            }
150
            }
148
151
152
            // Remove the status icons added by the automatic linker
153
            $(divs[i]).find('.subfield_status').remove();
154
149
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
155
            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
150
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
156
            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
151
157
(-)a/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js (-3 / +4 lines)
Lines 1-10 Link Here
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
1
//z3950_search.js for Authorities, Bib records and Acquisitions module
2
function Import(Breeding, recordid, AuthType, FrameworkCode) {
2
function Import(Breeding, recordid, AuthType, FrameworkCode, index) {
3
3
4
    if ( AuthType == false ) {
4
    if ( AuthType == false ) {
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
5
        opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
6
    } else {
6
    } else {
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid;
7
        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid+"&index="+index;
8
    }
8
    }
9
    window.close();
9
    window.close();
10
    return false;
10
    return false;
Lines 87-96 $( document ).ready( function() { Link Here
87
        var data_authid = $( this ).data( "authid" );
87
        var data_authid = $( this ).data( "authid" );
88
        var data_biblionumber = $( this ).data( "biblionumber" );
88
        var data_biblionumber = $( this ).data( "biblionumber" );
89
        var data_frameworkcode = $( this ).data( "frameworkcode" );
89
        var data_frameworkcode = $( this ).data( "frameworkcode" );
90
        var data_index = $( this ).data( "index" );
90
        if ( data_headingcode == undefined ) {
91
        if ( data_headingcode == undefined ) {
91
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
92
            Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
92
        } else {
93
        } else {
93
            Import( data_breedingid, data_authid, data_headingcode );
94
            Import( data_breedingid, data_authid, data_headingcode, "", data_index );
94
        }
95
        }
95
        return false;
96
        return false;
96
    });
97
    });
(-)a/t/Biblio.t (-1 / +2 lines)
Lines 164-166 warnings_like { $ret = UpdateTotalIssues() } Link Here
164
164
165
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
165
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
166
166
167
- 
167
is(C4::Biblio::AddAuthorityFromHeading(), 0, 'AddAuthorityFromHeading returns zero if not passed heading, field or bib');
168
1;

Return to bug 11299