<?php
include ('logue.php');
include ('entete2.php');
include ('entete.php');

echo"
<BODY TEXT=\"#ffffff\">
<BODY LINK=\"#ffffff\">
<BODY VLINK=\"#ffffff\">
<BODY ALINK=\"#ffffff\">
<body bgcolor=\"#000000\">
<style>
input {
border:1px 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>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
/*
$time = strftime("%Y-%m-%d %H:%M:%S", time() - (5*60));
$req = "SELECT COUNT(id) FROM matgraph_users WHERE date < '$time' AND id=idjoueur";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
echo"nb : $res <br>";
*/
$time = strftime("%Y-%m-%d %H:%M:%S", time() - (5*60));

$reqtotal = "SELECT COUNT(id) FROM matgraph_users WHERE id=idjoueur";
$restotal = mysql_query($reqtotal) or die('Erreur SQL! <br>'.$reqtotal.'<br>'.mysql_error());
$numtotal = mysql_result($restotal,0);
//$req222 = "SELECT id,login,date,central_lvl,mail FROM matgraph_users WHERE date < '".$time."' AND id=idjoueur AND galaxi > 0 ORDER by date DESC";
$req222 = "SELECT id,login,date,central_lvl,mail FROM matgraph_users WHERE id=idjoueur AND galaxi > 0 ORDER by date DESC";
$res222 = mysql_query($req222) or die('Erreur SQL! <br>'.$req222.'<br>'.mysql_error());
$num222 = mysql_num_rows($res222);
if ( $num222 > 0 ) {
	$avirer = "";
	$Online = "";
	$nbonline = 0;
	$pasbat = 0;
	$inactif2 = 0;
	$inactif24 = 0;
	$inactif48 = 0;
	$inactif12 = 0;
	$cb = 0;

	while ( $row = mysql_fetch_array($res222) ) {
		$diftemps = "";
		$difheure = "";
		$difmin = "";
		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['date'], $thetime);
		$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
		$diftemps = time() - $time;
		$difheure = round($diftemps / 3600,4);
		$difmin = $difheure * 60;
		if ($difmin <= "5" ) {
			$nbonline++;
			$Online .="<font color=\"00CC00\">".$row['login']."</font> ; "; 
		}

		if($row[central_lvl] == "0") {
			$pasbat++ ;
		}

		if($difheure > 168) {
		//$mail .="$row[mail] ; ";
			$inactif2++ ;
		}

		if($difheure > 48) {
			$inactif48++ ;
		}

		if($difheure > 24) {
			$inactif24++ ;
		}

		if($difheure > 12) {
			$inactif12++ ;
		}

		if($row['central_lvl'] == "0" && $difheure > 168) {

		$sql4 = "DELETE FROM matgraph_users WHERE id = $row[id]";
		$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
		$avirer .= "$row[login] <br> (aucun bat depuis 1 semaine)<form name=\"suprimer\" method=\"post\" action=\"membres_del.php\" target=\"_parent\"><input type=\"hidden\" name=\"id\" value=\"$row[id]\">
			<input type=\"image\" src=\"../imgs/del.gif\" width=\"25\" Style=\"border:0px solid #7E7E7E\">
			</form>"; }
		

		//echo "<br>Traitement de : $row[id]<br>";

		if($difheure > 1008) {
			//echo $row[id]."<br>";

			//$avirer .= "$row[login](inactifs depuis un moi et demi) <br> ";

			$cb +=1;

			$étape = 0;

			echo $étape."  ".$row[id]."<br>";


			$req = "DELETE FROM matgraph_vaisseaux WHERE iduser = $row[id] ";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";


			$req = "DELETE FROM matgraph_users WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_ally_recrut WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_commerce WHERE joueur1 = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_commerce WHERE joueur2 = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_bataille WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_contreespio WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_espio1 WHERE id = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_espio2 WHERE idjoueur = $row[id] OR idespionner = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_explorer WHERE receveur = $row[id] OR envoyeur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_idjoueur WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_mp WHERE receveur = $row[id] OR envoyeur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_msg WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_msgally WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_nbrevaisseaux WHERE user = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			//echo $étape."  ".$row[id]."<br>";

		} // Fin if AFK

	} // Fin While ( $row = mysql_fetch_array($res) )
}


$membres_actif_12h = $numtotal - $inactif12 ;
$membres_actif_24h = $numtotal - $inactif24 ;
$membres_actif_48h = $numtotal - $inactif48 ;
$membres_actif_2h = $numtotal - $inactif2 ;


echo"
Nombre de membres : $numtotal
<br>Noms des membres connectés : $Online
<br>Nombres de connectés : $nbonline
<br>Nombre de membres actifs ces 12 dernières heures : $membres_actif_12h
<br>Nombre de membres actifs ces 24 dernières heures : $membres_actif_24h
<br>Nombre de membres actifs ces 48 dernières heures : $membres_actif_48h
<br>Nombre de membres actifs cette semaine : $membres_actif_2h
<br>
<br>Nombre d'inactifs depuis plus de 12h : $inactif12
<br>Nombre d'inactifs depuis plus d'une journée : $inactif24
<br>Nombre d'inactifs depuis plus de deux jours : $inactif48
<br>Nombre d'inactifs depuis plus d'une semaine : $inactif2
<br>Nombre de membres non dévellopper : $pasbat
<br>Membres a virer : $avirer
<br>A envoyer un mail : $mail
<br><br>";

// del qq1 :
/*
$row[id] = 1500 ;
			$cb +=1;

			$étape = 0;

			echo $étape."  ".$row[id]."<br>";


			$req = "DELETE FROM matgraph_vaisseaux WHERE iduser = $row[id] ";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";


			$req = "DELETE FROM matgraph_users WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_ally_recrut WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_commerce WHERE joueur1 = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_commerce WHERE joueur2 = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_bataille WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_contreespio WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_espio1 WHERE id = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_espio2 WHERE idjoueur = $row[id] OR idespionner = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_explorer WHERE receveur = $row[id] OR envoyeur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_idjoueur WHERE idjoueur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_mp WHERE receveur = $row[id] OR envoyeur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_msg WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_msgally WHERE receveur = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

			$req = "DELETE FROM matgraph_nbrevaisseaux WHERE user = $row[id]";
			$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());

			$étape += 1;
			echo $étape."  ".$row[id]."<br>";

*/

  
/*   TABLEAU ALL MEMBERS !!
echo"<table width=\"618\"  border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>Membres</td>
    <td>Date</td>
    <td>Online</td>
  </tr>";



$req = "SELECT login,date FROM matgraph_users WHERE id=idjoueur ORDER by date DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  While ( $row = mysql_fetch_array($res) ) {
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[date], $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = time() - $time;
$difheure = round($diftemps / 3600,1);
$difmin = $difheure * 60;

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

echo"<tr>
    <td>$row[login]</td>
    <td>$row[date]</td>
    <td>$online</td>
  </tr>";
}}

echo"</table>";
*/
/* SELECT ALL MAILS !!
$req = "SELECT mail FROM matgraph_users WHERE id=idjoueur ORDER by date DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  While ( $row = mysql_fetch_array($res) ) {
  echo"$row[mail] ; "; }}
  */
?>
