<?php
###########################################################
# script générant le fichier "Public/banniere_stats.php3" #
# à lancer périodiquement                                 #
###########################################################

include("../config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_drapeaux.php3");

$fdest = fopen($GAME_DIR."Public/banniere_stats.php3","w+");
echo $GAME_DIR."Public/banniere_stats.php3<br>";
 fwrite ($fdest,
"<html>
<head>
	<title>Les statistiques KestuFoot</title>
</head>
<link rel=\"stylesheet\" href=\"".$SERVER_URL."common.css\">
<link rel=\"stylesheet\" href=\"".$SERVER_URL."links.css\">
<body bgcolor=".$BG_COLOR_FOND_2.">");

function flag($equip)
{
    global $FRUITS,$FRUIT_NAMES,$FRUIT_LIST, $INVISIBLE_FRUIT;

    for ($i=0;$i<$FRUITS;$i++)
	{
		if (strcmp($equip,$FRUIT_NAMES[$i])==0)
		{
			$ok = true;
			break;
		}
	}
	
	if ($ok)
		return $FRUIT_LIST[$i];
	else
		return $INVISIBLE_FRUIT;
}

# recup de la date actuelle
$current_european_date = date("Y-m-d H:i:s", my_local_time());

// on sélectionne le match en cours le plus récent
$match = db_fetch_array( main_db_query("SELECT * FROM Matchs WHERE Matchs.ShowTime<'".
$current_european_date."' AND Matchs.Date>'".$current_european_date."' ORDER BY Matchs.Date ASC"));

$stats = db_fetch_array( main_db_query("SELECT * FROM MatchsStats WHERE MatchId='$match[MatchId]'"));

# on calcule les statistiques du match
if ($stats[Win1] + $stats[Win2] + $stats[NullGame] != 0)
{
	$victoire1 = 100. * $stats[Win1] / ($stats[Win1] + $stats[Win2] + $stats[NullGame]);
	$victoire2 = 100. * $stats[Win2] / ($stats[Win1] + $stats[Win2] + $stats[NullGame]);
	$matchNul = 100. * $stats[NullGame] / ($stats[Win1] + $stats[Win2] + $stats[NullGame]);
}
else
{
	$victoire1 = $victoire2 = $matchNul = 100./3;
}


fwrite ($fdest,
"
<table bgcolor=".$BG_COLOR_FOND_1." width=\"96%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">
	<tr>
		<td class=\"boldLight\" colspan=1>".
			"&nbsp;&nbsp;La tendance KestuFoot
		</td>
	</tr>
	<tr>
		<td class=\"smallDark\" colspan=1>
	<table bgcolor=#FFFFFF width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\">
		<tr>
			<td class=\"smallbold\" align=\"center\" width=\"30%\">".$match[Team1]."</td>
			<td width=\"10%\" align=\"center\"><IMG SRC=\"".$IMAGES_DIR.flag($match[Team1])."\" ></td>
			<td class=\"smallbold\" align=\"center\">vs</td>
			<td width=\"10%\" align=\"center\"><IMG SRC=\"".$IMAGES_DIR.flag($match[Team2])."\" ></td>
			<td class=\"smallbold\" align=\"center\" width=\"30%\">".$match[Team2]."</td>
		</tr>
	</table>
	
	<table bgcolor=#FFFFFF width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
		<tr >
			<td align=center width=10><img src=\"".$IMAGES_DIR."Tree/spacer.gif\" height=1></td>
			<td align=center width=100% >
				<!-- stats -->
				<table width=\"96%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
				<tr><td height=1 bgcolor=#000000 colspan=7><img src=\"".$IMAGES_DIR."Tree/spacer.gif\" height=1></td></tr>
				<tr>
					<td bgcolor=#000000 width=1><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>
					<td align=center class=smallBoldDark bgcolor=\"".(($victoire1>=$victoire2)?"#00E088":"#FF8040")."\" width=\"".round($victoire1)."\"%\"><font color=white>".number_format($victoire1,1)."%</font></td>
					<td bgcolor=#000000 width=1><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>
					<td align=center class=smallBoldDark bgcolor=#88D8F8 align=center width=\"".(100-round($victoire1)-round($victoire2))."%\"><font color=white>".number_format($matchNul,1)."%</font></td>
					<td bgcolor=#000000 width=1><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>
					<td align=center class=smallBoldDark bgcolor=\"".(($victoire2>=$victoire1)?"#00E088":"#FF8040")."\" width=\"".round($victoire2)."%\"><font color=white>".number_format($victoire2,1)."%</font></td>
					<td bgcolor=#000000 width=1><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>
				</tr>
				<tr><td height=1 bgcolor=#000000 colspan=7><img src=\"".$IMAGES_DIR."Tree/spacer.gif\" height=1></td></tr>
				</table>
				<!-- stats fin -->
			</td>
			<td align=center  width=10><img src=\"".$IMAGES_DIR."Tree/spacer.gif\" height=1></td>
		</tr>
		<tr>
			<td class=std  align=center colspan=3>
				&nbsp;<a class=smallDarkLink href=\"".$SERVER_URL."\" target=\"KestuFoot\"><img src=\"".$IMAGES_DIR."triangleorange.gif\" border=0>&nbsp;Pariez sur KestuFoot, le jeu qui rend Foot</a><br>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
</body>
</html>");

fclose($fdest);

?>
