<?
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';

$status=mysql_fetch_array(mysql_query("SELECT * FROM `status` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$status['id_user']."' LIMIT 1"));

$set['title']='Статус '.$ank['nick']; // заголовок страницы

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

title();

if(!$ank)header("Location: /index.php?net_takogo_statusa");
if(!$status)header("Location: /index.php?net_takogo_statusa");

if(isset($_GET['del'])){
$statusk=mysql_fetch_array(mysql_query("SELECT * FROM `status_komm` WHERE `id` = '".intval($_GET['del'])."' LIMIT 1"));
if($ank['id']==$user['id'] || $user['level']>1){
mysql_query("DELETE FROM `status_komm` WHERE `id` = '$statusk[id]'");
}
header("Location: status.php?id=$status[id]");
exit;
}

############
if (isset($_GET['otv'])) {

$user_temp=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".intval($_GET['otv'])."'"));


if (isset($user) && isset($_POST['msg'])) {

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


if (!isset($err)) {

mysql_query("INSERT INTO `status_komm` (`id_user`, `time`, `msg`, `id_status`) values('$user[id]', '$time', '".$msg."', '$status[id]')");

mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");

if ($user['id']!=$user_temp['id']) {
$msg1="Вам ответили в комментариях к [url=/status/status.php?id=$status[id]]статусу[/url]";
mysql_query("INSERT INTO `jurnal` (`id_kont`, `msg`, `time`) values('$user_temp[id]', '$msg1', '".time()."')");
}

unset($_POST[msg]);
unset($msg);

header("Location: ?id=$status[id]".SID);
exit;
}
}
}

#########
if (isset($_POST['msg']) && isset($user))
{
$msg=mysql_real_escape_string($_POST['msg']);
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);

$mat=antimat($msg);
if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;

if (strlen2($msg)>1024){$err[]='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err[]='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `status_komm` WHERE `id_status` = '$status[id]' AND `msg` = '".$msg."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
elseif(!isset($err)){

mysql_query("INSERT INTO `status_komm` (id_status,id_user, time, msg) values('$status[id]','$user[id]', '".time()."', '".$msg."')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
if($ank['id']!=$user['id'])mysql_query("INSERT INTO `jurnal` (`id_kont`, `msg`, `time`, `type`) values('$ank[id]', 'К вашему статусу [url=/status/status.php?id=$status[id]]оставили комментарий[/url]', '".time()."', 'sys')");

msg('Сообщение успешно добавлено');
}
}



err();
aut(); // форма авторизации
if(isset($user) && isset($_GET['like']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_rating` WHERE `id_status` = '$status[id]' AND `id_user` = '$user[id]'"), 0)==0){
mysql_query("INSERT INTO `status_rating` (`id_status`, `id_user`, `rating`) VALUES ('$status[id]', '$user[id]', '1')");

}

if(isset($user) && isset($_GET['act']) && $_GET['act']=='off'){
$id_post=mysql_fetch_array(mysql_query("SELECT * FROM `status_komm` WHERE `id` = '".intval($_GET['id_post'])."' LIMIT 1"));
if($id_post['id_user']==$user['id'] || $user['level']>1 || $ank['id']==$user['id']){
mysql_query("UPDATE `status_komm` SET `act` ='1' WHERE `id` = '$id_post[id]' LIMIT 1");
msg('Сообщение скрыто');
}
}
if(isset($user) && isset($_GET['act']) && $_GET['act']=='on'){
$id_post=mysql_fetch_array(mysql_query("SELECT * FROM `status_komm` WHERE `id` = '".intval($_GET['id_post'])."' LIMIT 1"));
if($id_post['id_user']==$user['id'] || $user['level']>1 || $ank['id']==$user['id']){
mysql_query("UPDATE `status_komm` SET `act` ='0' WHERE `id` = '$id_post[id]' LIMIT 1");
}
}
echo "<table class='post'>\n";
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 "<img src='/style/themes/$set[set_them]/user/$ank[pol].png' alt='' />";
echo "  </td>\n";
}

echo "  <td class='p_t'>\n";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a>\n";
echo " ".online($ank['id'])." ";
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($status['msg'])."<br />Добавлено: ".vremja($status['time'])." <a href='?id=".$status['id']."&amp;like'><img src='klass.png' alt='+1' /></a> ".mysql_result(mysql_query("SELECT COUNT(*) FROM `status_rating` WHERE `id_status` = '$status[id]'"), 0)."<br /> \n";
if ($ank['id']==$user['id'] || $user['level']>1)
echo "<a href='index.php?id=$ank[id]&amp;del=$status[id]'>Удалить</a> / <a href='index.php?id=$ank[id]&amp;edit=$status[id]'>Изменить</a><br />\n";
echo "  </td>\n";
echo "   </tr>\n";
echo "</table>";
if(isset($_GET['otv']) && isset($user)){
$user_temp=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".intval($_GET['otv'])."'"));
echo "<form class='p_m' method=\"post\" name='message' action=\"\">\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 "Сообщение:<br />\n<textarea name=\"msg\">$user_temp[nick],</textarea><br />\n";


if (isset($user) && $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";
}
elseif (isset($user))
{
echo "<form class='p_m' method=\"post\" name='message' action=\"\">\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 "Сообщение:<br />\n<textarea name=\"msg\"></textarea><br />\n";


if (isset($user) && $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";
}
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `status_komm` WHERE `id_status`='$status[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$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";

}

$q=mysql_query("SELECT * FROM `status_komm` WHERE `id_status`='$status[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q))
{


$ank2=mysql_fetch_array(mysql_query("SELECT id,nick,pol FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
echo "   <tr>\n";
if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";
avatar($ank2['id']);
echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
echo "<img src='/style/themes/$set[set_them]/user/$ank2[pol].png' alt='' />";
echo "  </td>\n";
}

echo "  <td class='p_t'>\n";
echo "<a href='/info.php?id=$ank2[id]'>$ank2[nick]</a>\n";
echo " ".online($ank2['id'])." (".vremja($post['time']).")";
if($post['act']==1)echo "<img src='off.png' alt='off message' />";
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";

if($post['act']==0 || $ank2['id']==$user['id'] || $user['level']>1 || $ank['id']==$user['id'])
echo output_text($post['msg'])."<br />\n";
else echo "Сообщение скрыто<br />";
echo "<div align='right'>";
if (isset($user) && $ank['id']==$user['id'] || $user['level']>1)
echo "<a href='?id=$status[id]&amp;del=$post[id]'><img src='delete.gif.png' alt='delete' /></a>\n";
if (isset($user))
echo "<a href='?id=$status[id]&amp;otv=$ank2[id]'><img src='otvet.gif.png' alt='otvet' /></a>\n";
if(isset($user) && $post['act']==0 && ($ank2['id']==$user['id'] || $user['level']>1 || $ank['id']==$user['id']))
echo "<a href='?id=$status[id]&amp;id_post=$post[id]&amp;act=off'><img src='off.png' alt='off' /></a><br />\n";
if(isset($user) && $post['act']==1 && ($ank2['id']==$user['id'] || $user['level']>1 || $ank['id']==$user['id']))
echo "<a href='?id=$status[id]&amp;id_post=$post[id]&amp;act=on'><img src='on.png' alt='on' /></a><br />\n";
echo "</div>";
echo "  </td>\n";
echo "   </tr>\n";

}
echo "</table>\n";




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


echo "<div class='foot'>\n";
echo "&raquo;<a href='index.php?id=$ank[id]'>Все статусы</a><br />\n";
echo "</div>\n";

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

?>
