Файл: titwar.ru/mail.php
Строк: 105
<?
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 = 'Dialogue with '.$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().'')');
}
if($ho['r'] != $user['r']) $_s = 100; else $_s = 1;
$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'] < 5) $errors[] = 'Error, you can send mail one time per 5 seconds';
if($user['s'] < $_s) $errors[] = 'Error, you need <img src='/images/icon/silver.png' alt='*'/> '.($_s - $user['s']).' silver<div class='separator'></div><a href='/trade/' class='button'>Buy</a>';
if($errors) {
echo '<div class='content' align='center'>';
foreach($errors as $error) {
echo $error.'<br/>';
}
echo '</div>
<div class='line'></div>';
}
else
{
$text = eregi_replace( "[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "Ads", $text);
$text = str_replace(array('ru',
'Ru',
'RU',
'mpesh',
'tk',
'rU',
'r u',
'Mpesh',
't k',
'www',
'http'), '*', $text);
mysql_query('UPDATE `users` SET `s` = `s` - '.$_s.' WHERE `id` = ''.$user['id'].''');
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='line'></div>
<div class='content'>
<form action='/mail/'.$ho['id'].'/' method='post'>
Message:<br/><textarea name='text' style='width: 100%;'></textarea><br/>
<input type='submit' value='Send'/> <a href='/mail/'.$ho['id'].'/'>Refresh</a>
</form>
<center><font color='#909090'><small><small>Cost of mail '.($user['r'] == $ho['r'] ? 'your':'foreign').' race <img src='/images/icon/silver.png' alt='*'/> '.$_s.'</font></small></small></font></center>
</div>
<div class='line'></div>
<div class='menu'>';
$max = 100;
$count = 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);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));
if($page > $pages) $page = $pages;
if($page < 1) $page = 1;
$start = $page * $max - $max;
if($count > 0) {
$col = array('#ffffff', '#90c0c0', '#90c0c0');
$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 ' <li><span style='float: right; color: '.(($row['read'] == 0) ? '#90c090':'#909090').';'>'.date('d.m | H:i', $row['time']).'</span><img src='/images/icon/race/'.$from['r'].($from['online'] > time() - 300 ? '':'-off').'.png' alt='*'/> <a href='/user/'.$from['id'].'/'>'.$from['login'].'</a><br/><font color=''.$col[$from['access']].''>'.bb(smiles($row['text'])).'</font></li>';
if($row['to'] == $user['id'] && $row['read'] == 0) mysql_query('UPDATE `mail` SET `read` = '1' WHERE `id` = ''.$row['id'].''');
}
echo ' ';
}
else
{
echo '<li align='center'><font color='#909090'>You have no mails</font></li>';
}
echo ' <li><a href='/mail'><img src='/images/icon/arrow.png' alt='*'/> Mailbox</a></li></div>
</div>';
include './system/f.php';
}
else
{
$title = 'Mailbox';
include './system/h.php';
echo '
<div class='line'></div>';
$max = 50;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `contacts` WHERE `user` = ''.$user['id'].'''),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));
if($page > $pages) $page = $pages;
if($page < 1) $page = 1;
$start = $page * $max - $max;
if($count > 0) {
echo '<div class='list'>';
$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'].'''));
echo '<li><a href='/mail/'.$row['ho'].'/'><img src='/images/icon/race/'.$ho['r'].($ho['online'] > time() - 300 ? '':'-off').'.png' alt='*'/> '.$ho['login'].', '.$ho['level'].' ур ';
$new = mysql_result(mysql_query('SELECT COUNT(*) FROM `mail` WHERE `from` = ''.$ho['id'].'' AND `to` = ''.$user['id'].'' AND `read` = '0''),0);
if($new > 0) echo '<font color='#90c090'>+'.$new.'</font>';
$lost = mysql_fetch_array(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 1'));
if($lost) echo '
<font color='#909090'>'.(mb_strlen($lost['text'],'UTF-8') >= 255 ? mb_substr($lost['text'],0, 255, 'UTF-8').'...':$lost['text']).'</a></font>';
echo '</li>';
}
echo '</div>
<div class='line'></div>
<div class='menu'></div>';
}
else
{
echo '<div class='content'><font color='#909090'>Mailbox is empty</font></div>';
}
include './system/f.php';
}
?>