<?php
define('_IN_JOHNCMS', 1);
$headmod = 'tournament';
$textl = 'Заявка';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");

$kk = @mysql_query("select * from `fman_clubs` where id='" . $datauser[manager2] . "' LIMIT 1;");
$kom = @mysql_fetch_array($kk);
$vaqt = time();
if (empty($kom[id]))
{
    echo display_error('У Вас нет команды');
    require_once ('../incfiles/end.php');
    exit;
}

$q = @mysql_query("select * from `r_cup` where id='" . $id . "' LIMIT 1;");
$cup = @mysql_fetch_array($q);

if (empty($cup[id]))
{
    echo display_error('Кубка не существует');
    require_once ('../incfiles/end.php');
    exit;
}

$result = @mysql_query("SELECT SUM(fiz) FROM `fman_players` WHERE (`id`='".$kom['p1']."' or `id`='".$kom['p2']."' or `id`='".$kom['p3']."' or `id`='".$kom['p4']."' or `id`='".$kom['p5']."' or `id`='".$kom['p6']."' or `id`='".$kom['p7']."' or `id`='".$kom['p8']."' or `id`='".$kom['p9']."' or `id`='".$kom['p10']."' or `id`='".$kom['p11']."') AND `team_id`='".$kom['id']."' LIMIT 11");


$dostart = $cup['time'] - $vaqt;
if ($dostart > 900 || $cup['status'] == 'yes')
{
    echo display_error('Приём заявок запрещен');
    require_once ('../incfiles/end.php');
    exit;
}


$req = mysql_query("SELECT * FROM `r_bilet` where id_cup = '" . $id . "' and id_team = '" . $kom[id] . "' order by time desc;");
$total = mysql_num_rows($req);

if ($total != 0)
{
    echo display_error('Вы уже подали заявку');
    require_once ('../incfiles/end.php');
    exit;
}


mysql_query("insert into `r_bilet` set 
`time`='".$vaqt."', 
`id_cup`='".$id."', 
`id_team`='".$kom[id]."', 
`union_team`='0', 
`name_team`='".$kom[name]."';");

header('location: /tournament/cup.php?id='.$id);
exit;


require_once ("../incfiles/end.php");
?>
