<?php

			include('correlation.php');
			include('echec_fonctions_communes.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;');
	
			stockage_joueurs_DB($joueur);
	
			$nb_parties = count($table_parties);
/*			
			$jour = date('d-m-Y');
			$heure = date("H_i_s");
			$infos = $jour.'-'.$heure;
			$filename = "sauvegarde_edition_" .$infos .".txt"; 
			//chdir("sauvegarde_echec");
											
			$fp = fopen($filename, 'a+'); 
			for ($i=0; $i < $nb_parties; $i++)
			{
				fputs ($fp, $table_parties[$i]);
				if($i != $nb_parties - 1)
					fputs($fp, "\n");
			}
						
			fclose($fp);
*/	
			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 );
	
			}
			
			
			echo 1;
			

?>