Bug 11961 - Add a "Z39.50 search" button to the authority creation and modification...
authorFrédérick <frederick.capovilla@libeo.com>
Mon, 20 Jan 2014 16:04:52 +0000 (11:04 -0500)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Sat, 24 Jan 2015 21:19:06 +0000 (18:19 -0300)
This button lets you replace existing authorities using a Z39.50 search.

http://bugs.koha-community.org/show_bug.cgi?id=11961
Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>
All tests pass

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

C4/Breeding.pm
authorities/authorities.pl
cataloguing/z3950_auth_search.pl
koha-tmpl/intranet-tmpl/prog/en/includes/authorities-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_auth_search.tt

index 7bd95fb..b5a4717 100644 (file)
@@ -520,6 +520,7 @@ sub Z3950SearchAuth {
     my $subject= $pars->{subject};
     my $subjectsubdiv= $pars->{subjectsubdiv};
     my $srchany= $pars->{srchany};
+    my $authid= $pars->{authid};
 
     my $show_next       = 0;
     my $total_pages     = 0;
@@ -672,11 +673,12 @@ sub Z3950SearchAuth {
                             $row_data{server}       = $servername[$k];
                             $row_data{breedingid}   = $breedingid;
                             $row_data{heading}      = $heading;
+                            $row_data{authid}       = $authid;
                             $row_data{heading_code}      = $heading_authtype_code;
                             push( @breeding_loop, \%row_data );
                         }
                         else {
-                            push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1});
+                            push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'authid'=>-1});
                         }
                     }
                 }    #if $numresults
index e610e7f..3ea3680 100755 (executable)
@@ -323,6 +323,27 @@ sub CreateKey {
     return int(rand(1000000));
 }
 
+=item GetMandatoryFieldZ3950
+
+    This function return an hashref which containts all mandatory field
+    to search with z3950 server.
+
+=cut
+
+sub GetMandatoryFieldZ3950($){
+    my $authtypecode = shift;
+
+    #Tags guessed (see GuessAuthTypeCode from AuthoritiesMarc.pm)
+
+    return {
+        '100'.'a' => 'authorpersonal',
+        '110'.'a' => 'authorcorp',
+        '111'.'a' => 'authormeetingcon',
+        '130'.'a' => 'uniformtitle',
+        '150'.'a' => 'topic',
+    };
+}
+
 sub build_tabs {
     my ( $template, $record, $dbh, $encoding,$input ) = @_;
 
@@ -562,6 +583,8 @@ my ($template, $loggedinuser, $cookie)
 $template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,breedingid=>$breedingid,);
 
 $tagslib = GetTagsLabels(1,$authtypecode);
+$mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
+
 my $record=-1;
 my $encoding="";
 if (($authid) && !($breedingid)){
index 806b387..8ea4f41 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Koha;
 my $input        = new CGI;
 my $dbh          = C4::Context->dbh;
 my $error         = $input->param('error');
+my $authid  = $input->param('authid') || 0;
 my $nameany     = $input->param('nameany');
 my $authorany     = $input->param('authorany');
 my $authorcorp     = $input->param('authorcorp');
@@ -61,6 +62,7 @@ $template->param(
     subject      => $subject,
     subjectsubdiv   => $subjectsubdiv,
     srchany      => $srchany,
+    authid => $authid,
 );
 
 if ( $op ne "do_search" ) {
@@ -97,6 +99,7 @@ my $pars= {
         subject => $subject,
         subjectsubdiv => $subjectsubdiv,
         srchany => $srchany,
+        authid => $authid,
 };
 Z3950SearchAuth($pars, $template);
 output_html_with_http_headers $input, $cookie, $template->output;
index 203e9a0..b460cdc 100644 (file)
@@ -7,7 +7,13 @@
         });
 
         $("#z3950submit").click(function(){
-            window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl","z3950search",'width=800,height=500,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+            [% IF ( authid ) %]
+                if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
+                    window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=[% authid %]","z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+                }
+            [% ELSE %]
+                window.open("/cgi-bin/koha/cataloguing/z3950_auth_search.pl","z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
+            [% END %]
             return false;
         });
 
