View file mail.php

File size: 4.8Kb
<?php
error_reporting(0);
include 'sys/db.php';
include 'sys/conf.php';
include 'sys/start.php';
include 'sys/functions.php';
$config_title_name = "Почта";
include 'style/head.php';
if(isset($user['login'])){
echo'<div class="title">
<a href="mail.php">Входящие</a> | <a href="mail.php?send">Исходящие</a>
</div>
';
$rand=mt_rand(1000,99999);
$_SESSION['rand']=$rand;
if(isset($_GET['add'])){
	$add=intval($_GET['add']);
	$query_send=mysql_query("SELECT login FROM `users` WHERE id = '$add' LIMIT 1;")or die(mysql_error());
	if(mysql_num_rows($query_send)==0){
		echo'
			<div class="error">Такого пользователя не существует</div>
		';
	}else{
	echo'<div class="title">
		Новое Сообщение
	</div>
	<div class="content">
	<form action="action.php" method="post">
	Кому: '.strip(mysql_result($query_send,0,0)).' '.strip(mysql_result($query_send,0,1)).'<br />
	Сообщение:<br />
	<textarea name="msg"></textarea><br /><br />
	<input type="hidden" name="id" value="'.$add.'" />
	<input type="submit" name="addmsg" value="Отправить" />
	</form>
	</div>
	';
	};
}elseif(isset($_GET['send'])){
	$list=10;
	$t=mysql_result(mysql_query("SELECT COUNT(*) FROM mail WHERE send = '$id';"),0);
	if(isset($_GET['n']) && (int)($_GET['n'])!='' && (int)($_GET['n'])>0){
		$n=(int)($_GET['n']);
		$tot=$n;
		if($tot>$t){
			$tot=$t;
		};
	}else{
		$tot=$t;
	};
	if($tot%$list==0){
		$start=(int)($tot-$list);
	}else{
		$start=(int)($tot-$tot%$list);
		$tot=$start+$list;
		if($tot>$t){
			$tot=$t;
		};
	};
	if($start<0) $start=0;
	$query=mysql_query("SELECT * FROM `mail` WHERE rec = '$user[id]' AND outbox = '1' ORDER BY id DESC LIMIT $start, $list;")or die(mysql_error());
	$total=mysql_num_rows($query);
	if($total==0){
		echo'<div class="error">
			Нет сообщений
		</div>';
	}else{
		for($i=0; $i<$total; $i++){
			$msg=mysql_fetch_array($query);
			echo'<div class=content>
			<a href="anketa.php?id='.$msg['send'].'">'.get_login($msg['send']).'</a>
			</div>
			<div class=content>
				'.$msg['msg'].'<br />
				'.date("H:i:s d:m:Y",$msg['time']).'
			</div>
			<div class=content>
				<a href="action.php?delsend='.$msg['id'].'&amp;r='.$rand.'">Удалить</a> |
				<a href="mail.php?add='.$msg['send'].'">Написать еще</a>
				';
				echo'
			</div>
			';
		};
		if($t>1) {echo' <a href="action.php?delallsend&amp;r='.$rand.'">Удалить все</a> <hr />';};
		echo'<div class=content>
		Страницы:
		';
		$total=(int)($t/$list);
		if((int)($t%$list)!=0) $total++;
		$stok=$start/$list+1;
		for($i=1; $i<=$total; $i++){
			if($i==$stok){
				echo' '.$i.' ';
			}else{
				echo' <a href="mail.php?send&amp;n='.(int)($list*$i-1).'">'.$i.'</a> ';
			};
		};
		echo'</div>
		';
	};
}else{
	$list=10;
	$t=mysql_result(mysql_query("SELECT COUNT(*) FROM mail WHERE rec = '$id' ;"),0);
	if(isset($_GET['n']) && (int)($_GET['n'])!='' && (int)($_GET['n'])>0){
		$n=(int)($_GET['n']);
		$tot=$n;
		if($tot>$t){
			$tot=$t;
		};
	}else{
		$tot=$t;
	};
	if($tot%$list==0){
		$start=(int)($tot-$list);
	}else{
		$start=(int)($tot-$tot%$list);
		$tot=$start+$list;
		if($tot>$t){
			$tot=$t;
		};
	};
	if($start<0) $start=0;
	$query=mysql_query("SELECT * FROM `mail` WHERE send = '$user[id]' AND inbox = '1' ORDER BY id DESC LIMIT $start, $list;")or die(mysql_error());
	$total=mysql_num_rows($query);
	if($total==0){
		echo'<div class="error">
			Нет сообщений
		</div>';
	}else{
		for($i=0; $i<$total; $i++){
			$msg=mysql_fetch_array($query);
			if($msg['pro']==0){
				$new=' <b>(новое!)</b> ';
				mysql_query("UPDATE `mail` SET pro = '1' WHERE id = '".$msg['id']."';")or die(mysql_error());
			}else{
				$new='';
			};
			echo'<div class=content>
			<a href="anketa.php?id='.$msg['rec'].'">'.get_login($msg['rec']).'</a> '.$new.'
			</div>
			<div class=content>
				'.$msg['msg'].'<br />
				'.date("H:i:s d:m:Y",$msg['time']).'
			</div>
			<div class=content>
				<a href="action.php?delrec='.$msg['id'].'&amp;r='.$rand.'">Удалить</a> |
				<a href="mail.php?add='.$msg['rec'].'">Ответить</a>
				';
				echo'
			</div>';
		};
		if($t>1) {echo' <a href="action.php?delallrec&amp;r='.$rand.'">Удалить все</a><hr />';};
		echo'<div class=title>
		Страницы:
		';
		$total=(int)($t/$list);
		if((int)($t%$list)!=0) $total++;
		$stok=$start/$list+1;
		for($i=1; $i<=$total; $i++){
			if($i==$stok){
				echo' '.$i.' ';
			}else{
				echo' <a href="mail.php?n='.(int)($list*$i-1).'">'.$i.'</a> ';
			};
		};
		echo'</div>
		';
	};
};




echo "<div class=stat><a href='index.php'>Прихожая</a></div>\n";
}else{ header ("Location: index.php"); exit;}
include 'style/foot.php';
?>