<?

/******************************
	MANAGE REQUESTS
/******************************/


if(!$_POST['action']){

	header ("Location: /index.php");
}
else{

	
	switch($_POST['action']){
		case "update":
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
only_reg();





			

$res=mysql_query("SELECT * FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '".intval($_POST['id'])."' OR `id_user` = '".intval($_POST['id'])."' AND `id_kont` = '$user[id]' ORDER BY id DESC ");


	

######################################################




		while($row = mysql_fetch_array($res)){

  $ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$row[id_user]' LIMIT 1")); 
##############################################
//сокращает строки
                        
$text=wordwrap($row['message'],85, "</br>\n", 1);
$text=mysql_escape_string($text);
########################################  


echo "<div id='body'>\n";

echo "<div id='rowup'>\n"; //рамка для ника и сообщений 
echo "<div id='avatar'>\n"; //рамка для фотки 

	
if(is_file(H."/files/avatar/$row[id_user].gif")){
	echo "<img src='/files/avatar/$row[id_user].gif' align='left' width='44' height='44' alt=''/>\n";}
	else
if(is_file(H."files/avatar/$row[id_user].jpg")){
	echo "<img src='/files/avatar/$row[id_user].jpg' align='left' width='44' height='44' alt=''/>\n";}
	else
if(is_file(H."files/avatar/$row[id_user].png")){
	echo "<img src='/files/avatar/$row[id_user].png' align='left' width='44' height='44' alt=''/>\n";}
	else{
	echo "<img src='/img/user.png' align='left' width='44' height='44' alt=''/>\n";
				
	}



echo "</div>\n";
echo "<div id='nick'>\n"; //рамка для ника
echo"<img src='/img/online/man_on.gif' alt='' class='icon'/>\n";
echo"<a href='/info.php?id=$ank[id]' style='text-decoration: none'>$ank[nick]</a>";
echo" (".vremja($row['time']).")<br/>";

echo "</div>\n";

echo"<div id='text'>";//рамка для текста



echo"$row[msg]<br/>";
if($row['read']==0){
echo"<font color='red'>(не прочитано)</font>";

if($row['id_user']!=$user['id']){
setcookie("$row[id]","$row[id]",time()+3600);

if($_COOKIE[$row['id']]!=$row['id']){
?>

<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' WIDTH=0 HEIGHT=0><PARAM NAME=movie VALUE='/mail/sound.swf'><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src='/mail/sound.swf' 
quality=high bgcolor=#FFFFFF  WIDTH=0 HEIGHT=0 TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT>

<?
}
}


}
###########################################################################
echo"</div>";
			
echo "</div>\n";



			
}



echo "</div>\n";







			break;
		case "insert":
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
only_reg();


#############################################
//здесь происходит замена плохих слов
##############################################
$slowa = array("блять", "хуй", "пизда", "ёбок", "гавно", "дерьмо", "залупа", "пиздец");
$message = str_replace($slowa, "", $_POST['message']);
######################################################
 


mysql_query("INSERT INTO `mail` (`msg`, `id_user`, `id_kont`,`time`,`read`) values('$message', '$user[id]','".intval($_POST['id'])."','$time','0')");
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `konts` WHERE `id_user` = '".intval($_POST['id'])."' AND `id_kont` = '$user[id]'"), 0)==0)
{
mysql_query("INSERT INTO `konts` (`id_user`, `id_kont`,`time`) values( '".intval($_POST['id'])."','$user[id]','$time')");}
			break;
	}
	
}


?>