<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$row = mysql_fetch_assoc(mysql_query("select * from `blogs_records` where `id` = ".int($_GET['id']).""));
$str['mesto'] = 'Дневники';
$str['block'] = $set['site'].' / Дневники / Пользователь '.$user['login'].' / '.$row['title'];
include '../style/'.$style.'/head.php';
if(empty($row['title']))
{
	echo '<div class="on">Запись не найдена!</div>';
	include '../style/'.$style.'/foot.php';
	exit;
}
if(isset($_POST['text']) and !empty($_POST['text']) and !empty($_POST['rate']))
{
	$flood = mysql_fetch_assoc(mysql_query("select `time` from `blogs_comments` where `id_user` = ".$user['id']." order by `time` desc limit 1"));
    if($flood['time']<(time()-30))
    {
		echo '<div class="mess">Комментарий успешно добавлен!</div>';
		mysql_query("INSERT INTO `blogs_comments` (id_user,id_record,rate,text,time) VALUES (".$user['id'].",".$row['id'].",".int($_POST['rate']).",'".protect($_POST['text'])."',".time().")");
		mysql_query("UPDATE `blogs_records` SET `rate`=`rate`+".int($_POST['rate'])." WHERE `id`=".$row['id']."");
                            mysql_query("update `users` set `balls`=`balls`+1 where `id` = ".$user['id']."");	
}
	else
	{
		echo '<div class="mess">Антифлуд 30 секунд!</div>';
	}
}
$query = mysql_query("select * from `blogs_comments` where `id_record` = ".$row['id']." limit ".$page.",".$set['str']."");
$total = mysql_result(mysql_query("select count(*) from `blogs_comments` where `id_record` = ".$row['id'].""),0);
if($total == 0)
{
	echo '<div class="on">Комментариев нет! Будь первым!</div>';
}
while($r = mysql_fetch_assoc($query))
{
	$i++;
	if($i%2)
	{
		echo '<div class="forum1">';
	}
	else
	{
		echo '<div class="forum2">';
	}
	$u = mysql_fetch_assoc(mysql_query("select `login`,`id` from `users` where `id` = ".$r['id_user'].""));
    echo '<img class="ico" src="../style/'.$style.'/ico/personal.gif" alt="" />
    <a href="../p/'.$u['login'].'">'.$u['login'].'</a>';
    echo status($u['id']);
    echo '('.clock($r['time']).')
    <div class="ftext">'.text($r['text']).'<br />
    <b>Рейтинг</b>: '.$r['rate'].'<br />
    </div></div>';
}
echo '<div class="mess">
<form method="post" action="comments.php?id='.$row['id'].'">
<div>
<b>Сообщение</b>:<br/>
<textarea cols="22" rows="2" name="text" id="text"></textarea><br/>
<b>Оценка:</b>:<br/>
<select name="rate">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br/>
<input value="Отправить" type="submit"/></div></form></div>';
if($total > $set['str'])
{
	pages($page, $total, 'comments.php?id='.$row['id'].'&amp;', $set['str']);
}
echo '<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="index.php">Дневники</a><br/>
</div>';
include '../style/'.$style.'/foot.php';
?>