#!/usr/bin/perl

use DBI;
use CGI qw/:standard/;

my $thepara = param('pval');
my $thepara2 = param('afield');
my $cnt = 0;
my $totcnt = 0;
#$ENV{"ORACLE_HOME"} = "/u01/home/dba/oracle/product/8.0.5";
$dbh=DBI->connect ("DBI:Oracle:host=172.20.138.6;sid=ORA1;port=1521","scha","chaora") or die "Did not connect to database";

print "Content-Type: text/html\n\n";

print "<html>\n";
print "<body>\n";
print "<center>\n";
print "<table border=0><tr>\n";

print "<form action=\"printall.pl\">\n";

print "<td>Author Name: </td><td><INPUT TYPE=\"input\"  name=\"afield\" value=\"$thepara2\"></td>\n";

print "<td>Publication type: </td><td>\n";
print "<SELECT name = \"pval\">\n";

print "<OPTION value=\"0\">All types\n";
if($thepara == 1) {
     print "<OPTION value=\"1\" selected>Journals\n";
 }
else {
     print "<OPTION value=\"1\">Journals\n";
 }
if($thepara == 2) {
    print "<OPTION value=\"2\" selected>Book Chapters\n";
}
else {
    print "<OPTION value=\"2\">Book Chapters\n";
}
if($thepara == 3) {
    print "<OPTION value=\"3\" selected>Proceedings\n";
}
else {
    print "<OPTION value=\"3\">Proceedings\n";
}
if($thepara == 4) {
    print "<OPTION value=\"4\" selected>Tech Report\n";
}
else {
    print "<OPTION value=\"4\">Tech Report\n";
}
print "</select></td>\n";
print "<td><INPUT TYPE=\"Submit\" value=\"Search\" name=\"asearch\">\n";
print "</td><td><INPUT TYPE=\"Reset\"></td></form>\n";
print "<form 
action=\"http://vulcan.seidenberg.pace.edu/~scha/FPAR.html\">\n";
print "<td><INPUT TYPE=\"Submit\" value=\"About\"></td></form>\n";

print "</tr></table>\n";





print "<br><p>\n";
$sth=$dbh->prepare("select affiliation, a_email, a_url, a_title, a_rank, a_pic from Authors where a_name = '$thepara2'");
$sth->execute;

print "<table border = 0 width=500>\n";

($theaff,$theem,$theurl,$thetit,$therank,$thepic) = $sth->fetchrow();
$sth->finish;

print "<tr><td valign=top><img src=\"$thepic\"></td>\n";
print "<td width=20></td>\n";
print "<td valign=top><br><p>$thetit $thepara2<br>\n";
print "$therank<br>\n";
print "$theaff<br>\n";
print "Email = <A HREF=\"mailto:$theem\">$theem</a><br>\n";
print "URL = <A HREF=\"$theurl\">$theurl</a><br>\n";

print "</td></tr>\n";
print "</table>\n";
print "</center>\n";



if ($thepara == 1 || $thepara == 0) {
    $sth=$dbh->prepare("select distinct Paper.P_ID, Paper.Title, Paper.Year, Paper.Page, Journal.volume, Journal.issue, Journal.Jname from Paper, Journal, writes  where Paper.P_ID = Journal.P_ID and writes.P_ID = Paper.P_ID and writes.a_name like '$thepara2%' order by Paper.Year desc");
    $sth->execute;
    print "<h3>Journal</h3>\n";
    print "<center>\n";
    print "<table border = 1 width=900>\n";
    print "<tr><th>.</th><th width=200>Title</th><th>Journal</th><th>Volume</th><th>Year</th><th>Page</th></tr>\n";


    while (($thepid,$thetitle,$theyear,$thepage,$thevol,$theissue,$thejname) = $sth->fetchrow())  {
	$cnt++;
	$totcnt++;
	print "<tr><td valign=top>$cnt</td><td valign=top><A HREF=\"jpsearch.pl?v=$thepid\">$thetitle</A></td><td valign=top>$thejname</td><td valign=top>$thevol ($theissue)</td><td valign=top>$theyear</td><td valign=top>$thepage</td></tr>\n";
    }
    $sth->finish;
    print "</table>\n";
    print "There are $cnt Journal Papers for $thepara2.\n";
    print "</center>\n";
}

