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

$categorie = $_POST["categorie"];

/* //si test admin
if($idlogin !== '1') {
	echo '<script language=javascript> alert ("Salut '.$login.' , Désolé mais cette fonction n\'est pas encore disponible, reviens plus tard");</script>';
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("mp_lire.php");
	-->
	</script>';
	exit;
}
*/
//liste id :

$liste_id = "(0";

$reqtmpid = "SELECT id FROM matgraph_users WHERE idjoueur = $idlogin";
$restmpid = db_mysql_Query($reqtmpid) or die('Erreur SQL! <br>'.$reqtmpid.'<br>'.mysql_error());
while( $rowtmpid = mysql_fetch_array($restmpid) ) {
	$liste_id = $liste_id." OR receveur = $rowtmpid[id]";
}
$liste_id = $liste_id.")";


// MP :
if($categorie == 'mp') {

	$sql5 = "SELECT * FROM matgraph_mp WHERE $liste_id";
	$res5 = db_mysql_Query($sql5)or die('erreur sql<br>'.$sql5.'<br>'.mysql_error());
	if ($num5 >0) {
	  While ( $row5 = mysql_fetch_array($res5) ) {
	
			$sql4 = "INSERT INTO `matgraph_mp_log` ( `id` , `lu` , `date` , `envoyeur` , `receveur` , `planete_receveur` , `planete_envoyeur` , `sujet` , `message` )
			VALUES (
			'$row5[id]', '$row5[lu]' , '$row5[date]' , '$row5[envoyeur]' , '$row5[receveur]' , '$row5[planete_receveur]' , '$row5[planete_envoyeur]' , '$row5[sujet]' , '".addslashes($row5[message])."'
			)";
			
			$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
			
		}
	}
	
	$sql4 = "DELETE FROM matgraph_mp WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}

// msg ally :
if($categorie == 'ally') {
	$sql4 = "DELETE FROM matgraph_msgally WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}

// bataille :
if($categorie == 'bataille') {
	
	$sql4 = "DELETE FROM matgraph_bataille WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());

}

//espio :
if($categorie == 'espio') {
	$sql4 = "DELETE FROM matgraph_espio1 WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}

//Contre espio :
if($categorie == 'contreespio') {
	$sql4 = "DELETE FROM matgraph_contreespio WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}

//Autre msg :
if($categorie == 'msg') {

	$sql5 = "SELECT * FROM matgraph_msg WHERE $liste_id";
	$res5 = db_mysql_Query($sql5)or die('erreur sql<br>'.$sql5.'<br>'.mysql_error());
	if ($num5 >0) {
	  While ( $row5 = mysql_fetch_array($res5) ) {
	
			$sql4 = "INSERT INTO `matgraph_msg_log` ( `id` , `date` , `lu` , `receveur` , `sujet` , `msg` )
			VALUES (
			'$row5[id]', '$row5[date]', '$row5[lu]', '$row5[receveur]', '$row5[sujet]', '".addslashes($row5[msg])."'
			)";
			
			$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
			
		}
	}
	
	$sql4 = "DELETE FROM matgraph_msg WHERE $liste_id";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}


echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("mp_lire.php");
-->
</script>';
  
?>