Koha AMS integration

This describes the modifications which have been done to a standard Koha 2.2.5 installation in order to be provide a basic AMS integration for IMAR: “Simion Stoilow” Institute of Mathematics of the Romanian Academy library system.

AMS integration

One of the requirements of the customization was to allow a basic AMS integration. For each ISBN code the corresponding AMS code had to be found using a crawler.

This was achieved by a value_builder plugin which consists of 3 parts:

The usmarc_field_ams.pl

#!/usr/bin/perl
 
use strict;
use C4::Auth;
use CGI;
use C4::Context;
use HTML::Template;
use C4::Search;
use C4::Output;
 
=head1
 
plugin_parameters : other parameters added when the plugin is called by the dopop function
 
=cut
sub plugin_parameters {
    my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
    return "";
}
 
 
sub plugin_javascript {
    my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
    my $function_name= "ams".(int(rand(100000))+1);
    my $res="
<br/>
<script>
function Focus$function_name(subfield_managed) {
return 1;
}
 
function Blur$function_name(subfield_managed) {
return 1;
}
 
function Clic$function_name(fi) {
    var isbn = \"\";
    var isbncnt = 0;
    for (i=0 ; i<document.forms['f'].field_value.length ; i++) {
        if (document.forms['f'].kohafield[i].value == \"biblioitems.isbn\"){
            if(document.forms['f'].field_value[i].value.length>0) {
                isbn = document.forms['f'].field_value[i].value;
                if(isbn.length > 0){
                     //document.f.field_value[i].value = 'test';
                     newin=window.open(\"../plugin_launcher.pl?plugin_name=usmarc_field_ams.pl&index=\"+fi+\"&isbn=\"+isbn,\"field_ams_\" + isbncnt,'width=500,height=400,toolbar=false,scrollbars=yes');
                }
                isbncnt = isbncnt + 1;
            }
        }
    }
 
    if(isbncnt==0){
        alert(\"Please fill the ISBN field first\");
    }
}
</script>
";
    return ($function_name,$res);
}
 
sub plugin {
    my ($input) = @_;
    my %env;
    my $index= $input->param('index');
    my $isbn = $input->param('isbn');
 
    if ($isbn =~ /([0-9X]{10,13})/i){
	$isbn = $1;
    }else{
	print "ISBN:".$isbn." does not match format\n";
    }
 
    my ($template, $loggedinuser, $cookie)
	= get_template_and_user({template_name => "value_builder/usmarc_field_ams.tmpl",
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
			     flagsrequired => {editcatalogue => 1},
                             debug => 1,
			     });
    if(eval {require Business::ISBN}){
	require Business::ISBN;
	my $isbn_object = Business::ISBN->new($isbn);
	if($isbn_object->is_valid() == Business::ISBN::GOOD_ISBN()){
	    $isbn = $isbn_object->as_string;
	}
    }
    my $amsCodes = getAMSCodes($isbn);
    $template->param(index=> $index, isbn => $isbn, amsCodes => $amsCodes);
    print $input->header(-cookie => $cookie),$template->output;
}
 
sub getAMSCodes{
    my $amsServer = "www.ams.org";
    if(eval {require Net::HTTP}){
	require Net::HTTP;
	my ($isbn)=@_;
 
	#my $query = "/msnmain?preferred_language=en&pg3=ALLF&s3=".$isbn."&l=20&reference_lists=show&simple_headlines=full&contributed_items=show&redirect=Providence%2C+RI+USA&Submit=Start+Search&fn=130&form=basicsearch";
	my $query = "/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&pg4=AUCN&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&r=1&s4=&s5=&s6=&s7=".$isbn."&s8=All&yearRangeFirst=&yearRangeSecond=&yrop=eq";
 
	my $s = Net::HTTP->new(Host => $amsServer) || die $@;
	$s->write_request(GET => $query, 'User-Agent' => "Mozilla/5.0");
	my($code, $mess, %h) = $s->read_response_headers;
 
	my $buf;
	while (1) {
	    my $tbuf;
	    my $n = $s->read_entity_body($tbuf, 1024);
	    die "read failed: $!" unless defined $n;
	    last unless $n;
	    $buf = $buf.$tbuf;
	}
        #TODO: check for no results
 
	#if($buf =~ /<a href=\".*\/msnmain\?fn=705[^>]+>([^<]+)<\/a><\/div>/i) {
	if($buf =~ /<a href="\/mathscinet\/search\/mscdoc.html\?code=[^>]+>([^<]+)<\/a>/){
	    print $isbn." AMS codes found ".$1;
	    return $1;
	}
    }
    return "";
}
 
1;

The usmarc_field_ams.tmpl

<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->AMS category type search<!-- TMPL_VAR name="biblionumber" --><!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 
<div id="main-compact">
	<h1>AMS category search for ISBN<!-- TMPL_VAR name="isbn" --></h1>
<form name="f_pop">
<p>
	  <label class="labelsubfield">&nbsp;&nbsp;ISBN:</label><input type="text" size="30" name="isbn" value="<!-- TMPL_VAR name="isbn" -->"/>
<input type="submit" value="Search again" class="submit"/></br>
</p>
	  <p>
	  <label class="labelsubfield">Result:</label><input type="text" size="30" name="f1" value="<!-- TMPL_VAR name="amsCodes" -->"/>
<input type="button" value="Fill and close" onclick="javascript:putBack();" class="submit"/>
<input type="hidden" name="plugin_name" value="usmarc_field_ams.pl"/>
<input type="hidden" name="index" value="<!-- TMPL_VAR name="index" -->"/>
</p>
</form>
<script language="JavaScript" type="text/javascript">
        function putBack() {
                opener.document.f.field_value[<!-- TMPL_VAR name="index" -->].value= document.f_pop.f1.value;
                self.close();
                return false;
        }
</script>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->

Leave a Reply

*