<?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: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>";
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'); 

$nom = htmlentities (addslashes($_POST["nom"]));
$tag = htmlentities (addslashes($_POST["tag"]));

$form = "<br><br><form action=\"ally_fonder_envoi.php\" method=\"post\" name=\"form1\" target=\"_parent\">
  <table width=\"322\"  border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
      <td height=\"45\">Nom de l'alliance : </td>
      <td>
        <div align=\"left\">
          <input name=\"nom\" type=\"text\" id=\"nom\" maxlength=\"35\" value=\"$nom\">
        </div></td>
    </tr>
    <tr>
      <td height=\"37\">Tag de l'alliance : </td>
      <td>
        <div align=\"left\">
          <input name=\"tag\" type=\"text\" id=\"tag\" maxlength=\"6\" value=\"$tag\">
        </div></td>
    </tr>
    <tr>
      <td height=\"32\" colspan=\"2\"><div align=\"center\">
        <input type=\"submit\" name=\"Submit\" value=\"Fonder\">
      </div></td>
    </tr>
  </table>
</form>";

if(empty($nom) OR empty($tag)) {
echo"<br>Un des champs est vide.<br><br>";
echo"$form";
exit;
}

$req = "SELECT id FROM matgraph_ally WHERE nom='$nom' ORDER by id ASC";
$res = db_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"<br>Ce nom est déja pris.<br><br>";
echo"$form";
exit;
}}

$req = "SELECT id FROM matgraph_ally WHERE tag='$tag'ORDER by id ASC";
$res = db_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"<br>Ce tag est déja pris.<br><br>";
echo"$form";
exit;
}}

//////////
////////
////
//

$requete = "INSERT INTO  matgraph_ally VALUES ('', '$idlogin', '$nom', '$tag', '', '', '', '', '0', '5','Fondateur')";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$sql2 = "SELECT id FROM matgraph_ally WHERE nom='$nom' AND tag='$tag'";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

$sql = "UPDATE matgraph_users SET ally='$row2[id]', statut='-1'  WHERE id='$idlogin'";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());

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

?>
