<?



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

//========Удаление поста

if(isset($_GET['dell'])){
$us_adm=intval($_GET['id']);
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id` = '".intval($_GET['id'])."'"),0)==1)
{
$post=mysql_fetch_array(mysql_query("SELECT * FROM `us_wall` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = $post[id_user] LIMIT 1"));
if ($ank['dostup']>$ank['dostup'] || $ku['dostup']==1 || $ku['id']==$ank['id'] || $ku['id']==$post['id_user_adm'])
mysql_query("DELETE FROM `us_wall` WHERE `id` = '$post[id]'");
}
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL)
header("Location: ".$_SERVER['HTTP_REFERER']);
}


//=======Лайк

if(isset($_GET['kull'])){
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id` = '".intval($_GET['id'])."'"),0)==1)
{
$id=intval($_GET['id']);
$check=mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$id' AND `uid` = '$ku[id]'"),0);
$blog=mysql_fetch_array(mysql_query("SELECT * FROM `us_wall` WHERE `id` = '$id' LIMIT 1"));
$whowrite = get_user($blog['id_user']);
$waladm = get_user($blog['id_user_adm']);
if (isset($post) && $check==0)
mysql_query("INSERT INTO `wall_love` SET `id_msg` = '$id', `uid` = '$ku[id]', `time` = '".time()."'");
}
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL)
header("Location: ".$_SERVER['HTTP_REFERER']);
}



echo '<div class="event"><h1>Стена игрока: <a href="?user='.$row['id_user'].'">'.nc($row['id_user']).'</a>';
echo " ".med($row['id_user'])."";
echo '</h1></div>';

$us_adm = intval($_GET['id']);
$k_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id_user_adm` = $us_adm ",$db), 0);
$k_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id_user_adm` = $us_adm AND `time` > '".(time()-86400)."'",$db), 0);
if ($k_n==0)$k_n=NULL;
else $k_n='+'.$k_n;
echo "<div class='block'>Всего записей на стене: <b>$k_p</b><font color='tomato'>$k_n</font></div>";

echo "<div class='block'><form action='?stena&id=$ank[id]".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><label>Сообщение".(isset($otv)?" для $otvu[nick]":null).": [<a href='?smiles'>Смайлы</a>]<br><textarea class='wide' rows='2' name='msg'></textarea></label><br><input type='submit' value='Написать'></form></div>";

//написание сообщения
if (isset($_POST['msg']) && isset($ank))
{
$msg=$_POST['msg'];
if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
else{
$msg=mysql_real_escape_string($msg);
if($ku['id']==$ank['id']){mysql_query("INSERT INTO `us_wall` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `id_user_adm` = '$ku[id]', `type` = 'komm', `mother` = '$ank[id]', `time` = '$time'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");}
if($ku['id']!=$ank['id']){mysql_query("INSERT INTO `us_wall` SET `msg` = '".my_esc($msg)."', `id_user` = '$ank[id]', `id_user_adm` = '$ku[id]', `type` = 'komm', `mother` = '$ank[id]', `time` = '$time'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");}
header("Location:?stena&id=$ku[id]");

}
}
/*
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `id_user` = '".$post['id_user']."'"),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 `us_wall` WHERE `id_user` = '".$row['id_user']."' ORDER BY id DESC LIMIT $start, $set[p_str]");
*/
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `us_wall` WHERE `type` = 'komm' AND `mother` = '$row[id_user]'"),0);
if ($k_post==0)
{echo "<div class='block'>Нет сообщений..</div>";}
$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 `us_wall` WHERE `type` = 'komm' AND `mother` = '$row[id_user]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_array($q))
{
if ($post['type']=='komm')
{
echo '<div class="block">'.on_k($post['id_user_adm']).' <a class="" href=?user='.$post['id_user_adm'].'>'.nc($post['id_user_adm']).'</a>';
echo " ".med($post['id_user_adm'])."";


echo "<br/><span class='minor small'>".vremja($post['time'])."</span>";
echo '<br />'.output_text($post['msg'], $post['id_user_adm']).'';


if ($ank['dostup']>$ank['dostup'] || $ku['dostup']==1 || $ku['id']==$ank['id'] || $ku['id']==$post['id_user_adm'])
{echo " <a href='?stena=$ku[id]&dell&id=$post[id]'><img src='img/icons/cross.png' alt='' /></a>\n";}


$checklove = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_love` WHERE `id_msg` = '$post[id]' AND `uid` = '$ku[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'><a href='?like&id=$post[id]'>Нравится</a> ";
if ($countlove!=0)
{
echo "<img src='wall/yas.png' alt='' /><b>$countlove</b> чел";
}
echo "</span><br />";
}
else
{
echo "&nbsp;<span style='float:right'><a href='?stena=$ku[id]&kull&id=$post[id]'>Мне нравится</a> <img src='wall/no.png' alt='' />";
if ($countlove!=0)
{
echo "<b>$countlove</b> чел";
}
echo "</span>";
}
echo "</div>";
}
if ($post['reply']!=NULL){
$urepl=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[who_reply]' LIMIT 1"));
echo "<br />&nbsp;<span style='float:right'>";
if (isset($ank) && $ank['id']!=$post['id_user']){
echo '<a href="reply.php?id='.$post['id'].'"><img src="/img/mailbest.gif" alt="" class="rpg" /></a>';
}
}
}
if ($k_page>1)str("?stena&id=$ank[id]&",$k_page,$page); // Вывод страниц




















include_once 'inc/foot.php';
?>