<?php
	session_start();
	include('database.php');
	DB_connexion(); 
	
	ini_set( 'display_errors', '0');
	error_reporting( 0 );
	
	/*if(!isset($_SESSION['logged']) )
	{		header ('Location: interdiction.php');
	}
	
	if($_SESSION['logged']== "no")
	{
		header ('Location: interdiction.php');
	}*/

/****************************************************************/	
	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;
	}
	
	if(isset($_SESSION['sauvegarde_formulaire']))
	{
		$_POST = $_SESSION['sauvegarde_formulaire'] ;
		unset($_SESSION['sauvegarde_formulaire']);		
	}	

/****************************************************************/		
	
	if( isset($_POST['valide_form']) && $_POST['valide_form'] == "ok" )
	  {
	  
		/*$champ_nom = $_POST["nom"];
		$champ_prenom = $_POST["prenom"];

		// creation d'une entrée dans la table
		$heure = date("H:i");
					
		$sql = "INSERT INTO joueurs( id, nom, prenom, score, partie ,date_inscription, heure_inscription) 
					VALUES('', '$champ_nom', '$champ_prenom', '1000' , '0'  , NOW(), '$heure' )"; 
					
		$requete = mysql_query($sql);*/
		
		$elo = 1000;
		$champ_nom = $_POST["nom"];
		$sql = " INSERT INTO classement ";
		$sql = $sql . " (joueur, elo, parties, prior) VALUES ";
		$sql = $sql . " ('$champ_nom', '$elo','$partie','$prior') ";
		$result = mysql_query($sql);
		$_SESSION['message'] = "ok";
		
		/*CREATE TABLE IF NOT EXISTS joueurs (
		id tinyint(4) unsigned NOT NULL AUTO_INCREMENT,
		nom varchar(30) NOT NULL DEFAULT '',
		prenom varchar(30) NOT NULL DEFAULT '',
		score varchar(30) NOT NULL DEFAULT '',
		partie varchar(30) NOT NULL DEFAULT '',
		date_inscription date NOT NULL DEFAULT '0000-00-00',
		heure_inscription time NOT NULL DEFAULT '00:00:00',
		PRIMARY KEY (id)
		)*/
		
		/*CREATE TABLE IF NOT EXISTS partie (
		id tinyint(4) unsigned NOT NULL AUTO_INCREMENT,
		joueur1 varchar(30) NOT NULL DEFAULT '',
		joueur2 varchar(30) NOT NULL DEFAULT '',
		resultat_partie varchar(30) NOT NULL DEFAULT '',
		score_joueur1 varchar(30) NOT NULL DEFAULT '',
		score_joueur2 varchar(30) NOT NULL DEFAULT '',
		date_partie date NOT NULL DEFAULT '0000-00-00',
		heure_partie time NOT NULL DEFAULT '00:00:00',
		PRIMARY KEY (id)
		)*/
	  
	  }
	
?>

<!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" xml:lang="fr" lang="fr" dir="ltr">
<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">
#bloc_ajouter_joueur { float: left;
					width: 831px; 
					padding: 50px 50px 25px 50px;
					}	
					
#navigation_tournoi{
					float: left;
					width: 910px; // 870
					padding: 10px 0px 0px 10px;
		}
					
					
p {
  margin-top: 0px;
}
 
fieldset {
  margin-bottom: 15px;
  padding: 10px;
}
 
legend {
  padding: 0px 3px;
  font-weight: bold;
  font-variant: small-caps;
}
 
label {
  width: 110px;
  display: inline-block;
  vertical-align: top;
  margin: 6px;
}					
					
input[type=submit] {
  width: 150px;
  padding: 10px;
}					
					
</style>

<script type="text/javascript">

function call_update()
{
	 ajax_routine(); 
	 setTimeout("call_update()", 1000); //appelle la fonction 1 fois par  seconde
}

/*function checkUser(user)
{
	if(user.value == '')// if the value property of the username field equals ''....
	{
		document.getElementById('info').innerHTML = '';// pass '' to the span
		return;
	}
	
	params = "user=" + user.value;// what we will send to the server
	request = new ajaxRequest();// create a new ajaxRequest object
	
	// Ajax call will go to zncheckuser.php which reports whether the username is available
	request.open("POST", "joueur_requete_ajax.php", true);// use the POST method, with the target url being zncheckuser.php, and request is handled asycnhronously
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");// next 3 lines set up headers to let server know a POST request is coming
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");
	
	request.onreadystatechange = function()
	{
		if(this.readyState == 4)
		{
			if(this.status == 200)
			{	
				if(this.responseText != null)
				{	
					document.getElementById('info').innerHTML = this.responseText;// the response to the Ajax call is  returned to the span
				}
				else alert("Ajax error: No data received");
			}
			else alert("Ajax error: " + this.statusText);
		}
	}
	
	request.send(params);
}
	*/
/*function ajaxRequest()
{
	try// Non IE Browser?
	{
		var request = new XMLHttpRequest();
	}
	catch(e1)
	{
		try// IE 6+?
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e2)
		{
			try//IE 5?
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e3)// there is no Ajax support
			{
				request = false;
			}
		}
	}
	return request;
}*/


</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 -->
<!---------------------------------------------------------->	
	
			<div class="barre_vide"></div>
			
			<div id="navigation_tournoi">
				<ul id="menu_horiz">
				<li class="tournoi_joueur_tag_selected"><a href="ajouter_joueur.php" title="aller à la section">Nouveau</a></li>
				<li class="tournoi_partie_tag"><a href="partie.php" title="aller à la section">Partie</a></li>
				<li class="tournoi_classement_tag"><a href="classement.php" title="aller à la section">classement</a></li>
				<li class="tournoi_liste_joueurs_tag"><a href="liste_joueurs.php" title="aller à la section">Joueurs</a></li>
				<li class="tournoi_stats_tag"><a href="historique.php" title="aller à la section">Historique</a></li>
				<li class="tournoi_securite_tag"><a href="admin.php" title="aller à la section">Admin</a></li>
				</ul>
			</div>
			
			<div id="bloc_ajouter_joueur">
	
			<form method="post" id="form_ajouter_joueur" action="ajouter_joueur.php" onsubmit="return valider_infos_joueur(this)" > 

				<fieldset style="width: 600px">
				<legend>Joueur </legend>
				<input type="hidden" name="valide_form" id="valide_form" value="" />
				<label for="nom">Nom</label>
                <input id="nom" type="text" name="nom" onKeyUp="verif_joueur(this.value, 'statut_nom')">     <span id='statut_nom'></span> <br>
				<!--
				<label for="Prenom">Prénom</label>
		        <input id="prenom" type="text" name="prenom" onKeyUp="verif_mot(this.value, 'statut_prenom')">     <span id='statut_prenom'></span> <br>
			-->
				<input id="send" name="send" type="submit" value="Enregistrer" />  <!-- <span id='statut_enregistrement'></span> -->
				 <br>
				  <br>
<?php
				if($_SESSION['message'] == "ok")
				{	echo '<div id="message_traitement" style="display:block">Inscription du joueur dans la base de donnée.</div>';
					$_SESSION['message'] = "none";
				}
?>						
				
				</fieldset>
			</form>
		
		
			</div>
		

			<br/>
			<br/>
			<br/>
			<br/>
			<br/>
           

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

	<script type="text/javascript">
		call_update()
	</script>

</body>
</html>
