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

$nik_zag = 'Загадка';

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

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

$i = mb_strlen($tran, 'UTF8');

$wop = rand(1,9);
$wop = preg_replace("#1#i","[b]<b>Загадка</b>:[/b]",$wop);
$wop = preg_replace("#2#i","[b]А вот и <b>Загадка</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>Загадка</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>Загадка</b>:[/b]",$wop);
$vp = "".$wop." ".$re["vopros"]." ($i букв)";

mysql_query("Update vopros set number = '".$nom."', question = '".$vp."', answer = '".$answ."', tran = '".$tran."' WHERE ids ='3'");
mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$vp."', `ot_user` = '11', `room` = '14', `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 = '3'");
$r = mysql_query("Select count(*) as num from botg");
$a = mysql_fetch_assoc($r);
$num = $a["num"];
$rnd = rand(1,$a['num']);
$re = mysql_fetch_assoc (mysql_query("Select * from botg where id='".$rnd."'"));
$answ = $re['answer'];
$tran = $re['translit'];
$nom = 5;
$vr = $st;
$a1 = mysql_fetch_assoc("Select * from vopros where ids ='3'");
$b1 = mysql_fetch_assoc ($a1);
$otvet = $b1["answer"];
$vp = "Ответ на загадку был: [b]".$otvet."[/b]!";

$db->sql_query ("INSERT INTO message (user,user_id,time,msg,rm,emo,bb,color) VALUES ('<b>$nik_zag</b>','0','$time','$vp','$rm','0','0','1')");

$db->sql_query ("Update vopros set number = '".$nom."', answer = '".$answ."', tran = '".$tran."' WHERE ids ='3'");

$ehvi=@file(H.'bots/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);

$db->sql_query ("INSERT INTO message (user,user_id,time,msg,rm,emo,bb,color) VALUES ('<b>$nik_zag</b>','0','$time','$vp','$rm','0','0','1')");

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

$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...";

$db->sql_query ("INSERT INTO message (user,user_id,time,msg,rm,emo,bb,color) VALUES ('<b>$nik_zag</b>','0','$time','$vp','$rm','0','0','1')");

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

$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...";

$db->sql_query ("INSERT INTO message (user,user_id,time,msg,rm,emo,bb,color) VALUES ('<b>$nik_zag</b>','0','$time','$vp','$rm','0','0','1')");
}
?>

?>