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

$icon = "<img src='star.png' alt=''/>";

$count_posts = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels` WHERE  `status` = '1' AND `time` < '$duel_time'"), 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` WHERE  `status` ='1' AND `time` < '$duel_time' ORDER BY `id` DESC LIMIT {$start}, {$set['p_str']}");

while ($duel = mysql_fetch_assoc($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` = '{$ank['id']}' AND `id_duel` ='$duel[id]'"), 0);
$dank = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_rat` WHERE  `id_dank` = '{$ank2['id']}' AND `id_duel` ='$duel[id]'"), 0);

	echo "<table class='post'>";

	echo "<tr>";
	echo "<td class='p_t'>";

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>";
	echo "</tr>";
	echo "<tr>";
	echo "<td class='p_m'>";
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 "<img src='who.png' alt=''/> <a href='duel.who.php?id=$duel[id]&amp;user'>Кто голосовал?</a> ($duser " . number($duser,'голос', 'голоса', 'голосов') . ")";
echo "</div>";
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td class='p_t'>";
	echo "Против:";
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td class='p_m'>";
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 "<img src='who.png' alt=''/> <a href='duel.who.php?id=$duel[id]&amp;user'>Кто голосовал?</a> ($dank " . number($dank,'голос', 'голоса', 'голосов') . ")";
echo "</div>";

	echo "</td>\n";
	echo "</tr>\n";
	echo "</table>";
}

if ($count_pages > 1)str('?', $count_pages, $page);

echo "<div class='foot'>";
echo "&laquo; <a href='./'>Дуэли</a><br />";
echo "</div>";

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