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:
- create the usmarc_field_ams.pl script (intranet-cgi/value_builder)
- create the usmarc_field_ams.tmpl file (intranet-html/intranet-tmpl/npl/en/value_builder/)
- link the script with the tag 084, subfield 2 in the MARC structure definition (http://article.gmane.org/gmane.comp.misc.koha/3093/match=084)
The usmarc_field_ams.pl
<pre lang="perl">
#!/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></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[^">]+>([^/i) {
if($buf =~ /</a><a ams="" codes="" found="" href="\/mathscinet\/search\/mscdoc.html\?code=[^>]+>([^<]+)<\/a>/){
print $isbn." return="">
<h2>The usmarc_field_ams.tmpl</h2>
<pre lang="xml">
AMS category type search
<div id="main-compact">
<h1>AMS category search for ISBN</h1>
<form name="f_pop">
<p>
<label class="labelsubfield"> ISBN:</label><input isbn="" name="isbn" size="30" type="text" value="<!-- TMPL_VAR name="></input>"/>
<input class="submit" type="submit" value="Search again"></input>
</p>
<p>
<label class="labelsubfield">Result:</label><input amscodes="" name="f1" size="30" type="text" value="<!-- TMPL_VAR name="></input>"/>
<input class="submit" onclick="javascript:putBack();" type="button" value="Fill and close"></input>
<input name="plugin_name" type="hidden" value="usmarc_field_ams.pl"></input>
<input index="" name="index" type="hidden" value="<!-- TMPL_VAR name="></input>"/>
</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>
</div></a>