#!/usr/local/bin/perl5

if ($ENV{QUERY_STRING}=~ /name=(france|italy|japan|china)/) {
   $search= $1;
} else {
  print("Location: index.cgi\n\n");
  exit(0);
}
$new= $ENV{QUERY_STRING}=~ /newjoin/;

if ($new) {
    $desc= "Welcome!";
} else {
    $desc="Introducing...";
}

open(POP, "people");

$count= 1;
$totalcount= 1;
$list= "";

while (<POP>) {
    ($name, $email, $effort, $team, $img, $haiku)= split(/\#\#\#/);
    if (($team eq $search) && ($totalcount > 4)) {
	$haiku=~ s!///!<br>!g;
	$list.= "<tr align=center>\n<td align=center>";
	if ($img ne "") {
	    $list.= "<a href=\"$img\"><img src=\"$img\" height=70 border=0></a>";
	} else {
	    $list.= "<img src=\"images/unknown.jpg\" height=70>";
	}
	$list.= "</td>\n";
	$list.= "<td align=center><font size=+1 face\"Arial,Helvetica,Geneva\"><a href=\"mailto:$email\">$name</a></font></td>\n";
	$list.="<td align=center><font face=\"Arial,Helvetica,Geneva\">$haiku</font></td>";
	$list.="</tr>\n";
	$count++;
    }
    elsif ($team eq $search) {
	$capmail = $email;
    }
	
    $totalcount++;
}

$pic = $search._pic;
$n = $search._name;
if ($search eq "japan") {
    if ($new) {
	$teamstr = "has chosen you to join her team of sous chefs...";
    }
    else {
	$teamstr = "and her team of sous chefs...";
    }
}
else {
    if ($new) {
	$teamstr = "has chosen you to join his team of sous chefs...";
    }
    else {
	$teamstr = "and his team of sous chefs...";
    }
}

print <<EOF;
Content-type: text/html

<html>
<head>
<title>List of Chefs</title>
</head>
<body bgcolor=#ffFFff>
<font face="Arial,Helvetica,Geneva">
<font size=+2>
<b>$desc</b>
</font>
<p>
<center><a href="mailto:$capmail"><img src=images/$n.gif border=0></a><br><img src=images/$pic.gif></center>
<p>
$teamstr
<p><center><table cellspacing=5 border=1 width=700>

$list

</table>
</center>

<p>
<a href=index.cgi><img src=images/home.gif></a>
</font>
</body>
</html>
EOF
    ;
