Файл: public_html/mail.php
Строк: 59
<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
if(!$user) {
header('location: /');
exit;
}
$id = _string(_num($_GET['id']));
if($id) {
$ho = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = ''.$id.'''));
if(!$id OR !$ho OR $id == $user['id']) {
header('location: /mail/');
exit;
}
$title = 'Диалог с '.$ho['login'];
include './system/h.php';
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `contacts` WHERE `user` = ''.$user['id'].'' AND `ho` = ''.$ho['id'].'''),0) == 0) {
mysql_query('INSERT INTO `contacts` (`user`,
`ho`,
`time`) VALUES (''.$user['id'].'',
''.$ho['id'].'',
''.time().'')');
}
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `contacts` WHERE `ho` = "'.$user['id'].'" AND `user` = "'.$ho['id'].'"'),0) == 0) {
mysql_query('INSERT INTO `contacts` (`ho`,
`user`,
`time`) VALUES (''.$user['id'].'',
''.$ho['id'].'',
''.time().'')');
}
$text = _string($_POST['text']);
if($text) {
$antiflood = mysql_fetch_array(mysql_query('SELECT * FROM `mail` WHERE `from` = ''.$user['id'].'' ORDER BY `time` DESC LIMIT 1'));
if(time() - $antiflood['time'] < 2) $errors[] = 'Отправлять сообщения можно 1 раз в секунду!';
if($errors) {
echo '<div class='block red' align='center'>';
foreach($errors as $error) {
echo $error.'<br/>';
}
echo '</div>
<div class='line'></div>';
}
else
{
$text = eregi_replace( "[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "Реклама", $text);
$text = str_replace(array('ru',
'net',
'com',
'рф',
'tk',
'su',
'us',
'mobi',
'ua',
'www',
'http'), '*', $text);
mysql_query('INSERT INTO `mail` (`from`,
`to`,
`text`,
`time`) VALUES (''.$user['id'].'',
''.$ho['id'].'',
''.$text.'',
''.time().'')');
mysql_query('UPDATE `contacts` SET `time` = ''.time().'' WHERE `user` = ''.$user['id'].'' AND `ho` = ''.$ho['id'].''');
mysql_query('UPDATE `contacts` SET `time` = ''.time().'' WHERE `ho` = ''.$user['id'].'' AND `user` = ''.$ho['id'].''');
header('location: /mail/'.$ho['id'].'/');
}
}
echo '
<div class='block'>
<form action='/mail/'.$ho['id'].'/' method='post'>
Сообщение:<br/><input name='text' style='width: 97%;' class='text'></a>
<input type='submit' value='Отправить'> <a href='/smiles'><img src='/images/smiles/mini_ulibka.gif'></a>
</form>
</div>
<div class='line'></div> ';
$max = 10;
$k_post = mysql_result(mysql_query('SELECT COUNT(*) FROM `mail` WHERE `from` = "'.$user['id'].'" AND `to` = "'.$ho['id'].'" OR `to` = "'.$user['id'].'" AND `from` = "'.$ho['id'].'"'),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
if($k_post > 0) {
$q = mysql_query('SELECT * FROM `mail` WHERE `from` = ''.$user['id'].'' AND `to` = ''.$ho['id'].'' OR `to` = ''.$user['id'].'' AND `from` = ''.$ho['id'].'' ORDER BY `time` DESC LIMIT '.$start.', '.$max.'');
while($row = mysql_fetch_array($q)) {
$from = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = ''.$row['from'].'''));
echo '<div class='block' style='padding: 1; border-bottom: 1px solid #252525;'><span style='float: right; color: '.(($row['read'] == 0) ? '#90c090':'#909090').';'>'.date('d.m | H:i', $row['time']).'</span> <a href='/user/'.$from['id'].'/'>'.$from['login'].'</a><br/>'.smiles($row['text']).'</div>';
if($row['to'] == $user['id'] && $row['read'] == 0) mysql_query('UPDATE `mail` SET `read` = '1' WHERE `id` = ''.$row['id'].''');
}
if($k_page>1) echo str('?',$k_page,$page);
}
else
{
echo '<div class='block'><font color='#909090'>Сообщений нет!</font></div>';
}
echo '<div class='line'></div>
<a href='/mail' class='link'>Почта</a>';
include './system/f.php';
}
else
{
$title = 'Почта';
include './system/h.php';
$max = 10;
$k_post = mysql_result(mysql_query('SELECT COUNT(*) FROM `contacts` WHERE `user` = ''.$user['id'].'''),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
if($k_post > 0) {
$q = mysql_query('SELECT * FROM `contacts` WHERE `user` = ''.$user['id'].'' ORDER BY `time` DESC LIMIT '.$start.', '.$max.'');
while($row = mysql_fetch_array($q)) {
$ho = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = ''.$row['ho'].'''));
$new = mysql_result(mysql_query('SELECT COUNT(*) FROM `mail` WHERE `from` = ''.$ho['id'].'' AND `to` = ''.$user['id'].'' AND `read` = '0''),0);
echo '<a href='/mail/'.$row['ho'].'' class='link'>'.$ho['login'].'';
if($new > 0) echo '<font color='#90c090'> (+'.$new.')</font></a><div class='line'></div>';
if($new < 1) echo '</a><div class='line'></div>';
}
if($k_page>1) echo str('?',$k_page,$page);
}
else
{
echo '<div class='block'><font color='#909090'>Почта пуста!</font></div>';
}
include './system/f.php';
}
?>