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

$sql2 = "SELECT ally,statut FROM matgraph_users WHERE id='$idlogin'";
$res2 = db_mysql_Query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2); 

$sql_options = "SELECT admin,administrer FROM matgraph_ally_statut WHERE id='$row2[statut]'";
$res_options = db_mysql_Query($sql_options)or die('erreur sql<br>'.$sql_options.'<br>'.mysql_error());
$row_options = mysql_fetch_array($res_options);

if($row2[ally] == "no") {
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("ally_index.php");
	-->
	</script>';
	exit;
}

if($row2[statut] !== "0" AND $row_options[administrer] == "1" OR $row2[statut] == "-1") {

	$sql = "SELECT * FROM matgraph_ally WHERE id='$row2[ally]'";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$row = mysql_fetch_array($res); 

	$nom = htmlentities ($_POST["nom"]);
	$tag = htmlentities ($_POST["tag"]);
	$url = htmlentities ($_POST["url"]);
	$img = htmlentities ($_POST["img"]);
	$presentation = htmlentities ($_POST["presentation"]);
	$txtinterne = htmlentities ($_POST["txtinterne"]);

	$form = "<form name=\"form1\" method=\"post\" action=\"ally_admin_envoi.php\" target=\"_parent\">
	  <table width=\"618\"  border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
	    <tr>
	      <td width=\"159\"><strong>Nom : </strong></td>
	      <td width=\"453\"><div align=\"center\">
	        <input name=\"nom\" type=\"text\" id=\"nom\" value=\"$nom\" maxlength=\"35\">
	      </div></td>
	    </tr>
	    <tr>
	      <td><strong>Tag : </strong></td>
	      <td width=\"453\"><div align=\"center\">
	        <input name=\"tag\" type=\"text\" id=\"tag\" value=\"$tag\" maxlength=\"6\">
	      </div></td>
	    </tr>
	    <tr>
	      <td><strong>Url Page d'accueil : </strong></td>
	      <td width=\"453\"><div align=\"center\">
	        <input name=\"url\" type=\"text\" id=\"url\" value=\"$url\" maxlength=\"300\">
	      </div></td>
	    </tr>
	    <tr>
	      <td><strong>Url Logo : </strong></td>
	      <td width=\"453\"><div align=\"center\">
	        <input name=\"img\" type=\"text\" id=\"img\" value=\"$img\" maxlength=\"300\">
	      </div></td>
	    </tr>
	    <tr>
	      <td colspan=\"2\"><strong>Pr&eacute;sentation : </strong></td>
	    </tr>
	    <tr>
	      <td colspan=\"2\"><div align=\"center\">
	        <textarea name=\"presentation\" cols=\"70\" id=\"presentation\">$presentation</textarea>
	      </div></td>
	    </tr>
	    <tr>
	      <td colspan=\"2\"><strong>Texte interne : </strong></td>
	    </tr>
	    <tr>
	      <td colspan=\"2\"><div align=\"center\">
	        <textarea name=\"txtinterne\" cols=\"70\" id=\"txtinterne\">$txtinterne</textarea>
	      </div></td>
	    </tr>
	    <tr>
	      <td colspan=\"2\"><div align=\"center\">
	        <input type=\"submit\" name=\"Submit\" value=\"Envoyer\">
	      </div></td>
	    </tr>
	  </table>
	</form>";
	if ($nom !== $row[nom]) {
		$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;
			}
		}
	}

	if ($tag !== $row[tag]) {
		$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;
			}
		}
	}

	$sql = 'UPDATE matgraph_ally SET nom="'.$nom.'",tag="'.$tag.'",url="'.$url.'",img="'.$img.'",presentation="'.$presentation.'",txtinterne="'.$txtinterne.'" WHERE id="'.$row[id].'" ';
	$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_admin.php");
	-->
	</script>';
}
else {
	echo '<script language="javascript" type="text/javascript">
	<!--
	window.location.replace("ally_index.php");
	-->
	</script>';
	exit;
}
?>

