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

Размер файла: 6.68Kb
<?php

$title='Чат';
require"../system/config.php";
require"../system/func.php";
require"../system/head.php";
require"../system/error.php";
if($vhod==1){
$r = (int)$_GET['r'];
$luserm = mysql_num_rows(mysql_query("SELECT * FROM `chat_room` WHERE `id_room`='$r'"));
if($luserm==0){echo'Нет такой комнаты'; require"../system/foot.php"; exit;} $page=(int)$_GET['page'];
switch($_GET['act']){
default:
$urdda = mysql_fetch_array(mysql_query("SELECT * FROM `chat_room` WHERE `id_room`='$r' LIMIT 1")); echo'<div class="i" align="center"><b>'.$urdda['name'].'</b></div>';
if($vhod==1){
$couje=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."' AND `pol`='1'"),0);

$queje=mysql_query("SELECT `login` FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."' AND `pol`='1' ORDER BY `id_user`");
$coumu=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."' AND `pol`='0'"),0);
$quemu=mysql_query("SELECT `login` FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."' AND `pol`='0' ORDER BY `id_user`");

echo'<form action="/chat/room.php?act=msg&amp;r='.$r.'&amp;page='.$page.'" method="post"><select name="nik" class="form"><option value="">девушек('.$couje.'):</option>';
while($datje=mysql_fetch_array($queje)){
echo'<option value="'.$datje['login'].'">'.$datje['login'].'</option>';} echo'<option value="">парней('.$coumu.'):</option>';
while($datmu=mysql_fetch_array($quemu)){
echo'<option value="'.$datmu['login'].'">'.$datmu['login'].'</option>';}
echo'</select><input type="text" size="18" name="text" class="form"/><br>
<input type="submit" value="Написать" class="but"/></form>';
}
$total=mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_msg` WHERE `id_room`='$r'"),0);
if($page < 0 || $page > $total) $page = 0;

if ($total < $page + 10) $end = $total;
else $end = $page + 10;
if($total==0){echo'<br/>Нет еще не одного сообщения<br/>';}
$result = mysql_query("SELECT * FROM `chat_msg` WHERE `id_room`='$r' ORDER BY `id_msg` DESC LIMIT $start, $num");
$query=mysql_query("SELECT * FROM `chat_msg` WHERE `id_room`='$r' ORDER BY `id_msg` DESC LIMIT $page,10");
while( $data = mysql_fetch_array($query)){

echo '<div class="p"><u>'.date('H:i',$data['time']).'</u> '.nik_tri($data['id_user']);
if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){echo' <a href="/chat/room.php?act=del&amp;r='.$r.'&amp;m='.$data['id_msg'].'&amp;page='.$page.'&"><font color="red">[Del]</font></a>  <a href="/chat/room.php?act=edit&amp;r='.$r.'&amp;m='.$data['id_msg'].'&amp;page='.$page.'&"><font color="#0000ff;">[Edit]</font></a>';}}
echo'<br>'.vizual($data['text']).'</div>';
}
strmpage($page, 10, $total, "/chat/room/$r/");  $onde=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."'"),0);
echo'<div class="p"><a href="/chat/room.php?act=kto_onl&amp;r='.$r.'">Кто тут?</a> ['.$onde.']</div>';
break;
case msg:
$text=prov($_POST['text']); $nik=prov($_POST['nik']);
if(mb_strlen($text)<1 || mb_strlen($text)>4000) { echo'Слишком короткое или длинное сообщение'; require"../system/foot.php"; exit;}else{
if($vhod==1){   mysql_query("UPDATE `users` SET `balls`=`balls`+1 WHERE `id_user`='$id_user'");
if(!empty($nik)){$text='[b]'.$nik.'[/b], '.$text;}

mysql_query("INSERT INTO `chat_msg` SET `id_room`='$r', `id_user`='$id_user', `text`='$text', `time`='".time()."'");
header("Location: ../chat/room/$r/page=$page");
}}
break;
case del: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$m=(int)$_GET['m']; $qres=mysql_query("SELECT * FROM `chat_msg` WHERE `id_msg`='$m'");
if(mysql_num_rows($qres)==0){echo'Нет такого сообщения';  require"../system/foot.php"; exit;}else{ mysql_query("DELETE FROM `chat_msg` WHERE `id_msg`='$m'"); echo'Успешно удалено';}
}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;
case edit: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$m=(int)$_GET['m'];
$qres=mysql_query("SELECT * FROM `chat_msg` WHERE `id_msg`='$m';"); if(mysql_num_rows($qres)==0){echo'Нет такого сообщения'; require"../system/foot.php"; exit;}else{  $qqq=mysql_fetch_array(mysql_query("SELECT * FROM `chat_msg` WHERE `id_msg`='$m'"));  echo'<form action="room.php?act=edit2&amp;m='.$m.'&amp;page='.$page.'&amp;r='.$r.'" method="post">
Сообщение<br><input type="text" value="'.$qqq['text'].'" size="18" name="texta"/><br><input type="submit" value="Редактировать"/></form>'; }
}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;
case edit2: if($vhod==1){if($adm_pr==2 or $adm_pr==3 or $adm_pr==4){
$m=(int)$_GET['m'];
$qres=mysql_query("SELECT * FROM `chat_msg` WHERE `id_msg`='$m'"); if(mysql_num_rows($qres)==0){
echo'Нет такого сообщения'; require"../system/foot.php"; exit;}else{
$texta=prov($_POST['texta']);  if($texta==""){echo'Ниче не написано'; require"../system/foot.php"; exit;}
mysql_query("UPDATE `chat_msg` SET `text`='$texta' WHERE `id_msg`='$m'"); echo' Успешно отредактировано<br/> <<<a href="/chat/room/'.$r.'/page='.$page.'">Назад</a>';
}}else{header("Location:index.php"); exit;}}else{header("Location:index.php"); exit;} break;

case'kto_onl':
$qg=mysql_num_rows(mysql_query("SELECT * FROM `chat_room` WHERE `id_room`='$r' LIMIT 1"));
if($qg==0){echo'Нет такой комнаты';}else{
$onl=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."'"),0);  echo'<div class="i">Кто в комнате ['.$onl.']</div>';

$query=mysql_query("SELECT `id_user` FROM `users` WHERE `gdeon` LIKE '/chat/room.php?r=".$r."%' AND `online`>'".(time()-120)."'"); if(mysql_num_rows($query)){echo'В комнате никого нет';}else{

while($data=mysql_fetch_array($query)){echo nik_tri($data['id_user']).',';} } echo'<div class=""><a href="/chat/room/'.$r.'/">Назад в комнату</a></div>';
}
break;

}}else{echo'Чтоб зайти в чат,нужно быть зарегистрированым';}
$onl=mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `gdeon` LIKE '/chat/%' AND `online`>'".(time()-120)."'"),0);
echo'<div class="p"><a href="/pages/online.php?act=chat">Кто в чате?</a> ['.$onl.']</div>';

echo'<div class="p"><img src="'.$dirsite.'/design/default/act.gif" alt="-"> <a href="'.$dirsite.'/pages/help.php">Помощь</a></div>';
require"../system/foot.php";
?>