<?
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
//require_once"../template/maincore.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
/*
 $text = file(BASEDIR."local/profil/$log.prof");
 if ($text!=""){
 	$udata = explode(":||:",$text[0]);
 	$provlog=trim($udata[0]);
 	$provpar=trim($udata[1]);
 	$privat=trim($udata[10]);}
 */
  	if ($provlog==$_SESSION['log'] && $provpar==md5($_SESSION['par']) && $_SESSION['log']!="" && md5($_SESSION['par'])!=""){
 		$id_room=$_GET['id_room'];
 		$room_ok='0';
 		if (!file_exists("../local/datachat/rooms.dat")){
 			header ("Location: index.php?".SID."");
 			}
 			else
 			{
 				$datarooms=file("../local/datachat/rooms.dat");
 				$datarooms=array_reverse($datarooms);
 				$datarooms_k=count($datarooms);
 				for ($i=0;$i<$datarooms_k;$i++){
 					$room=explode(":||:",$datarooms[$i]);
 					if ($id_room==$room[0])
 					{
 						$room_ok='1';
 						$room2=$room;
 						}
 					}
 				}
 				if ($room_ok!='1'){
 					header ("Location: index.php?".SID."");
 					}
 					if (isset($_GET['act']) && $_GET['act']=='send')
 					{
 						$msg=stripslashes(htmlspecialchars($_POST['msg']));
 						$msg=str_replace("\r\n","<br />",$msg);
 						$msg=str_replace("\r","<br />",$msg);
 						$msg=str_replace("\n","<br />",$msg);
 						$msg=eregi_replace("((https?|ftp)://[[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&amp;._=/~%#]*(\\?[[:alnum:]?+&amp;_=/%#]*)?)?)", "<a href='\\1'>\\1</a>", $msg);
 						if (isset($_POST['trans'])){
 							if($trans=="y"){
 								$msg=transliter($msg);
 								}
 							$msg = antimat($msg);
 							$msg = smiles($msg);
 							/*
 							$zag=utf_to_win($zag);
 							$zag==wordwrap($zag,60,' ',1);
 							$zag=win_to_utf($zag);
 							$msg=utf_to_win($msg);
 							$msg=wordwrap($msg,100,' ',1);
 							$msg=win_to_utf($msg);
 							*/
 							$mio="[$brow, $ip]";
 							$text="$name|рус|$mio|$zag|$msg|$date|$time|$id|$fid|$tektime|";
 							$msg=str_replace($trans1,$trans2,$msg);
 							}
 							$priv='';
 							if (isset($_POST['privat'])){
 								$priv=$kont;
 								}
 								if ($msg!='')
 								{
 									$msg=base64_encode($msg);
 									$date=base64_encode(date("(G:i / d.m)"));
 									$fm=fopen("../local/datachat/$id_room.chat","a");
 									flock($fm,LOCK_EX);
 									fputs($fm,"$log:||:$date:||:$msg:||:$priv:||::||::||::||::||::||::||::||:\r\n");
 									fflush($fm);
 									flock($fm,LOCK_UN);
 									fclose($fm);
 									chmod ("../local/datachat/$id_room.chat", 0666);
 									header ("Location: chat.php?id_room=$id_room&".SID."");
 									}
 									else
 									{
 										header ("Location: index.php?".SID."");
 										exit;
 										}
 						}
 						else
 						{
 							header ("Location: index.php?".SID."");
 							exit;
 							}
 		 	}
 	else
 	{
 	echo '<br>Вы не авторизованы, чтобы добавить сообщение, необходимо<br>';
 	echo '<b><a href="../pages/vhod.php?'.SID.'">Авторизоваться</a></b> или в начале <b>
 	<a href="../pages/registration.php?'.SID.'">Зарегистрироваться</a></b><br><br>';
 	}
?>
