<?


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

$prod = @mysql_query ("Select user from users where id='4' LIMIT 1;");
$z = @mysql_fetch_array ($prod);
$prodavec = $z["user"];

$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);

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

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

$st = getmicrotime();
$a = @mysql_query ("Select * from users where id='2'");
$b = mysql_fetch_array ($a);
$p = $b["postsch"];
$p++;
@mysql_query ("Update users set postsch='".$p."', onl='".$st."' where id ='2'");
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$rs."".$vp."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");

} else {
$victint = 300;
$st = time();
$st = $st + $victint;
$interval="5 минут";
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;
$a1 = mysql_query ("Select answer from vopros where klu4='1'");
$b1 = mysql_fetch_array ($a1);
$otvet = $b1["answer"];
$vp = "Ответ на вопрос был: ".$otvet."!";
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$vp."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");

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

$a = mysql_query ("Select postsch from users where id='".$uid."'");
$b = mysql_fetch_array ($a);
$p = $b["postsch"];
$p++;
$st = getmicrotime();
@mysql_query ("Update users set postsch='".$p."', onl='".$st."', room='0' where id ='".$uid."'");
$ehvi=@file('../system/badumn.txt');
$mda=$ehvi[rand(0,count($ehvi)-1)];
$mda = str_replace("", '', $mda);
$mda = str_replace("\r", '', $mda);
$vp = "".$mda."Следующий вопрос через ".$interval.".";
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$vp."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
}
}else
if ((($vr-time())<180)&&($nom == 0)){
$nom = 1;
mysql_query ("Update vopros set number = '".$nom."', answer = '".$answ."' WHERE klu4 ='1'");


$st = getmicrotime();
$a = @mysql_query ("Select * from users where id='2'");
$b = mysql_fetch_array ($a);
$p = $b["postsch"];
$p++;
@mysql_query ("Update users set postsch='".$p."', onl='".$st."' where id ='2'");

$v = utf_to_win($answ);
$v = substr($v,0,1);
$v = win_to_utf($v);
$vp = "Подсказка: $v...";
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$vp."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
} else
if ((($vr-time())<90)&&($nom < 2)){
$nom = 2;
mysql_query ("Update vopros set number = '".$nom."', answer = '".$answ."' WHERE klu4 ='1'");
$st = getmicrotime();
$a = @mysql_query ("Select * from users where id='2'");
$b = mysql_fetch_array ($a);
$p = $b["postsch"];
$p++;
@mysql_query ("Update users set postsch='".$p."', onl='".$st."' where id ='2'");

$v = utf_to_win($answ);
$v = substr($v,0,2);
$v = win_to_utf($v);
$vp = "Подсказка: $v...";
$today=date ("H:i");
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$vp."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
}
?>
