View file wip-site-portal/src/chat_online.php

File size: 3.51Kb
<?
require('ini.php');
$link=connect();

@$r=intval($_GET['r']);
@$mod=$_GET['mod'];
@$type=$_GET['type'];

if($type and $type!='club' and $type!='pos') $type=false;

$user=login('nick, loc');

if($user['loc']!='chat') mysql_query("update wip_users set loc='chat' where id='$user[id]';");

head('Кто в чате');
echo '<small>';

switch($mod){
	default:
		//Слишком много ест - объединить некоторые запросы
		
		$room_no=false;
		
		# Кто здесь?
		if($r){
			
			$now_room = mysql_query("SELECT `name` FROM `wip_chat_rooms` WHERE `id`='".$r."';");
			
			if(mysql_affected_rows()>0){
				
				$room = mysql_fetch_row($now_room);
				
				$onl=mysql_fetch_row(mysql_query("SELECT COUNT(`id`) FROM `wip_users` WHERE `chat_room` = '".$r."' AND `chat_online` > '".(time()-300)."';"));
			
				echo 'В комнате <b><a href="chat_talk.php?sid='.$sid.'&amp;r='.$r.'">'.$room[0].'</a></b> '.$onl[0].' человек:<br/>';
				
				$select_users = mysql_query("SELECT `nick` FROM `wip_users` WHERE `chat_room` = '".$r."' AND `chat_online` > '".(time()-300)."' AND `chat_inv`!=1;");
				if(mysql_affected_rows()>0){
					while($res_users=mysql_fetch_row($select_users)) echo $res_users[0].', ';
					echo '<br/>';
				}
			
				echo '---<br/>';
				$room_no = "AND `id`!='".$r."' ";
				
			}
		}
		###
		/*
		if($type!='club'){
			$onl_clubs=mysql_fetch_row(mysql_query("select count(u.id) from wip_users as u, wip_chat_rooms as r where u.chat_room=r.id and r.type='club' and u.chat_online>'".(time()-300)."' and u.chat_inv!=1;"));
			echo '<a href="chat_online.php?sid='.$sid.'&amp;type=club">Клубы</a> ['.$onl_clubs[0].']<br/>';
		}
		if($type!='pos'){
			$onl_pos=mysql_fetch_row(mysql_query("select count(u.id) from wip_users as u, wip_chat_rooms as r where u.chat_room=r.id and r.type='pos' and u.chat_online>'".(time()-300)."' and u.chat_inv!=1;"));
			echo '<a href="chat_online.php?sid='.$sid.'&amp;type=pos">Посольства</a> ['.$onl_pos[0].']<br/>';
		}
		
		if($type){
			$onl=mysql_fetch_row(mysql_query("select count(u.id) from wip_users as u, wip_chat_rooms as r where u.chat_room=r.id and r.type='' and u.chat_online>'".(time()-300)."' and u.chat_inv!=1;"));
			echo '<a href="chat_online.php?sid='.$sid.'">Основные комнаты</a> ['.$onl[0].']<br/>';
		}
		
		echo '---<br/>';
		if($type=='club') echo '<b>В клубах:</b><br/>';
		elseif($type=='pos') echo '<b>В посольствах:</b><br/>';*/
		else echo '<b>В основных комнатах:</b><br/>';
		
		$select=mysql_query("SELECT `id`, `name` FROM `wip_chat_rooms` WHERE `type`='".$type."' ".$room_no.";");
	
		while($res=mysql_fetch_assoc($select)){
			$onl=mysql_fetch_row(mysql_query("select count(id) from wip_users where chat_room='$res[id]' and chat_online>'".(time()-300)."' and chat_inv!=1;"));
			
			echo '<a href="chat_talk.php?sid='.$sid.'&amp;r='.$res['id'].'">'.$res['name'].'</a> ['.$onl[0].']<br/>';
			
			$select_users=mysql_query("select nick from wip_users where chat_room='$res[id]' and chat_online>'".(time()-300)."' and chat_inv!=1;");
			if(mysql_affected_rows()>0){
				while($res_users=mysql_fetch_row($select_users)) echo ''.$res_users[0].', ';
				echo '<br/>';
			}
						
		}
		break;

		
}

echo '---<br/>';
echo '<a href="chat.php?sid='.$sid.'">Список комнат</a><br/>';
echo '<a href="enter.php?sid='.$sid.'">Главное меню</a>';
echo '</small>';
foot();

mysql_close($link);
?>