<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
$title = 'Отряд';
include ('inc/header.php');
if(!$user) {
header('location: /');
exit();
}
$id = num($_GET['id']);
if($user['group'] == '0' and !$id) {
echo '<div class="main center">Вы не состоите в отряде!</div>';
echo '<a href="/groups.php" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$gr = mysql_fetch_array(mysql_query('SELECT * FROM `groups` WHERE `id` = "'.$id.'" LIMIT 1'));
mysql_free_result($gr);
if(!$gr) {
echo '<div class="main center">Отряд не найден!</div>';
echo '<a href="/" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($user['group'] == '0' and $_GET['to'] == 'vst') {
if($gr['status'] == '0') {
echo '<div class="main center">Закрыт свободный вход в этот отряд!</div>';
echo '<a href="/groups.php" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `group` = '".$gr['id']."' where `id` = '".$user['id']."'");
echo '<div class="main center">Вы вступили в отряд!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['to'] == 'zakok' and $gr['leader'] == $user['id']) {
if($gr['status'] == '1') {
mysql_query("update `groups` set `status` = '0' where `id` = '".$gr['id']."'");
echo '<div class="main center">Вы закрыли вход в отряд!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($gr['status'] == '0') {
mysql_query("update `groups` set `status` = '1' where `id` = '".$gr['id']."'");
echo '<div class="main center">Вы открыли вход в отряд!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
}
if($user['group'] == $gr['id']) {
if($_GET['to'] == 'ex') {
mysql_query("update `accounts` set `group` = '0' where `id` = '".$user['id']."'");
echo '<div class="main center">Вы покинули отряд!</div>';
echo '<a href="/groups.php" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
}
if($_GET['to'] == 'bon') {
if($gr['bonus'] > '10000') {
echo '<div class="main center">Максимальный бонус - 10000 ед.!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($user['cash'] < '50000') {
echo '<div class="main center">Не хватает '.(50000- $user['cash']).' рублей!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `groups` set `bonus` = `bonus` + '10' where `id` = '".$gr['id']."'");
mysql_query("update `accounts` set `cash` = `cash` - '50000' where `id` = '".$user['id']."'");
echo '<div class="main center">Бонус повышен!</div>';
echo '<a href="/group.php?id='.$gr['id'].'" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
echo '<div class="main"><img src="/style/src/group.png" height="20"> Отряд: '.$gr['name'].' <span style="float: right">'.$gr['rating'].' <img src="/style/src/rating.png"></span><br><br><small>Бонус: + '.$gr['bonus'].' к рейтингу и деньгам в боях!</small></div>';
$max = text(num($_GET['max']));
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `accounts` where `group` = '".$gr['id']."'"),0);
mysql_free_result($k_post);
if($max and $max >= '11') {
$sql = mysql_query("SELECT * FROM `accounts` where `group` = '".$gr['id']."' ORDER BY `rating` DESC LIMIT 0, $max");
}else{
$sql = mysql_query("SELECT * FROM `accounts` where `group` = '".$gr['id']."' ORDER BY `rating` DESC LIMIT 0, 10");
}
while($a = mysql_fetch_assoc($sql)) {
echo '<a href="/profile.php?id='.$a['id'].'" class="mini-link"><img src="/style/src/to.png" height="20"> '.$a['name'].' <span style="float: right">'.$a['rating'].' <img src="/style/src/rating.png"></span></a>';
mysql_free_result($a);
}
if($k_post > '10' and !$max) {
echo '<div class="new-line"></div><a href="?max='.$k_post.'" class="link center">Показать всех</a>';
}
if($k_post > '10' and $max) {
echo '<div class="new-line"></div><a href="?" class="link center">Скрыть всех</a>';
}
if($k_post < '1') {
echo '<div class="main center">Игроков тут нет!</div>';
}
if($gr['leader'] == $user['id']) {
echo '<div class="new-line"></div><a href="?id='.$gr['id'].'&to=zakok" class="link center">Открыть/закрыть вход</a>';
}
if($user['group'] == '0') {
echo '<div class="new-line"></div><a href="?id='.$gr['id'].'&to=vst" class="link center">Вступить в отряд</a>';
}
if($user['group'] == $gr['id']) {
echo '<div class="new-line"></div><a href="?id='.$gr['id'].'&to=bon" class="link center">Повысить бонус + 10 за 50000 <img src="/style/src/cash.png" height="14"></a>';
echo '<div class="new-line"></div><a href="?id='.$gr['id'].'&to=ex" class="link center">Покинуть отряд</a>';
}
include ('inc/footer.php');
?>