<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
$title = 'Отряды';
include ('inc/header.php');
if(!$user) {
header('location: /');
exit();
}
if(isset($_POST['new_group'])) {
$group = text($_POST['group']);
if($user['cash'] < '50000') {
echo '<div class="main center">Не хватает '.(50000- $user['cash']).' рублей!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(strlen($group) < 3 or strlen($group) > 19) {
echo '<div class="main center">Допустимая длина названия отряда 3-19 символов!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `groups` WHERE `name` = \''.$group.'\''),0) != 0) {
echo '<div class="main center">Выбранное название занято!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query('INSERT INTO `groups` (`name`, `leader`) VALUEs ("'.$group.'", "'.$user['id'].'")');
$id = mysql_insert_id();
mysql_query("update `accounts` set `cash` = `cash` - '50000', `group` = '".$id."' where `id` = '".$user['id']."'");
echo '<div class="main center">Отряд создан!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$max = text(num($_GET['max']));
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `groups`"),0);
mysql_free_result($k_post);
if($max and $max >= '11') {
$sql = mysql_query("SELECT * FROM `groups` ORDER BY `rating` DESC LIMIT 0, $max");
}else{
$sql = mysql_query("SELECT * FROM `groups` ORDER BY `rating` DESC LIMIT 0, 10");
}
while($g = mysql_fetch_assoc($sql)) {
echo '<a href="/group.php?id='.$g['id'].'" class="mini-link"><img src="/style/src/group.png" height="20"> '.$g['name'].' <span style="float: right">'.$g['rating'].' <img src="/style/src/rating.png"></span></a>';
mysql_free_result($g);
}
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>';
}
echo '<form action="?new=ok" method="POST" class="main center">Название отряда:<br><input type="text" name="group"><input type="submit" name="new_group" value="Создать" class="input_send"><div class="new-line"></div><small>стоимость создания - 50000 рублей!</small></form>';
include ('inc/footer.php');
?>