<?
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']))$ank['id']=intval($_GET['id']);
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$ank['id']."' LIMIT 1"));

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

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

title();

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

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

###############

if(isset($_GET['edit'])){
$status=mysql_fetch_array(mysql_query("SELECT * FROM `status` WHERE `id` = '".intval($_GET['edit'])."' LIMIT 1"));
if(isset($_POST['ok'])){
$opis=mysql_real_escape_string($_POST['opis']);
if(strlen2($opis)<1)$err='Заполните описание';
if(strlen2($opis)>70)$err='Не более 70 символов';

if(!isset($err)){
mysql_query("UPDATE `status` SET `msg` = '".$opis."' WHERE `id` = '$status[id]' LIMIT 1");

header("Location: status.php?id=$status[id]");
}
}
if($status['id_user']==$user['id'] || $user['level']>1){
echo "<form class='foot' action='?id=$ank[id]&amp;edit=$status[id]' method=\"post\">";

echo "Описание:<br />\n";
echo "<textarea name='opis'>$status[msg]</textarea><br />\n";

echo "<input class=\"submit\" name='ok' type=\"submit\" value=\"Изменить\" /><br />\n";
}
echo "&laquo;<a href='?id=$ank[id]'>Отмена</a><br />\n";
echo "</form>";
include_once '../sys/inc/tfoot.php';
exit;
}


#####################
if(isset($_GET['add'])){
if(isset($_POST['ok'])){
$opis=mysql_real_escape_string($_POST['opis']);
if(strlen2($opis)<1)$err='Заполните описание';
if(strlen2($opis)>70)$err='Не более 70 символов';
if(!isset($err)){
mysql_query("INSERT INTO `status` (id_user, time, msg) values('$user[id]', '".time()."', '".$opis."')");
$id=mysql_insert_id();
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");

header("Location: status.php?id=$id");
}
}
echo "<form class='foot' action='?id=$ank[id]&amp;add' method=\"post\">";

echo "Описание:<br />\n";
echo "<textarea name='opis'></textarea><br />\n";

echo "<input class=\"submit\" name='ok' type=\"submit\" value=\"Добавить\" /><br />\n";

echo "&laquo;<a href='?id=$ank[id]'>Отмена</a><br />\n";
echo "</form>";
include_once '../sys/inc/tfoot.php';
exit;
}

err();
aut(); // форма авторизации
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `status` WHERE `id_user`='$ank[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` WHERE `id_user`='$ank[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'])." ";
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'])."<br />Добавлено: ".vremja($post['time'])." <img src='klass.png' alt='+1' />".mysql_result(mysql_query("SELECT COUNT(*) FROM `status_rating` WHERE `id_status` = '$post[id]'"), 0)."<br /><a href='/status/status.php?id=$post[id]'><b>Перейти</b></a> \n";
if ($ank['id']==$user['id'])
echo "<a href='?id=$ank[id]&amp;del=$post[id]'>Удалить</a> / <a href='?id=$ank[id]&amp;edit=$post[id]'>Изменить</a><br />\n";
echo "  </td>\n";
echo "   </tr>\n";

}
echo "</table>\n";




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

echo "<div class='foot'>\n";
if ($ank['id']==$user['id'])
echo "<a href='?id=$ank[id]&amp;add'>Добавить статус</a><br />\n";
echo "&raquo;<a href='/info.php?id=$ank[id]'>В анкету</a><br />\n";
echo "</div>\n";

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