<?
include '../config.php';
include '../func.php';
head();
aut();
ban();

echo head . 'Битва брендов' . div . katalog;
echo '<center>';
$all = mysql_result(mysql_query("SELECT count(*) FROM `brand`"), 0);

if($all == 0)
    echo 'Бренды еще не созданы';
    
$result = mysql_query("SELECT * FROM brand order by id desc limit 1");
while($brand = mysql_fetch_assoc($result)){
    echo '<b>' . $brand['name'] . '</b><br/><br/>';
    echo '<b>' . $brand['brand1'] . '</b> VS <b>' . $brand['brand2'] . '</b><br/>';
    
    if ($brand['time'] > time())
        echo '<b>Битва активна</b><br/>';
    else
        echo 'Битва завершена<br/>';
        
    echo '<br/>';
    
    echo '<img src="files/'.$brand['f_brand_1'].'" alt="" /> VS <img src="files/'.$brand['f_brand_2'].'" alt="" /><br/>';
    
    $vote1 = mysql_result(mysql_query("SELECT count(*) FROM `brand_vote` WHERE `golos` = '1' AND `brand` = '".$brand['id']."'"), 0);
    $vote2 = mysql_result(mysql_query("SELECT count(*) FROM `brand_vote` WHERE `golos` = '2' AND `brand` = '".$brand['id']."'"), 0);
    
    if ($brand['time'] > time())
        
        echo '<b><a href="vote.php?mod=1&bitva='.$brand['id'].'">' . $brand['brand1'] . '</a> ['.$vote1.'] </b> или <b><a href="vote.php?mod=2&bitva='.$brand['id'].'">' . $brand['brand2'] . '</a> ['.$vote2.'] </b>?<br/><br/>';
    
    else {
        if ($vote1 > $vote2)
            $znak = '>';
        elseif($vote1 < $vote2)
            $znak = '<';
        else
            $znak = '=';
            
        echo '<b>' . $brand['brand1'] . ' ['.$vote1.'] </b> '.$znak.' <b>' . $brand['brand2'] . ' ['.$vote2.'] </b><br/><br/>';
    
    }
    if ($brand['time'] > time())    
    echo '<b>Пора выяснить что круче!</b><br/>';
    echo '<b>Битва запущена:</b> ' . date2($brand['date']) . '</b><br/>';
    $coments = mysql_result(mysql_query("SELECT count(*) FROM `brand_coment` WHERE `brand` = '".$brand['id']."'"), 0);
    if ($brand['coment'] == 1)
    echo '<b><a href="coment.php?bitva='.$brand['id'].'">Коментарии</a></b> ['.$coments.']<br/>';
}

$brand_all = mysql_result(mysql_query("SELECT count(*) FROM `brand`"), 0);
echo '<br/><b>Все битвы</b> ['.$brand_all.']<br/>';

if($brand_all){
$onpage = 5;
$allpage = ceil($brand_all/$onpage);
$this_page = (isset($_GET['p'])) ? intval($_GET['p']) : 1 ;
if($this_page < 1 || $this_page > $allpage)$this_page = 1;
$start = $this_page*$onpage - $onpage;
$result = mysql_query("SELECT * FROM brand order by id desc limit ".num($start).",".num($onpage)."");
while($brand = mysql_fetch_assoc($result)){
    $vote1 = mysql_result(mysql_query("SELECT count(*) FROM `brand_vote` WHERE `golos` = '1' AND `brand` = '".$brand['id']."'"), 0);
    $vote2 = mysql_result(mysql_query("SELECT count(*) FROM `brand_vote` WHERE `golos` = '2' AND `brand` = '".$brand['id']."'"), 0);
            if ($vote1 > $vote2)
            $znak = '>';
        elseif($vote1 < $vote2)
            $znak = '<';
        else
            $znak = '=';
    echo '<b><a href="view.php?bitva='.$brand['id'].'">' . $brand['brand1'] . ' '.$znak.' ' . $brand['brand2'] . '</a></b> ['.$vote1.'/'.$vote2.']<br/>';
}

echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"index.php?p={p}",1,1);
}
echo div . katalog;
echo '<center><b><a href="end.php">Завершенные битвы</a></b><br/>';

echo '</center>';
echo div;


echo div;
navig();
foot();
?>
