<?php

			include('correlation.php');
			include('echec_fonctions_communes.php');
			include('chessmaster.php');

			$datas = $_POST['datas'];
			$table_parties = array_filter(explode("\n", $_POST['datas']));
			
			$joueur = array();
			$sql = "SELECT * FROM classement ORDER by joueur asc"; 
			$results = mysql_query($sql);
								
			while($row = mysql_fetch_assoc($results))
			{
					$joueur[] = $row['joueur'];
			}
				
			// regenerer le classement
			mysql_query('TRUNCATE TABLE classement;');
			mysql_query('TRUNCATE TABLE evolution;');
			mysql_query('TRUNCATE TABLE parties;');
			mysql_query('TRUNCATE TABLE chessmaster;');
	
			stockage_joueurs_DB($joueur);
	
			$nb_parties = count($table_parties);

			for ($item=0; $item < $nb_parties ; $item++)
			{
				
				$pieces = explode(";", $table_parties[$item]);
			
				$donnees[0] = $pieces[0];
				list($jour, $mois, $annee) = explode('/', $donnees[0]);
				$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
			
				$donnees[0] = $timestamp;
				$donnees[1] = $pieces[1];
				$donnees[2] = $pieces[2];
				$donnees[3] = $pieces[3];
				$donnees[4] = $pieces[4];
			
				$indice = $item + 1;
				algo_elo($donnees, "nostatistique", "sql", $indice );
				chess_master($donnees,$indice);
	
			}
			
			echo 1;

?>