Просмотр файла priv.php

Размер файла: 11.3Kb
<?
include $_SERVER['DOCUMENT_ROOT']."/template/head.php";

if(isset($id))
{
	$max_mess_priv=30;
	//кнопки
	echo'<table width="100%"><tr><td valign="top" width="50%" align="left">
	<a href="priv.php?pr=st"><div class="e">Стандартная почта</div></a>
	</td><td valign="top" width="50%" align="left">
	<a href="priv.php?pr=dio"><div class="e">Диологи</div></a>
	</td></tr></table>';

	if($_GET['pr']=="dio"){$_SESSION['priv']=$_GET['pr'];}
	if($_GET['pr']=="st"){$_SESSION['priv']=$_GET['pr'];}
	
	
		//добовление контактов
	if($_GET['id']!="")
	{
		if(mysql_fetch_array(mysql_query("select * from `prof` where `id`='".$_GET['id']."'")))
		{
			$c1=mysql_query("select * from `mail` where id_user='$id' and contact='".$_GET['id']."'");
			if(mysql_num_rows($c1)==0)
			{mysql_query("insert into `mail`(`id_user`,`contact`) values('$id','".$_GET['id']."');");}
			$c2=mysql_query("select * from `mail` where id_user='".$_GET['id']."' and contact='$id'");
			if(mysql_num_rows($c2)==0)
			{mysql_query("insert into `mail`(`id_user`,`contact`) values('".$_GET['id']."','$id');");}
		}
	}
	

	if($_SESSION['priv']=="dio")
	{





##########################Контакты####################################

		//удаление контактов
		if(isset($_GET['del_contact']))$c_priv=mysql_query("select * from `mail` where `id`='".$_GET['del_contact']."' and `id_user`='$id'");
		if(mysql_num_rows($c_priv)==1)
		{
			$c_log = mysql_fetch_array($c_priv);
			mysql_query("delete from `mail` where `id`='".$_GET['del_contact']."' and `id_user`='$id'");
			mysql_query("delete from `priv` where id_user='$id' and komu='".$c_log[contact]."' 
						and ot_kogo='$id' or id_user='$id' and ot_kogo='".$c_log[contact]."' and komu='$id'");
			echo'<h3>Контакт удален!</h3>';
		}
	
	



		//выбор контакта

		$page_contact=$_GET[page_contact];
		if(empty($page_contact)){$page_contact=0;}
		$mess_contact = mysql_query("select * from `mail` where id_user='$id' ORDER BY `id` DESC  LIMIT ".$page_contact." ,".$max_mess_priv."");
		echo'<table width="100%"><tr><td valign="top" width="30%" align="left">';
		if(mysql_num_rows($mess_contact)==0){echo'<h3><center>Нет контактов!</center></h3>';}
		while ($mess_contact_array = mysql_fetch_array($mess_contact)) 
		{
			echo '<br/><div class="f"><table width="100%"><tr><td valign="top" width="40%" align="left">';
			$contact_log = mysql_fetch_array(mysql_query("select * from `prof` where id='$mess_contact_array[contact]'"));
			$contact_new_mess = mysql_fetch_array(mysql_query("select * from `priv` where id_user='$id' and `ot_kogo`='$mess_contact_array[contact]' and sys='1' ORDER BY `id` DESC  LIMIT 1"));
			photo_sten($contact_log[foto],$contact_log[id]);
			echo '</td><td valign="top" width="60%">';
			echo '<br><a href="priv.php?id='.$contact_log[id].'"><b>'.$contact_log[name].' '.$contact_log[fam].'</b></a><br/>';
			online($contact_log[id]);
			echo $contact_new_mess[data].'<br>'.$contact_new_mess[text].'<p><a href="./priv.php?del_contact='.$mess_contact_array[id].'">Удалить из контактов</a><p>';
			echo '</td></tr></table></div>';
		}
		mess_str("mail",$max_mess_priv,$page_contact);
		echo'</td><td valign="top" width="70%" align="left">';

	
	
	
	
	
		
		#############################Диологи#############################################
		if($_GET['id']!="")
		{
		
		
			@mysql_query("UPDATE `priv` SET `sys` = '0' where `id_user` = '$id' and `ot_kogo` = '".$_GET['id']."'");
			if($str = mysql_fetch_array(mysql_query("select * from `prof` where `id`='".$_GET['id']."'")))
			{
				//добовление сообщения
				if($_POST[text]!="")
				{	
					$r_m=mysql_fetch_array(mysql_query("select * from `priv` where id_user='$id' ORDER BY `id` DESC  LIMIT 1"));
					if($r_m[text]==$_POST[text]){echo'Ваше сообщение повторяет предыдущее!';}
					else
					{
						$data = $den.' '.$mesac.' '.$god.'г.<br/>'.$time;
						if(mysql_query("insert into `priv`(`id_user`,`komu`,`ot_kogo`,`data`,`text`) 
										values('$id','".$_GET['id']."','$id','$data','".$_POST[text]."');") 
						and mysql_query("insert into `priv`(`id_user`,`komu`,`ot_kogo`,`data`,`text`,`sys`) 
										values('".$_GET['id']."','".$_GET['id']."','$id','$data','".$_POST[text]."','1');"))
						{echo "Сообщение отправлено!<br/>";} else {echo mysql_error();}
					}
				}
			
			
				//удаление сообщений
				if(isset($_GET['del']))$u_priv=mysql_query("select * from `priv` where `id`='".$_GET['del']."' and `id_user`='$id'");
				if(mysql_num_rows($u_priv)==1)
				{
					if(mysql_query("delete from `priv` where id='".$_GET['del']."'")){echo'<h3>Cообщение удалено!</h3>';}
				}


			
				echo"<form action=\"priv.php?id=".$_GET['id']."\" method=\"post\">
				$str[name] $str[fam]<br/>
				сообщение:<br/>
				<textarea cols=\"25\" rows=\"3\" name=\"text\"></textarea><br/>
				<input value=\"Отправить\" type=\"submit\" /><br/>
				</form>";
			}
			else
			{echo'<h2><b><center>Такой страницы нет!</center></b></h2>';}
			
			
			$page_priv=$_GET[page_priv];
			if(empty($page_priv)){$page_priv=0;}
			
			$mess_priv = mysql_query("select * from `priv` where id_user='$id' and komu='".$_GET['id']."' and ot_kogo='$id' or id_user='$id' and ot_kogo='".$_GET['id']."' and komu='$id' ORDER BY `id` DESC  LIMIT ".$page_priv." ,".$max_mess_priv."");
			$mess_p = mysql_query("select * from `priv` where id_user='$id' and komu='".$_GET['id']."' and ot_kogo='$id' or id_user='$id' and ot_kogo='".$_GET['id']."' and komu='$id'");
			$mess_p_c=mysql_num_rows($mess_p);
			if($mess_p_c==0){echo'<h3><center>Сообщений нет!</center></h3>';}
			while ($mess_priv_array = mysql_fetch_array($mess_priv)) 
			{
				echo '<br/><div class="f"><table width="100%"><tr><td valign="top" width="25%" align="left">';
				$priv_log = mysql_fetch_array(mysql_query("select * from `prof` where id='$mess_priv_array[ot_kogo]'"));
				photo_sten($priv_log[foto],$priv_log[id]);
				echo '<br><a href="anketa.php?id='.$priv_log[id].'"><b>'.$priv_log[name].' '.$priv_log[fam].'</a><br/>';
				online($priv_log[id]);
				echo $mess_priv_array[data].'<br></td><td valign="center" width="65%" align="left">';
				echo check($mess_priv_array[text]).'</b><br/>';
				echo '</td><td valign="top" width="10%">';
				echo'<a href="./priv.php?id='.$priv_log[id].'&del='.$mess_priv_array[id].'">Удалить</a><p>';
				echo '</td></tr></table></div>';
			}
			
		
			$str_col=ceil($mess_p_c/$max_mess_priv);
			for($i=1; $i<$str_col+1; $i++)
			{
				if(($page_priv/$max_mess_priv+1)==$i){echo $i;}else{echo'<a href="?page_priv='.($i-1)*$max_mess_priv.'">'.$i.'</a>';}
			}
			
			
			
			
			
		}else{echo'<h3><center>Выбирите собеседника!</center></h3>';}
		
		echo'</td></tr></table>';	
		
	}
	
	
	
	
	
	
	
	
	
	if($_SESSION['priv']=="st" or !isset($_SESSION['priv']))
	{
		
		
		$priv = $_GET['priv'];
		$otpr = $_GET['otpr'];

		if($_GET['id'])$mail = $_GET['id'];
		if($_GET['mail'])$mail = $_GET['mail'];





		
		//добовление сообщения
		if(!empty($otpr) and $_POST[text]!="")
		{
			$r_m=mysql_fetch_array(mysql_query("select * from `priv` where id_user='$id' ORDER BY `id` DESC  LIMIT 1"));
			if($r_m[text]==$_POST[text]){echo'Ваше сообщение повторяет предыдущее!';}
			else
			{
				$data = $den.' '.$mesac.' '.$god.'г.<br/>'.$time;
				if(mysql_query("insert into `priv`(`id_user`,`komu`,`ot_kogo`,`data`,`text`) values('$id','".$otpr."','$id','$data','".$_POST[text]."');")
				and mysql_query("insert into `priv`(`id_user`,`komu`,`ot_kogo`,`data`,`text`,`sys`) values('".$otpr."','".$otpr."','$id','$data','".$_POST[text]."','1');"))
				{echo "Сообщение отправлено!<br/>";} else {echo mysql_error();}
			}
		}




		//кнопки
		echo'<table width="100%"><tr><td valign="top" width="50%" align="left">
		<a href="priv.php?priv=prin"><div class="e">Входящие</div></a>
		</td><td valign="top" width="50%" align="left">
		<a href="priv.php?priv=otpr"><div class="e">Отправленые</div></a>
		</td></tr></table>';






		if(isset($_GET['del']))$u_priv=mysql_query("select * from `priv` where `id`='".$_GET['del']."' and `id_user`='$id'");
		if(mysql_num_rows($u_priv)==1)
		{
			if(mysql_query("delete from `priv` where id='".$_GET['del']."'")){echo'<h3>Cообщение удалено!</h3>';}
		}

		if(!empty($mail) and empty($otpr))
		{
			if($str = mysql_fetch_array(mysql_query("select * from `prof` where `id`='$mail'")))
			{
		
		

				echo"<form action=\"priv.php?otpr=$mail\" method=\"post\">
				Получатель $str[name] $str[fam]<br/>
				сообщение:<br/>
				<textarea cols=\"25\" rows=\"3\" name=\"text\"></textarea><br/>
				<input value=\"Отправить\" type=\"submit\" /><br/>
				</form>";

		
			}
			else
			{echo'<h2><b><center>Такой страницы нет!</center></b></h2>';}
		}
		
		
		
		if(empty($mail))
		{
		
			if(empty($priv)){$priv="prin";}
			
			$page_priv=$_GET[page_priv];
			if(empty($page_priv)){$page_priv=0;}
			if($priv == "otpr")
			{
				$result_sten = mysql_query("select * from `priv` where ot_kogo='$id' and id_user='$id' ORDER BY `id` DESC  LIMIT ".$page_priv." ,".$max_mess_priv."");
				$result_sten1 = mysql_query("select * from `priv` where ot_kogo='$id' and id_user='$id'");
			}
			if($priv == "prin")
			{
				$result_sten = mysql_query("select * from `priv` where komu='$id' and id_user='$id' ORDER BY `id` DESC  LIMIT ".$page_priv." ,".$max_mess_priv."");
				$result_sten1 = mysql_query("select * from `priv` where komu='$id' and id_user='$id'");
				@mysql_query("UPDATE `priv` SET `sys` = '0' where `id_user` = '$id'");
			}
			$mess_c=mysql_num_rows($result_sten1);
			if($mess_c==0){echo'<h3><center>Сообщений нет!</center></h3>';}
			while ($mess_sten = mysql_fetch_array($result_sten)) 
			{
				echo '<br/><div class="f"><table width="100%"><tr><td valign="top" width="15%" align="left">';
				if($priv == "otpr"){$sten_log = mysql_fetch_array(mysql_query("select * from `prof` where id='$mess_sten[komu]'"));}
				if($priv == "prin"){$sten_log = mysql_fetch_array(mysql_query("select * from `prof` where id='$mess_sten[ot_kogo]'"));}
				photo_sten($sten_log[foto],$sten_log[id]);
				echo '<a href="anketa.php?id='.$sten_log[id].'"><b>'.$sten_log[name].' '.$sten_log[fam].'</a><br/>'.$mess_sten[data].'<br>';
				online($sten_log[id]);
				echo '</td><td valign="top" width="75%" align="left">';
				echo check($mess_sten[text]).'</b><br/>';
				echo '</td><td valign="top" width="10%">';
				if($priv == "prin"){echo'<a href="./priv.php?mail='.$mess_sten[ot_kogo].'">Ответить</a><p>';}
				echo'<a href="./priv.php?del='.$mess_sten[id].'">Удалить</a><p>';
				echo '</td></tr></table></div>';
			}
			$str_col=ceil($mess_c/$max_mess_priv);
			for($i=1; $i<$str_col+1; $i++)
			{
				if(($page_priv/$max_mess_priv+1)==$i){echo $i;}else{echo'<a href="?page_priv='.($i-1)*$max_mess_priv.'">'.$i.'</a>';}
			}
		}
	}	
}

include $_SERVER['DOCUMENT_ROOT']."/template/foot.php";
?>