<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>
<link rel="stylesheet" href="admin.css">

<body>
<script>
function func(textarea,val) {
	textarea.value=val;	
}
</script>
<div align=center class=trTitle>- Statistiques Longévité des Joueurs -</DIV>
<p>&nbsp;</p>


<form name=main action='longevite.php3' method="post">
<table align=center border=0 cellpadding=2 cellspacing=5>
<tr>
	<td align=center class='trTitle'>
	la Longévité...
	</td>
</tr>
<tr>
	<td align=center class='univers'>
	Pas	<INPUT name="Pas" value="<?php echo $Pas; ?>" size="15" class='univers'>
	(en secondes)<br><font style="color=Red"> champ obligatoire</font>
	&nbsp;<input type="button" value="1j" onClick="javascript:func(main.Pas,'86400');" class='univers'>
	&nbsp;<input type="button" value="7j" onClick="javascript:func(main.Pas,'604800');" class='univers'>
	&nbsp;<input type="button" value="28j" onClick="javascript:func(main.Pas,'2419200');" class='univers'>
	&nbsp;<input type="button" value="Raz" onClick="javascript:func(main.Pas,'');" class='univers'></td>
	</td>
</tr>
<tr>
	<td align=center>
	<input type=hidden name=ok value=1>
	<input type="submit" value="Dessiner" class='univers'>&nbsp;
	<INPUT type="reset" value="Annuler" class='univers'>
	</td>
</tr>
</table>
</FORM>


<?
include("generic.inc");

#############
# FUNCTIONS #
#############

function showRow($row)
{
	static $iColor;
	
	$color = ($iColor % 2 == 0)? "#FFFFFF":"#E8E8E8";
	$iColor++;
	$t = explode(";",$row);
	echo "<tr bgcolor=".$color."  class='univers'>\n";
	for($r=0;$r<(count($t)-1);$r++)
	{
		echo "<td align=center>".$t[$r]."</td>\n";
	}
	echo "</tr>\n";
}

function sectotime($sec)
{
	$j = round($sec/86400);
	$h = round(($sec%86400)/3600);
	$m = round((($sec%86400)%3600)/60);
	$s = round((($sec%86400)%3600)%60);
	return "$j j, $h:$m:$s";
}

#################
# END FUNCTIONS #
#################



if ($Pas)
{
	echo "<table align=center border=0 cellpadding=4 cellspacing=4 >";
	echo "<tr class='trTitle' align=center>";
	echo "<td>Nbe de Pas<br>en activité</td>";
	echo "<td>Joueurs actifs durant<br>le Nbe de Pas</td>";
	echo "<td>%</td>";
	echo "<td></td>";
	echo "</tr>";
	
	$rows = main_db_query
	("
		SELECT Players.Id AS id , Members.Time AS ins , MAX(Paris.Date) AS der 
		FROM Players 
		LEFT JOIN Members ON Players.MemberId=Members.Id 
		LEFT JOIN Paris ON Players.Id=Paris.PlayerId
		WHERE Paris.Date!=''
		AND Members.Time!=''
		GROUP BY Players.Id
	");
	
	$moy = $i = 0;
	while ($result = db_fetch_array($rows))
	{
		$Nbe[round((time_diff($result[ins],$result[der]))/$Pas)]++;
		$moy = ( $moy*$i + time_diff($result[ins],$result[der]) )/($i+1);
		$i++;
	}
	$moy = sectotime($moy);
	for ($i=0 ; $i<count($Nbe) ; $i++)
	{
		$nbTotal = db_fetch_array(main_db_query("SELECT COUNT(*) AS total FROM Players"));
		$Nbe[$i] = ($Nbe[$i]!="")?$Nbe[$i]:0;
		$pc = ($nbTotal[total]>0)?round($Nbe[$i]*10000/$nbTotal[total])/100:0;
		$pc10 = 10*$pc;
		$pcx = ($pc!="")?"<img align=left src='pointvert.jpg' width='".$pc10."' height=10 border=0>":"";
		
		$m = $i.";".
			$Nbe[$i].";".
			$pc." %;".
			$pcx."\n;";
		
		showRow($m);
	}
	
	
	
	echo "<tr class='trTitle' align=center>";
	echo "<td>Nbe de Pas<br>en activité</td>";
	echo "<td>Joueurs actifs durant<br>le Nbe de Pas</td>";
	echo "<td>%</td>";
	echo "<td></td>";
	echo "</tr>";
	echo "</table><p>&nbsp;</p>";
	echo "<table align=center>
		<tr class='trTitle' align=center>
			<td>Longévité moyenne
			</td>
		</tr>
		<tr class='univers' align=center>
			<td>$moy
			</td>
		</tr>
		</table>";
}









?>
</body>
</html>
