<?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,recrutement,listemembres,administrer,mailcollectif 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") {
	$req = "SELECT * FROM matgraph_ally_recrut WHERE idjoueur = $idlogin";
	$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	if ($num == 0) {
		echo "<div align=\"center\"><a href=\"ally_fonder_form.php\" target=\"_parent\">Fonder une alliance</a></div>";
		echo "<br><br><div align=\"center\"><a href=\"ally_recrut.php\" target=\"_parent\">Demmander à etre recruter</a></div>";
		exit;
	}
	else { 
		echo "<br><br><div align=\"center\">Vous avez deja fait une demmande de recrutement.
		<br><div align=\"center\"><a href=\"ally_del_recrut.php\" target=\"_parent\">Suprimer la demmande.</a></div>";
		exit;
	}
}

$reponse  = db_mysql_Query("SELECT pts_ally FROM matgraph_ally WHERE id='$row2[ally]'");
$reponse2 = db_mysql_Query("SELECT COUNT(id) FROM matgraph_ally WHERE pts_ally > ".mysql_result($reponse,0));
$classement = mysql_result($reponse2,0)+1;

$reqtotal = "SELECT * FROM matgraph_ally";
$restotal = db_mysql_Query($reqtotal) or die('Erreur SQL! <br>'.$reqtotal.'<br>'.mysql_error());
$numtotal = mysql_num_rows($restotal);


$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); 

$req = "SELECT id FROM matgraph_users WHERE ally='$row[id]' ORDER by id ASC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
$present = htmlentities (stripslashes($row[presentation]));
$interne = htmlentities (stripslashes($row[txtinterne]));

$bbcode= array (
"/\[b\](.+?)\[\/b\]/si",
"/\[i\](.+?)\[\/i\]/si",
"/\[u\](.+?)\[\/u\]/si",
"/\[url=(.+?)\](.+?)\[\/url\]/si",
"/\[img\](.+?)\[\/img\]/si",

);
$htmlcode= array (
"<b>$1</b>",
"<i>$1</i>",
"<u>$1</u>",
"<a href='$1'>$2</a>",
"<img src='$1'>"
);
$present=preg_replace($bbcode,$htmlcode,$present);

$present=preg_replace('!\[color=(.+)\](.+)\[/color\]!isU', "<span style='color:$1'>$2</span>", $present); //couleur
$present=preg_replace('!\[align=(left|center|right)\](.+)\[/align\]!isU', "<div align='$1'>$2</div>", $present); //aligner

$present=nl2br($present);

$bbcode= array (
"/\[b\](.+?)\[\/b\]/si",
"/\[i\](.+?)\[\/i\]/si",
"/\[u\](.+?)\[\/u\]/si",
"/\[url=(.+?)\](.+?)\[\/url\]/si",
"/\[img\](.+?)\[\/img\]/si",

);
$htmlcode= array (
"<b>$1</b>",
"<i>$1</i>",
"<u>$1</u>",
"<a href='$1'>$2</a>",
"<img src='$1'>"
);
$interne=preg_replace($bbcode,$htmlcode,$interne);

$interne=preg_replace('!\[color=(.+)\](.+)\[/color\]!isU', "<span style='color:$1'>$2</span>", $interne); //couleur
$interne=preg_replace('!\[align=(left|center|right)\](.+)\[/align\]!isU', "<div align='$1'>$2</div>", $interne); //aligner

$interne=nl2br($interne);

echo "<table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">";

if(!empty($row[img])) { 
	echo"
	  <tr>
	    <td colspan=\"2\"><div align=\"center\"><img src=\"$row[img]\"></div></td>
	  </tr>";
}

echo "
  <tr style =\"background-color:#222222;\">
    <td width=\"119\"><strong>Nom : </strong></td>
    <td width=\"493\" align=\"center\">$row[nom]";
    
if($row2[statut] !== "0" AND $row_options[administrer] == "1" OR $row2[statut] == "-1") {
	echo " (Admininistration: <a href=\"ally_admin.php\" target=\"_parent\">Présentation</a>";
	if($row2[statut] !== "0" AND $row_options[admin] == "1" OR $row2[statut] == "-1") { 
		echo "; <a href=\"ally_droit.php\" target=\"_parent\">Statuts</a>";
		echo "; <a href=\"ally_defcon.php\" target=\"_parent\">DefCon</a>";
	}
	if($row2[statut] !== "0" AND $row2[statut] == "-1") {
		$req = "SELECT id FROM matgraph_users WHERE ally='$row2[ally]' AND id = idjoueur  ORDER BY id ASC";
		$res = db_mysql_Query($req);
		$num = mysql_num_rows($res);
		
		if ($num > 1) {
			echo "; <a href=\"ally_ceder.php\" target=\"_parent\">Ceder l'alliance</a>";
		}
		else {
			echo "; <a href=\"ally_terminer_confirm.php\" target=\"_parent\">Supprimer l'alliance</a>";
		}
	}
	echo ")";
}

echo"</td>
  </tr>
  <tr>
    <td><strong>Tag : </strong></td>
    <td align=\"center\">$row[tag]</td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td><strong>Classement : </strong></td>
    <td align=\"center\">$classement / $numtotal</td>
  </tr>
  <tr>
    <td><strong>Membres : </strong></td>
    <td align=\"center\">$num";

if($row2[statut] !== "0" AND $row_options[listemembres] == "1" OR $row2[statut] == "-1") {
	echo" (<a href=\"ally_liste_membres.php\" target=\"_parent\">Liste des membres</a>)";
} 
	
echo"</td></tr>";

if($row2[statut] !== "0" AND $row_options[mailcollectif] == "1" OR $row2[statut] == "-1") {
	echo"<tr style =\"background-color:#222222;\">
	    <td><strong>Mail collectif : </strong></td>
	    <td align=\"center\"><a href=\"ally_mail_collectif.php\" target=\"_parent\">Envoyer un mail collectif</a></td>
	  </tr>";
}

$req = "SELECT * FROM matgraph_ally_recrut WHERE idally = $row[id]";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);

if($num > 0) {
	if($row2[statut] !== "0" AND $row_options[recrutement] == "1" OR $row2[statut] == "-1") {
		echo"<tr>
		    <td><strong>Demmande(s) de recrutement : </strong></td>
		    <td align=\"center\"><a href=\"ally_demmande_recrut.php\" target=\"_parent\">$num Demmande(s)</a></td>
		  </tr>";
	}
}

echo"<tr style =\"background-color:#222222;\">
    <td height=\"39\" colspan=\"2\"><strong>Pr&eacute;sentation : </strong></td>
  </tr>
  <tr>
    <td colspan=\"2\">$present</td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td><strong>Page d'accueil :
    </strong></td>
    <td align=\"center\"><a href=\"$row[url]\" target=\"_blank\">$row[url]</a></td>
  </tr>
  <tr>
    <td colspan=\"2\"><strong>Texte interne : </strong></td>
  </tr>
  <tr style =\"background-color:#222222;\">
    <td colspan=\"2\">$interne</td>
  </tr>";

if($row2[statut] !== "-1") {
	echo"<tr>
	    <td colspan=\"2\" height=\"50\"><div align=\"center\"><a href=\"ally_quit.php\" target=\"_parent\">Quitter l'alliance</a></div></td>
	  </tr>"; 
}

echo"</table>
<br/>";
?>
