From 67942831f5722e3a29602f76b2cbb95674c971b8 Mon Sep 17 00:00:00 2001
From: Bouzid Fergani <bouzid.fergani@inlibro.com>
Date: Fri, 6 Oct 2017 08:25:23 -0400
Subject: [PATCH] Bug11299 - Populated field for record when import authority
 in z3950

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 cataloguing/z3950_auth_search.pl                                   | 4 ++++
 koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt | 3 ++-
 koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt   | 6 ++++++
 .../intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt | 5 +++--
 koha-tmpl/intranet-tmpl/prog/js/z3950_search.js                    | 7 ++++---
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/cataloguing/z3950_auth_search.pl b/cataloguing/z3950_auth_search.pl
index c808b7b7b1..1cc5154652 100755
--- a/cataloguing/z3950_auth_search.pl
+++ b/cataloguing/z3950_auth_search.pl
@@ -42,6 +42,8 @@ my $subjectsubdiv       = $input->param('subjectsubdiv');
 my $srchany       = $input->param('srchany');
 my $op            = $input->param('op')||'';
 my $page            = $input->param('current_page') || 1;
+my $index         =$input->param('index');
+
 $page = $input->param('goto_page') if $input->param('changepage_goto');
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
@@ -63,6 +65,7 @@ $template->param(
     subjectsubdiv   => $subjectsubdiv,
     srchany      => $srchany,
     authid => $authid,
+    index => $index,
 );
 
 if ( $op ne "do_search" ) {
@@ -72,6 +75,7 @@ if ( $op ne "do_search" ) {
     $template->param(
         serverloop   => $serverloop,
         opsearch     => "search",
+        index        => $index,
     );
     output_html_with_http_headers $input, $cookie, $template->output;
     exit;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
index d339b238d2..a307ebbe5a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
@@ -20,8 +20,9 @@
         $("#z3950submit").click(function(){
             if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
                 var strQuery = GetZ3950Terms();
+                var index = "&index=" + "[% index %]";
                 if(strQuery){
-                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid %]"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid %]"+strQuery+index,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
                 }
             }
             return false;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
index 54e370a6f8..18d10a91a2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
@@ -178,6 +178,7 @@ function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
     tag_subfield_line.append(elem);
     var tag_subfield_line_a = $('.subfield_line[id^=subfield' + heading.tag + 'a]').eq(tag_index);
     var subfield_a = tag_subfield_line_a.children('.input_marceditor').eq(0);
+    var index = subfield_a.attr('id');
     elem.click(function() {
         var popup = window.open("", "new_auth_popup",'fullscreen,toolbar=false,scrollbars=yes');
         if(popup !== null) {
@@ -203,6 +204,11 @@ function addCreateAuthorityButton(tag_subfield_line, heading, tag_index) {
                 name: 'tagbiblio',
                 value: heading.tag
             }));
+            form.append($('<input>').attr({
+                type: 'hidden',
+                name: 'index',
+                value: index
+            }));
             $('.tag[id^=tag_' + heading.tag + '_]').eq(tag_index).find(':input').each(function(){
                 form.append($('<input>').attr({
                     type: 'hidden',
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt
index 6e6de65fa3..d0f0f11a58 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt
@@ -65,6 +65,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
         <form method="post" action="z3950_auth_search.pl" name="f" class="checkboxed">
         <input type="hidden" name="op" id="op" value="do_search" />
         <input type="hidden" name="authid" value="[% authid %]" />
+        <input type="hidden" name="index" value="[% index %]" />
         <div class="yui-g">
             <div class="yui-u first">
                 <fieldset class="rows">
@@ -120,12 +121,12 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
     <tbody>[% FOREACH breeding_loo IN breeding_loop %]
         [% IF ( breeding_loo.breedingid ) %]
         <tr id="row[% breeding_loo.breedingid %]">
-            <td>[% breeding_loo.server %] <div class="linktools"><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid %]" class="previewMARC">Preview MARC</a> <a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid %]" data-heading_code="[% breeding_loo.heading_code %]" data-authid="[% breeding_loo.authid %]">Import</a><a href="#" id="close_menu" title="Close this menu"> X </a></div> </td>
+            <td>[% breeding_loo.server %] <div class="linktools"><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid %]" class="previewMARC">Preview MARC</a> <a href="#" class="import_record" data-breedingid="[% breeding_loo.breedingid %]" data-heading_code="[% breeding_loo.heading_code %]" data-authid="[% breeding_loo.authid %]" data-index="[% index %]">Import</a><a href="#" id="close_menu" title="Close this menu"> X </a></div> </td>
             <td>[% breeding_loo.heading %]</td>
             <td>[% breeding_loo.heading_code %]</td>
             <td class="actions">
                 <a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid %]" class="previewMARC btn btn-default btn-xs"><i class="fa fa-eye"></i> Show MARC</a>
-                <a href="#" class="import_record btn btn-default btn-xs" data-breedingid="[% breeding_loo.breedingid %]" data-heading_code="[% breeding_loo.heading_code %]" data-authid="[% breeding_loo.authid %]"><i class="fa fa-download"></i> Import</a>
+                <a href="#" class="import_record btn btn-default btn-xs" data-breedingid="[% breeding_loo.breedingid %]" data-heading_code="[% breeding_loo.heading_code %]" data-authid="[% breeding_loo.authid %]" data-index="[% index %]"><i class="fa fa-download"></i> Import</a>
             </td>
         </tr>
         [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js b/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js
index 95ef673dfe..986566dc94 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/z3950_search.js
@@ -1,10 +1,10 @@
 //z3950_search.js for Authorities, Bib records and Acquisitions module
-function Import(Breeding, recordid, AuthType, FrameworkCode) {
+function Import(Breeding, recordid, AuthType, FrameworkCode, index) {
 
     if ( AuthType == false ) {
         opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
     } else {
-        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid;
+        opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid+"&index="+index;
     }
     window.close();
     return false;
@@ -87,10 +87,11 @@ $( document ).ready( function() {
         var data_authid = $( this ).data( "authid" );
         var data_biblionumber = $( this ).data( "biblionumber" );
         var data_frameworkcode = $( this ).data( "frameworkcode" );
+        var data_index          = $( this ).data( "index" );
         if ( data_headingcode == undefined ) {
             Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
         } else {
-            Import( data_breedingid, data_authid, data_headingcode );
+            Import( data_breedingid, data_authid, data_headingcode, '', data_index  );
         }
         return false;
     });
-- 
2.11.0