<?php
include"../tools.php";
include"../head.php";
echo "<div>";
echo "<div class='contur_rek'>
<div class='header_rek'><span style='color:#c00000;'><p align='center'><big><b>Персональные сообщения</b></big></p></span></div></div>";
function tr_to_win($str)
{
$str=strtr($str,array("__"=>" ","_"=>"","a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","e"=>"е","yo"=>"ё","zh"=>"ж","z"=>"з","i"=>"и","j"=>"й","k"=>"к","l"=>"л","m"=>"м","n"=>"н","o"=>"о","p"=>"п","r"=>"р","s"=>"с","t"=>"т","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","ch"=>"ч","sh"=>"ш","sch"=>"щ","q"=>"ъ","x"=>"ы","%"=>"ь","ye"=>"э","yu"=>"ю","ya"=>"я",
"A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","E"=>"Е","YO"=>"Ё","ZH"=>"Ж","Z"=>"З","I"=>"И","J"=>"Й","K"=>"К","L"=>"Л","M"=>"М","N"=>"Н","O"=>"О","P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","CH"=>"Ч","SH"=>"Ш","SCH"=>"Щ","Q"=>"Ъ","X"=>"Ы","YE"=>"Э","YU"=>"Ю","YA"=>"Я"));
return $str;
}
$msg = hacker(htmlspecialchars(stripslashes($_POST['msg'])));
$foruser= hacker(htmlspecialchars(stripslashes($_POST['foruser'])));
if ($_POST['msgtrans']==1)
{
$msg = tr_to_win($msg);
}
if (!empty($_SESSION['login']))
{
if ($act=="send")
{
if (!empty($foruser) and !empty($msg))
{$m = mysql_query("select * from `users` where login='".$foruser."';");
$count = mysql_num_rows($m);
if ($count==1)
{$realtime=time()+$sdvigclock*3600;
mysql_query("insert into `let` values(0,'".$foruser."','".$msg."','".$realtime."','".$_SESSION['login']."','in','no');");
mysql_query("insert into `let` values(0,'".$foruser."','".$msg."','".$realtime."','".$_SESSION['login']."','out','no');");
echo"Письмо отправлено!";
} else {echo "<div>Такого пользователя не существует</div>";}
}
else
{echo "<div>Не введено имя пользователя или сообщение!</div>";
}
}
if ($act=="write")
{if (!empty($otv))
{$messages = mysql_query("select * from `users` where id='".intval($otv)."';");
$user = mysql_fetch_array($messages);
}
echo "<div class='contur'>
<div class='header'>Написать письмо";
echo "<form action='letters.php?act=send' method='post'>
Для<br/>
<input type='text' name='foruser' value='".$user['login']."' />
<br /> Cообщение<br />
<textarea rows='5' name='msg'></textarea><br/><br />
<input type='checkbox' name='msgtrans' value='1' /> Транслит сообщения
<br/>
<input type='submit' value='добавить' />
</form>";
echo "<a href='letters.php?act=trans'>Транслит</a><br /></div></div>";
}
if ($act=="in")
{
$messages = mysql_query("select * from `let` where user='$_SESSION[login]' and type='in' order by time desc;");
echo "<div class='contur'>
<div class='header'>Входящие</div></div>";
while($massiv = mysql_fetch_array($messages))
{ $mas = mysql_fetch_array(mysql_query("select * from `users` where `login`='$massiv[author]';"));
echo "<div class='contur'>
<div class='header'><a href='../../search.php?user=".$mas[id]."'>$massiv[author]</a> ".date("d.m.y H:i",$massiv[time])."</div>$massiv[text]<br/><a href='letters.php?act=write&otv=".$mas[id]."'>Ответить</a><br/><a href='letters.php?act=delmess&del=".$massiv[id]."'>Удалить</a></div>";
if ($massiv['read']=="no")
{ mysql_query("update `let` set `read`='yes' where `id`='".$massiv['id']."';");
}
}
}
if ($act=="delmess")
{mysql_query("delete from `let` where `id`='".intval($del)."';");
echo "<div>Сообщение удалено!</div>";}
if ($act=="out")
{
$messages = mysql_query("select * from `let` where author='".$_SESSION['login']."' and type='out' order by time desc;");
echo "<div class='contur'>
<div class='header'>Исходящие</div></div>";
while($massiv = mysql_fetch_array($messages))
{
echo "<div class='contur'>
<div class='header'>Для: ".$massiv['user']." ".date("d.m.y H:i",$massiv[time])."</div>".$massiv['text']."<br/><a href='letters.php?act=delmess&del=".$massiv['id']."'>Удалить</a></div></div>";
}
}
echo "<div class='contur'>
<div class='header'><a href='index.php'>В письма</a><br />";
echo "<a href='letters.php?act=write'>Написать</a></div></div>";
}
if ($_GET[act]=="trans")
{
echo "<div class='contur'>
<div class='header'>Правила транслита";
echo "<br/>
а - a<br/>
б - b<br/>
в - v<br/>
г - g<br/>
д - d<br/>
е - e<br/>
ё - yo<br/>
ж - zh<br/>
з - z<br/>
и - i<br/>
к - k<br/>
л - l<br/>
м - m<br/>
н - n<br/>
о - o<br/>
п - p<br/>
р - r<br/>
с - s<br/>
т - t<br/>
у - u<br/>
ф - f<br/>
х - h<br/>
ц - c<br/>
ч - ch<br/>
ш - sh<br/>
щ - sch<br/>
ъ - q<br/>
ы - x<br/>
ь - %<br/>
э - ye<br/>
ю - yu<br/>
я - ya<br/><br/>
А - A<br/>
Б - B<br/>
В - V<br/>
Г - G<br/>
Д - D<br/>
Е - E<br/>
Ё - YO<br/>
Ж - ZH<br/>
З - Z<br/>
И - I<br/>
К - K<br/>
Л - L<br/>
М - M<br/>
Н - N<br/>
О - O<br/>
П - P<br/>
Р - R<br/>
С - S<br/>
Т - T<br/>
У - U<br/>
Ф - F<br/>
Х - H<br/>
Ц - C<br/>
Ч - CH<br/>
Ш - SH<br/>
Щ - SCH<br/>
Ъ - Q<br/>
Ы - X<br/>
Э - YE<br/>
Ю - YU<br/>
Я - YA</div></div>
";
}
echo "<a href='../'>На главную</a></div>";
require ('../foot.php');
?>