<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>


<?php
include("../config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_calcul_points.php3");
include($BIB."bib_admin.php3");
include($BIB."calcul_performance.php3");


# pas de timeout possible qql soit l'action effectuée
set_time_limit($TIME_LIMIT);

# d'abord les dynasties
$players = main_db_query("SELECT Id,NickName FROM Players");

if (isset($DISPLAY))
{
	echo "Mise à jour des performances des ".db_num_rows($players)." joueurs<br>";
}

$i=1;
$current_european_date = date("Y-m-d H:i:s", my_local_time());
$CurTour = db_fetch_array(main_db_query("SELECT * FROM Tours Where EndTime>'".$current_european_date."' AND ShowTime<'".$current_european_date."' AND Done='0'"));

# on supprime le contenu de la table des stats
main_db_query("DELETE FROM Stats");

while ($player=db_fetch_array($players))
{
	if (isset($DISPLAY))
	{
		echo "<span class=smallDark>".$i.". ".$player[NickName]."</span> : ";
		flush();
	}

	// Calcul des perfs totales du joueur

	$TourPerfs = calcul_performance($player[Id],"",$CurTour[ShowTime], $CurTour[EndTime], "");
	$GenPerfs = calcul_performance($player[Id],"","", "", "");

	$TourReussite = $TourPerfs[2] + $TourPerfs[3];
	$GenReussite = $GenPerfs[2] + $GenPerfs[3];
	
	# on insere les stats du joueurs
	$CurRows=main_db_query("INSERT INTO Stats (PlayerId, TourExacts, TourGagnants, TourPerdants, Exacts, Gagnants, Perdants,  TourPerformance, Performance, TourNbParis, NbParis, TourReussite, Reussite)  VALUES ('".$player[Id]."', '".$TourPerfs[2]."', '".$TourPerfs[3]."', '".$TourPerfs[4]."', '".$GenPerfs[2]."', '".$GenPerfs[3]."', '".$GenPerfs[4]."',  '".$TourPerfs[1]."', '".$GenPerfs[1]."', '".$TourPerfs[5]."', '".$GenPerfs[5]."','".$TourReussite."','".$GenReussite."')");

	if (isset($DISPLAY))
	{
		echo " TourPerformance='".$TourPerfs[1]."', Performance='".$GenPerfs[1]."'<br>";
		flush();
	}
	$i++;
}

if (isset($DISPLAY))
{
	echo "Fin de la mise à jour des stats <br>";
		flush();
}

?>