<?php
@session_start();

require_once $_SERVER['DOCUMENT_ROOT']."/includes/start.php";
if(isset($_SESSION['auth']) and $_SESSION['auth']==1){

if(isset($HTTP_GET_VARS['rm'])) {$rm = $HTTP_GET_VARS['rm'];}
$rm = mysql_escape_string($rm);
mysql_query ("Select rm from rooms where rm='".$rm."';");
if(mysql_affected_rows() == 0){
header ("Location: /enter.php?"); exit;
}else{
$room =  mysql_fetch_assoc(mysql_query("SELECT * FROM `rooms` WHERE `rm` = '".$rm."' LIMIT 1"));
}

if($_GET['go']=='delete'){

if(isset($_GET['id'])){
$del = $_GET['id'];
}else{
$del = "";
}
if($del!==""){
mysql_query("DELETE FROM `msg` WHERE `id` = '$del' and rm='$rm'");
mysql_query("OPTIMIZE TABLE `msg`");
header ("Location: room.php?rm=$rm"); exit;
}else{
header ("Location: room.php?rm=$rm"); exit;
}
}

echo $_up;

$mtime = time();
mysql_query("update users set rtime=$mtime where login='$usr[login]' limit 1");
mysql_query("update users set room=$rm where login='$usr[login]' limit 1");
echo '<center><b>'.$room['name'].' ('.mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `room` = "'.$rm.'" and `rtime`>"'.intval( time( ) - 100 ).'"'),0).')</b></center>
[<a href="global_say.php?rm='.$rm.'"><b>Сказать</b></a>] | ';
if($usr['status']>="2"){
echo '[<a href="admin_say.php?rm='.$rm.'"><b style="color:red;">Сообщение</b></a>] |';
}
echo ' [<a href="faq.php?smiles"><b>Смайлы</b></a>] | [<a href="?history.php?rm='.$rm.'"><b>История</b></a>] | [<a href="?rm='.$rm.'"><b>Обновать</b></a>]<br>';
echo '<div style="padding:3px 5px 3px 5px;">
<form method="post" action="fast_say.php?rm='.$rm.'&amp;">
<input name="text" maxlength="150" size="60%"/> <input value="Написать" type="submit"/>
</form>
</div><div class="list">';



$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `msg` WHERE rm=$rm"), 0);

$data = mysql_query("SELECT * FROM `msg` WHERE rm = $rm ORDER BY `id` DESC LIMIT 15");
if($total==0){
echo 'Сообщений нет...';
}else{

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

$fi = mysql_query( "select `login`,`clogin`,`ctext` from `users` where id='$res[from_id]';" );
$fi_info = @mysql_fetch_array( @$fi );
$from_login = $fi_info['login'];

if($fi_info['clogin']==1){ $from_login='<font color="black">'.$from_login.'</font>'; } ///черный
if($fi_info['clogin']==2){ $from_login='<font color="#666">'.$from_login.'</font>'; } ///серый
if($fi_info['clogin']==3){ $from_login='<font color="#300">'.$from_login.'</font>'; } ///темнокрасный
if($fi_info['clogin']==4){ $from_login='<font color="red">'.$from_login.'</font>'; } ///красный
if($fi_info['clogin']==5){ $from_login='<font color="#f00">'.$from_login.'</font>'; } ///светлокрасный
if($fi_info['clogin']==6){ $from_login='<font color="#030">'.$from_login.'</font>'; } ///темнозеленый
if($fi_info['clogin']==7){ $from_login='<font color="green">'.$from_login.'</font>'; } ///зеленый
if($fi_info['clogin']==8){ $from_login='<font color="#0f0">'.$from_login.'</font>'; } ///светлозеленый
if($fi_info['clogin']==9){ $from_login='<font color="#003">'.$from_login.'</font>'; } ///темносиний
if($fi_info['clogin']==10){ $from_login='<font color="blue">'.$from_login.'</font>'; } ///синий
if($fi_info['clogin']==11){ $from_login='<font color="#00f">'.$from_login.'</font>'; } ///светлосиний
if($fi_info['clogin']==12){ $from_login='<font color="#330">'.$from_login.'</font>'; } ///темножелтый
if($fi_info['clogin']==13){ $from_login='<font color="yellow">'.$from_login.'</font>'; } ///желтый
if($fi_info['clogin']==14){ $from_login='<font color="#ff0">'.$from_login.'</font>'; } ///светложелтый
if($fi_info['clogin']==15){ $from_login='<font color="#303">'.$from_login.'</font>'; } ///темносиреневый
if($fi_info['clogin']==16){ $from_login='<font color="#A0A">'.$from_login.'</font>'; } ///сиреневый
if($fi_info['clogin']==17){ $from_login='<font color="#f0f">'.$from_login.'</font>'; } ///светлосиреневый
if($fi_info['clogin']==18){ $from_login='<font color="#033">'.$from_login.'</font>'; } ///хуйнятемная
if($fi_info['clogin']==19){ $from_login='<font color="#0aa">'.$from_login.'</font>'; } ///хуйня
if($fi_info['clogin']==20){ $from_login='<font color="#0aa">'.$from_login.'</font>'; } ///светлая хуйня






if($fi_info['ctext']==1){ $clr_text='#000'; }
if($fi_info['ctext']==2){ $clr_text='#fff'; }
if($fi_info['ctext']==3){ $clr_text='#666'; }
if($fi_info['ctext']==4){ $clr_text='#ff0'; }
if($fi_info['ctext']==5){ $clr_text='#f60'; }
if($fi_info['ctext']==6){ $clr_text='#00f'; }
if($fi_info['ctext']==7){ $clr_text='#0ff'; }
if($fi_info['ctext']==8){ $clr_text='#82e'; }
if($fi_info['ctext']==9){ $clr_text='#f00'; }
if($fi_info['ctext']==10){ $clr_text='#0f0'; }

if($fi_info['clogin']=="gradient"){

$gr = mysql_query("select `start`,`end` from `gr` where id_user='$res[from_id]';" );
$gr_login = @mysql_fetch_array( @$gr );
$from_login = GradientText("$from_login", "$gr_login[start]", "$gr_login[end]");

}

if($res['from_id']==$usr['id'] && $res['for_id']!=='' && $res['type']=='private' or $res['for_id']==$usr['id'] && $res['type']=='private'){

$for_id = mysql_query( "select `login` from `users` where id='$res[for_id]';" );
$for_id_info = @mysql_fetch_array( @$for_id );
$for_id_login = $for_id_info['login'];

echo '<span style="background:#DADADA;"><font color="black">'.$res['time'].'</font> <a href="for_say.php?rm='.$rm.'&amp;who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <b>приватно для <b><u>'.$for_id_login.'</b></u></b>: <font color="'.$clr_text.'">'.$res['text'].'</font>';
if($usr['status']>=2){
echo '[<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]';
}
echo '</span><br>';

}else{

if($res['type']!=='private' && $res['for_id']==''){

if($res['type']=="PRED"){

echo '<span style="background:#FFB9A1;color:red;"><font color="black">'.$res['time'].'</font> <b><u>Робот</b></u>: <b>'.$res['text'].'</b>';
if($usr['status']>=2){
echo '[<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]';
}
echo '</span><br>';


}elseif($res['type']=="PRESENT"){

echo '<span style="background:#FFB9A1;color:red;"><font color="black">'.$res['time'].'</font> <b><u>Робот</b></u>: <b>'.$res['text'].'</b>';
if($usr['status']>=2){
echo '[<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]';
}
echo '</span><br>';


}elseif($res['type']=="adminMSG"){

echo '<font color="black">'.$res['time'].' <img src="/imgs/ads.gif"/> <b style="color:#3D9900;"><u>Сообщение</b></u>:</font><div style="background:#EEEEEE;color:#000;border-top:1px solid #CCCCCC;border-bottom:1px solid #CCCCCC;padding:1px 5px 1px 5px;"><b>'.$res['text'].'</b>';
if($usr['status']>=2){
echo '[<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]';
}
echo '</div>';


}else{

echo '<font color="black">'.$res['time'].'</font> <a href="for_say.php?rm='.$rm.'&amp;who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <font color="'.$clr_text.'">'.$res['text'].'</font>';
if($usr['status']>=2){
echo ' [<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]';
}
echo '<br>';

}

}else{


if($res['type']!=='private' && $res['for_id']!==''){

$dfor_id = mysql_query( "select `login` from `users` where id='$res[for_id]';" );
$dfor_id_info = @mysql_fetch_array( @$dfor_id );
$dfor_id_login = $dfor_id_info['login'];

echo '<font color="#000">'.$res['time'].'</font> <a href="for_say.php?rm='.$rm.'&amp;who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <b>для <a href="for_say.php?rm='.$rm.'&amp;who='.$res['for_id'].'"><b><u>'.$dfor_id_login.'</b></u></a></b>: <font color="'.$clr_text.'">'.$res['text'].'</font> [<a href="?go=delete&amp;id='.$res['id'].'&amp;rm='.$rm.'">x</a>]<br>';

}}}}}


