<?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'Ошибка 1';
include 'inc/nogi.php';
exit;
}
$us = mysql_fetch_array($req);
if(empty($us[clan])){
echo' <div class="title">Ошибка</div>
<div class="empty_block item_center"> Вы не состоите в банде! </div>';
echo'<div class="block_link">';
echo"<a href='../index.php'> <img src ='../img/images/arrow.png'> Вернуться</a></div>";
include '../system/foot.php';
exit;
}
/////////////

if($us[clan]!="$clans[id]"){

$req = mysql_query("SELECT * FROM `clans` where `id`='$us[clan]' or `leader`='$us[clan]' ");

$req = mysql_query("SELECT * FROM `clans` where `id`='$us[clan]' or `leader`='$us[clan]' ");

$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 '' ;
switch($_GET[mod]){
default:

echo '<div class="title">Заявки</div>';

if (isset($_GET['yes'])){
	$_GET['yes']=intval($_GET['yes']);
	if ($_GET['yes']!=$user['id']){
	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `clans_invite` WHERE `usr`='".$_GET['yes']."' AND `clan`='".$clan1['id']."'"),0)){
		if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id`='".$_GET['yes']."'"),0)){

$req = mysql_query("SELECT * FROM `clans` where `leader`='$user[id]'");
$avto=mysql_num_rows($req);
if($avto==1){
$clanss = mysql_fetch_array($req);

$req = mysql_query("SELECT `id` FROM `user` where `clans`='$user[clan]'");
////////////////////////////
$kk=mysql_num_rows($req);

if($kk==$clanss[composition]){
echo"<img src=\"pic/main/!.png\"> В банде нет свободных мест для вступлений.";
include '../system/foot.php';
exit;
}
}

mysql_query("UPDATE `user` SET `clan`='$user[clan]', `clan_prava` = 'rookie' WHERE `id` = '".mysql_real_escape_string($_GET['yes'])."' ");

$req = mysql_query("SELECT `login`,`id` FROM `user` WHERE `id` = '".mysql_real_escape_string($_GET['yes'])."'");

$pic = mysql_fetch_array($req);
$dater= time();
$n2='Персонаж <a href=\"../users.php?id='.$pic[id].'\">'.$pic[login].'</a> вступил в банду!';
mysql_query("INSERT INTO `clans_journal` SET `clan`='$user[clan]',
`msg`='$n2', `time` = '$dater' ");

mysql_query("DELETE FROM `clans_invite` WHERE `usr`='".mysql_real_escape_string($_GET['yes'])."'"); 			

echo '<img src="/pic/main/!.png" alt="*"/> Заявка принята.<hr>';
		}
	}
	}
}

if (isset($_GET['del'])){
	$_GET['del']=intval($_GET['del']);
	if ($_GET['del']!=$user['id']){
	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `clans_invite` WHERE `usr`='".$_GET['del']."' AND `clan`='".$clan1['id']."'"),0)){
		if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id`='".$_GET['del']."'"),0)){
mysql_query("DELETE FROM `clans_invite` WHERE `clan`='".$clan1['id']."' AND `usr`='".mysql_real_escape_string($_GET['del'])."'"); 			
echo '<img src="/pic/main/!.png" alt="*"/> Заявка отклонена.<hr>';
		}
	}
	}
}


////

$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `clans_invite` WHERE `clan` ='$user[clan]' "),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`, `usr` FROM `clans_invite` WHERE `clan` ='$user[clan]'  ORDER BY clan DESC LIMIT $start,$cop ");
////////////////////////////




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


while($ur=mysql_fetch_array($req)){

$result = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`='".$ur['usr']."'"));



echo '<div class="block">';
echo"
<a href='../users.php?id=$result[id]'>";

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


 echo "$result[login] - <img src='/img/icon/lvl.png' alt='*'/> $result[lvl] </a>";
echo '(<a href="?&yes='.$result['id'].'">Принять</a>) (<a href="?&del='.$result['id'].'">Отклонить</a>)';
echo ' </div>';
echo ' <div class="line"> </div>';
}


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

echo '<a href="invite.php?&page='.($page-1).'">&lt;</a> ';
}

if($page-1>0){

echo '<a href="invite.php?&page='.($page-1).'">'.($page-1).'</a> ';

}

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

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

echo ' <a href="invite.php?&page='.($page+1).'">'.($page+1).'</a>';

}

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

echo ' <a href="invite.php?&page='.($page+1).'">&gt;</a>';

}

echo "</div>";


}else{
echo " <div class='empty_block del_bottom item_center'> Нет игроков </div>";
}
}}
/////

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

//////////////////
}else{
header ("Location: index.php"); exit;
} 

include '../system/foot.php';
?>