index ea47100..693b61e 100644 (file)
                 $("#f").submit();
             }
                });
+        $("#z3950submit").click(function(){
+            if (confirm(_("Please note that this Z39.50 search could replace the current record."))){
+                var strQuery = GetZ3950Terms();
+                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');
+                }
+            }
+            return false;
+        });
         });
 
 /**
+ * check if z3950 mandatories are set or not
+ */
+function GetZ3950Terms(){
+ var strQuery="&authtypecode="+document.forms['f'].authtypecode.value;
+    var mandatories = new Array();
+    var mandatories_label = new Array();
+    [% FOREACH BIG_LOO IN BIG_LOOP %][% FOREACH innerloo IN BIG_LOO.innerloop %][% FOREACH subfield_loo IN innerloo.subfield_loop %][% IF ( subfield_loo.z3950_mandatory ) %]mandatories.push("[% subfield_loo.id %]");
+        mandatories_label.push("[% subfield_loo.z3950_mandatory %]");[% END %][% END %][% END %][% END %]
+
+    for(var i=0,len=mandatories.length; i<len ; i++){
+        var field_value = document.getElementById(mandatories[i]).value;
+        if( field_value ){
+            strQuery += "&"+mandatories_label[i]+"="+field_value;
+        }
+    }
+    return strQuery;
+}
+
+/**
  * check if mandatory subfields are written
  */
 function AreMandatoriesNotOk(){
@@ -177,6 +205,9 @@ function confirmnotdup(redirect){
 
     <div id="toolbar" class="btn-toolbar">
         <div class="btn-group"><a href="#" id="addauth" class="btn btn-small" accesskey="w"><i class="icon-hdd"></i> Save</a></div>
+        <div class="btn-group">
+            <a class="btn btn-small" id="z3950submit" href="#"><i class="icon-search"></i> Z39.50 search</a>
+        </div>
     </div>
 
 <div id="authoritytabs" class="toptabs numbered">
index 6ef6136..c53e938 100644 (file)
@@ -7,8 +7,8 @@
 [% INCLUDE 'datatables.inc' %]
 <script type="text/javascript">
 //<![CDATA[
-function Import(Breeding,AuthType) {
-    opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType;
+function Import(Breeding,AuthType,authid) {
+    opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+authid;
     window.close();
     return false;
 }
@@ -103,6 +103,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
         <h2>Z39.50 Authority search points</h2>
         <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 %]" />
         <div class="yui-g">
             <div class="yui-u first">
                 <fieldset class="rows">
@@ -110,13 +111,19 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
                     <li><label for="srchany">Keyword (any): </label> <input type="text" id="srchany" name="srchany" value="" /></li>
                     <li><label for="nameany">Name (any): </label> <input type="text" id="nameany" name="nameany" value="" /></li>
                     <li><label for="authorany">Author (any): </label> <input type="text" id="authorany" name="authorany" value="" /></li>
-                    <li><label for="authorpersonal">Author (personal): </label> <input type="text" id="authorpersonal" name="authorpersonal" value="" /></li>
-                    <li><label for="authorcorp">Author (corporate): </label> <input type="text" id="authorcorp" name="authorcorp" value="" /></li>
-                    <li><label for="authormeetingcon">Author (meeting/conference): </label> <input type="text" id="authormeetingcon" name="authormeetingcon" value="" /></li>
+                    <li><label for="authorpersonal">Author (personal): </label> <input type="text" id="authorpersonal" name="authorpersonal" value="[% authorpersonal | html %]" /></li>
+                    <li><label for="authorcorp">Author (corporate): </label> <input type="text" id="authorcorp" name="authorcorp" value="[% authorcorp | html %]" /></li>
+                    <li><label for="authormeetingcon">Author (meeting/conference): </label> <input type="text" id="authormeetingcon" name="authormeetingcon" value="[% authormeetingcon | html %]" /></li>
+                </ol>
+                </fieldset>
+            </div>
+            <div class="yui-u">
+                <fieldset class="rows">
+                <ol>
                     <li><label for="subject">Subject heading: </label> <input type="text" id="subject" name="subject" value="" /></li>
                     <li><label for="subjectsubdiv">Subject sub-division: </label> <input type="text" id="subjectsubdiv" name="subjectsubdiv" value="" /></li>
-                    <li><label for="title">Title (any): </label> <input type="text" id="title"  name="title" value="[% title |html %]" /></li>
-                    <li><label for="uniformtitle">Title (uniform): </label> <input type="text" id="uniformtitle"  name="uniformtitle" value="[% uniformtitle |html %]" /></li>
+                    <li><label for="title">Title (any): </label> <input type="text" id="title"  name="title" value="[% title | html %]" /></li>
+                    <li><label for="uniformtitle">Title (uniform): </label> <input type="text" id="uniformtitle"  name="uniformtitle" value="[% uniformtitle | html %]" /></li>
                 </ol>
                 </fieldset>
             </div>
@@ -152,12 +159,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 %]" rel="gb_page_center[600,500]">Preview MARC</a> <a href="#" onclick="Import([% breeding_loo.breedingid %],'[% breeding_loo.heading_code %]'); return false">Import</a><a href="#" onclick="closemenu();return false;" 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 %]" rel="gb_page_center[600,500]">Preview MARC</a> <a href="#" onclick="Import([% breeding_loo.breedingid %],'[% breeding_loo.heading_code %]','[% breeding_loo.authid %]'); return false">Import</a><a href="#" onclick="closemenu();return false;" title="Close this menu"> X </a></div> </td>
             <td>[% breeding_loo.heading %]</td>
             <td>[% breeding_loo.heading_code %]</td>
             <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% breeding_loo.breedingid %]" title="MARC" rel="gb_page_center[600,500]">MARC</a></td>
             <!-- <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;importid=[% breeding_loo.breedingid %]" title="MARC" rel="gb_page_center[600,500]">Card</a></td> -->
