<?php
include_once '../sys/inc/home.php';
include_once H.'sys/inc/start.php';
include_once H.'sys/inc/compress.php';
include_once H.'sys/inc/sess.php';
include_once H.'sys/inc/settings.php';
include_once H.'sys/inc/db_connect.php';
include_once H.'sys/inc/ipua.php';
include_once H.'sys/inc/fnc.php';
include_once H.'sys/inc/user.php';

include_once 'duels_start.php';

$set['title'] = 'Дуэли';
include_once H.'sys/inc/thead.php';
title();
aut();

$q = mysql_query("SELECT * FROM `duels` WHERE  `status` ='1' AND `time` > '$duel_time' ORDER BY `id` ASC LIMIT 1");
$duel = mysql_fetch_assoc($q);
$icon = "<img src='star.png' alt=''/>";

$duser_rat = mysql_fetch_array(mysql_query("SELECT * FROM `duels_rat` WHERE `id_user` = '{$user['id']}' AND `id_duel` = '{$duel['id']}' LIMIT 1"));

if ($duel['time'] > $duel_time){
if (isset($user)) {
if ($duser_rat['id_duser']=='0' || !$duser_rat['id']){
$golosuser = "<img src='yes.gif' alt=''/> <a href='duel.php?id=$duel[id]&amp;user'>Мне нравится</a><br />";
} else {
$golosuser = "<img src='yes.gif' alt=''/> Вам нравится<br />";
}
if ($duser_rat['id_dank']=='0' || !$duser_rat['id']){
$golosank = "<img src='yes.gif' alt=''/> <a href='duel.php?id=$duel[id]&amp;ank'>Мне нравится</a><br />";
} else {
$golosank = "<img src='yes.gif' alt=''/> Вам нравится<br />";
}
}
}

if (mysql_num_rows($q)){
$ank = get_user($duel['id_user']);
$ank2 = get_user($duel['id_ank']);

$duser = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_rat` WHERE  `id_duser` = '1' AND `id_duel` = '$duel[id]'"), 0);
$dank = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_rat` WHERE  `id_dank` = '1' AND `id_duel` = '$duel[id]'"), 0);

	echo "<table class='post'>";
	echo "<tr>\n";
	echo "<td class='p_t'>\n";
	echo "<img src='/style/icons/duels.png' alt=''/> <a href='duel.php?id=$duel[id]'>Дуэль №$duel[id]</a> (" . vremja($duel['time'] + $duel_config['duel_time']) . ")<br />";
	echo "</td>\n";
	echo "</tr>\n";
	echo "<tr>\n";
	echo "<td class='p_m'>\n";
	echo "<img src='/style/themes/{$set['set_them']}/user/{$ank['pol']}.png' alt='' /> <a href='/info.php?id=$duel[id_user]'>{$ank['nick']}</a> " . ($duser >= $dank? $icon:'') . "<br />";
	echo "<img class='photo' src='avatars/$duel[id]/$duel[id_user].jpg' alt=''/> <br />";
	echo "<div class='$div'>";
	echo $golosuser;
	echo "<img src='who.png' alt=''/> <a href='duel.who.php?id=$duel[id]&amp;user'>Кто голосовал?</a> ($duser " . number($duser,'голос', 'голоса', 'голосов') . ")";
	echo "</div>";
	echo "</td>\n";
	echo "</tr>\n";
	echo "<tr>\n";
	echo "<td class='p_t'>\n";
	echo "Против:";
	echo "</td>\n";
	echo "</tr>\n";
	echo "<tr>\n";
	echo "<td class='p_m'>\n";
	echo "<img src='/style/themes/{$set['set_them']}/user/{$ank2['pol']}.png' alt='' /> <a href='/info.php?id=$duel[id_ank]'>{$ank2['nick']}</a> " . ($dank > $duser? $icon:'') . "<br />";
	echo "<img class='photo' src='avatars/$duel[id]/$duel[id_ank].jpg' alt=''/> <br />";
	echo "<div class='$div'>";
	echo $golosank;
	echo "<img src='who.png' alt=''/> <a href='duel.who.php?id=$duel[id]&amp;ank'>Кто голосовал?</a> ($dank " . number($dank,'голос', 'голоса', 'голосов') . ")";
	echo "</div>";
	echo "</td>\n";
	echo "</tr>\n";
	echo "</table>";
} else {
	echo "<div class='post'>";
	echo 'Дуэлей нету =(';
	echo "</div>";
}


$icon = "<img src='/style/icons/duels.png' alt=''/>";
echo "<div class='post'>";
echo "{$icon} <a href='duels.php'>Все дуэли</a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `duels` WHERE `status`='1' AND `time` > '$duel_time'"), 0).")<br />";
if (isset($user)) {
echo "{$icon} <a href='duels.php?order=myd'>Мои дуэли</a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `duels` WHERE `status`='1' AND `id_user` = '{$user['id']}' AND `time` > '$duel_time'"), 0) . ")<br />";
echo "{$icon} <a href='duels.php?order=my'>Мои участия</a> (" . mysql_result(mysql_query("SELECT COUNT(*) FROM `duels` WHERE `status`='1' AND `id_ank` = '{$user['id']}' AND `time` > '$duel_time'"), 0) . ")<br />";
}
echo "{$icon} <a href='duels.archive.php'>Архив дуэлей</a> (" . mysql_result(mysql_query("SELECT COUNT(*) FROM `duels` WHERE `status`='1' AND `time` < '$duel_time'"), 0) . ")<br />";
if ($user['group_access'] == 15)echo "{$icon} <a href='admin_panel.php'><font color='red'>Админка дуэлей</font></a><br />";
echo "</div>";


include_once H.'sys/inc/tfoot.php';
?>