<?
include '../config.php';
include '../func.php';
list($msec, $sec) = explode(chr(32), microtime());
head();
aut();
ban();
$room = num($_GET['room']);
$room_info = mysql_fetch_assoc(mysql_query("SELECT * FROM `room` WHERE `id` = '".$room."'"));

####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = '".$room."' WHERE `id` = '".$id_session."'");
####################################################

if ( $config['status_chat'] == 0) {
    echo "<div class=\"head\">Чат</div><div class=\"main\">";
    echo link1 . 'Чат отключен' . div;
    navig();
    foot();
    exit();
}
echo "<div class=\"head\">История: <b>".$room_info['room']."</b></div>";
$all = mysql_result(mysql_query("SELECT count(*) FROM chat_msg WHERE `room` = '".$room."'"), 0);
if($all){
$onpage = $history_msg_chat_session;
$allpage = ceil($all/$onpage);
$this_page = (isset($_GET['p'])) ? intval($_GET['p']) : 1 ;
if($this_page < 1 || $this_page > $allpage)$this_page = 1;
$start = $this_page*$onpage - $onpage;

$result = mysql_query("SELECT * FROM chat_msg  where `room` = '".$room."' order by id desc limit ".$start.",".$onpage."");

while($msg = mysql_fetch_assoc($result)){
     echo '<div class="'.($i++ % 2 ? 'link1' : 'link2').'">';
    //////////////
    $ot_user = num($msg['ot_user']);
    $ot = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$ot_user."'"));
    
    
    $to_user = num($msg['to_user']);
    $to = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$to_user."'"));
    
    $date = num($msg['date']);
    $private = num($msg['private']);
    $room = num($msg['room']);
    $emotion = num($msg['emotion']);
    $color = num($msg['color']);
    $antispam = num($msg['antispam']);
    $message = html($msg['msg']);
    $time = date2($date);
    
    if (!empty($to_user)) {
        
        if ($to['login'] == $login_session) {
            $message = '<b>'.$to['login'].'</b>, '.$message;
        }
        
    }
    
    if ($private != 1) {
    
    echo xstatus($ot['xstatus'],$ot_user).' <a href="inslide.php?user='.$ot_user.'&room='.$room.'"><b>'.colorl($msg['ot_user']).'</b></a>['.$time.'] '.antirek(smile($message)). div;
    
    } else {
        
        if ( $ot_user == $id_session ) {
            
            echo xstatus($ot['xstatus'],$ot_user).' <a href="inslide.php?user='.$ot_user.'&room='.$room.'"><b>'.colorl($msg['ot_user']).'</b></a>['.$time.'] [!P] '.antirek(smile($message)). div;
            
        }
        
        if ( $to_user == $id_session ) {
            
            echo xstatus($ot['xstatus'],$ot_user).' <a href="inslide.php?user='.$ot_user.'&room='.$room.'"><b>'.colorl($msg['ot_user']).'</b></a>['.$time.'] [!P] '.antirek(smile($message)). div;
            
        }
        
    }
  
}

echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"history.php?room=".$room."&p={p}",1,1);
echo div;
}

$online = mysql_result(mysql_query("SELECT count(*) FROM `profile` WHERE `time` > '".(time()-300)."' ORDER BY `time`"), 0);

echo '<div class="razdel"><center><a href="chat.php?room='.$room.'">В чат</a> <a href="index.php?">Комнаты</a> <a href="../index.php">Главная</a> <a href="menu.php?room='.$room.'">Меню</a> <a href="../cabinet.php">Кабинет</a></center>' .div;



foot();
echo "[".round(($sec+$msec)-$headtime,5)."] сек.<br/>\n";

?>