<?
if ($msg=="!вопрос"||$msg=="!vopros"){
$r = mysql_query ("select * from vopros where klu4 = '1'");
$a = mysql_fetch_array($r);
$vp = $a ["question"];
$i = $a ["number"];
if ($i!=5){
$st = getmicrotime();
$today=date ("H:i");

$rnd = rand(0,99999999);
$rs = "Вопрос:  ";

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."';");

}
}
if ($msg=="!ответ"||$msg=="!otvet"){
$a = mysql_query ("Select answer from vopros");
$b = mysql_fetch_array ($a);
$uposts=$row['posts'];
$vposts=$row['credits'];
$byeotv=$row['byeotv'];
$usid=$row['user'];
$otvet = $b["answer"];
$uposts1=$uposts-100;
$byeotv=$byeotv+1;
if ($uposts>=100){
mysql_query ("Update users set posts='".$uposts1."', byeotv='".$byeotv."' where id='".$myid."'");
$st = time();
$today=date ("H:i");
$mes = "Правильный ответ на текущий вопрос: ".$otvet." =)";
$rnd = rand(0,99999999);

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$mes."',time='".(time()+1)."', privat = '".$myid."'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
}else{
$st = time();
$today=date ("H:i");
$mes = "У вас недостаточно постов! Ответ стоит 100 постов!";
$rnd = rand(0,99999999);
mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$mes."',time='".(time()+1)."', privat = '".$myid."'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");

}
}
$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){
$st = getmicrotime();
$today=date ("H:i");
$b = mysql_fetch_array($a);
$i = $b["credits"];
$a = @mysql_query ("Select user from users order by credits desc LIMIT 101");
$j = 1;
$b = mysql_fetch_array($a);

while (($b["user"] != $stsus)&&($j <= 100)) {$b = mysql_fetch_array($a); $j++;}
if ($j<=100) $s= "И он занимает в рейтинге $j место";
else $s = "И его место в рейтинге за пределами первой сотни.";
$mes = "У пользователя $stsus $i правильных ответов. $s";
$rnd = rand(0,99999999);
if($towhom == $uid) $th = $myid; else $th ="";

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$mes."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
 $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'");
               } else {
$st = getmicrotime();
$today=date ("H:i");
$mes = "Игрока с ником $stsus нет в базе данных!";
$rnd = rand(0,99999999);
if($towhom == $uid) $th = $myid; else $th ="";

mysql_query ("Insert into forum_message set topic='".$id."', section='".$f."', subfor = '".$sf."', login ='2', msg='".$mes."',time='".(time()+1)."', privat = '0'");
mysql_query("update `forum_topic` set time='".(time()+1)."' where id='".$id."';");
$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'");
}
}
$latumnik=mysql_fetch_array(mysql_query("Select latuser from users where id='2' LIMIT 1;"));

if (($amsg == $kansw||$amsg == $tran)&&$nom!=5){
$st = time();
$victint = 300;
$st = $st + $victint;
$interval="5 минут";
mysql_query ("Update vopros set number = '5', time = '".$st."', answer = ' ', 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'");

$st = getmicrotime();
$select = @mysql_query ("Select credits,sex from users where id='".$myid."'");
$inf = mysql_fetch_array ($select);
$creditss = $inf["credits"];
$p = $row['credits'];
$o = $row['daya'];
$p++;$o++;
 mysql_query ("Update users set credits='".$p."', daya='".$o."' where id ='".$myid."'");

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


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

}

?>