<?php
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';

if(!isset($_GET['id']))
{
$set['title']='Ошибка';
include_once '../../sys/inc/thead.php';
title();
aut();
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
echo "Нет такой записи!";
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
include_once '../../sys/inc/tfoot.php';
exit();
}
$id = intval($_GET['id']);
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_list` WHERE  `id` = '".intval($_GET['id'])."'"),0) ==0)
{
$set['title']='Ошибка';
include_once '../../sys/inc/thead.php';
title();
aut();
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
echo "Нет такой записи!";
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
include_once '../../sys/inc/tfoot.php';
exit();
}
$notes=mysql_fetch_array(mysql_query("select * from `blog_list` where `id`='".intval($_GET['id'])."';"));
if($notes['privat'] == 1)
{
if (($user['level'] < 2) && ($user['id']!=$notes['id_user']))
{
$set['title']='Закрыто';
include_once '../../sys/inc/thead.php';

title();
aut();
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
echo "Это приватная заметка!";
echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";
include_once '../../sys/inc/tfoot.php';
exit();
}
}


$ank=get_user($notes['id_user']);
$set['title']='Заметки - '.$ank['nick'].'';
include_once '../../sys/inc/thead.php';

title();
aut();
err();
if (isset($user) && $user['id']!=$ank['id'])
{mysql_query("UPDATE `blog_list` SET `count` = '".($notes['count']+1)."' WHERE `id` = '$ank[id]' LIMIT 1");}

if (isset($user) && $user['id']!=$ank['id']){
mysql_query("UPDATE `blog_list` SET `count` = '".($notes['count']+1)."' WHERE `id` = '$notes[id]' LIMIT 1");}

if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>512){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_komm` WHERE `id_blog` = '".intval($_GET['id'])."' AND `id_user` = '$user[id]' AND `msg` = '".mysql_real_escape_string($msg)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
else{

if($notes['id_user']!=$user['id']){
$msg_p = 'Привет, '.$user['nick'].' оставил в твоей заметке [url=/notes/list.php?id='.$notes['id'].'][b]'.$notes['name'].'[/b][/url] комментарий';
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$notes[id_user]', '".my_esc($msg_p)."', '$time')");
}
mysql_query("INSERT INTO `blog_komm` (`id_user`, `time`, `msg`, `id_blog`) values('$user[id]', '$time', '".mysql_real_escape_string($msg)."', '".intval($_GET['id'])."')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Ваш комментарий успешно принят');
}
}
elseif (isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_komm` WHERE `id` = '".intval($_GET['del'])."' AND `id_blog` = '".intval($_GET['id'])."'"),0))
{
if (isset($user) && ($user['level']>=2) || isset($user) && ($user['id']=$notes['id_user']))
{
mysql_query("DELETE FROM `blog_komm` WHERE `id` = '".intval($_GET['del'])."' LIMIT 1");
msg('Комментарий удален');
}

}



echo"<div class='foot'>\n";
echo"<a href='index.php'>Заметки</a><br />\n";
echo"</div>\n";



echo "<table class='post'>\n";
echo "   <tr>\n";


echo "  <td class='p_t'>\n";
echo "".status($ank['id'])." ";
echo " ".group($ank['id'])." <a href='/info.php?id=$ank[id]'>$ank[nick]</a> ".medal($ank['id'])." ".online($ank['id'])."\n";

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

if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";
echo "<b>".htmlspecialchars($notes['name'])."</b> \n";
echo "".vremja($notes['time'])."<br />\n";
echo "".output_text($notes['msg'])." \n";
if (($user['level'] >= 2) || ($user['id'] ==$notes['id_user']))
{
echo "[<a href='edit.php?id=$notes[id]'><img src='/style/icons/edit.gif' alt='*' /> ред</a>] [<a href='edit.php?id=$notes[id]&amp;del'><img src='/style/icons/delete.gif' alt='*' /> удл</a>]<br />";
}

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

echo "</table>\n";


echo"<div class='foot'>Комментарии:</div>\n";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_komm` WHERE `id_blog` = '".intval($_GET['id'])."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `blog_komm` WHERE `id_blog` = '".intval($_GET['id'])."' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
echo "<table class='post'>\n";
if ($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет комментариев\n";
echo "  </td>\n";
echo "   </tr>\n";
}
while ($post = mysql_fetch_assoc($q))
{
//$ank=mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
$ank=get_user($post['id_user']);

echo "   <tr>\n";
if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";
avatar($ank['id']);
echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
echo "".status($ank['id'])." ";
echo "  </td>\n";
}
echo "  <td class='p_t'>\n";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a> ".medal($ank['id'])." ".online($ank['id'])."\n";
echo "".vremja($notes['time'])."\n";
echo "  </td>\n";
echo "   </tr>\n";
echo "   <tr>\n";
if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";
echo output_text($post['msg'])."\n";
if (isset($user) && ($user['level']>=2) || isset($user) && ($user['id'] == $notes['id_user']))
echo "[<a href='list.php?id=".intval($_GET['id'])."&amp;del=$post[id]'>удл</a>]<br />\n";
echo "  </td>\n";
echo "   </tr>\n";
}
echo "</table>\n";


if ($k_page>1)str("?id=".intval($_GET['id']).'&amp;',$k_page,$page); // Вывод страниц



if (isset($user))
{
echo "<form method=\"post\" name='message' action=\"list.php?id=".intval($_GET['id'])."&amp;page=$page\">\n";
if ($set['web'] && is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php'))
include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';
else
echo "<div class='foot'>Сообщение:</div><textarea name=\"msg\"></textarea><br />\n";
if ($user['set_translit']==1)echo "<label><input type=\"checkbox\" name=\"translit\" value=\"1\" /> Транслит</label><br />\n";
echo "<input value=\"Отправить\" type=\"submit\" />\n";
echo "</form>\n";
}


include_once '../../sys/inc/tfoot.php';

?>