Файл: chat/room.php
Строк: 128
<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
if ($id) {
$type = $db -> query("SELECT * FROM `chat` WHERE `id` = '".$id."'");
if ($type -> num_rows > 0) $the = $type -> fetch_assoc(); else $the = false;
} else $the = false;
if($the != false){
////Боты
$func->aut();
$bot = $db -> query("SELECT * FROM `chat_bots` WHERE `room` = '".$id."'")-> fetch_assoc();
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////умник////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
if($bot['id']=='1'){
$v = $db -> query("SELECT * FROM `chat_vik` WHERE `id` = '".$bot['sid']."'")-> fetch_assoc();
///задаем вопрос
if($bot['status']=='1'){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Вопрос: ".$v['vopros']." (".mb_strlen($v['otvet'])." буквы)',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='2',`doptime`='".time()."' WHERE `id` = '".$bot['id']."'");
}
$botset = $db -> query("SELECT * FROM `chat_bots` WHERE `room` = '".$id."'")-> fetch_assoc();
$u = $db -> dbcount('COUNT(*)','chat_post',"`time`>$botset[doptime] and `text`=' $v[otvet]'");
//даём 1 подсказку
if($u==0 and $bot['status']=='2' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Подсказка: ".mb_substr($v['otvet'],0,1)."',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='3' WHERE `id` = '".$bot['id']."'");
}
///даём 2 подсказку
if($u==0 and $bot['status']=='3' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Подсказка: ".mb_substr($v['otvet'],0,2)."',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='4' WHERE `id` = '".$bot['id']."'");
}
///ни кто неугадал
if($u==0 and $bot['status']=='4' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Ответ ни кто не дал,следующий вопрос через ".$bot['int']." сек.',`time` = '".time()."'");
$db -> query("UPDATE `chat_bots` SET `status`='5' WHERE `id` = '".$bot['id']."'");
}
///Отгадываем слово
if($u>0 and $bot['status']!='5' and $bot['status']!='6'){
$up=$db -> query("SELECT * FROM `chat_post` WHERE `time`>$botset[doptime] and `text`=' $v[otvet]'")->fetch_assoc();
$db -> query("UPDATE `users` SET `ym`=ym+1,`balls`=balls+$nastr[ym] WHERE `login` = '".$up['yaid']."'");
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = '".$up['yaid']." угадывает слово!Следующий вопрос через ".$bot['int']." сек.',`time` = '".time()."'");
$db -> query("UPDATE `chat_bots` SET `status`='6' WHERE `id` = '".$bot['id']."'");
}
if((time()>=$bot['time']+$bot['int']*4)and($bot['status']=='5' or $bot['status']=='6')){
$v_up = $db -> dbcount('COUNT(*)','chat_vik',"`id`='".($bot['sid']+1)."'");
if($v_up>0){
$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=sid+1 WHERE `id` = '".$bot['id']."'");}
else{$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=1 WHERE `id` = '".$bot['id']."'");}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////ФУРА////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
if($bot['id']=='2'){
$v = $db -> query("SELECT * FROM `chat_god` WHERE `id` = '".$bot['sid']."'")-> fetch_assoc();
///задаем вопрос
if($bot['status']=='1'){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Отгадайте слово из четырёх букв!',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='2',`doptime`='".time()."' WHERE `id` = '".$bot['id']."'");
}
$botset = $db -> query("SELECT * FROM `chat_bots` WHERE `room` = '".$id."'")-> fetch_assoc();
$u = $db -> dbcount('COUNT(*)','chat_post',"`time`>$botset[doptime] and `text`=' $v[otvet]'");
//даём 1 подсказку
if($u==0 and $bot['status']=='2' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Подсказка: ".mb_substr($v['otvet'],0,1)."',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='3' WHERE `id` = '".$bot['id']."'");
}
///даём 2 подсказку
if($u==0 and $bot['status']=='3' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Подсказка: ".mb_substr($v['otvet'],0,2)."',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='4' WHERE `id` = '".$bot['id']."'");
}
///ни кто неугадал
if($u==0 and $bot['status']=='4' and time()>=$bot['time']){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = 'Ответ ни кто не дал,следующий вопрос через ".$bot['int']." сек.',`time` = '".time()."'");
$db -> query("UPDATE `chat_bots` SET `status`='5' WHERE `id` = '".$bot['id']."'");
}
///Отгадываем слово
if($u>0 and $bot['status']!='5' and $bot['status']!='6'){
$up=$db -> query("SELECT * FROM `chat_post` WHERE `time`>$botset[doptime] and `text`=' $v[otvet]'")->fetch_assoc();
$db -> query("UPDATE `users` SET `ym`=ym+1,`balls`=balls+$nastr[ym] WHERE `login` = '".$up['yaid']."'");
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = '".$up['yaid']." угадывает слово!Следующий вопрос через ".$bot['int']." сек.',`time` = '".time()."'");
$db -> query("UPDATE `chat_bots` SET `status`='6' WHERE `id` = '".$bot['id']."'");
}
if((time()>=$bot['time']+$bot['int']*4)and($bot['status']=='5' or $bot['status']=='6')){
$v_up = $db -> dbcount('COUNT(*)','chat_god',"`id`='".($bot['sid']+1)."'");
if($v_up>0){
$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=sid+1 WHERE `id` = '".$bot['id']."'");}
else{$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=1 WHERE `id` = '".$bot['id']."'");}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////ШУТ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
if($bot['id']=='3'){
$v = $db -> query("SELECT * FROM `chat_shut` WHERE `id` = '".$bot['sid']."'")-> fetch_assoc();
///задаем вопрос
if($bot['status']=='1'){
$db -> query("INSERT INTO `chat_post` SET `room` = '".(int)$id."', `yaid` = '".$bot['name']."', `text` = '$v[text]',`time` = '".time()."'");
$time=time()+$bot['int'];
$db -> query("UPDATE `chat_bots` SET `time`='".$time."',`status`='2',`doptime`='".time()."' WHERE `id` = '".$bot['id']."'");
}
if((time()>=$bot['time']+$bot['int']*4)and($bot['status']=='2')){
$v_up = $db -> dbcount('COUNT(*)','chat_shut',"`id`='".($bot['sid']+1)."'");
if($v_up>0){
$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=sid+1 WHERE `id` = '".$bot['id']."'");}
else{$db -> query("UPDATE `chat_bots` SET `status`='1',`sid`=1 WHERE `id` = '".$bot['id']."'");}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
$diz -> head('Комната '.$the['name'].'');
$diz -> title("$the[topik]");
$count = $db -> dbcount('COUNT(`id`)','chat_post',"`room` = '".$id."'");
$num = isset($ya['num']) ? (int)$ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1;
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
if ($aut) {echo '<div class="fon"><a href="newpost.php?id='.(int)$id.'&apage='.(int)$page.'">Сказать</a>';
if($nastr['smiles']=='on')echo ' | <a href="'.ROOT.'help/smile.php">Смайлы</a></div>';
if($ya['chatobon']=='1')header('refresh: '.$ya['chatob'].'; url=room.php?id='.$id.'');
}
if($s!=null){
echo'<div class="fon">'.$s.'';
if($p!=null){echo'<br/>'.$p;}
echo'</div>';
}
$for = $db -> query("SELECT * FROM `chat_post` WHERE `room` = '".(int)$id."' ORDER BY `time` DESC LIMIT ".$start.",".$num);
if($count==0){echo'<div class="fon">Сообщений пока нет</div>';}
while ($assoc = $for -> fetch_assoc()) {
$arr = $db -> query("SELECT `id` FROM `users` WHERE `login` = '$assoc[yaid]' LIMIT 1")-> fetch_assoc();
$otv = null;
if ($aut) {
if ($ya['level'] > 3) {
$del = '<a href="delpost.php?id='.$assoc['id'].'">[Удал]</a>';}
if ($ya['id']!=$arr['id'] and $assoc['yaid']!=$bot['name']) {
$otv = '<a href="newpost.php?id='.$id.'&otv='.$arr['id'].'&page='.$page.'">'.$assoc['yaid'].'</a>';
}else{$otv = ''.$assoc['yaid'].'';
}
}
echo '<div class="fon">
<table><tr valign="top"><td>'.$func->avatar($arr['id']).'</td>
<td style="padding-left:5px;">'.$otv.'</br>
'.$func -> times(date('d m Y в H:i',$assoc['time'])).'<br/>
'.$func -> tags($func -> smiles($assoc['text'])).'<br/>'.$del.'</td>
</tr></table></div>';
}
echo '<div class="fon">
<form action="newpost.php?id='.$id.'&page='.$page.'" method="post">
<hr><textarea name="text" rows="1" cols="15"></textarea><br/>
<input type="submit" value="Сказать"/></form></div>';
$v = $db -> query("SELECT * FROM `chat_vik` WHERE `id` = '".$bot['sid']."'")-> fetch_assoc();
$act = 'room.php?id='.$id;
$msg .= ''.$func -> pagenav($act,$page,$total).'';}
else header('location: index.php');
echo '<div class="levo"><a href="./index.php" class="levo_tuch"> '.$diz -> img('back.png').' Назад</a></div>';
echo '<div class="levo"><a href="/index.php" class="levo_tuch"> '.$diz -> img('home.png').' На главную</a></div>';
#####Копирайт#######
$diz -> out($msg);
?>