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


echo"<style>
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;
}
input {
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>";
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');


if(!empty($_POST["new_pseudo"]))
{
	$new_pseudo = $_POST["new_pseudo"];
	if( ereg("^[][()a-zA-Z0-9+-]{3,}$", $new_pseudo) === false )
	{
		echo "<br><form action=\"profil_changepseudo.php\" method=\"post\" target=\"_parent\">
		<table width=\"718\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#006600\">
			<tr> 
				<td> Pseudo invalide <br><br>Par mesure de sécurité les pseudos sont changés au bout de 7 jours.</td>
			</tr>
		  <tr>
			<td colspan=\"2\"><b><font color=\"23BC23\">Login souhaité :</b><br><input type=\"text\" name=\"new_pseudo\" value=\"$new_pseudo\" size=\"20\" maxlength=\"20\"></td>
		</tr>
		  <tr>
			<td colspan=\"2\"><div align=\"center\"><br><input type=\"submit\" name=\"Submit\" value=\"Modifier\">
			</div></td>
		  </tr>
		  </table>";
		exit;
	}
	$req = "SELECT * FROM matgraph_users WHERE login = '$new_pseudo' ORDER by id ASC";
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	
	$req2 = "SELECT * FROM matgraph_changementlogin WHERE login = '$new_pseudo' ORDER by id ASC";
	$res2 = db_mysql_Query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
	$num2 = mysql_num_rows($res2);
	
	if ( $num == 0 && $num2 == 0 )
	{
		$req3 = "SELECT * FROM matgraph_changementlogin WHERE login = '$new_pseudo' ORDER by id ASC";
		$res3 = db_mysql_Query($req3) or die('Erreur SQL! <br>'.$req3.'<br>'.mysql_error());
		$num3 = mysql_num_rows($res3);
		if ( $num3 == 0)
		{
			$date =  strftime("%Y-%m-%d %H:%M:%S", time() + (60*60*24*7));
			$requete = "INSERT INTO matgraph_changementlogin VALUES ('', '$idlogin', '$new_pseudo', '$date')";
			$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
			echo '<script language="javascript" type="text/javascript">
			<!--
			window.location.replace("profil.php");
			-->
			</script>';
		}
		else
		{
			echo "<br><form action=\"profil_changepseudo.php\" method=\"post\" target=\"_parent\">
			<table width=\"718\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#006600\">
				<tr> 
					<td> Vous avez deja une demande de changement de pseudo en cours <br><br>Par mesure de sécurité les pseudos sont changés au bout de 7 jours.</td>
				</tr>
			  <tr>
				<td colspan=\"2\"><b><font color=\"23BC23\">Login souhaité :</b><br><input type=\"text\" name=\"new_pseudo\" value=\"$new_pseudo\" size=\"20\" maxlength=\"20\"></td>
			</tr>
			  <tr>
				<td colspan=\"2\"><div align=\"center\"><br><input type=\"submit\" name=\"Submit\" value=\"Modifier\">
				</div></td>
			  </tr>
			  </table>";
			  exit;
		}
	}
	else
	{
			echo "<br><form action=\"profil_changepseudo.php\" method=\"post\" target=\"_parent\">
		<table width=\"718\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#006600\">
			<tr> 
				<td> Pseudo déjà utilisé ou souhaité <br><br>Par mesure de sécurité les pseudos sont changés au bout de 7 jours.</td>
			</tr>
		  <tr>
			<td colspan=\"2\"><b><font color=\"23BC23\">Login souhaité :</b><br><input type=\"text\" name=\"new_pseudo\" value=\"$new_pseudo\" size=\"20\" maxlength=\"20\"></td>
		</tr>
		  <tr>
			<td colspan=\"2\"><div align=\"center\"><br><input type=\"submit\" name=\"Submit\" value=\"Modifier\">
			</div></td>
		  </tr>
		  </table>";
		  exit;
	}
}
else
{


echo"<br><form action=\"profil_changepseudo.php\" method=\"post\" target=\"_parent\">
<table width=\"718\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#006600\">
	<tr> 
		<td>Par mesure de sécurité les pseudos sont changés au bout de 7 jours.</td>
	</tr>
  <tr>
    <td colspan=\"2\"><b><font color=\"23BC23\">Login souhaité :</b><br><input type=\"text\" name=\"new_pseudo\" value=\"$new_pseudo\" size=\"20\" maxlength=\"20\"></td>
</tr>
  <tr>
    <td colspan=\"2\"><div align=\"center\"><br><input type=\"submit\" name=\"Submit\" value=\"Modifier\">
    </div></td>
  </tr>
  </table>";
}

?>

