<?php
	session_start();
	include('database.php');
	DB_connexion(); 
	
	if(!empty($_POST) )
	{
		$_SESSION['sauvegarde_formulaire'] = $_POST ;
     
		$page_actuelle = $_SERVER['PHP_SELF'] ;
		if(!empty($_SERVER['QUERY_STRING']))
		{
			$page_actuelle .= '?' . $_SERVER['QUERY_STRING'] ;
		}
     
		header('Location: ' . $page_actuelle);
		exit;
	}
	
	/*$champ_login = "";
	$champ_nom = "";
	$champ_prenom = "";
	$champ_email = "";
	$champ_pass1 = "";
	$champ_pass2 = "";
	
	if(!empty($_POST["login"]))
	{	$champ_login = $_POST["login"];
	}
	if(!empty($_POST["nom"]))
	{	$champ_nom = $_POST["nom"];
	}
	if(!empty($_POST["prenom"]))
	{	$champ_prenom = $_POST["prenom"];
	}
	if(!empty($_POST["email"]))
	{	$champ_email = $_POST["email"];
	}
	if(!empty($_POST["pass1"]))
	{	$champ_pass1 = $_POST["pass1"];
	}
	if(!empty($_POST["pass2"]))
	{	$champ_pass2 = $_POST["pass2"];
	}*/
	
	if(isset($_SESSION['sauvegarde_formulaire']))
	{
		$_POST = $_SESSION['sauvegarde_formulaire'] ;
		unset($_SESSION['sauvegarde_formulaire']);		
	}			
	
	$champ_login = "";
	$champ_nom = "";
	$champ_prenom = "";
	$champ_email = "";
	$champ_pass1 = "";
	$champ_pass2 = "";
	
	if( isset($_POST['valide_form']) && $_POST['valide_form'] == "ok" )
	  {
	
					$champ_login = $_POST["login"];
					$champ_nom = $_POST["nom"];
					$champ_prenom = $_POST["prenom"];
					$champ_email = $_POST["email"];
					$champ_pass1 = $_POST["pass1"];
					$champ_pass2 = $_POST["pass2"];
	
					// Génération de la clef d'activation
                    $caracteres = array("a", "b", "c", "d", "e", "f", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
                    $caracteres_aleatoires = array_rand($caracteres, 8);
                    $cle_activation = "";
                         
                    foreach($caracteres_aleatoires as $i)
                         {
                              $cle_activation .= $caracteres[$i];
                         }
				
					$date = date("d-m-Y"); 
					$heure = date("H:i");
					$statut_compte = "creation";
					
					$sql = "INSERT INTO membres( id, login, nom, prenom, password, email, statut_compte, cle, avatar,date_inscription, heure_inscription) 
					VALUES('', '$champ_login', '$champ_nom', '$champ_prenom' , '$champ_pass2', '$champ_email' ,'creation', '$cle_activation', 'no_avatar.jpg', NOW(), '$heure' )"; 
					
					$requete = mysql_query($sql);
					
					$to = $champ_email;
					$from  = "admin@analog-design.net";  

					$jour  = date("d-m-Y");
					$heure = date("H:i");
					
					$chemin = getcwd();
					$pieces = explode("/", $chemin);
					$portion_path = "/" .$pieces[4] ."/" .$pieces[5] ."/" .$pieces[6];
					
					$sujet = "Activation de votre compte utilisateur";
                              
                    $message = "Pour valider votre inscription, merci de cliquer sur le lien suivant :\n";
					$message .= "http://" . $_SERVER["SERVER_NAME"] .$portion_path;
					$message .= "/activer_compte_utilisateur.php?id=" . mysql_insert_id();
                    $message .= "&cle=" . $cle_activation;
		
					//$message .= "http://" . $_SERVER["SERVER_NAME"];
                    //$message .= "/WORKAREA/WEBSITE/Online_16_02_2013/activer_compte_utilisateur.php?id=" . mysql_insert_id();
							  
					$local_or_public = $_SERVER["SERVER_NAME"];		  
					if($local_or_public != "localhost")
					{
						mail($to, $sujet, $message);
					}
					
					//echo '<body onLoad="alert(\'Votre inscription est prise en compte, pour activer votre compte, voir votre email \')">'; 
					
					$_SESSION['message'] = "ok";
					
					/// creation du répertoire de l'utilisateur
					chdir('Users');
					mkdir($champ_login);
					
					// creation d'une entrée dans la table
					$sql = "INSERT INTO user_online( id, login, connexion, session, time)
					VALUES('', '$champ_login', 'offline' , 'none' , '0' )"; 
				    $requete = mysql_query($sql);
					
					$champ_login = "";
					$champ_nom = "";
					$champ_prenom = "";
					$champ_email = "";
					$champ_pass1 = "";
					$champ_pass2 = "";
				
	}	
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Site perso,cours,ouvrages" />
<meta name="Keywords" content="WEBSITE perso " />
<meta name="Distribution" content="Global" />
<meta name="Robots" content="" />
<meta http-equiv="Content-Language" content="fr" />
<meta name="rating" content="general" />
<meta name="author" content="Patrice DELPY" />
<meta name="copyright" content="Copyright 2013" />
<meta name="generator" content="Patoche" />
<title>Patoche WEBSITE - 2013 - Template du site - en cours de développemment ...</title>
<!---------------------------------------------------------->	
<?php
		include('include_css_template_commun.php');
		include('include_css.php');
		include('css_tools_skill.php');
		include('include_javascript.php');

?>

<style type="text/css">
			 
</style>

<!-- diaporama -->
<link href="diaporama/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="diaporama/js/jquery.jDiaporama.js"></script>
<script type="text/javascript" src="diaporama/js/script.js"></script>

<!---------------------------------------------------------->	
</head>

<body>
<!---------------------------------------------------------->	
	<div class="main"> <!-- main -->
<!---------------------------------------------------------->	

          <div class="header">
                <div class="balise_titre">Patoche</div>
                <div class="balise_citation">
                &quot;Etre conscient que l'on est ignorant est un grand pas vers le savoir&quot;
                </div>
          </div> 
 
          <div class="banniere"></div>  

<!---------------------------------------------------------->
<?php
/*	include("include_barre_login.php");
	echo '<div id="box_icon">';
	include("debug_connexion_membre.php");
	echo '</div>';
	include("include_menu.php");*/
	
	echo '<div id="box_infos">';
			include("include_menu.php");
			
			echo '<div id="box_icon2">';
			include("connexion_membre.php");
			echo	'</div>';
			
			echo '<div id="box_icon3">';
			include("include_barre_login.php");
						
			echo	'</div>';

	echo	'</div>';
	$_SESSION['page_active'] = basename (__FILE__ );
?>

		

<!---------------------------------------------------------->	
            <div class="contenu"> <!-- contenu -->
<!---------------------------------------------------------->	
           
			
			<!--	<h2 class = "retrait">Exercices & problémes corrigés :</h2> -->
				
			<!--	onsubmit="return valider_inscription(this)" -->
				
			<div id="container_inscription">
			
				<form method="post" id="form_inscription" action="inscription.php" onsubmit="return valider_inscription_elo(this)">

				<h1>Inscription d'un Joueur:</h1>
				
				<input type="hidden" name="valide_form" id="valide_form" value="" />
				
				<div>
					<label for="login">Login</label>
					<input id="login" name="login" type="text" onKeyUp="verif_login(this.value, 'statut_login')" value = "<?php echo $champ_login; ?>"  />
					<span id="statut_login"></span>
				</div>
				
				<div>
					<label for="nom">Nom</label>
					<input id="nom" name="nom" type="text" onKeyUp="verif_mot(this.value, 'statut_nom')" value = "<?php echo $champ_nom; ?>"  />
					<span id="statut_nom"></span>
				</div>
			
				<div>
					<label for="prenom">Prénom</label>
					<input id="prenom" name="prenom" type="text" onKeyUp="verif_mot(this.value, 'statut_prenom')" value = "<?php echo $champ_prenom; ?>"  />
					<span id="statut_prenom"></span>
				</div>
			
				<div>
					<label for="email">E-mail</label>
					<input id="email" name="email" type="text" onKeyUp="verif_email(this.value)" value = "<?php echo $champ_email; ?>" />
					<span id="statut_email"></span>
				</div>
				
				<div>
					<label for="pass1">Password</label>
					<input id="pass1" name="pass1" type="password" onKeyUp="verif_password(this.value)" value = "" />
					<span id="statut_pass1"></span>
				</div>
				<div>
					<label for="pass2">Confirmer le password</label>
					<input id="pass2" name="pass2" type="password" onKeyUp="confirmation_password(this.value)" value = "" />
					<span id="statut_pass2"></span>
				</div>

				<div>
					<input id="send" name="send" type="submit" value="Inscription"/>
				</div>
				
<?php
				/*if($_SESSION['message'] == "ok")
				{	echo '<div id="message_traitement" style="display:block">Votre inscription est prise en compte, pour activer votre compte, voir votre email.</div>';
					$_SESSION['message'] = "none";
				}*/
?>		
				
				</form>
			</div>

<!---------------------------------------------------------->	
<?php			
            include('include_pied_page.php');
			include('include_publicite.php');
?>
<!---------------------------------------------------------->	
			</div>  <!-- contenu -->
<!---------------------------------------------------------->	
	</div>   <!-- main -->
<!---------------------------------------------------------->	

</body>
</html>
