<?                     

$um = @mysql_query ("Select user from users where id='2' LIMIT 1;");
$y = @mysql_fetch_array ($um);
$umnik = $y["user"];
$uid = "2";
$uus = "".$umnik."";

$a = mysql_query ("Select * from vopros where klu4 = '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 klu4 = '1'"); 
$r = mysql_query ("Select count(*) as num from bots");
$a = mysql_fetch_array($r);
$num = $a["num"];
$rnd = rand(1,$num); 

$qu = mysql_query ("Select * from bots where number='".$rnd."'");
$re = mysql_fetch_array ($qu);     
$answ = $re["answer"];   
$tran = $re["tran"];
$nom = 0;
$vr = $st; 
$otv = utf_to_win($answ);    
$i = strlen($otv);
$vp = $re["vopros"]." (<b>$i букв</b>)";
$rs = "<b>Вопрос: </b>";

mysql_query ("Update vopros set number = '".$nom."', question = '".$vp."', answer = '".$answ."', tran = '".$tran."' WHERE klu4 ='1'");
$a = mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
$st = getmicrotime();
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='0' where id ='".$uid."'");
$today=date ("H:i"); 
$rnd = rand(0,99999999);
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$rs."".$vp."', id='".$st."', towhom='', hid='0', usid='".$uid."', komu=''");  
} else { 
$victint = $set["victint"];
$st = time();           
$st = $st + $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 klu4 = '1'");
$r = mysql_query ("Select count(*) as num from bots");
$a = mysql_fetch_array($r);
$num = $a["num"];
$rnd = rand(1,$num); 
$qu = mysql_query ("Select * from bots where number='".$rnd."'");
$re = mysql_fetch_array ($qu);     
$answ = " "; 
$tran = " ";
$nom = 5;
$vr = $st; 
mysql_query ("Update vopros set number = '".$nom."', answer = '".$answ."', tran = '".$tran."' WHERE klu4 ='1'");

$a = mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
$st = getmicrotime();                
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='0' where id ='".$uid."'");
$vp = "Трудно вспомнить, когда не знаешь!!! Следующий вопрос через ".$interval.".";
$today=date ("H:i"); 
$rnd = rand(0,99999999);
mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$vp."', id='".$st."', towhom='', hid='0', usid='".$uid."', komu=''");                        
}
}else 
if ((($vr-time())<180)&&($nom == 0)){
$nom = 1;  
mysql_query ("Update vopros set number = '".$nom."', answer = '".$answ."' WHERE klu4 ='1'");

$a = mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
$st = getmicrotime();  
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='0' where id ='".$uid."'");
$v = utf_to_win($answ);
$v = substr($v,0,1);
$v = win_to_utf($v);
$vp = "<b>Подсказка:</b> $v...";
$today=date ("H:i");
$rnd = rand(0,99999999);
@mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$vp."', id='".$st."', towhom='', hid='0', usid='".$uid."', komu=''");    
} else 
if ((($vr-time())<90)&&($nom < 2)){
$nom = 2; 
mysql_query ("Update vopros set number = '".$nom."', answer = '".$answ."' WHERE klu4 ='1'");
$a = mysql_query ("Select posts from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["posts"]; 
$p++;
$st = getmicrotime();  
@mysql_query ("Update users set posts='".$p."', onl='".$st."', room='0' where id ='".$uid."'");           

$v = utf_to_win($answ);
$i = strlen($v)/3;
if ($i<2) $i=2;
$v = substr($v,0,$i);
$v = win_to_utf($v);
$vp = "<b>Подсказка:</b> $v...";
$today=date ("H:i");
$rnd = rand(0,99999999);
@mysql_query ("Insert into room0 set klu4= '".$rnd."', time='".$today."', who='".$uus."', message='".$vp."', id='".$st."', towhom='', hid='0', usid='".$uid."', komu=''");   
} 
?>