echo '</div><div style="padding:3px;">В комнате:</div><div class="list">';



$q_online = mysql_query("SELECT `id`,`login`,`clogin` FROM users WHERE rtime>'".intval( time( ) - 100 )."' AND `room`='$rm' order by rtime desc;" );
while($donline = mysql_fetch_array($q_online)){

if($donline['clogin']==1){ $donline['login']='<font color="black">'.$donline['login'].'</font>'; }
if($donline['clogin']==2){ $donline['login']='<font color="#666">'.$donline['login'].'</font>'; }
if($donline['clogin']==3){ $donline['login']='<font color="#300">'.$donline['login'].'</font>'; }
if($donline['clogin']==4){ $donline['login']='<font color="red">'.$donline['login'].'</font>'; }
if($donline['clogin']==5){ $donline['login']='<font color="#f00">'.$donline['login'].'</font>'; }
if($donline['clogin']==6){ $donline['login']='<font color="#030">'.$donline['login'].'</font>'; }
if($donline['clogin']==7){ $donline['login']='<font color="green">'.$donline['login'].'</font>'; }
if($donline['clogin']==8){ $donline['login']='<font color="#0f0">'.$donline['login'].'</font>'; }
if($donline['clogin']==9){ $donline['login']='<font color="#003">'.$donline['login'].'</font>'; }
if($donline['clogin']==10){ $donline['login']='<font color="blue"><b><u>'.$donline['login'].'</b></u></font>'; }
if($donline['clogin']==10){ $donline['login']='<font color="#00f"><b><u>'.$donline['login'].'</b></u></font>'; }
if($donline['clogin']==10){ $donline['login']='<font color="330"><b><u>'.$donline['login'].'</b></u></font>'; }
if($donline['clogin']==10){ $donline['login']='<font color="yellow"><b><u>'.$donline['login'].'</b></u></font>'; }

if($donline['clogin']=="gradient"){
$gr = mysql_query("select `start`,`end` from `gr` where id_user='$donline[id]';" );
$gr_login = @mysql_fetch_array( @$gr );
$donline[login] = GradientText("$donline[login]", "$gr_login[start]", "$gr_login[end]");
}
echo '<a href="/u'.$donline['id'].'"><font color="'.$donline['clogin'].'">'.$donline['login'].'</font></a>, ';
}
echo '</div>';

echo $_down;
}else{

header ("Location: /?"); exit;

}
?>