#!/usr/bin/perl -w
# --------------------------------------------------------------------------------- 
# Author: James Brunskill (Library/University of Waikato) - brunskil@waikato.ac.nz 
# Original Release Date: 09/03/2007
# Last Updated : 09/03/2007
#
# Description/Purpose:
# Automatically redirects an OpenURL Request to the voyager catalog, based on title search
#
# --------------------------------------------------------------------------------- 
use strict;
use CGI;

my $q=new CGI;

my $catalog_url="http://waikato.lconz.ac.nz/cgi-bin/Pwebrecon.cgi?DB=local&SAB1={TITLE}&BOOL1=as+a+phrase&FLD1=Title+%28TKEY%29&GRP1=OR+with+next+set&SAB2={ISBN}&BOOL2=all+of+these&FLD2=ISBN%2FISSN+%28SSBN%29&GRP2=AND+with+next+set&SAB3=&BOOL3=all+of+these&FLD3=Keyword+Anywhere+%28GKEY%29&CNT=25&HIST=1";

# grab the title parameter

my $title = $q->param('title') || '';
my $isbn = $q->param('isbn') || '';

if ( $title eq "" && $isbn eq "")
{
print $q->header();

print "Sorry this is not a valid search!";

}
else
{
#update the catalog url to include the ISBN and Title
$catalog_url =~ s/{TITLE}/$title/g;
$catalog_url =~ s/{ISBN}/$isbn/g;

#Redirect this page to the catalogue search
print $q->redirect("$catalog_url");
}
