<?php
define('_IN_JOHNCMS', 1);
$headmod = 'tournament23454';
$textl = $lng['cup_turn'];
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");

// Новички
if ($id == 1)
{

//////////
$req = mysql_query("SELECT * FROM `r_cup` order by time desc LIMIT 1;");
$arr = mysql_fetch_array($req);
$reqs = mysql_query("SELECT * FROM `r_bilet` where id_cup = '" . $arr[id] . "' order by time asc;");
$totalbilet = mysql_num_rows($reqs);

$arrn = mysql_num_rows($req);
$cuptime = $vaqt - $arr['time'];

// $cuptime = 10000000000;
// $arr['status'] = 'yes';

//ПРОВЕРЯЕМ
if ($totalbilet>=8 or $arrn=='0')
{
$vaqt = time();

if ($arr['id_cup'] == 10)
{$id_cup = 1;}
else
{$id_cup = $arr['id_cup']+1;}

switch ($id_cup)
{
case "1":
$namecup = 'Yosh menejer kubogi';
$prizcup = 1000000;

break;
case "2":
$namecup = 'Ishbilarmon kubogi';
$prizcup = 4500000;

break;
case "3":
$namecup = 'Lider kubogi';
$prizcup = 4000000;

break;
case "4":
$namecup = 'Kitobxonlar kubogi';
$prizcup = 3500000;

break;
case "5":
$namecup = 'Menejer.cf kubogi';
$prizcup = 5000000;

break;
case "6":
$namecup = 'Do`stlar kubogi';
$prizcup = 3500000;

break;
case "7":
$namecup = 'Burunduq kubogi';
$prizcup = 4000000;

break;
case "8":
$namecup = 'Gladiator kubogi';
$prizcup = 3500000;

break;
case "9":
$namecup = 'Jentlmen kubogi';
$prizcup = 5000000;

break;
case "10":
$namecup = 'Oficiant kubogi';
$prizcup = 5500000;

break;
}

//echo 'СТАРТ!!!<br/>';
mysql_query("insert into `r_cup` set
`id_cup`='".$id_cup."',
`time`='".$vaqt."',
`name`='".$namecup."',
`priz`='".$prizcup."'
;");
}
// КУБКОВЫЕ МАТЧИ
echo '<div class="phdr"><b>'.$lng['cup_turn'].'</b></div>';

$req = mysql_query("SELECT * FROM `r_cup` order by time desc LIMIT 10;");
//$total = mysql_num_rows($req);


while ($arr = mysql_fetch_array($req))
{
	$b = mysql_query("SELECT * FROM `r_bilet` where id_cup = '" . $arr[id] . "' order by time desc;");
$totalbilet = mysql_num_rows($b);

echo"<table class='menu' width='100%'><tbody>
		<tr>
		<td width='15%' align='center'>
		<img class='image_table' src='/images/cup/b_$arr[id_cup].jpg' alt='CUP' heigth='80' width='80' />
		</td>
		<td width='85%'>
		<a href='cup.php?id=$arr[id]'>";
		if($totalbilet<8){echo'<b style="color: #FF2F2F;">';}else{
	echo"<b>";	
}
		echo''.$arr['name'].'</b></a>
		<div class="sub">
		'.$lng['date'].': <b>'.date("d.m H:i", $arr['time']).'</b><br />
		'.$lng['cup_players'].': <b>'.$totalbilet.'/8</b><br />
		'.$lng['award'].': <b>$'.$arr['priz'].'</b>
		</div></td>
		</tr>
		</tbody></table>';
}



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




//echo 'СТАРТ!!!<br/>';
/*
mysql_query("insert into `r_cup` set
`id_cup`='".$id_cup."',

`ot`='".$ot."',
`do`='".$do."',

`time`='".$vaqt."',
`name`='".$namecup."',
`priz`='".$prizcup."'
;");*/

///////



///////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////

///////
require_once ("../incfiles/end.php");
exit;
}
// КУБКОВЫЕ МАТЧИ
echo '<div class="phdr"><b>'.$lng['cup_turn'].'</b></div>';


$req = mysql_query("SELECT * FROM `r_cup` order by time desc LIMIT 10;");
//$total = mysql_num_rows($req);


while ($arr = mysql_fetch_array($req))
{	
$b = mysql_query("SELECT * FROM `r_bilet` where id_cup = '" . $arr[id] . "' order by time desc;");
$totalbilet = mysql_num_rows($b);

echo'<div class="uitems">

<div class="uitem1" style="padding: 5px;"><a href="cup.php?id=20" style=""><img src="/images/cup/m_'.$arr[id_cup].'.jpg" alt="CUP" style="max-width: 48px;"/></a></div>

<div class="uitem2"><a href="cup.php?id='.$arr[id].'" style="padding: 5px; margin-left: 64px;">';

if($totalbilet<8){echo'<b style="color: #FF2F2F;">';}else{
	echo"<b>";
	
}

echo''.$arr['name'].'</b>

<span class="grey" style="font-size:11px;">'.date("H:i", $arr['time']).' </span><br/>

<span style="color: #000; padding-top: 6px; display: block;">
'.$lng['award'].': <b>' . $arr['priz'] . ' $</b><br/>

'.$lng['cup_players'].': <b>' . $totalbilet . '/8</b><br/>
</span>

 </a></div><div style="clear:both"></div></div>
';
}

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