<?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';
only_reg();

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header('Location: ./');
    exit;
}

$id = (int)$_GET['id'];

$q = mysql_query("SELECT * FROM `duels` WHERE `id` = '{$id}'");
$duel = mysql_fetch_assoc($q);

if (!mysql_num_rows($q)) {
    header('Location: ./');
    exit;
}
if (!isset($_GET['user']) && !isset($_GET['ank'])) {
    header('Location: ./');
    exit;
}
if (isset($_GET['user']) && isset($_GET['ank'])) {
    header('Location: ./');
    exit;
}

if (isset($_GET['user'])) {
    $UserAnk = 'user';
}
if (isset($_GET['ank'])) {
    $UserAnk = 'ank';
}
$set['title'] = 'Кто голосовал?';
include_once H.'sys/inc/thead.php';
title();
aut();

$count_posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_rat` WHERE `id_d$UserAnk` = '1' AND `id_duel` = '{$duel['id']}' "), 0);
$count_pages = k_page($count_posts, $set['p_str']);
$page = page($count_pages);
$start = $set['p_str']*$page-$set['p_str'];

if ($count_posts == 0) {
	echo "<div class='post'>";
	echo "Голоса отсутствуют";
	echo "</div>";
}

$q = mysql_query("SELECT * FROM `duels_rat` WHERE `id_d$UserAnk` = '1' AND `id_duel` = '{$duel['id']}' ORDER BY `id` DESC LIMIT {$start}, {$set['p_str']}");
while ($who = mysql_fetch_assoc($q)) {
    $ank = get_user($who['id_user']);
 
    $title = "<a href='/info.php?id={$ank['id']}'>{$ank['nick']}</a>" . online($ank['id']) . ' (' . vremja($who['time']) . ')';
    $icon = "<img src='/style/themes/{$set['set_them']}/user/{$ank['pol']}.png' alt='' />";
	
	echo "<table class='post'>\n";
	echo "<tr>\n";
    echo "<td class='icon14'>\n";
    echo $icon;
    echo "</td>\n";
	echo "<td class='p_t'>\n";
	echo $title;
	echo "</td>\n";
	echo "</tr>\n";
	echo "</table>\n";
}

if ($count_pages > 1)str("?id={$duel['id']}&amp;{$UserAnk}&amp;", $count_pages, $page);

echo "<div class='foot'>
&laquo; <a href='duel.php?id={$duel['id']}'>К дуэли</a><br />
&laquo; <a href='./'>Дуэли</a><br />
</div>";

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