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

Размер файла: 15.18Kb
<?php
@session_start();

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

///ПРОВЕРКА $_GET['rm']
if(eregi("[^0-9]" , $_GET['rm'])){

header ("Location: /enter.php?"); exit;

}

if(eregi("[^0-9]" , $_GET['page'])){
header ("Location: /enter.php?"); exit;
}

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($usr['status']<$room['status']){

echo 'Извините, но в эту комнату Вам доступ запрешен!<br>'; exit;

}


///УДАЛЕНИЕ СООБЩЕНИЯ
if($_GET['go']=='delete' && $usr['status']>3){

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;

}}


///ОЧИСТКА КОМНАТЫ
if($_GET['go']=='clear' && $usr['status']>3){

mysql_query( "Delete from msg where rm=$rm" );
mysql_query( "OPTIMIZE TABLE msg WHERE rm=$rm" );
mysql_query( "TRUNCATE TABLE msg WHERE rm=$rm" );

header ("Location: room.php?rm=$rm"); exit;

}

///ВЕРХ СТРАНИЦЫ+АВТООБНОВЛЕНИЕ ЧЕРЕЗ КАЖДЫЕ 30 СЕКУНД
echo $_up; echo '<meta http-equiv="Refresh" content="30" />';

///ЗАПИСЬ В БД ЮЗЕРОВ (КОМНАТА И ВРЕМЯ)
$mtime = time();
mysql_query("update users set rtime=$mtime where login='$usr[login]' limit 1");
mysql_query("update users set room=$rm where id='$usr[id]' limit 1");

echo '<div class="box1">
<center><b>
'.$room['name'].' ('.mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `room` = "'.$rm.'" and `rtime`>"'.intval( time( ) - 100 ).'"'),0).')
</b></center></div>';

echo '<div class="auth"><a href="say.global.php?rm='.$rm.'">Сказать</a> ';

if($usr['status']>3){

echo '<a href="say.admin.php?rm='.$rm.'"><b>Обьявление</b></a> <a href="?rm='.$rm.'&go=clear"><b>Очистить</b></a>';

}

echo '<a href="?rm='.$rm.'">Обновать</a> <a href="faq.php?smiles">Смайлы</a> <a href="?history.php?rm='.$rm.'">История</a></div>';

echo '<div style="padding:3px 5px 3px 5px;" class="MSG">
<form method="post" action="say.fast.php?rm='.$rm.'">
<input name="text" maxlength="150" size="40%"/> <input value="Отправить" type="submit"/>
</form></div>';




$at_page=15;
$count=mysql_result(mysql_query("SELECT COUNT(`id`) FROM `msg` WHERE rm = $rm"), 0);

$pages=ceil($count/$at_page);

$page=abs(intval(@$_REQUEST['page'])); //берем страницу от пользователя
if($page==0) $page=1; //если страница не введена - значит берем первую
define('PAGE', $page); //заносим в переменную эту страницу, хотя можно так и не делать
unset($page); //удаляем эту переменную, хотя можно использовать именно её

$from=(PAGE-1)*$at_page; //отнимаем одну страницу, чтобы первая страница выводила первые записи, а не начиная с десятой


$from=(PAGE-1)*$at_page; //отнимаем одну страницу, чтобы первая страница выводила первые записи, а не начиная с десятой
$data=mysql_query("SELECT * FROM msg WHERE rm = $rm ORDER BY `id` DESC LIMIT $from, $at_page");
$res = @mysql_fetch_array($data);

///if($room['type']=="umnik"){

///include 'umnik.php';

///}

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

echo '<div class="list">';
if($total==0){

echo 'Сообщений нет...'; echo $_down; exit;

}

do
{



$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 `grN` where id_user='$res[from_id]';" );
$gr_login = @mysql_fetch_array( @$gr );
$from_login = GradientText("$from_login", "$gr_login[start]", "$gr_login[end]");

}

