<?php
include ('header.inc.php');

include('classes/PlayerRound.php');
include('classes/PlayerTotal.php');
include('classes/Round.php');
include('classes/Song.php');

if(!isset($_GET['start_rank'])) $_GET['start_rank']=1;
if(!isset($_GET['number_rank'])) $_GET['number_rank']=40;

//Instanciation des classes
$o_actual_player = new PlayerAccount();
if(isset($_GET["pid"]))
{
	$o_actual_player->SetPlayerID($_GET["pid"]);
}
else
{
	?><b><font face='Arial' color='#FF0000'>Ce joueur n'existe pas.</font></b><br><br><?php
	include ('footer.inc.php');
	exit;
}
$o_player_total = new PlayerTotal();
$o_player_total->SetPlayerID($_GET["pid"]);
if($o_player_total->GetPlayerTotalRounds()==0)
{
	?><b><font face='Arial' color='#FF0000'>Ce joueur n'a joué aucune parties.</font></b><br><br><?php
	include ('footer.inc.php');
	exit;
}
$o_player_round=new PlayerRound();
$o_round = new Round();
$o_song = new Song();

//Get rounds info 
$a_last_rounds=$o_player_round->GetPlayerRound($o_actual_player->GetPlayerID(),$_GET['start_rank'],$_GET['number_rank']-1); 
//calculate the number of elements to show 
$i_nomber_show = count($a_last_rounds);
if($i_nomber_show%2!=0) $i_nomber_show++;

?>
<center><br>
<i class="accstyle"><b><img src="images/icons/li.png" alt="" />&nbsp;Liste des musiques jouées par <?php echo $o_actual_player->GetPlayerName();?> :</b></i><br>
<span class="accstyle">(De la plus récente à la plus ancienne)</span><br><br>
<table border='0' width='540' cellpadding='0' cellspacing='0' class="ranking">
	<tr align='center'>
		<td width='25' style="text-align: left;" >N°</td>
		<td width='145' style="text-align: left;">Musique</td>
		<td width='50' style="text-align: center;">Note</td>
		<td width='25' style="text-align: left;">N°</td>
		<td width='145' style="text-align: left;">Musique</td>
		<td width='50' style="text-align: center;">Note</td>
	</tr>
	<?php
//loop for create the table
for($i=0;$i<(($i_nomber_show/2));$i++)
{
	$o_player_round->SetRoundKey($a_last_rounds[$i]);
	$o_round->SetRoundID($o_player_round->GetPlayerRoundID());
	$o_song->SetSongID($o_round->GetRoundSong());
	$a_song_name=$o_song->GetSongName();
	?>
	<tr>
		<td><?php echo $i+$_GET['start_rank'];?></td>
		<td><a href='player-stats.php?pid=<?php echo $o_actual_player->GetPlayerID();?>&round_key=<?php echo $a_last_rounds[$i];?>' class="accstyle" style="text-decoration: none;"><?php echo $a_song_name["title"];?></a></td>
		<td><center><img src="images/Grade<?php echo $o_player_round->GetPlayerRoundGrade();?>.png" height="20" /></center></td>
	<?php
	if(isset($a_last_rounds[(($i)+($i_nomber_show/2))]))
	{
		$o_player_round->SetRoundKey($a_last_rounds[(($i)+($i_nomber_show/2))]);
		$o_round->SetRoundID($o_player_round->GetPlayerRoundID());
		$o_song->SetSongID($o_round->GetRoundSong());
		$a_song_name=$o_song->GetSongName();
		?>
		<td><?php echo ($i+$_GET['start_rank']+($i_nomber_show/2));?></td>
		<td><a href='player-stats.php?pid=<?php echo $o_actual_player->GetPlayerID();?>&round_key=<?php echo $a_last_rounds[(($i)+($i_nomber_show/2))];?>' class="accstyle" style="text-decoration: none;"><?php echo $a_song_name["title"];?></a></td>
		<td><center><img src="images/Grade<?php echo $o_player_round->GetPlayerRoundGrade();?>.png" height="20" /></center></td>
	</tr>
		<?php
	}
	else
	{
		?>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
		<?php
	}
}
?>
</table>
<br>
<?php
//Page system
if($_GET['start_rank']>$_GET['number_rank'])
{
	?>
	
	<a href='player-music.php?pid=<?php echo $_GET["pid"];?>&start_rank=<?php echo $_GET['start_rank']-$_GET['number_rank'];?>&number_rank=<?php echo $_GET['number_rank'];?>'class="accstyle">&lt;&lt;Précédent</a> - 
	<?php
}
?><i class="accstyle">Page <?php echo ((($_GET['start_rank']-1)/$_GET['number_rank'])+1);?></i>
<?php
if(($_GET['start_rank']-1+$i_nomber_show)%$_GET['number_rank']==0)
{
	?>
	 - <a href='player-music.php?pid=<?php echo $_GET["pid"];?>&start_rank=<?php echo $_GET['start_rank']+$_GET['number_rank'];?>&number_rank=<?php echo $_GET['number_rank'];?>' class="accstyle">Suivant&gt;&gt;</a></center><br>
	<?php
}
//Select the number of musics showed
?>
</center>
<center>
<form action='' method='get' class="smofr">
<table><tr>
	<td><input type='hidden' name='start_rank' id='start_rank' value='<?php echo $_GET['start_rank'];?>'/><input type='hidden' name='pid' id='pid' value='<?php echo $_GET['pid'];?>'/></td></tr>
	<tr><td>Nombre de joueurs par page : </td><td><input type='text' size='3' maxlength='3' name='number_rank' id='number_rank' value='<?php echo $_GET['number_rank'];?>' class="smofr" style="width: 40px;"/></td><td><input type='submit' name='submit' id='submit' value='Ok' class="buttons"/></td></tr>
</table>
</form>
</center>
<?php
include ('footer.inc.php');
?>

