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

$set['title']='Почта - save';
include_once 'sys/inc/thead.php';
title();
if(isset($_GET['id'])){

$post=mysql_fetch_assoc(mysql_query("SELECT * FROM `mail_save` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
$ank=get_user($post['id_user']);
echo "  <div class='p_t'>\n";
if ($ank)
echo "<a href=\"/info.php?id=$ank[id]\">$ank[nick]</a>".online($ank['id'])."\n";
else
echo "[DELETED] \n";
echo "(".vremja($post['time']).")\n";
echo "</div>";
echo "  <div class='p_m'>\n";
echo output_text($post['msg'])."</div>\n";
echo "<div class='foot'>";
echo "<a href='/mail_save.php'>Назад</a><br />";
echo "</div>";
include_once 'sys/inc/tfoot.php';
exit;

}
if (isset($_GET['del'])) {
$post=mysql_fetch_assoc(mysql_query("SELECT * FROM `mail_save` WHERE `id` = '".intval($_GET['del'])."' LIMIT 1"));
if($post['id_user']==$user['id']){



mysql_query("DELETE FROM `mail_save` WHERE `id` = '".intval($_GET['del'])."' AND `id_user` = '$user[id]' LIMIT 1");
msg('Сообщение удалено');}
}




echo "<table class='post'>";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `mail_save` WHERE `id_user` = '$user[id]'"),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 "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет сообщений\n";
echo "  </td>\n";
echo "   </tr>\n";

}
$q=mysql_query("SELECT * FROM `mail_save` WHERE `id_user` = '$user[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q))
{
$ank=get_user($post['id_ank']);
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";
if ($ank)
echo "<a href=\"/info.php?id=$ank[id]\">$ank[nick]</a>".online($ank['id'])."\n";
else
echo "[DELETED] \n";
echo "(".vremja($post['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";
if(strlen($post['msg'])>100)echo mb_substr(output_text($post['msg']),0,100)." ... <br /><a href='/mail_save.php?id=$post[id]'>Читать полностью</a><br />"; else echo output_text($post['msg'])."<br />\n";
######################

$qq=mysql_query("SELECT * FROM `mail_files` WHERE `id_post` = '".$post['id_post']."'");
while ($files=mysql_fetch_assoc($qq)){

echo "<a href='/files.php?id=$post[id_file]'>$files[name]$ras</a> (".size_file($files['size']).") \n";
echo "<br />\n";
}

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

echo "<a href='/mail_save.php?del=$post[id]'>Удалить</a> \n";

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






}
echo "</table>\n";
if ($k_page>1)str("mail_save.php?",$k_page,$page); // Вывод страниц



echo "<div class='foot'>\n";
echo "&laquo;<a href='konts.php'>Мои контакты</a><br />\n";
echo "&laquo;<a href='umenu.php'>Мое меню</a><br />\n";
echo "</div>\n";
include_once 'sys/inc/tfoot.php';
?>