#!/usr/local/bin/perl 
my $INCLUDE_HEADER=($ENV{'DOCUMENT_ROOT'}||"/home/httpd/html");
require "/home/sites/site3/lokad/header1.inc";
print "<head>
<title>IAAPA Membership Verification Page</title>
</head>
<P><BR><BR>";
use CGI;
$q=new  CGI;
$playercode=$q->param('playercode'); 
$playernr = $q->param('playernr'); 
$alias =$q->param('alias');
$email =$q->param('email');
if (length($playercode) == 0 && length($playernr.$email.$alias) > 0 ) {
#
#   This is if only playernr was entered as playerid
#
print"<H2>IAAPA Membership Verification Page</H2>
</center>";
if ($alias ne "") { ($qalias = $alias) =~ tr /a-z/A-Z/; $condit = "alias like '$qalias%'";}
if ($email ne "") {  @pl2 = split("@",$email); ($qalias = @pl2[0]) =~ tr /a-z/A-Z/; $condit = "playerid like '$qalias%'";}
if ($playernr ne "") { $condit = "playernumber = $playernr";}
  $query = "select playernumber, playercode, emailaddress, alias from players where $condit";
  die "Try to create cursor on players stopped\n" unless ($cursor = $dbh->prepare($query));
  $cursor->execute;
  if  (@row=$cursor->fetchrow) {
#       if there is line found in players 
     if (@row[0] > 0 && @row[1] > 0 &&  length(@row[2]) != 0) {
#
#             Here we have a player with playercode  playerid and emailaddress
#             And we send his playercode and playerid to him with sendmail
#  
	         
	 $dx=localtime(time());
	 @d2=split( " ", $dx);
	 $dagsx=@d2[0].", ".@d2[2]." ".@d2[1]." ".@d2[4]." ".@d2[3]." -0500";
         open(SMAIL,"|/usr/sbin/sendmail @row[2]") or die "Could not start sendmail\n";
		printf(SMAIL "From: engineering\@axisandallies.net\n");
		printf(SMAIL "To: %s\n",@row[2]);
		printf(SMAIL "Subject: Information on your IAAPA Membership\n",$gn);
		printf(SMAIL "Date: %s\n",$dagsx);
		printf(SMAIL "MIME-Version: 1.0\n");
		printf(SMAIL "Content-Type: text/plain; charset=iso-8859-1\n");
		printf(SMAIL "Content-Transfer-Encoding: 8bit\n\n");
		printf(SMAIL "\n\n Player Number: %d \n Password: %d\n\nAlias: %s\n\n",@row[0],@row[1],@row[3]);
		printf(SMAIL "Make sure you make note of this information for future reference\n");
                printf(SMAIL "and also ensure your player information is correct on \n");
                printf(SMAIL "site.  Remember your association alias is used for\n");
                printf(SMAIL "the user name when logging on to member only areas of the site\n");
	close(SMAIL);  
     print("<br><br><center><p><h2>Your query has been successful</h2><p><br> <h2>Your player number, alias and password were found in the IAAPA database and have been sent to your email address <i>@row[2]</i> by email.  Please check your incoming mail folder for your membership information. <br> In this email you will receive a player number and a password, use them on this page to continue.  Note that your alias is your user name for the member areas of the site, your player number is used for game challenges and your password is used in both cases</h2></p><BR>");   
     print("<FORM METHOD=POST ACTION=/cgi-local/axis/players.cgi><TABLE>");
     print("<TD>Player number <TD><input name=playernr><TR>"); 
     print("<TD>Password <TD><input name=playercode><TR>");
     print("<TD> <INPUT TYPE=submit VALUE='Get member'></table></FORM>");
        } 
# end of have number code and email
          else { 
print"<H2>IAAPA Membership Verification Page</H2>
</center><br><br>";
print("<P>Unfortunately your ID was not found in the member database having playernumber and password. Please check your spelling or contact the IAAPA Help Desk</P>");}}   
#             /* if line found ends */
        else { 
           print("<P>Unfortunately your ID was not found in the members base having playernumber and playercode</P>");}
   } 
