<?php

##############################################################################
# forgotten.php3                                                             #
#                                                                            #
# Copyright ViralGames SARL 2000                                             #
##############################################################################

include("config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_mailing.php3");
include($BIB."bib_tables.php3");
include($BIB."bib_check_members.php3");

/*------------ TAG HEADER ----*/
$header_title = "Mot de passe Kestufoot oublié";
$header_description = "";
$header_keywords = "Mot de passe, pronostics, matchs de foot, pronostic gratuit, jeu de pronostics, jeu de foot, matchs de foot, pronostics gratuits.";
/*------------ /TAG HEADER ----*/

$sess = open_page($sessid);

$error = ""; 
# If form has been filled out
if (isset($modif)) {
  if (!checkemail($Email)){
    $error = $error.C_MAILINVALIDE."<br>"; 
  }
    
  # If no error
  if (empty($error)) {
    $search = main_db_query("SELECT * FROM Members LEFT JOIN Players ON Players.MemberId=Members.Id WHERE Email='$Email'");
    $result = db_fetch_array($search);
    if(empty($result)) {
      $error = $error."$Email ".C_NESTPASMB."<br>"; 
    }
  }
}

# If first visit or error
if( isset($modif) && empty($error) ) {  
  $subject = C_PWDTITLE;
  $message = C_PSEUDOEST.$result[NickName]."\n";

  $pass=genRandomPassword();
  main_db_query("UPDATE Members SET Password='".encryptePassword($pass)."' WHERE Email='".$result[Email]."'");
  
  $message.=C_PWDEST.
    " $pass\n" .
      C_CHANGERPWD."\n".C_ABIENTOTKTF." ".$SERVER_URL." \n\n"; 

  generic_mail($Email, $subject, $message,
	       "From: $FROM_FIELD\n" . 
	       "Reply-To: $REPLY_TO_FIELD\n" . 
	       "X-Mailer: PHP/" . phpversion());
  
  $info = "Un email contenant vos identifiants vient de vous être envoyé";
  //$sess->redirect($LOGIN_PAGE, "");
}

	$title = C_FORGOTTENTITLE;
	$title_image = "Titres/Titre-Mot-de-passe.gif";

	$page_courante='';
	$sub_header='subh_connecte.inc';
	$form_action = $sess->action($FORGOTTEN_PAGE);
	$form_name = "modif";

	include("header.inc");
	include("form_header.inc");
	include("mot-de-passe-oublie.inc"); 
	include("form_footer.inc");
	include("footer.inc");

close_page($sess);
?> 

