<?
/*
$a = mysql_query("Select * from vopros where ids = '1'");
$b = mysql_fetch_array($a);
$nom = $b["number"];
$vr = $b["time"];
$answ = $b["answer"];

if ($time>=$vr){
if ($nom == 5){
$st = $time;
$st = $st + 240;
mysql_query("Update vopros set time = '".$st."' WHERE ids = '1'");
$r = $db->sql_query ("Select count(*) as num from question");
$a = mysql_fetch_array($r);
$num = $a["num"];
$rnd = rand(1,$num);

$qu = mysql_query("Select * from question where number='".$rnd."'");
$re = mysql_fetch_array($qu);
$answ = $re["answer"];
$tran = $re["tran"];
$nom = 0;
$vr = $st;

$i = strlen($tran);




$wop = rand(1,9);
$wop = preg_replace("#1#i","[b]Вопрос:[/b]",$wop);
$wop = preg_replace("#2#i","[b]А вот и вопрос:[/b]",$wop);
$wop = preg_replace("#3#i","[b]Ответите ли вы на это:[/b]",$wop);
$wop = preg_replace("#4#i","[b]А теперь ответьте на это:[/b]",$wop);
$wop = preg_replace("#5#i","[b]Вопросик:[/b]",$wop);
$wop = preg_replace("#6#i","[b]Вопросище:[/b]",$wop);
$wop = preg_replace("#7#i","[b]Отвечаем на:[/b]",$wop);
$wop = preg_replace("#8#i","[b]Итак:[/b]",$wop);
$wop = preg_replace("#9#i","[b]ВНИМАНИЕ! Вопрос:[/b]",$wop);
$vp = "".$wop." ".$re["vopros"]." ($i букв)";

mysql_query("Update vopros set number = '".$nom."', question = '".$vp."', answer = '".$answ."', tran = '".$tran."' WHERE ids ='1'");


mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");

} else {

$victint = $set['victint'];
$st = $time + $victint;
if ($victint=='10') $interval='10 секунд';
else if ($victint=='30"') $interval='30 секунд';
else if ($victint=='60') $interval='минуту';
else $interval='2 минуты';
mysql_query("Update vopros set time = '".$st."' WHERE ids = '1'");
$r = mysql_query("Select count(*) as num from question");
$a = mysql_fetch_array($r);
$num = $a["num"];
$rnd = rand(1,$a['num']);
$re = mysql_fetch_array(mysql_query("Select * from question where number='".$rnd."'"));
$answ = $re['answer'];
$tran = $re['tran'];
$nom = 5;
$vr = $st;
$a1 = mysql_query("Select answer from vopros where ids='1'");
$b1 = mysql_fetch_array($a1);
$otvet = $b1["answer"];
$vp = "Ответ на вопрос был: [b]".$otvet."[/b]!";

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


mysql_query("Update vopros set number = '".$nom."', answer = '".$answ."', tran = '".$tran."' WHERE ids ='1'");

$ehvi=@file(H.'badumn.txt');
$mda=$ehvi[rand(0,count($ehvi)-1)];
$mda = preg_replace("#\n#i", '', $mda);
$mda = preg_replace("#\r#i", '', $mda);
$vp = $mda.' Следующий вопрос через '.$interval;
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


}
}else
if ((($vr-$time)<180)&&($nom == 0)){
$nom = 1;
mysql_query ("Update vopros set number = '".$nom."' WHERE ids ='1'");

$answ2 = $answ;
$answ2=substr($answ2, 0, 2);
$answ2=preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,500}).*#s','$1',$answ2);

$vp = "[b]Подсказка:[/b] $answ2...";

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


} else
if ((($vr-$time)<90)&&($nom < 2)){
$nom = 2;
mysql_query("Update vopros set number = '".$nom."' WHERE ids ='1'");

$answ2 = $answ;


$answ2=substr($answ2, 0, 4);
$answ2=preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,500}).*#s','$1',$answ2);

$vp = "[b]Подсказка:[/b] $answ2...";

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");

}


$a = mysql_query("Select * from vopros where ids = '1'");
$b = mysql_fetch_array ($a);
$nom = $b['number'];
$vr = $b['time'];
$answ = $b['answer'];
$amsg = $msg;
$tran = $b['tran'];

if ($msg=='!вопрос'||$msg=='!vopros'){
$r = mysql_query ("select * from vopros where ids = '1'");
$a = mysql_fetch_array($r);
$vp = $a ['question'];
$i = $a ['number'];
if ($i!=5){
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
}else{
$vp = 'Вопрос еще не задан...';
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
}
}

if ($msg=='!ответ'||$msg=='!otvet'){
$b = mysql_fetch_array (mysql_query ("Select answer from vopros"));
$user['byeotv']++;
if ($rooms['baryga']!=0){
if ($user['posts']>=$set['cena_answ']){
mysql_query ("Update users set posts='".($user['posts']-$set['cena_answ'])."', byeotv='".$user['byeotv']."' where id='".$user["id"]."'");

$mes = "Правильный ответ на текущий вопрос: [b]".$b["answer"]."[/b] =)";
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");

}else{

$mes = 'У вас недостаточно постов! Ответ стоит [b]'.$set['cena_answ'].'[/b] постов!';
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");

}

}else{

$mes = "Извините, но в этой комнате я не работаю...";
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
}

}
$s = substr ($msg,0,5);
if (($s == "stats")&&(strlen($msg) > 6)){
$stsus = substr ($msg,6,strlen($msg)-6);
$a = @mysql_query ("Select credits from users where user='".$stsus."'");
if (mysql_affected_rows() != 0){

$b = mysql_fetch_array($a);
$i = $b["credits"];
$a = @mysql_query ("Select * from users order by credits desc LIMIT 101");
$j = 1;
$b = mysql_fetch_array($a);

while (($b["user"] != $stsus)&&($j <= 100)) {$b = $db->sql_fetchrow($a); $j++;}
if ($j<=100) $s= "И он занимает в рейтинге $j место";
else $s = "И его место в рейтинге за пределами первой сотни.";
$mes = "У пользователя $stsus $i правильных ответов. $s";


mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


} else {

$mes = "Игрока с ником $stsus нет в базе данных!";


mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


}
}


if (($msg == $answ||$tran == $amsg)&&$nom!=5){

$agent = htmlentities(addslashes($soft));
if (((strpos ($agent,"M3Gate") !== false)||(strpos ($agent,"Opera") !== false)||(strpos ($agent,"emulator") !== false)||(strpos ($agent,"WinWAP") !== false)||(strpos ($agent,"Wapsilon") !== false)||(strpos ($agent,"Mozilla") !== false)||(strpos ($agent,"M3GATE") !== false))&&($set["vict"] == 0)){

$mes = "Вы правильно ответили на этот вопрос. Но с компа ответы не засчитываются.";

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


}else{

$victint = $set['victint'];
$st = $time + $victint;
if ($victint=="10") $interval="10 секунд";
else if ($victint=="30") $interval="30 секунд";
else if ($victint=="60") $interval="минуту";
else $interval="2 минуты";
mysql_query ("Update vopros set number = '5', time = '".$st."', answer = ' ', tran = ' ' WHERE ids ='1'");
$st = getmicrotime();



$today=date ("H:i");
$creditss1=$user["credits"];
if($user["sex"]==1)$sex1="его";
else if($user["sex"]==0)$sex1="её";
else $sex1="их";
$mes = "[b]".$user['user']."[/b],Правильно отвечает на вопрос! И это $sex1 $creditss1 правильный ответ!. Следующий вопрос через ".$interval.".";
$rnd = rand(0,99999999);

mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$mes."', `ot_user` = '1', `room` = '1', `date` = '".(time()+1)."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");


}
}
*/

?>