<?php
include ('logue.php');
include ('entete2.php');
include ('ressource.php');
include ('entete.php');
echo"
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
input {
border:0px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php');

$sql2 = "SELECT ally,statut FROM matgraph_users WHERE id='$idlogin' LIMIT 0,1";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$idally = $row2[ally];
if($row2[ally] == "no") {
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("ally_index.php");
-->
</script>';
exit; }

if($row2[statut] !== "0" AND $row2[statut] !=="-1") {
$sql = "SELECT listemembres FROM matgraph_ally_statut WHERE id='$row2[statut]' LIMIT 0,1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
if($row[listemembres] == "1") {
$listemembres = "ok";}
}
else {
$listemembres = "ok";}

if($row2[statut] !== "0" AND $row2[statut] !=="-1") {
	$sql = "SELECT online FROM matgraph_ally_statut WHERE id='$row2[statut]' LIMIT 0,1";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$row = mysql_fetch_array($res);
	if($row[online] == "1") 
	{
		$online2 = "ok";
	}
}
else {
$online2 = "ok";}

if($row2[statut] !== "0" AND $row2[statut] !=="-1") {
$sql = "SELECT admin FROM matgraph_ally_statut WHERE id='$row2[statut]' LIMIT 0,1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
if($row[admin] == "1") {
$admin = "ok";}
}
else {
$admin = "ok";}
if($listemembres !== "ok") {
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("ally_index.php");
-->
</script>';
exit; }

$sql = "SELECT * FROM matgraph_ally WHERE id='$row2[ally]' LIMIT 0,1";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
$idfonda = $row[idfondateur];
$status_fondateur = $row['statut_fondateur'];

// on fait directement la requete dont on aura besoin après
//$req = "SELECT id FROM matgraph_users WHERE ally='$row[id]' ORDER by id ASC";
$req = "SELECT id,login,pts,galaxi,system,position,date,statut FROM matgraph_users WHERE ally='$row[id]' ORDER by pts DESC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);

echo"<table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
  <tr style =\"background-color:#111111;\">
    <td align=\"center\" colspan=\"";
if($admin == "ok") { echo"9";} else { echo"8"; } echo"\"> Liste des membres (Nombre: $num) </td>
  </tr>
  <tr style =\"background-color:#222222;\">";
if($admin == "ok") {
echo"<td align=\"center\" width=\"25\">Del</td>
<td align=\"center\" width=\"30\">Edit</td>";}
echo"<td align=\"center\">N&deg;</td>
    <td align=\"center\">Pseudo</td>
    <td align=\"center\">Coordonn&eacute;es</td>
    <td align=\"center\">Statut</td>
    <td align=\"center\">Points</td>
    <td align=\"center\">Online</td>
    <td align=\"center\">MP</td>
  </tr>";

// J ai commenté cette requete, car on peux la faire au dessus
//$req = "SELECT id,login,pts,galaxi,system,position,date,statut FROM matgraph_users WHERE ally='$row[id]' ORDER by pts DESC";
//$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
//$num = mysql_num_rows($res);
if ( $num > 0 ) {
$i = 1;
  While ( $row = mysql_fetch_array($res) ) {

$sql4 = "SELECT nom FROM matgraph_ally_statut WHERE id='$row[statut]' LIMIT 0,1";
$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$row4 = mysql_fetch_array($res4);

if($row[statut] == "-1") {
	if($status_fondateur==''){
		$sql5 = "UPDATE matgraph_ally SET statut_fondateur='Fondateur' WHERE id='$row[statut]'";
		$res5 = db_mysql_Query($sql5)or die('erreur sql<br>'.$sql5.'<br>'.mysql_error());
		$statut = 'Fondateur';
	}else{
		$statut = $status_fondateur;
	}
}else{
	$statut = $row4[nom] ; 
}

// On recupere la date la plus eleve, plutot que d'utiliser row[date], qui est la date de la PM
$req_online = "SELECT date FROM matgraph_users WHERE idjoueur = $row[id] ORDER BY date DESC LIMIT 0,1";
$res_online = db_mysql_Query($req_online) or die('Erreur SQL! <br>'.$req_online.'<br>'.mysql_error());
$row_online = mysql_fetch_array($res_online);

// Donc on parse row_online[date], et plus row[date]
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row_online[date], $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

// on arrondi a la minute
$diftemps = time() - $time;
//$difheure = round($diftemps / 3600,1);
//$difmin = $difheure * 60;
$difmin = round($diftemps / 60,1);

if ($difmin < 10 ) {
$online = "<font color=\"00CC00\">Online</font> ($row_online[date])"; } else {
$online = "<font color=\"FF0000\">Offline</font> ($row_online[date])";}

$pts = number_format($row[pts] / 1000, 0, ',', ' ');
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">";
if($admin == "ok") {
if($row[id] == $idfonda){ echo"<td width=\"25\">&nbsp;</td>";} else {
echo"<form name=\"suprimer\" method=\"post\" action=\"ally_membre_del.php\" target=\"_parent\">
		<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
		<input type=\"hidden\" name=\"idally\" value=\"$idally\">
	<td width=\"25\" align=\"center\">
    	<input type=\"image\" src=\"imgs/del.gif\" width=\"25\">
    </td>
	</form>"; }}
if($admin == "ok") {
if($row[id] == $idfonda){ 
	echo"<td width=\"25\"><a href=\"ally_statut_edit.php?pers=fondateur\"><img src=\"imgs/edit.gif\" width=\"30\" alt=\"edit\"/></a></td>";
} else {
echo"<td width=\"30\" align=\"center\">
	<form name=\"suprimer\" method=\"post\" action=\"ally_membre_edit.php\" target=\"_parent\">
		<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
		<input type=\"hidden\" name=\"idally\" value=\"$idally\">
    	<input type=\"image\" src=\"imgs/edit.gif\" width=\"30\">
	</form>
    </td>"; }}

echo"<td>$i</td>
    <td align=\"center\">$row[login]</td>
    <td align=\"center\">[$row[galaxi]:$row[system]:$row[position]]</td>
    <td align=\"center\">".htmlentities($statut)."</td>
    <td align=\"center\">$pts</td>
    <td align=\"center\">";
if($online2 == "ok") { echo"$online"; } else { echo"-";}echo"</td>
    <form name=\"galaxi1\" method=\"post\" action=\"mp_envoi.php\" target=\"_parent\">
	<input name=\"galaxi\" type=\"hidden\" value=\"$row[galaxi]\">
	<input name=\"system\" type=\"hidden\" value=\"$row[system]\">
	<input name=\"position\" type=\"hidden\" value=\"$row[position]\">
	<input name=\"idreceveur\" type=\"hidden\" value=\"$row[id]\">
	<td align=\"center\"><input type=\"image\" src=\"imgs/msg.gif\"></td></form>
  </tr>";
  $i++;
}}
echo"<form action=\"ally_index.php\" method=\"post\" name=\"form1\" target=\"_parent\"> <tr>
  <td height=\"50\" colspan=\"";
if($admin == "ok") { echo"9";} else { echo"8"; } echo"\" align=\"center\" valign=\"middle\"><input type=\"submit\" name=\"Submit2\" value=\"Retour\" Style=\"border:1px solid #7E7E7E;\"></td>
  </tr></form>
</table>";

?>
