#!/usr/bin/perl
#############################################################################
# Script: prorapid.cgi
# Author: Scott Stockton
# Date: 10/31/2005
# Description:
#############################################################################
# Comments
#############################################################################
#############################
# Set required includes
#############################
use CGI qw(-oldstyle_urls);
use LWP;
use URI::URL;
#############################
# Subprocedure Forward Declarations
#############################
sub header;
sub footer;
sub get_libraries;
sub get_recinfo;
sub lib_select_form;
#############################
# Set required variables
#############################
$workdir = "/www/docs/alliance/prospector/rapid/";
$header_file = "$workdir" . "prorapid_head.html";
$footer_file = "$workdir" . "prorapid_foot.html";
$libraries_file = "/home/rnelson/rapid_libraries.txt";
$my_url = "http://www.coalliance.org/prospector/rapid/prorapid.cgi";
###########################################################
# Main Proc
&get_libraries;
my $qry = new CGI;
if ($qry->param('title')) {
$my_title = $qry->param('title');
}
elsif ($qry->param('rft.jtitle')) {
$my_title = $qry->param('rft.jtitle');
}
if ($qry->param('issn')) {
$my_issn = $qry->param('issn');
}
elsif ($qry->param('rft.issn')) {
$my_issn = $qry->param('rft.issn');
}
# Handle the redirection after a library has been selected
if ($qry->param('lib_selected')) {
$my_lib = $qry->param('library');
$my_destination = "$lib_list{$my_lib}[2]";
$my_destination =~ s/[\n\r\f]//g;
if ($my_destination =~ /\?/) {
$connector = "&";
}
else {
$connector = "?";
}
if ($lib_list{$my_lib}[0] =~ /Colorado State University/) {
if ($my_title) {
$my_destination .= "$connector" . "rft.jtitle=$my_title";
}
if ($my_issn) {
$my_destination .= "&" . "rft.issn=$my_issn";
}
}
else {
if ($my_title) {
$my_destination .= "$connector" . "title=$my_title";
}
if ($my_issn) {
$my_destination .= "&" . "issn=$my_issn";
}
}
# print $qry->header;
# &header;
# print qq(Original URL: "$lib_list{$my_lib}[2]" \n);
# print qq(URL: "$my_destination" \n);
# print qq(Connector: "$connector" \n);
# &footer;
print $qry->redirect($my_destination);
}
# Handle the initial display of the form
else {
print $qry->header;
&header;
&lib_select_form;
&footer;
}
exit;
# End Main Proc
###########################################################
###########################################################
# Sub Procedures
#############################
# header reads in the html header file
#############################
sub header {
if (open(H, "<$header_file")) {
while () {
print;
}
close H;
}
}
#############################
# footer reads in the html footer file
#############################
sub footer {
if (open(F, "<$footer_file")) {
while () {
print;
}
close F;
}
}
#############################
# get_libraries reads in the text file with the list of libraries.
#############################
sub get_libraries {
if (-r $libraries_file ) {
open(LIBS, "<$libraries_file") or die "Couldn't open library file\n";
while ($line = ) {
chomp $line;
($lib_num, $lib_name, $lib_code, $lib_res_url) = split(/\|/, $line);
$lib_list{$lib_num} = ["$lib_name", "$lib_code", "$lib_res_url"];
}
close LIBS;
}
return $lib_list;
}
#############################
# get_recinfo tries to connect to prospector to find the issn and title
#############################
sub get_recinfo {
$ua = new LWP::UserAgent;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0 ");
$req = new HTTP::Request('GET',"$my_src");
$response = $ua->simple_request($req);
$rescode = $response->code;
if ($response->is_success) {
$prospector_page = $response->content;
}
}
#############################
# lib_select_form presents the user with a drop-down form to select a library.
#############################
sub lib_select_form {
print qq(
\n);
print qq(Request an Article:
With which institution are you affiliated ?
\n);
print qq();
print qq(
);
print qq(
\n);
}
# End Sub Procedures
###########################################################