<?
require'../config.php';
$align='left';
$title='Битва брэндов';
aut();
head();



include_once 'func.php';


$bitva = num($_GET['bitva']);
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` = '".$user['id']."', `brand` = '".$brand['id']."', `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)){
$us = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '".$coment['user']."'"));
echo '<b>'.$us['nick'].'</b> ' . date2($coment['date']) . '<br/>' . $coment['coment'] . '<hr>';
}
echo '<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>';

}

echo '</center>';
echo gb.'<a href="'.H.'brend">Назад</a>'.div;
echo gb.'<a href="'.H.'enter">Прихожая</a>'.div;
foot();
?>