if ($thepara == 2 || $thepara == 0) {
    $sth=$dbh->prepare("select distinct Paper.P_ID, Paper.Title, Paper.Year, Paper.Page, Bchap.Btitle, Bchap.Editors from Paper, Bchap, writes where Paper.P_ID = Bchap.P_ID  and writes.P_ID = Paper.P_ID and writes.a_name like '$thepara2%'  order by Paper.Year desc");
    $sth->execute;

    print "<h3>Book Chapters</h3>\n";
    print "<center>\n";
    print "<table border = 1 width=900>\n";
    print "<tr><th>.</th><th width=200>Title</th><th>Book Title</th><th>Editors</th><th>Year</th><th>Page</th></tr>\n";

    $cnt = 0;
    while (($thepid,$thetitle,$theyear,$thepage,$thebtit,$theedit) = $sth->fetchrow())  {
	$cnt++;
	$totcnt++;
	print "<tr><td valign=top>$cnt</td><td valign=top><A HREF=\"bcpsearch.pl?v=$thepid\">$thetitle</A></td><td valign=top>$thebtit</td><td valign=top>$theedit</td><td valign=top>$theyear</td><td valign=top>$thepage</td></tr>\n";
    }
    $sth->finish;
    print "</table>\n";
    print "There are $cnt Book Chapter Papers for $thepara2.\n";
    print "</center>\n";
}

if ($thepara == 3 || $thepara == 0) {
    $sth=$dbh->prepare("select distinct Paper.P_ID, Paper.Title, Paper.Year, Paper.Page, Paper.Publisher, Conf.cname, Conf.theurl  from Paper, Conf, writes  where Paper.P_ID = Conf.P_ID and Conf.refereed = 'Y'  and writes.P_ID = Paper.P_ID and writes.a_name like '$thepara2%'  order by Paper.Year desc");
    $sth->execute;

    print "<h3>Refereed Conference Proceedings</h3>\n";
    print "<center>\n";
    print "<table border = 1 width=900>\n";
    print "<tr><th>.</th><th width=200 valign=top>Title</th><th>Conference</th><th>Publisher</th><th>Year</th><th>Page</th></tr>\n";

    $cnt = 0;
    while (($thepid,$thetitle,$theyear,$thepage,$thepub,$thecname,$theurl) = $sth->fetchrow())  {
	$cnt++;
	$totcnt++;
	print "<tr><td valign=top>$cnt</td><td><A HREF=\"cpsearch.pl?v=$thepid\">$thetitle</A></td><td valign=top><A HREF=\"$theurl\">$thecname</A></td><td valign=top>$thepub</td><td valign=top>$theyear</td><td valign=top>$thepage</td></tr>\n";
    }
    $sth->finish;

    print "</table>\n";
    print "There are $cnt refereed conference proceeding Papers for $thepara2.\n";
    print "</center>\n";


    $sth=$dbh->prepare("select distinct Paper.P_ID, Paper.Title, Paper.Year, Paper.Page, Paper.Publisher, Conf.cname, Conf.theurl  from Paper, Conf, writes  where Paper.P_ID = Conf.P_ID and Conf.refereed = 'N'  and writes.P_ID = Paper.P_ID and writes.a_name like '$thepara2%'  order by Paper.Year desc");
    $sth->execute;


    print "<h3>Unrefereed Conference Proceedings</h3>\n";
    print "<center>\n";
    print "<table border = 1 width=900>\n";
    print "<tr><th>.</th><th width=200>Title</th><th>Conference</th><th>Publisher</th><th>Year</th><th>Page</th></tr>\n";

    $cnt = 0;
    while (($thepid,$thetitle,$theyear,$thepage,$thepub,$thecname,$theurl) = $sth->fetchrow())  {
	$cnt++;
	$totcnt++;
	print "<tr><td valign=top>$cnt</td><td valign=top><A HREF=\"cpsearch.pl?v=$thepid\">$thetitle</A></td><td valign=top><A HREF=\"$theurl\">$thecname</A></td><td valign=top>$thepub</td><td valign=top>$theyear</td><td valign=top>$thepage</td></tr>\n";
    }
    $sth->finish;
    print "</table>\n";
    print "There are $cnt unrefereed conference proceeding Papers for $thepara2.\n";
    print "</center>\n";
}


if ($thepara == 4 || $thepara == 0) {
    $sth=$dbh->prepare("select distinct Paper.P_ID, Paper.Title, Paper.Year, tech_rep.institute from Paper, tech_rep, writes where Paper.P_ID = tech_rep.P_ID  and writes.P_ID = Paper.P_ID and writes.a_name like '$thepara2%'  order by Paper.Year desc");
    $sth->execute;

    print "<h3>Technical Reports</h3>\n";
    print "<center>\n";
    print "<table border = 1 width=900>\n";
    print "<tr><th>.</th><th width=200>Title</th><th>Institute</th><th>Year</th></tr>\n";

    $cnt = 0;
    while (($thepid,$thetitle,$theins,$theyear) = $sth->fetchrow())  {
	$cnt++;
	$totcnt++;
	print "<tr><td valign=top>$cnt</td><td valign=top><A HREF=\"trsearch.pl?v=$thepid\">$thetitle</A></td><td valign=top>$theins<td valign=top>$theyear</td></tr>\n";
    }
    $sth->finish;
    print "</table>\n";
    print "There are $cnt technical reports for $thepara2.\n";
    print "</center>\n";
}
    print "Total $totcnt papers for $thepara2 retrieved.\n";


print "</body>\n";
print "</html>\n";
$dbh->disconnect;
