<?php

// this defines some of your basic setup
include_once 'config.php';
// the facebook client library
include_once $BIB.'facebook.php';
include_once $BIB.'bib_generic.php3';
include_once $BIB.'bib_quiz_facebook.php3';
include_once $BIB.'bib_facebook_user.php3';

include "header.php";


$friends = getFriendPlayers($user);
$maxfriendline = 5;
$i = 1;

echo "<div id=liste_amis>\n";
echo "<h2>CLIQUEZ SUR VOS AMIS POUR VOIR LEURS STATS</h2>\n";
echo "<table width=100%>\n";

foreach($friends AS $friend)
{
	if($i == 0)
	{
		echo "<tr>\n";
	}	
	
	echo "<td align=center width=20%>\n";
		echo "\t<center><a href='?friend_user=".$friend."'>\n";
		echo "\t<fb:profile-pic uid='".$friend."' size='thumb' linked='false' />\n";
		echo "\t<br/><fb:name uid='".$friend."' useyou='false' linked='false'/></a></center>\n";
	echo "</td>\n";
	
	if($i == $maxfriendline)
	{		
		echo "<tr>\n";
		$i = 0;
	}
	else
	{
		$i++;
	}
}
echo "</table>";
echo "</div>";


if(!$friend_user)
{
	$friend_user=$user;
	$titre = "VOS STATS QUIZFOOT";
}
else
{
	$player = getVGUser($friend_user);
	$titre = "LES STATS QUIZFOOT DE ".$player["first_name"]." ".$player["last_name"];
}
?>





<div id="principal">

	<div id="quiz">
		<h2><?php echo $titre;?> :</h2>
		<div id="stats">
			<ul>
			<?php
			if(!$friend_user)
			{
				$friend_user=$user;
			}
			//on va lister les themes			
			$query = "SELECT * FROM Qcm_Histo WHERE uid=".$friend_user." AND EndTime<> '0000-00-00 00:00:00' ORDER BY ThemeId, EndTime DESC";
			$rows = main_db_query($query);
			$i=0;
			$histo = array();
			while($row = db_fetch_assoc($rows))
			{
				if($histo[$row["ThemeId"]]["Points"] < $row["Points"])
				{
					$histo[$row["ThemeId"]]["ThemeId"]=$row["ThemeId"];
					$histo[$row["ThemeId"]]["Points"]=$row["Points"];
					$histo[$row["ThemeId"]]["Temps"]=$row["Temps"];
				}
				elseif($histo[$row["ThemeId"]]["Points"] == $row["Points"])
				{
					if($histo[$row["ThemeId"]]["Temps"] > $row["Temps"])
					{
						$histo[$row["ThemeId"]]["ThemeId"]=$row["ThemeId"];
						$histo[$row["ThemeId"]]["Points"]=$row["Points"];
						$histo[$row["ThemeId"]]["Temps"]=$row["Temps"];
					}
				}				
			}
			foreach($histo AS $row)
			{
				echo "\t<li class='question'>\n";
					echo "\t\t<h3>".getThemeName($row["ThemeId"])."</h3>\n";
					echo "\t\t<table><tr><td><a href='".$QUIZ_PAGE."?Id=".$row["ThemeId"]."'><img src='".$IMAGES_DIR."Themes/".getImageTheme($row["ThemeId"])."' border=0></a></td>\n";
					echo "\t\t<td>";					
					echo "\t\t<b>Score :</b> ".$row["Points"]." %<br />\n";				
					echo "\t\t<b>Temps :</b> ".formatTime($row["Temps"])."<br />\n";
					echo "</td></tr></table>\n";	
					echo "\t\t<br /> >><a href='".$QUIZ_PAGE."?Id=".$row["ThemeId"]."'>Jouer ce quiz</a><br />\n";
					echo "\t\t<br /><div class='resultats'>Joué ".getNbTimesTheme($row["ThemeId"])." fois | ";
					echo "Score moyen ".getMoyenneTheme($row["ThemeId"])." %</div>\n";					
				echo "\t</li>\n";
				$i++;
			}
			if($i==0)
			{
				echo "\t<li class='question'>aucun quiz pour le moment</li>\n";
			}
			?>
			</ul>
		</div>
	</div>
	

	<div id="promo_right">
		<a href="http://www.kestufoot.com/trck_bannieres.php3?code=FACEBOOK_243" target="_blank"><img src="<?php echo $IMAGES_DIR?>sky_promo.gif" border=0></a>
	</div>
	
</div>

<?php
include "footer.php";
?>