<?php
include '../system/bd.php';
include '../system/cook.php';
include ("../system/gzip.php");
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include '../system/head.php';




$req = mysql_query("SELECT * FROM `user` WHERE `id` = '$user[id]'");
////////////////////////////

$avto=mysql_num_rows($req);
if($avto=="0"){
echo"<img src='/pic/main/!.png' alt='*'/> Ошибка 1";
include '../system/foot.php';
exit;
}

$us = mysql_fetch_array($req);

if(empty($_GET[id])){echo"<img src='/pic/main/!.png' alt='*'/> Ошибка 2";
include '../system/foot.php';
exit;}


$req = mysql_query("SELECT * FROM `clans` where `id`='".mysql_real_escape_string($_GET['id'])."'");

$avto=mysql_num_rows($req);
if($avto==1){
$clan1 = mysql_fetch_array($req);
$req = mysql_query("SELECT `id` FROM `user` where `clan`='$clan1[id]'");


////////////////////////////
$kk=mysql_num_rows($req);


echo '' ;
} else{
echo"Ошибка 3";
include '../system/foot.php';
exit;}

switch($_GET[mod]){
default:

$nickas = strip_tags($clan1[leader]);

if(empty($user[clan])){


$req = mysql_query("SELECT * FROM `clans_invite` where `usr`='$user[id]' and `clan` ='$clan1[id]'");
$avto=mysql_num_rows($req);
if($avto==0){
echo"<center> <a href=\"?mod=invite&id=$clan1[id]\"> Заявка на вступление в банду </a></center>";
}else{
echo"<center> <a href=\"?mod=nou&id=$clan1[id]\">Отменить заявку на вступление</a></center>";
}
}



echo ' <div class="title">Клан</div>';

echo ' <div class="bor1"><div class="bor2"><div class="bor3"><div class="bor4"><div class="bor_bg item_center"> ';
echo" <b>$clan1[name]</b><br>";

echo ' </div> </div> </div> </div></div>';


echo ' <div class="empty_block"> ';
if(!empty($clan1[mail])){
$koment = strip_tags($clan1['mail']);

$koment = tags($koment);
echo"О банде: $koment";
echo '<br>';
}else{
echo"<img src='/pic/main/chat3.png' alt='*'/> О банде: Нет информации.";
echo '<br>';
}

echo"<img src='/pic/main/timereg.png' alt='*'/> Основана: ";
$d = time()-$clan1[datareg];
echo ' ('.sec2day($d).' назад)<br>';

echo"<img src='/pic/main/up.png' alt='*'/> Уровень банды: $clan1[lvl]/5";

echo"<br><img src='/pic/main/progress.gif' alt='*'/> Опыт банды: $clan1[exp] ";

echo"<center>Характеристики:<br>";
echo"<img src='../img/icon/hp.png' alt='*'/> $clan1[hp] 0";
echo"<img src='../img/icon/attack.png' alt='*'/> $clan1[attack] ";
echo"<img src='../img/icon/def.png' alt='*'/> $clan1[def]";
echo"</center>";
echo"";
echo ' </div>';

echo ' <div class="bor1"><div class="bor2"><div class="bor3"><div class="bor4"><div class="bor_bg item_center"> ';
echo"<center>Состав банды: <img src='/pic/main/banda1.png' alt='*'/> ($kk) из ($clan1[composition])</center>";
echo ' </div> </div> </div> </div></div>';
////////////////////////////

$req = mysql_query("SELECT * FROM `clans` WHERE `id` = '$clan1[id]'");
$cl = mysql_fetch_array($req);




$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `clan` ='$clan1[id]' "),0);

$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';


$req = mysql_query("SELECT `clan`, `clan_prava`, `clan_exp`,`login`,`exp`, `id`, `rasa`,  `sex`, `storona`, `online`, `lvl` FROM `user` WHERE `clan` ='$clan1[id]'  ORDER BY clan_prava  LIMIT $start,$cop ");
////////////////////////////






$avto=mysql_num_rows($req);
if($avto>=1){

While($us1 = mysql_fetch_array($req))
{


echo '<div class="block_link">';

echo"
<a href='../users.php?id=$us1[id]'>";
$d = time()-7000;
if($us1[online] < $d) { 
echo"<img src='../img/user/icons/".$us1[storona]."_".$us1[rasa]."_off.png'>"; 
}else{
echo"<img src='../img/user/icons/".$us1[storona]."_".$us1[rasa].".png'>";
}

 echo "$us1[login] ";
if($us1[clan_prava] == leader){
echo " <font color=#32CD32>Лидер</font>";
}
if($us1[clan_prava] == deputy){
echo " <font color=#32CD32>Заместитель</font>";
}
if($us1[clan_prava] == squaddie){
echo " <font color=#32CD32>Новобранец</font>";
}

if($us1[clan_prava] == rookie){
echo " <font color=#32CD32>Новобранец</font>";
}
echo " $us1[clan_exp] exp 
</a></div>";
echo ' <div class="line"> </div>';
}

$re = mysql_query("SELECT * FROM `clans` where `id`='".mysql_real_escape_string($_GET['id'])."'");
$clan11 = mysql_fetch_array($re);

echo '
<div class="empty_block top pagi item_center">';
if($page-1>0){

echo '<a href="clans.php?id='.$cl[id].'&page='.($page-1).'">&lt;</a> ';

}

if($page-1>0){

echo '<a href="clans.php?id='.$cl[id].'?&page='.($page-1).'">'.($page-1).'</a> ';

}

echo '<b>'.$page.'</b>';

if($page+1<=$cp){

echo ' <a href="clans.php?id='.$cl[id].'?&page='.($page+1).'">'.($page+1).'</a>';

}

if($page+1<=$cp){

echo ' <a href="clans.php?id='.$cl[id].
'?&page='.($page+1).'">&gt;</a>';

}

echo " </div> ";

}else{
echo "<img src='/pic/main/!.png' alt='*'/> Нет игроков.";

}
break;

case 'nou':

mysql_query("DELETE FROM `clans_invite` WHERE `usr`='$user[id]' ");

$req = mysql_query("SELECT * FROM `clans` where `leader`='".mysql_real_escape_string($_GET['id'])."'");
$avto=mysql_num_rows($req);
if($avto==1){
$clan3 = mysql_fetch_array($req);
header ("Location: ?id=$clan3[leader]"); exit;

}else{
echo' вы отмелили заявку';
}

break;
case 'invite':








mysql_query("INSERT INTO `clans_invite` SET `clan` = '".intval($_GET['id'])."',`usr` = '$user[id]'");


$req = mysql_query("SELECT * FROM `clans` where `leader`='".mysql_real_escape_string($_GET['id'])."'");
$avto=mysql_num_rows($req);
if($avto==1){
$clan2 = mysql_fetch_array($req);
header ("Location: ?id=$clan2[id]"); 
exit;
}else{
echo' заявка отправлена';

}


////////////////
}
}else{
header ("Location: index.php"); exit;
}
include '../system/foot.php';
?>