# end of if only number entered as playerid 
   else {
   if (length($playercode) == 0 || length($playernr) == 0) {
print"<H2>IAAPA Membership Verification Page</H2>
</center><br><br>";
     print("<br><br><center><p><h2>If you don't know your player number or password please enter either your alias or the start of your email address.  In a couple minutes you will be emailed your player number and password if you have one in the IAAPA database</h2></p><BR>");   
     print("<FORM METHOD=POST ACTION=/cgi-local/public/index.cgi><TABLE>");
     print("<TD>Email address start: <TD><input name=email><TR>"); 
     print("<TD>Alias <TD><input name=alias><TR>"); 
     print("<TD> <INPUT TYPE=submit VALUE='Get member'></table></FORM>");}
  else {   
      $query = "select playerid, firstnam, lastname, rank, points,
         gamespl, Record, gameswon, gamelost, resetwon, reslost, gamesgm, Resetrec,
         joined, comments, playernumber, playercode, emailaddress, playerpool, poolspeed,
         city, state, Country, phone, oldemail, alias from players
          where playernumber = $playernr  and playercode =  $playercode";
	$poolopt="<option value='1'>Cheeth < 24h<option  value='2'>wolf < 48h<option value='3'>Hound < 3 days</select>";
       open(MYSQL, "$myexec \"$query\"|");
       if (<MYSQL>) {
          while (<MYSQL>){
          chomp;
          @row=split('\t',$_); }
       close(MYSQL); 
#       die "Try to create cursor on players stopped\n" unless ($cursor = $dbh->query($query));

#       if (@row = $cursor->fetchrow){
	if (@row[19]> 0 ) {$poolopt=~s/@row[19]'/@row[19]' SELECTED/g;}
            $checkch="select chpl1 from chgames where chpl2 = '@row[0]'";
       $checkgames="select gameno, confirmed from games where confirmed  = 'N' and (upper(gm) like '@row[0]%' or  pl2nr = $playernr  )";
       die "Try to create cursor on games stopped\n" unless ($games = $dbh->query($checkgames));
       die "Try to create cursor on challengers stopped\n" unless ($chcursor = $dbh->query($checkch));
       if (@chrow = $chcursor->fetchrow){
          $chall = "<TD><H3>You have challengers<td> <a href=/cgi-local/axis/Acceptch.cgi?code=$playercode&nr=$playernr> View challenges</a>";}
       else {$chall = "";}  
       if (@gamrow = $games->fetchrow){
          $gamesconfirm = "<TD><H3>You have unconfirmed gamefinish<td> <a href=/cgi-local/axis/confirmgamefinish.cgi?playercode=$playercode&alias=@row[25]&gameno=@gamrow[0]> Confirm gamefinish</a>";}
       else {$gamesconfirm = "";}  
print"<H2>IAAPA Membership Information update Page</H2>
</center>";
print("<FORM METHOD=POST ACTION=/cgi-local/axis/updateplayer.cgi>");
print("<table><td>Player ID<td>@row[0]$chall<tr>");
print("<td>Alias<td><input name=alias type=text align=left value=\"@row[25]\"><tr>");
print("<td>Firstname<td><input name=firstname type=text align=left value=\"@row[1]\"><td>Start a <a href=/cgi-local/axis/Gamestart.cgi?playernumber=$playernr&playercode=$playercode>new game </a><tr>");
print("<td>Lastname<td><input name=lastname type=text align=left value=\"@row[2]\">$gamesconfirm<tr>");
print("<td>Email address<td><input name=email type=text align=left value=@row[17]><tr>");
print("<td>City<td><input name=city type=text align=left value=\"@row[20]\"><tr>");
print("<td>State<td><input name=state type=text align=left value=\"@row[21]\"><tr>");
print("<td>Country<td><input name=Country type=text align=left value=\"@row[22]\"><tr>");
print("<td>Phone<td><input name=phone type=text align=left value=\"@row[23]\"><tr>");
@row[18]=~s/Y/CHECKED/g;
print("<td>Playerpool<td><input name=playerpool type=checkbox  value='Y' @row[18]><tr>");
print("<td>Speed<td><SELECT name=poolspeed>$poolopt<tr>");
print("<td>Joined<td>@row[13]<tr>");
print("<td>Rank<td>@row[3] @row[4]<tr>");
print("<td>Record<td><@row[5]> @row[6]<tr>"); 
print("<td>Old email address<td><@row[24]><tr>");
print("<td>Comments<td><input name=comments type=text align=left value='@row[14]'><tr>");
print("<input type=hidden name=playercode value=$playercode><input type=hidden name=playernr value=$playernr>");
     print("<TD> <INPUT TYPE=submit VALUE='Update member'></table></FORM>"); 
}
else{
print"<H2>IAAPA Membership Verification Page</H2>
</center><br><br>";
     print("<center><h4>The playernumber and password don't match</h4><br><br>"); 
     print("<FORM METHOD=POST ACTION=/cgi-local/public/index.cgi><TABLE>");
     print("<TD>Player number <TD><input name=playernr value=$playernr><TR>"); 
     print("<TD>Password <TD><input name=playercode value=$playercode><TR>"); 
     print("<TD> <INPUT TYPE=submit VALUE='Get member'></table></FORM>"); 
}}}

print "<BR><BR> <A HREF=/cgi-local/public/index.cgi><IMG src=/images/back.gif></A>"; 
