Файл: ferma/inc/mail.php
Строк: 197
<?
function cut_msg($text)
{
$text = substr($text, 0, 16);
return str_replace('∞','',$text);
}
if(isset($_GET['read_all']))
{
mysql_query("UPDATE `kolhoz_mail` SET `read` = '1' WHERE `id_user` = '$ku[id]' AND `type` = 'to' AND `read` = '0'");
header("Location:?mail");
}
elseif(isset($_GET['del_all']))
{
if(isset($_GET['ok']))
{
$q=mysql_query("SELECT * FROM `kolhoz_mail` WHERE `id_user` = '$ku[id]'");
while($post=mysql_fetch_array($q))
{
if($post['type']=='to' && $post['read']==1)mysql_query("DELETE FROM `kolhoz_mail` WHERE `id` = '$post[id]'");
elseif($post['type']=='at')mysql_query("DELETE FROM `kolhoz_mail` WHERE `id` = '$post[id]'");
}
header("Location:?mail");
}
podtv("?mail&del_all&ok","?mail");
include_once 'inc/foot.php';
}
elseif(isset($_GET['del']) && intval($_GET['del'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE `id` = '".intval($_GET['del'])."' AND `id_user` = '$ku[id]' LIMIT 1"),0)!=0)
{
mysql_query("DELETE FROM `kolhoz_mail` WHERE `id` = '".intval($_GET['del'])."'");
header("Location:?mail");
}
elseif(isset($_GET['msg']) && intval($_GET['msg'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE `id` = '".intval($_GET['msg'])."' AND `id_user` = '$ku[id]' LIMIT 1"),0)!=0)
{
$msg=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_mail` WHERE `id` = '".intval($_GET['msg'])."' AND `id_user` = '$ku[id]' LIMIT 1"));
if($msg['type']=='to' && $msg['read']==0)
{
mysql_query("UPDATE `kolhoz_mail` SET `read` = '1' WHERE `id` = '$msg[id]'");
mysql_query("UPDATE `kolhoz_mail` SET `read` = '1' WHERE `id` = '".($msg['id']+1)."'");
header("Location:?mail&msg=$msg[id]");
}
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$msg[id_kont]'"));
$anku=$ank;
echo "<div class='event'><g1><b><font color='F9EDA2'>Просмотр сообщения</font></b></g1></div>";
echo '<div class="content"><div class="block">';
echo "<ul><li><span class='minor'>".($msg['type']=='to'?"От":"Кому").":</span> <span>";
if($msg['id_kont']!=0)echo on_k($ank['id']);
echo " ".($msg['id_kont']==0?"Извещение":"<a class='' href='?user=$ank[id]'>".nc($ank['id'])."</a>")."</span></li><li><div class='title'><p>".output_text($msg['msg'], ($msg['type']=='to'?$ank['id']:$ku['id']))."</p></div></li><li class='small minor'><span>".vremja($msg['time'])."</span></li>".($msg['id_kont']==0?"":"<li class='pt'><li><img width='11' height='11' src='i/dot.png' alt='o'> <a href='?mail&new_msg=$ank[id]'>Ответить</a></li>")."<li><img width='11' height='11' src='i/dot.png' alt='o'> <a href='?mail&del=$msg[id]'>Удалить письмо</a></li> <li><img width='11' height='11' src='i/dot.png' alt='o'> <a href='?mail&del_all'> Очистить всё</a></li> <li><img width='11' height='11' src='i/dot.png' alt='o'> <a href='?mail&history=$ank[id]'>Переписка</a></li><br><li><img width='15' height='15' src='i/m.png' alt='o'> <a href='?mail'>Почта</a></li></ul></br></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['new_msg']))
{
if(isset($_GET['ok']) && isset($_POST['nick']) && isset($_POST['msg']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `nick` = '".hsc($_POST['nick'])."'"),0)!=0)
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `nick` = '".hsc($_POST['nick'])."'"));
$anku=$ank;
}
if(!isset($ank))
{
$err=1;
err_game("Фермер ненайден");
}
if($_POST['msg']==NULL)
{
$err=1;
err_game("Сообщение слишком короткое");
}
if($ku['level']<=1)
{
$err=1;
err_game("Писать можно только с 2 уровня");
}
if($ank['mail']==1 && $ku['status']==0)
{
$err=1;
err_game("Этот пользователь закрыл почту! Вы не можете отправлять ему сообщения.");
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_blacklist` WHERE `id_user` = '$ank[id]' AND `id_ank` = '$ku[id]' LIMIT 1"),0)!=0)
{
$err=1;
err_game("Этот пользователь внес Вас в чёрный список, Вы не можете отправлять ему сообщения.");
}
if(!isset($err))
{
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$ank[id]', `id_kont` = '$ku[id]', `msg` = '".my_esc($_POST['msg'])."', `time` = '$time', `type` = 'to'");
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '$ku[id]', `id_kont` = '$ank[id]', `msg` = '".my_esc($_POST['msg'])."', `time` = '$time', `type` = 'at', `read` = '1'");
$_SESSION['msg_ok']=1;
$_SESSION['msg_okk']=$ank['id'];
header("Location:?mail");
}
}
else
{
if($_GET['new_msg']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '".intval($_GET['new_msg'])."'"),0)!=0 && is_numeric(intval($_GET['new_msg'])))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['new_msg'])."'"));
$anku=$ank;
}
}
echo "<div class='event'><g1><b>Почта</b></g1></div>";
echo '<div class="content"><div class="block">';
if($ank['id']!=$ku['id'])echo "<li><img alt=''
width='16' height='16' src='i/icons/money.png'> ".
($ku['rating']>=$ank['rating']?"<a href='?perevod=
$ank[id]'>":null)."Переслать монеты".($ku
['rating']>=$ank['rating']?"</a>":null)."</li>";
if($ank['id']!=$ku['id'] && $ku['status']==3)echo
"<li><img alt='' width='16' height='16' src='i/icons/
ruby.png'> <a href='?perevod2=$ank[id]'>Переслать Очко </a></li>";
echo "<form action='?mail&new_msg".(isset($ank)?"=$ank[id]":null)."&ok' method='post'><div><label>Кому:<br><input type='text' class='wide' value='".(isset($ank)?"$anku[nick]":null)."' name='nick'></label></div><div><label>Сообщение:<br><textarea rows='5' class='wide' name='msg'></textarea></label></div><div><input type='submit' value='Отправить'></div></form></div>";
include_once 'inc/foot.php';
}
else
{
if(isset($_GET['history']) && intval($_GET['history'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '".intval($_GET['history'])."'"),0)!=0)
{
$history=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['history'])."'"),0);
$historyu=$history;
}
echo "<div class='event'><font color='F9EDA2'><g1><b>Личная почта</b></g1></font></div>";
if(isset($_SESSION['msg_ok']))
{
$ak=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_SESSION['msg_okk'])."'"));
$aku=$ak;
echo "<div class='feedback'><span class='info'>Ваше сообщение отправлено
'$aku[nick]'.</span><br></div>";
unset($_SESSION['msg_ok']);
unset($_SESSION['msg_okk']);
}
echo '<div class="content"><div class="block">';
echo "<ul>";
if(!isset($history))echo "<li class='minor pb'> ".(isset($_GET['new'])?"<a href='?mail'>":null)."<span>Все</span>".(isset($_GET['new'])?"</a>":null)." | ".(!isset($_GET['new'])?"<a href='?mail&new'>":null)."<span>Новые</span>".(!isset($_GET['new'])?"</a>":null)."</li>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE ".(isset($history)?"`id_kont` = '$history[id]' AND `id_user` = '$ku[id]'":"".(isset($_GET['new'])?"`read` = '0' AND ":null)."`id_user` = '$ku[id]'").""),0);
if ($k_post==0)
{
echo "".(isset($history)?"У вас нету переписки с $historyu[nick]":"Список пуст...")."";
}
$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 `kolhoz_mail` WHERE ".(isset($history)?"`id_kont` = '$history[id]' AND `id_user` = '$ku[id]'":"".(isset($_GET['new'])?"`read` = '0' AND ":null)."`id_user` = '$ku[id]'")." ORDER BY `time` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_kont]'"));
$anku=$ank;
echo "<li class='pb'><div><img width='12' height='12' src='i/i/".($post['type']=='to'?"".($post['read']==0?"3.png":"1.png")."":"2.png")."' alt='o'><span>";
if($post['id_kont']!=0)echo on_k($ank['id']);
echo " ".($post['id_kont']==0?"Извещение":"<a class='' href='?user=$ank[id]'>".nc($ank['id'])."</a>")."</span> <span class='minor small'>(<span>".vremja($post['time'])."</span>)</span></div><div class='title'>".cut_msg($post['msg'])."...</div><img width='11' height='11' src='i/dot.png' alt='o'> <a href='?mail&msg=$post[id]'>Прочитать</a></li>";
}
if($k_page>1)str("?mail".(isset($_GET['new'])?"&new":null)."".(isset($history)?"&history=$history[id]":null)."&",$k_page,$page); // Вывод страниц
echo "</ul>";
echo "<ul><li><img width='11' height='11' src='i/dot.png' alt=''> <a href='?mail&new_msg'>Написать письмо</a></li>";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_mail` WHERE `id_user` = '$ku[id]' AND `read` = '0'"),0)!=0)
echo "<li><img width='16' height='16' src='i/icons/mails.png' alt=''> <a href='?mail&read_all'>Отметить
все как прочитанные</a></li>";
echo "<li><img width='11' height='11' src='i/icons/delete.png' alt=''> <a href='?mail&del_all'> Удалить все прочитанные</a></li><li class='ptm minor'><span class='title'><font color='red' size='2' class='feedback'>Срок жизьни сообщений 30 дней</font></span></li></ul></div>";
include_once 'inc/foot.php';
}
?>