#!/usr/local/bin/perl

&cgi_init;

$essay = $queryelt{"ESSAY"};

srand();

$x = int(rand(3))+1;

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

if ($essay =~ /e_$/) {
  print "<HTML>
<HEAD>
<TITLE>QUOTES</TITLE>
</HEAD><body bgcolor=#000000 text=#ffdab9 LINK=#ffffff vlink=#ffdab9>
<CENTER>
<a href=./><img border=0 src=../gfx/nnn3.gif ismap></a><p>
You can read your reaction in the sentence-sizer.<p>
<FORM method=get action=./>Name:<BR>
<INPUT TYPE=hidden NAME=QUOTE VALUE=$quote>
<INPUT TYPE=text NAME=NAME SIZE=40,10><BR> <BR>
Your Reaction:<BR> 
<TEXTAREA NAME=TEXT ROWS=10 COLS=50></TEXTAREA><BR>
<BR> <BR>
<INPUT TYPE=submit VALUE=Submit border=0>
</FORM>
<BR>
<BR>
<A HREF=./><img src=../gfx/back.jpg border=0></a>

</CENTER></body></HTML>
";
} else {
print"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"120; URL=http://www.dds.nl/~n5mj/say/\">
<head><title>IsayUsaySsay</title></head>
<body background=../gfx/back_say.gif BGCOLOR=#000000 TEXT=#ffebcd LINK=#ffebcd vlink=#FFEBCD>
<map name=nnn>
<area shape=rect href=/~n5mj/quote/ coords=\"0,0,108,30\">
<area shape=rect href=/~n5mj/babylon/ coords=\"323,0,412,30\">
</map>
<center><a href=/cgi-bin/imagemap/~n5mj/map/nnnsay.map><img border=0 
usemap=#nnn ismap src=../gfx/nnn$x.gif></a><p>

<H1 ALIGN=CENTER><FONT SIZE=4>IsayUsaySsay</FONT></H1>

<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";

# read in all essays from current quote-dir

$n = 0;
opendir(DIR,"current");
while ($e = readdir(DIR)) {
  if ($e =~ /^e_/) {

    $essays[$n] = $e;
    $n++;
  }
}
closedir(DIR);

$i = 0;
$j = $n;
while ($j > 0) {
  $x = int(rand($n));
  while ($essays[$x] eq "") {
    $x = int(rand($n));
  }
  $essay[$i++] = $essays[$x];
  $essays[$x] = "";
  $j--;
}

if ($essay[0]) {
  open(IN,"current/$essay[0]");
  $_ = <IN>; chop;
  print "  <TR>
<TD><FONT SIZE=6><a href=current/t$essay[0].htm>$_</a></FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=5>$_<BR>";
  $_ = <IN>; chop;
  print "$_</FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=3>$_";
  $_ = <IN>; chop;
  print "</FONT><Br>$_</p></TD>";
  close(IN);
}

print "<TD><BR CLEAR=RIGHT>
<BR CLEAR=RIGHT>
<br>
";

if ($essay[1]) {
  open(IN,"current/$essay[1]");
  $_ = <IN>; chop;
  print "<TD><FONT SIZE=6><a href=current/t$essay[1].htm>$_</a></FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=5>$_<BR>";
  $_ = <IN>; chop;
  print "$_</FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=3>$_";
  $_ = <IN>; chop;
  print "</FONT><Br>$_</p></TD>";
  close(IN);
}

print "</tr>
  
<tr>
<TD>
<BR CLEAR=LEFT>
<BR CLEAR=LEFT>
<BR CLEAR=LEFT>
<BR CLEAR=LEFT>
";
if ($essay[2]) {
  open(IN,"current/$essay[2]");
  $_ = <IN>; chop;
  print "<BLOCKQUOTE><FONT SIZE=6><a href=current/t$essay[2].htm>$_</a></FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=5>$_<BR>";
  $_ = <IN>; chop;
  print "$_</FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=3>$_";
  $_ = <IN>; chop;
  print "</FONT><Br>$_</p></TD>";
  close(IN);
}

if ($essay[3]) {
  open(IN,"current/$essay[3]");
  $_ = <IN>; chop;
  print "
<TD><FONT SIZE=6><a href=current/t$essay[3].htm>$_</a></FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=5>$_<BR>";
  $_ = <IN>; chop;
  print "$_</FONT><BR>";
  $_ = <IN>; chop;
  print "<FONT SIZE=3>$_";
  $_ = <IN>; chop;
  print "</FONT><Br>$_</p></TD></tr>";
  close(IN);
}

print "</td></tr></TABLE>

<p><br>
</p>
<CENTER><a href=/cgi-bin/imagemap/~n5mj/map/si_bi.map><img border=0 src=../gfx/si_bi2.gif ismap></a><BR>
</CENTER></body></HTML>

";

sub cgi_init
{
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
	if ($ENV{'CONTENT_TYPE'} ne 'application/x-www-form-urlencoded')
	{
		print
		  'Content type must be application/x-www-form-urlencoded'.$nl;
		exit 1;
	}
	read(STDIN, $qstring, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'QUERY_STRING'})
{
	$qstring = $ENV{'QUERY_STRING'};
} else
{
	$qstring = '';
}

@querylist = split(m'&', $qstring);

for $i (@querylist)
{
	($key,$value) = split(/=/, $i);
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$queryelt{$key} = $value;
}
}

}