-            <td><a href="#" onclick="Import([% breeding_loo.breedingid %],'[% breeding_loo.heading_code %]'); return false">Import</a></td>
+            <td><a href="#" onclick="Import([% breeding_loo.breedingid %],'[% breeding_loo.heading_code %]','[% breeding_loo.authid %]'); return false">Import</a></td>
         </tr>
         [% END %]
     [% END %]</tbody>
@@ -177,6 +184,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
         <input type="hidden" id="subjectsubdiv" name="subjectsubdiv" value="[% subjectsubdiv %]" />
         <input type="hidden" id="heading"  name="heading" value="[% heading %]" />
         <input type="hidden" id="srchany" name="srchany" value="[% srchany %]" />
+        <input type="hidden" name="authid" value="[% authid %]" />
 
         [% FOREACH server IN servers %]
         <input type="hidden" name="id" id="z3950_[% server.id %]" value="[% server.id %]" />
@@ -192,7 +200,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
         <br />Go to page : <input id="goto_page" name="goto_page" value="[% current_page %]" size="4" /><input type="submit" name="changepage_goto" onclick="return validate_goto_page();" value="Go" />
     </form>
 
-<p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_auth_search.pl"><input type="submit" value="Try Another Search"/></form></p>
+<p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_auth_search.pl"><input type="hidden" name="authid" value="[% authid %]" /><input type="submit" value="Try Another Search"/></form></p>
     [% ELSE %]
         [% IF ( errconn ) %]
             <div class="dialog alert">
@@ -205,7 +213,7 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
             </div>
          [% END %]
    <div class="dialog message">Nothing found.</div>
-    <p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_auth_search.pl"><input type="submit" value="Try Another Search"/></form></p>
+    <p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_auth_search.pl"><input type="hidden" name="authid" value="[% authid %]" /><input type="submit" value="Try Another Search"/></form></p>
     [% END %]
 
 [% END %]