View file mail.php

File size: 7.36Kb
<?
///////////////////////////
///by Kyber 2011
///Поддержка klybok.net
///ICQ 626-000-895
///Не для продажы!!!
///Потрачено 23 часа 
///Реквизиты для помощи: 
///R 191559143752
///Z 109983295073
///U 211922671748 
///Изменять код скрипта ЗАПРЕЩЕНО!!!
///Нарушители получат блок хостинга
///////////////////////////
include_once 'inc/fnc.php';
include_once 'inc/sys.php';
	if (!isset($U)) header('Location: index.php?');
head('Почта');
echo R(3).'<div class="head">Почта</div>';
switch($_GET['act']) {
default:
	if ($_GET['ok'] == 's') echo '<span class="err">Письмо успешно отправлено</span>';
	elseif ($_GET['ok'] == 'd') echo '<span class="err">Письмо успешно удалено</span>';
$kv = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u2` = '$U[id]' AND `read` = '1'"), 0);
$ki = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u1` = '$U[id]' AND `read` = '1'"), 0);
$ko = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u1` = '$U[id]' AND `read` = '0'"), 0);
$k = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u2` = '$U[id]' AND `read` = '0'"), 0);
	if ($k > 0) $kn = '+'.$k;
echo '<div class="cont">
<a href="?act=in">Входящие письма</a> ['.$kv.'] <b>'.$kn.'</b><br />
<a href="?act=out">Исходящие письма</a> ['.$ki.']<br />
<a href="?act=out2">Отправленые письма</a> ['.$ko.']<br /></div>';
break;

case 'in':
$k = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u2`= '$U[id]'"), 0);
	if ($k == 0) echo '<b>Пока пусто</b><br />';
	else 
	{
	$k_page =  ceil( $k / $SET['k_p_s']);
	$page = page();
	$s = $page * $SET['k_p_s'] - $SET['k_p_s'];
	$q = mysql_query("SELECT * FROM `mail` WHERE `u2` = '$U[id]' ORDER BY `read` ASC, `time` DESC LIMIT $s, $SET[k_p_s] ");
		while ($m = mysql_fetch_assoc($q)) {
		$u = mysql_fetch_assoc(mysql_query("SELECT id, nick FROM `users` WHERE `id` = '$m[u1]'"));
			if($m['read'] == 0) $s='<b>(не прочитано)</b>'; else $s='';
		echo '<div class="cont">
		От: <a href="anketa.php?id='.$u['id'].'"><b>'.$u['nick'].'</b></a> '.$s.'<br />
		Отправлено: '.data($m['time']).'<br />
		<a href="?act=msg&amp;id='.$m['id'].'">Текст: '.mb_substr($m['msg'], 0, 10).'...</a>
		</div>';	
		}
	if ($k_page > 1) str('?act=in&amp;', $k_page, $page);
	}
echo '<a href="?">Почта</a><br />';
break;

case 'out':
$k = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u1`= '$U[id]' AND `read` = '1' "), 0);
	if ($k == 0) echo '<b>Пока пусто</b><br />';
	else
	{
	$k_page =  ceil( $k / $SET['k_p_s']);
	$page = page();
	$s = $page * $SET['k_p_s'] - $SET['k_p_s'];
	$q = mysql_query("SELECT * FROM `mail` WHERE `u1`= '$U[id]' AND `read` = '1' ORDER BY `time` DESC LIMIT $s, $SET[k_p_s] ");
		while ($m = mysql_fetch_assoc($q)) {
		$u = mysql_fetch_assoc(mysql_query("SELECT id, nick FROM `users` WHERE `id` = '$m[u2]'"));
		echo '<div class="cont">
		Кому: <a href="anketa.php?id='.$u['id'].'"><b>'.$u['nick'].'</b></a><br />
		Отправлено: '.data($m['time']).'<br />
		<a href="?act=msg2&amp;id='.$m['id'].'">Текст: '.mb_substr($m['msg'], 0, 10).'...</a>
		</div>';	
		}
	if ($k_page > 1) str('?act=in&amp;', $k_page, $page);
	}
echo '<a href="?">Почта</a><br />';
break;

case 'out2':
$k = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `u1`= '$U[id]' AND `read` = '0'"), 0);
	if ($k == 0) echo '<b>Пусто</b><br />';
	else
	{
	$k_page =  ceil( $k / $SET['k_p_s']);
	$page = page();
	$s = $page * $SET['k_p_s'] - $SET['k_p_s'];
	$q = mysql_query("SELECT * FROM `mail` WHERE `u1` = '$U[id]' AND `read` = '0' ORDER BY `time` DESC LIMIT $s, $SET[k_p_s] ");
		while ($m = mysql_fetch_assoc($q)) {
		$u = mysql_fetch_assoc(mysql_query("SELECT id, nick FROM `users` WHERE `id` = '$m[u2]'"));
		echo '<div class="cont">
		Кому: <a href="anketa.php?id='.$u['id'].'"><b>'.$u['nick'].'</b></a><br />
		Отправлено: '.data($m['time']).'<br />
		<a href="?act=msg2&amp;id='.$m['id'].'">Текст: '.mb_substr($m['msg'], 0, 10).'...</a>
		</div>';	
		}
	if ($k_page > 1) str('?act=in&amp;', $k_page, $page);
	}
echo '<a href="?">Почта</a><br />';
break;

case 'msg':
$id = intval($_GET['id']);
$q =  mysql_query("SELECT * FROM `mail` WHERE `id` = '$id'");
	if (mysql_num_rows($q) == 0) header('Location: ?act=in');
$m =  mysql_fetch_assoc($q);
$q1 =  mysql_query("SELECT id,nick FROM `users` WHERE `id` = '$m[u1]'"); 
$u =  mysql_fetch_assoc($q1);
mysql_query("UPDATE `mail` SET `read` = '1' WHERE `id` = '$m[id]' LIMIT 1");
echo '<div class="cont">
Отправитель: <a href="anketa.php?id='.$u['id'].'"><b>'.$u['nick'].'</b></a><br />
Отправлено: '.data($m['time']).'<br />
Текст: '.out($m['msg'], true, true).'<br />
<a href="?act=send&amp;id='.$m['u1'].'">Ответить</a> | <a href="?act=del&amp;id='.$m['id'].'">Удалить</a></div>
<a href="?act=in">Входящие</a><br />';
break;

case 'msg2':
$id = intval($_GET['id']);
$q =  mysql_query("SELECT * FROM `mail` WHERE `id` = '$id'");
	if (mysql_num_rows($q) == 0) header('Location: ?act=in');
$m =  mysql_fetch_assoc($q);
$q1 =  mysql_query("SELECT id,nick FROM `users` WHERE `id` = '$m[u2]'"); 
$u =  mysql_fetch_assoc($q1);
echo '<div class="cont">
Получатель: <a href="anketa.php?id='.$u['id'].'"><b>'.$u['nick'].'</b></a><br />
Отправлено: '.data($m['time']).'<br />
Текст: '.out($m['msg'], true. true).'<br />
<a href="?act=del&amp;id='.$m['id'].'">Удалить</a></div>
<a href="?act=out">Исходящие</a><br />';
break;

case 'send':
$id = intval($_GET['id']);
$q =  mysql_query("SELECT id,nick FROM `users` WHERE `id` = '$id'");
	if (mysql_num_rows($q)  == 0 OR $U['id'] == $id) header('Location: ?');
$a =  mysql_fetch_assoc($q);
	if(isset($_GET['go']) AND isset($_POST['msg']))
	{
	$r = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `msg` = '".in($_POST['msg'])."' AND `time` > '".($time-30)."' "), 0); 	
		if ($r == 0  AND mb_strlen(in($_POST['msg'])) > 2 AND mb_strlen(in($_POST['msg'])) < 1000 AND  mysql_query("INSERT INTO `mail` 
		(`u1`, `u2`, `msg`, `time`, `read`)
		VALUES 
		('$U[id]', '$id', '".in($_POST['msg'])."', '$time', '0')")) 
		header('Location: ?ok=s');	
 	else 
 	header('Location: ?act=send&id='.$id.'&err');
	}
	if (isset($_GET['err'])) echo '<span class="err">Ошибка((</span>';
echo '<div class="cont">
<form action="?act=send&amp;id='.$id.'&amp;go" method="post">
Кому: <b>'.$a['nick'].'</b><br />
Сообщение (3-1000):<br /><textarea name="msg" rows="3" cols="20"></textarea><br />
<input type="submit" value="Отправить" />
</form></div>
<a href="mail.php">Почта</a><br />';
break;

case 'del':
$id = intval($_GET['id']);
$m = mysql_fetch_assoc(mysql_query("SELECT id, u1, u2 FROM `mail` WHERE `id` = '$id'"));
	if ($U['id'] == $m['u1'] OR $U['id'] == $m['u2']) {
	mysql_query("DELETE FROM `mail` WHERE `id` = '$id'");	
	header('Location: ?ok=d');
	}
	else
	echo 'Ошибка((<br />';
break;
}
echo '<img src="inc/img/kab.png" alt="" /> <a href="cabinet.php">Кабинет</a><br /><img src="inc/img/home.png" alt="" /> <a href="/">На главную</a>';
foot();
?>