<?php
$umnik_last = mysql_fetch_array(mysql_query("SELECT * FROM `chat_msg` WHERE `room` = '".$room_info['id']."' AND `ot_user` = 52 ORDER BY id DESC LIMIT 1"));

if($umnik_last!=NULL && $umnik_last['umnik_st']!=4){
	$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` WHERE `id` = '".$umnik_last[vopros]."' LIMIT 1"));
	$umnik_post = mysql_fetch_array(mysql_query("SELECT * FROM `chat_msg` WHERE `room` = '".$room_info['id']."' AND `msg` like '".win2utf($umnik_vopros[otvet])."' ORDER BY id DESC LIMIT 1"));

if($umnik_post!=NULL){
	$ank=mysql_fetch_array(mysql_query("SELECT * FROM `profile` WHERE `id` = $umnik_post[ot_user] LIMIT 1"));

$add_balls=0;

if($umnik_last['umnik_st']==1){
	$add_balls=3;
	$add_iq=5;
	$pods='не используя подсказок';
	}

if($umnik_last['umnik_st']==2){
	$add_balls=2;
            $add_iq=3;
	$pods='используя одну подсказку';
	}

if($umnik_last['umnik_st']==3){
	$add_balls=1;
            $add_iq=1;
	$pods='используя обе подсказки';
	}

$msg = "Молодец, [b]$ank[login][/b], Вы дали верный ответ [b]".win2utf($umnik_vopros[otvet])."[/b] первее всех,$pods. [b]$ank[login][/b] получает $add_balls монет и $add_iq IQ.Берите пример с [b]$ank[login][/b], через 5 секунд напишу следующий вопрос!";

mysql_query("INSERT INTO `chat_msg` SET `vopros` = '".$umnik_vopros[id]."', `umnik_st` = '4', `msg` = '".$msg."', `ot_user` = '52', `room` = '".$room_info['id']."', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
    

mysql_query("UPDATE `profile` SET `many` = '".($ank['many']+$add_balls)."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `profile` SET `iq` = '".($ank['iq']+$add_iq)."' WHERE `id` = '$ank[id]' LIMIT 1");
}
}

/////////////////////////////////////////////////////////////////////


$umnik_last1 = mysql_fetch_array(mysql_query("SELECT * FROM `chat_msg` WHERE `room` = '".$room_info['id']."' AND `umnik_st` = '1' ORDER BY id DESC"));
if($umnik_last1!=NULL && $umnik_last['umnik_st']!=4 && $umnik_last1['date']<time()-120){
	$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` WHERE `id` = '$umnik_last1[vopros]' LIMIT 1"));
	$msg="Эх Вы, не ответили на такой легкий вопрос :-(. Правильный ответ был: ".win2utf($umnik_vopros[otvet]).". Через 5 сек спрошу что-нибудь полегче может угадаите:-)";
	mysql_query("INSERT INTO `chat_msg` SET `vopros` = '".$umnik_vopros[id]."', `umnik_st` = '4', `msg` = '".$msg."', `ot_user` = '52', `room` = '".$room_info['id']."', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
	}
    
////////////////////////////////////////////////////////////////////
$umnik_last = mysql_fetch_array(mysql_query("SELECT * FROM `chat_msg` WHERE `room` = '".$room_info['id']."' AND `umnik_st` <> '0' ORDER BY id DESC"));
if($umnik_last==NULL || $umnik_last['umnik_st']==4 && $umnik_last['date']<time()-5){
	$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` ORDER BY RAND() LIMIT 1"));
	$msg="[b]Так,внимательно читаем вопрос:[/b] \"". win2utf($umnik_vopros[vopros])."\"\nэто слово состоит из ".strlen2(win2utf($umnik_vopros['otvet']))." букв, угадываем! ;-)";
	
	mysql_query("INSERT INTO `chat_msg` SET `vopros` = '".$umnik_vopros[id]."', `umnik_st` = '1', `msg` = '".$msg."', `ot_user` = '52', `room` = '".$room_info['id']."', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
    }
///////////////////////////////////


if($umnik_last!=NULL && $umnik_last['umnik_st']==1 && $umnik_last['date']<time()-60){
	$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` WHERE `id` = '$umnik_last[vopros]' LIMIT 1"));

if(function_exists('iconv_substr')){
	$help=iconv_substr(win2utf($umnik_vopros['otvet']), 0, 1, 'utf-8');
	}else{
		$help=substr(win2utf($umnik_vopros['otvet']), 0, 2);
		}

for($i=0;$i<strlen2(win2utf($umnik_vopros['otvet']))-1 ;$i++){
	$help.='*';
	}

$msg="[b]Угадываем я сказал![/b], \"".win2utf($umnik_vopros[vopros])."\"\n [b]ну хорошо, помогу Вам :-) Слово начинается на букву:[/b] $help";
mysql_query("INSERT INTO `chat_msg` SET `vopros` = '".$umnik_vopros[id]."', `umnik_st` = '2', `msg` = '".$msg."', `ot_user` = '52', `room` = '".$room_info['id']."', `date` = '".time()."', `antispam` = '".$antispam."', `ip` = '".$ip."', `emotion` = '".num($_POST['emo'])."', `color` = '".num($_POST['color'])."'");
    }


?>