if($from_login==""){

$from_login='[Удален]';

}

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 '<div class="box1"><span style="background:#DADADA;"><font color="black">'.$res['time'].'</font> <a href="say.for.php?rm='.$rm.'&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']>3){
echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';
}
echo '</span></div>';

}else{

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

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

echo '<div class="box1"><span style="color:#008080;"><font color="black">'.$res['time'].' <b style="color:red"><u>Умник</b></u></font>: <b>'.$res['text'].'</b>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}
echo '</span></div>';


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

echo '<div class="box1"><span style="background:#DADADA;color:#B205FC;"><font color="black">'.$res['time'].' <b><u>Робот</b></u></font>: <b>'.$res['text'].'</b>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}
echo '</span></div>';


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

echo '<div class="box1"><font color="black">'.$res['time'].'</font> <b><u>Робот</b></u>: <b>'.$res['text'].'</b>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</div>';


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

echo '<div class="box1"><span style="background:#FFB9A1;color:red;"><font color="black">'.$res['time'].'</font> <b><u>Робот</b></u>: <b>'.$res['text'].'</b>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</span></div>';


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

echo '<div class="box1"><span style="background:#FFB9A1;color:red;"><font color="black">'.$res['time'].'</font> <b><u>Робот</b></u>: <b>'.$res['text'].'</b>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</span></div>';


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

echo '<div class="box1"><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;">'.$res['text'].'';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</div>';


}else{

if($res['from_id']==$usr['id']){

echo '<div class="box1"><span style="background:#BDD6A9;"><font color="black">'.$res['time'].'</font> <a href="say.for.php?rm='.$rm.'&who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <font color="'.$clr_text.'">'.$res['text'].'</font>';

if($usr['status']>3){

echo ' [<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';
}

echo '</span></div>';

}else{

echo '<div class="box1"><font color="black">'.$res['time'].'</font> <a href="say.for.php?rm='.$rm.'&who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <font color="'.$clr_text.'">'.$res['text'].'</font>';

if($usr['status']>3){

echo ' [<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</div>';

}

}

}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'];

if($res['from_id']==$usr['id'] or $res['for_id']==$usr['id']){

echo '<div class="box1"><span style="background:#DADADA;"><font color="#000">'.$res['time'].'</font> <a href="say.for.php?rm='.$rm.'&who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <b>для <a href="for_say.php?rm='.$rm.'&who='.$res['for_id'].'"><b><u>'.$dfor_id_login.'</b></u></a></b>: <font color="'.$clr_text.'">'.$res['text'].'</font>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</span></div>';

}else{

echo '<div class="box1"><font color="#000">'.$res['time'].'</font> <a href="say.for.php?rm='.$rm.'&who='.$res['from_id'].'"><b><u>'.$from_login.'</b></u></a>: <b>для <a href="for_say.php?rm='.$rm.'&who='.$res['for_id'].'"><b><u>'.$dfor_id_login.'</b></u></a></b>: <font color="'.$clr_text.'">'.$res['text'].'</font>';

if($usr['status']>3){

echo '[<a href="?go=delete&id='.$res['id'].'&rm='.$rm.'">x</a>]';

}

echo '</div>';

}

}

}}}
while ($res = @mysql_fetch_array($data));

echo '</div><div class="menu" align="right"><small>';

if(PAGE>1){

echo '<a href="?rm='.$rm.'&page='.(PAGE-1).'"><< Назад</a> ';

}else{

echo '<< Назад'; } echo ' | ';

if(PAGE<$pages){

echo ' <a href="?rm='.$rm.'&page='.(PAGE+1).'">Вперед >></a> ';

}else{

echo 'Вперед >>';

}

if($pages>1){}
echo '</small></div>';

echo '<div style="padding:3px;" class="MSG">В комнате:</div><div class="bm"><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">'.$donline['login'].'</font>';

}

if($donline['clogin']==11){

$donline['login']='<font color="#00f">'.$donline['login'].'</font>';

}

if($donline['clogin']==12){

$donline['login']='<font color="330">'.$donline['login'].'</font>';

}

if($donline['clogin']==13){

$donline['login']='<font color="yellow">'.$donline['login'].'</font>';

}


if($donline['clogin']==14){

$donline['login']='<font color="#ff0">'.$donline['login'].'</font>';

}

if($donline['clogin']==15){

$donline['login']='<font color="#303">'.$donline['login'].'</font>';

}

if($donline['clogin']==16){

$donline['login']='<font color="#A0A">'.$donline['login'].'</font>';

}

if($donline['clogin']==17){

$donline['login']='<font color="#f0f">'.$donline['login'].'</font>';

}

if($donline['clogin']==18){

$donline['login']='<font color="#033">'.$donline['login'].'</font>';

}

if($donline['clogin']==19){

$donline['login']='<font color="#0aa">'.$donline['login'].'</font>';

}

if($donline['clogin']==20){

$donline['login']='<font color="#0aa">'.$donline['login'].'</font>';

}

///ГРАДИЕНТ НИК
if($donline['clogin']=="gradient"){

$gr = mysql_query("select `start`,`end` from `grN` 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></div>';

echo $_down;

}else{

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

}
?>