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

$bitva = num($_GET['bitva']);
echo head . 'Битва брендов' . div . katalog;
echo '<center>';

$brand = mysql_fetch_assoc(mysql_query("SELECT * FROM `brand` WHERE `id` = '".$bitva."'"));
if (empty($brand['id'])) $err = 'Данной битвы не существует';
if ($brand['coment'] == 0) $err = 'Коментарии для битвы не доступны';



if (isset($err))
    echo '<b>Ошибка:</b> ' . $err . '<br/>';
else {
if (isset($_POST['submit'])) {
    $msg = html($_POST['msg']);
    if (mysql_query("INSERT INTO `brand_coment` SET `coment` = '".$msg."', `user` = '".$id_session."', `brand` = '".$brand['id']."', `date` = '".time()."' "))
    {
            $msg1 = '<b>'.user($id_session).'</b> оставил коментарий в <b><a href="brands/">брендах</a></b>';
            mysql_query("INSERT INTO `jurnal` SET  `msg` = '".$msg1."', `user` = '".$id_session."', `date` = '".time()."'");
        header('Location: coment.php?bitva='.(int)$_GET['bitva']);
    }
}



$all = mysql_result(mysql_query("SELECT count(*) FROM `brand_coment` WHERE `brand` = '".$brand['id']."'"), 0);

if($all == 0)
    echo 'Коментарий нет';
    
$result = mysql_query("SELECT * FROM brand_coment WHERE `brand` = '".$brand['id']."'");
while($coment = mysql_fetch_assoc($result)){
    echo '<b>'.user($coment['user']).'</b> ' . date2($coment['date']) . '<br/>' . $coment['coment'] . '<hr>';
}
    
    echo link1 . '<form action="coment.php?bitva='.$bitva.'" method="post" name="form">';
    echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;"></textarea><br/>';
    echo '<input name="submit" type="submit" class="button" value="Написать" /></form>' . div;

}

echo '</center>';
echo div;


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