<? require('header.php');

if(!(isset($_SESSION["username"]) && isset($_SESSION["password"])))
{
	?>
	<script type="text/javascript">
	location.replace("login.php");
	</script>
	<noscript>
	<meta http-equiv="refresh" content="0; url=login.php">
	</noscript>
	<?
	exit();
}
require('konkurs/setup.php');
?>
<div class="menucenter">
<div class='navil'>
<table align='center'>
<tr>
<td><a href="referal_kon.php" title="Конкурсы от реферера" style="font-size:12px;padding:5px;">Конкурсы от реферера</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href="refer_kon.php" title="Конкурсы для рефералов" style="font-size:12px;padding:5px;">Конкурсы для рефералов</a></td>
</tr>
</table>
</div>
<div class='navil'>
<table align='center'>
<tr>
<td><img src='images/yeskon.png' alt='' align='absmiddle' width='16px' height='16px'></td>
<td>Активный конкурс.</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><img src='images/stopkon.png' alt='' align='absmiddle' width='16px' height='16px'></td>
<td>Завершенный конкурс.</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><img src='images/infokon.png' alt='' align='absmiddle' width='16px' height='16px'></td>
<td>Не начатый конкурс.</td>
</tr>
</table>
</div>
<?
if($_GET["idk"]==""){
$refer_kon=mysql_query("SELECT * FROM still_konkurs_ref WHERE idref=(SELECT id FROM tb_users WHERE username='".$duser["referer"]."') ORDER BY time_start DESC");

if(mysql_num_rows($refer_kon) <= 0){

	echo "<div class=error>На данный момент нет конкурсов от вашего реферера</div>";include("footer.php");exit;

}

while ($rk=mysql_fetch_assoc($refer_kon)){
$mest = explode(",",$rk["mesto"]);
$start = date("d.m.Yг. в H:i",$rk["time_start"]);
$end = date("d.m.Yг. в H:i",$rk["time_start"]+($rk["time_end"]*86400));

if($rk["time_start"] > time()){$status_k = "infokon.png";}
elseif($rk["time_start"] < time() and $rk["time_start"]+($rk["time_end"]*86400) > time()){$status_k = "yeskon.png";}
else{$status_k = "stopkon.png";} ;?>
<div class='menukon' style='margin-top:10px;'>
<div class='namekon'>
Старт конкурса:<?=$start?> ; 
Окончание конкурса:<?=$end?>
</div>
<table>
<tr>
<td width='35px' align='left'><img src='images/<?=$status_k?>' alt='' ></td>
<td width='470px'>Конкурс: <a href="referal_kon.php?idk=<?=$rk["id"]?>"><?=$con_kon["vid"][intval($rk["vid"])]?></a> <br />
<span class='serfinfotextkon'>Призы: <?$i_p=0;foreach($mest as $value){$i_p++;?>
<font color='red'><?=$value?></font> руб &nbsp;<small>|</small>&nbsp;<?}?></span>
</td>
<td><a href="referal_kon.php?idk=<?=$rk["id"]?>"><small>Подробнее »</small></a></td>
</tr>
</table>
</div>
<?}
}elseif($_GET["idk"]!=""){

$refer_kon=mysql_query("SELECT * FROM still_konkurs_ref WHERE (idref=(SELECT id FROM tb_users WHERE username='".$duser["referer"]."') and id='".intval($_GET["idk"])."') or (idref = '".$duser["id"]."' and id='".intval($_GET["idk"])."')");

if(mysql_num_rows($refer_kon) <= 0){

	echo "<div class=error>Это не Ваш конкурс или такого конкурса нет <br> <a href=\"#\" onclick=\"history.back();return false;\">Вернуться назад</a></div>";include("footer.php");exit;

}

$rk=mysql_fetch_assoc($refer_kon);
$mest = explode(",",$rk["mesto"]);
$start = date("d.m.Yг. в H:i",$rk["time_start"]);
$end = date("d.m.Yг. в H:i",$rk["time_start"]+($rk["time_end"]*86400));
if($rk["time_start"] > time()){$status_k = "infokon.png";}
elseif($rk["time_start"] < time() and $rk["time_start"]+($rk["time_end"]*86400) > time()){$status_k = "yeskon.png";}
else{$status_k = "stopkon.png";} ;?>
<div class='menukon' style='margin-top:10px;'>
<div class='namekon'>
Старт конкурса:<?=$start?> ; 
Окончание конкурса:<?=$end?>
</div>
<table>
<tr>
<td width='35px' align='left'><img src='images/<?=$status_k?>' alt='' ></td>
<td width='470px'>Конкурс: <a href="referal_kon.php?idk=<?=$rk["id"]?>"><?=$con_kon["vid"][intval($rk["vid"])]?></a> <br />
<span class='serfinfotextkon'>Призы: <?$i_p=0;foreach($mest as $value){$i_p++;?>
<font color='red'><?=$value?></font> руб.; <?}?></span>
</tr>
</table>
</div>

<div class='menukon' style='margin-top:5px;padding:5px;'>
<div class="namekon" style='margin:-5px -5px 5px;color:red;'>Описание:</div>
<table>
<tr>
<td>
<?=$rk["text"]?>
</td>
</tr>
</table>
</div>
<div class="menuheadbbb" align='center' style='margin-top:5px;'>TOP 15 Пользователей</div>
<div class='menukon' style='margin-top:5px;'>
<div class='namekon'>
<table align='center' style='font-size:11px;'>
<tr>
<td align="center" width='33%' style='font-size:11px;'>Место</td>
<td align="center" width='33%' style='font-size:11px;'>Логин</td>
<td align="center" width='33%' style='font-size:11px;'>Набрано очков.</td>
</tr>
</table>
</div>

<table class='reyt' border='0' cellpadding='0' cellspacing='0'>
<?$top_kon=mysql_query("SELECT danie,(SELECT username FROM tb_users WHERE id=still_top_kon.idu) as nam
FROM still_top_kon WHERE idk='".$rk["id"]."' ORDER BY danie DESC LIMIT 15");

if(mysql_num_rows($top_kon) <= 0){?>
<tr>
<td colspan='3' style='border-bottom:0px;'>Нет участников</td>
</tr>
<?}else{
  $i_top = 0;
  while ($tk=mysql_fetch_assoc($top_kon)){$i_top++;?>
<tr>
<td align="center" width="33%"><?=$i_top?>.</td>
<td align="center" width="33%"><?=$tk["nam"]?></td>
<td align="center" width="33%"><?=round($tk["danie"],2)?></td>
</tr>
<?
  }

}?></table></div>
<?}?>

<? require 'footer.php'; ?>