Файл: world-faces.ru/world-faces.ru/chat/inc/umnik.php
Строк: 108
<?php
$umnik_last = mysql_fetch_array(mysql_query("SELECT * FROM `chat_post` WHERE `room` = '$room[id]' AND `umnik_st` <> '0' ORDER BY id DESC"));
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_post` WHERE `room` = '$room[id]' AND `msg` like '$umnik_vopros[otvet]' AND `umnik_st` = '0' ORDER BY id DESC LIMIT 1"));
if($umnik_post!=NULL){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $umnik_post[id_user] LIMIT 1"));
$add_balls=0;
if($umnik_last['umnik_st']==1){
$add_balls=25;
$add_iq=25;
$pods='не используя подсказок';
}
if($umnik_last['umnik_st']==2){
$add_balls=20;
$add_iq=20;
$pods='используя одну подсказку';
}
if($umnik_last['umnik_st']==3){
$add_balls=15;
$add_iq=15;
$pods='используя обе подсказки';
}
$msg = "Молодец,[b]$ank[nick][/b],nВы дали верный ответ [b]$umnik_vopros[otvet][/b] первее всех,$pods.n[b]$ank[nick][/b] получает $add_balls баллов и $add_iq IQ.nСледующий вопрос через $set[umnik_new] сек.";
mysql_query("INSERT INTO `chat_post` (`umnik_st`, `time`, `msg`, `room`, `vopros`, `privat`) values('4', '$time', '$msg', '$room[id]', '$umnik_vopros[id]', '0')");
mysql_query("OPTIMIZE TABLE `chat_post`");
mysql_query("UPDATE `user` SET `balls` = '".($ank['balls']+$add_balls)."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `iq` = '".($ank['iq']+$add_iq)."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `otvetov` = '".($ank['otvetov']+1)."' WHERE `id` = '$ank[id]' LIMIT 1");
}
}
$umnik_last1 = mysql_fetch_array(mysql_query("SELECT * FROM `chat_post` WHERE `room` = '$room[id]' AND `umnik_st` = '1' ORDER BY id DESC"));
if($umnik_last1!=NULL && $umnik_last['umnik_st']!=4 && $umnik_last1['time']<time()-$set['umnik_time']){
$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` WHERE `id` = '$umnik_last1[vopros]' LIMIT 1"));
$msg="На вопрос никто не ответил.Следующий вопрос через $set[umnik_new] сек.";
mysql_query("INSERT INTO `chat_post` (`umnik_st`, `time`, `msg`, `room`, `vopros`, `privat`) values('4', '$time', '$msg', '$room[id]', '$umnik_vopros[id]', '0')");
}
$umnik_last = mysql_fetch_array(mysql_query("SELECT * FROM `chat_post` WHERE `room` = '$room[id]' AND `umnik_st` <> '0' ORDER BY id DESC"));
if($umnik_last==NULL || $umnik_last['umnik_st']==4 && $umnik_last['time']<time()-$set['umnik_new']){
$umnik_vopros = mysql_fetch_array(mysql_query("SELECT * FROM `chat_vopros` ORDER BY RAND() LIMIT 1"));
$msg="[b]Вопрос:[/b] "$umnik_vopros[vopros]"n[b]Ответ:[/b] слово из ".strlen2($umnik_vopros['otvet'])." букв";
mysql_query("INSERT INTO `chat_post` (`umnik_st`, `time`, `msg`, `room`, `vopros`, `privat`) values('1', '$time', '$msg', '$room[id]', '$umnik_vopros[id]', '0')");
}
if($umnik_last!=NULL && $umnik_last['umnik_st']==1 && $umnik_last['time']<time()-$set['umnik_help']){
$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($umnik_vopros['otvet'], 0, 1, 'utf-8');
}else{
$help=substr($umnik_vopros['otvet'], 0, 2);
}
for($i=0;$i<strlen2($umnik_vopros['otvet'])-1 ;$i++){
$help.='*';
}
$msg="[b]Вопрос:[/b] "$umnik_vopros[vopros]"n[b]Первая подсказка:[/b] $help (".strlen2($umnik_vopros['otvet'])." букв)";
mysql_query("INSERT INTO `chat_post` (`umnik_st`, `time`, `msg`, `room`, `vopros`, `privat`) values('2', '$time', '$msg', '$room[id]', '$umnik_vopros[id]', '0')");
}
if($umnik_last!=NULL && $umnik_last['umnik_st']==2 && $umnik_last['time']<time()-$set['umnik_help']){
$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($umnik_vopros['otvet'], 0, 2, 'utf-8');
}else{
$help=substr($umnik_vopros['otvet'], 0, 4);
}
for($i=0;$i<strlen2($umnik_vopros['otvet'])-2 ;$i++){
$help.='*';
}
$msg="[b]Вопрос:[/b] "$umnik_vopros[vopros]"n[b]Вторая подсказка:[/b] $help (".strlen2($umnik_vopros['otvet'])." букв)";
mysql_query("INSERT INTO `chat_post` (`umnik_st`, `time`, `msg`, `room`, `vopros`, `privat`) values('3', '$time', '$msg', '$room[id]', '$umnik_vopros[id]', '0')");
}
?>