<?
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';
only_reg();

if (!isset($_GET['id']) || !is_numeric($_GET['id']))
{
header("Location: /index.php");
exit;
}


$us_adm = intval($_GET['id']);
$ank_adm=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $us_adm LIMIT 1"));

$set['title']='Стена '.$ank_adm['nick'];

include_once '../sys/inc/thead.php';
title();

if (isset($user) && $user['level']>2)include 'inc/admin_act.php';

if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
else{
$msg=mysql_real_escape_string($msg);
mysql_query("INSERT INTO `us_wall` (id_user,id_user_adm, time, msg, type) values('$user[id]', '$us_adm', '$time', '$msg', 'msg')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '$user[id]'");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[frend]' LIMIT 1"));

if ($user['pol']==1)
{
$ost = "написал";
}
else
{
$ost = "написала";
}

$msg_lenta="Ваш друг[u] $user[nick] [/u] ".$ost." сообщение на [url=/wall/?id=$us_adm] стену [/url] пользователя [u]$ank_adm[nick][/u]";

mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$msg_lenta', '$time')"); 
}
msg('Сообщение успешно добавлено');

if (isset($user) && $user['id']!=$us_adm){

if ($user['pol']==1)
{
$ost = "оставил";
}
else
{
$ost = "оставила";
}

$msg2="[u]$user[nick][/u] ".$ost." запись на Вашей [url=/wall/index.php?id=$us_adm]стене[/url]";
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$us_adm', '$msg2', '$time')");
}
}
}

if (isset($_POST['msg']) && !isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
elseif (isset($_SESSION['antiflood']) && $_SESSION['antiflood']>$time-300){$err='Для того чтобы чаще писать нужно авторизоваться';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `guest` WHERE `id_user` = '0' AND `id_user_adm` = $us_adm AND `msg` = '".mysql_escape_string($msg)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
else{
$msg=mysql_escape_string($msg);
$_SESSION['antiflood']=$time;
mysql_query("INSERT INTO `us_wall` (id_user, id_user_adm, time, msg, type) values('0', '$us_adm', '$time', '$msg', 'msg')");
msg('Сообщение успешно добавлено');
}
}

err();
aut(); // форма авторизации


if (isset($user))
{
echo '<form method="post" action="index.php?id='.$us_adm.'">';
echo "&raquo; Сообщение | <a href='/smiles.php'>Смайлы</a> | <a href='/apps/'>Приложения</a> | <a href='/apps/graffity/index.php?uid=$us_adm'>Граффити</a><br />\n<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 "<span style='float:right'><a href='/apps/'>Приложения</a></span><br />";
echo "</form>\n";
}


$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id_user_adm` = $us_adm"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
if ($k_post==0)
{
echo "<div class='err'>Нет сообщений</div>\n";
}

$q=mysql_query("SELECT * FROM `us_wall` WHERE `id_user_adm` = $us_adm ORDER BY id DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));

if($num==1){ echo "<div class='rowdown'>";
$num=0;}
else
{echo "<div class='rowup'>";
$num=1;}

if ($post['type']=='msg')
{
echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'>";
echo GradientText("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]");
echo "</a>";
echo "".adm($ank['id'])."\n";

echo "<span style='float:right'>(".vremja($post['time']).")</span><br/>\n";

echo "<span style='color:$ank[color]'>\n";
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['msg']))))))))."<br />\n";

$checklove = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$post[id]' AND `uid` = '$user[id]'"),0);
$countlove = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$post[id]'"),0);
if ($checklove==1)
{
echo "&nbsp;<span style='float:right'><img src='/wall/love.png' alt='' /> <a href='/wall/lovelist.php?id=$post[id]'>Нравится</a> ";
if ($countlove!=0)
{
echo "$countlove";
}
echo "</span><br />";
}
else
{
echo "&nbsp;<span style='float:right'><img src='/wall/love.png' alt='' /> <a href='/wall/love.php?id=$post[id]'>Мне нравится</a> ";
if ($countlove!=0)
{
echo "$countlove";
}
echo "</span><br />";
}

if ($post['reply']!=NULL){
$urepl=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[who_reply]' LIMIT 1"));
echo '<span style="color: red;text-decoration:underline">Ответ ';
echo GradientText("$urepl[nick]", "$urepl[ncolor]", "$urepl[ncolor2]");
echo '</span> '.esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['reply'])))))))).'';
}
echo "<br />&nbsp;<span style='float:right'>";
if (isset($user) && $user['id']!=$post['id_user']){
echo '<a href="reply.php?id='.$post['id'].'"><img src="/img/mailbest.gif" alt="" class="rpg" /></a>';
}
if ((isset($user) && $user['level']>2) OR ($user['id'] == $post['id_user_adm']))
{
echo " <a href='delete.php?id=$post[id]'><img src='/img/deletemail.gif' alt='' class='rpg' /></a>\n";
}
echo "</span>";
echo "<br />";
}

if ($post['type']=='graffity')
{
echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'>";
echo GradientText("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]");
echo "</a>\n";
echo "".adm($ank['id'])."\n";

echo "<span style='float:right'>(".vremja($post['time']).")</span><br />\n";

echo "<span style='color:$ank[color]'>\n";
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['msg']))))))))."</span>\n";
echo "<hr /><span style='text-decoration:underline'>Отправлено с приложения <a href='/apps/graffity/select.php'>Граффити на стену</a></span><hr />";
$checklove = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$post[id]' AND `uid` = '$user[id]'"),0);
$countlove = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$post[id]'"),0);
if ($checklove==1)
{
echo "&nbsp;<span style='float:right'><img src='/wall/love.png' alt='' /> <a href='/wall/lovelist.php?id=$post[id]'>Нравится</a> ";
if ($countlove!=0)
{
echo "$countlove";
}
echo "</span><br />";
}
else
{
echo "&nbsp;<span style='float:right'><img src='/wall/love.png' alt='' /> <a href='/wall/love.php?id=$post[id]'>Мне нравится</a> ";
if ($countlove!=0)
{
echo "$countlove";
}
echo "</span><br />";
}

if ($post['reply']!=NULL){
$urepl=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[who_reply]' LIMIT 1"));
echo '<span style="color: red;text-decoration:underline">Ответ ';
echo GradientText("$urepl[nick]", "$urepl[ncolor]", "$urepl[ncolor2]");
echo '</span> '.esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['reply'])))))))).'</span><br />';
//echo "<font color='grey'><span style='text-decoration:underline'>Отправлено с приложения <a href='/apps/graffity/'>Граффити на стену</a></span></font>";
}
echo "<br />&nbsp;<span style='float:right'>";
if (isset($user) && $user['id']!=$post['id_user']){
echo '<a href="reply.php?id='.$post['id'].'"><img src="/img/mailbest.gif" alt="" class="rpg" /></a>';
}
if ((isset($user) && $user['level']>2) OR ($user['id'] == $post['id_user_adm']))
{
echo " <a href='delete.php?id=$post[id]'><img src='/img/deletemail.gif' alt='' class='rpg' /></a>\n";
}
echo "</span>";
echo "<br />";
}



echo "</div>\n";

}



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

if (isset($user))
{
echo '<form method="post" action="index.php?id='.$us_adm.'">';
echo "&raquo; Сообщение:<br />\n<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";
}


echo "<div class='rowup'>&raquo; <a href='/info.php?id=$us_adm'>На страницу $ank_adm[nick]</a></div>";

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