Файл: games/class/class.php
Строк: 97
<?
# Стартуем викторину
function vic_start(){
$qw = DB::run() -> query("SELECT * FROM `session_vic`") -> rowCount();
if($qw >= 1){
# Проверяем играет ли уже кто то
$vic_start = DB::run() -> queryFetch("SELECT * FROM `vic_vopros` ORDER BY `id` DESC LIMIT 1");
if($vic_start['id'] == NULL){//если игрок только что зашел
$q = DB::run() -> query("SELECT * FROM `vic`") -> rowCount();//считаем сколько всего вопросов
//берем любой вопрос
$vic_vop = DB::run() -> queryFetch("SELECT * FROM vic WHERE id =?",array(mt_rand(1,$q)));
# добавляем его в основую викторину #
# подсказка
for($i=0;$i < utf_strlen($vic_vop['otvet']) ;$i++){
$pod.='*';
}
# подсказка 1
if(function_exists('iconv_substr')){
$help=iconv_substr($vic_vop['otvet'], 0, 1, 'utf-8');
}else{
$help=substr($vic_vop['otvet'], 0, 2);
}
for($i=0;$i < utf_strlen($vic_vop['otvet'])-1 ;$i++){
$help.='*';
}
# подсказка 2
if(function_exists('iconv_substr')){
$helps=iconv_substr($vic_vop['otvet'], 0, 2, 'utf-8');
}else{
$helps=substr($vic_vop['otvet'], 0, 2);
}
for($i=0;$i < utf_strlen($vic_vop['otvet'])-2 ;$i++){
$helps.='*';
}
# добавляем вопрос
DB::run()->query("INSERT INTO `vic_vopros`(`vopros`,`otvet`,`pod`,`pod_1`,`pod_2`,`step`,`time`) VALUES (?,?,?,?,?,?,?)",array($vic_vop['vopros'],$vic_vop['otvet'],$pod,$help,$helps,1,time() + 60));
function m($value)
{
$x = $value % 10;
if (($x == 1) && ($value != 11)) $s = 'буква';
elseif ((($x > 1) && ($x < 5)) && (floor($value / 10) != 1)) $s = 'буквы'; else $s = 'букв';
return $s;
}
$m = ''.utf_strlen($vic_vop['otvet']).' '.m(utf_strlen($vic_vop['otvet'])).'';
$text = ''.$vic_vop['vopros'].' ('.$m.')';
DB::run()->query("INSERT INTO `vic_msg`(`login`, `msg`, `data`) VALUES (?,?,?)",array('Умник',$text,times()));
}
}
}
# Выводим вопрос
function vic(){
$vic_start = DB::run() -> queryFetch("SELECT * FROM vic_vopros ORDER BY id DESC LIMIT 1");
$time = $vic_start['time'];
echo'<meta http-equiv="refresh" content="'.($vic_start['time'] - time()).';URL=?mode=index" />';
echo'Вопрос: <strong>'.$vic_start['vopros'].'</strong><br />';
if($vic_start['step'] == 1){echo $vic_start['pod'];
if($vic_start['time'] <= time()){
DB::run()->query("UPDATE `vic_vopros` SET `step`=?,`time`=? WHERE `id` =?",array(2,time() + 60,$vic_start['id'])); header ('location: ?mode=index');}}
if($vic_start['step'] == 2){echo $vic_start['pod_1'];
if($vic_start['time'] <= time()){DB::run()->query("UPDATE `vic_vopros` SET `step`=?,`time`=? WHERE `id` =?",array(3,time() + 60,$vic_start['id'])); header ('location: ?mode=index');}}
if($vic_start['step'] == 3){echo $vic_start['pod_2'];
if($vic_start['time'] <= time()){DB::run()->query("UPDATE `vic_vopros` SET `step`=?,`time`=? WHERE `id` =?",array(4,time() + 60,$vic_start['id'])); header ('location: ?mode=index');}}
if($vic_start['step'] == 4){ DB::run()->query("DELETE FROM `vic_vopros` WHERE `id` =?",array($vic_start['id'])); header ('location: ?mode=index'); }
if($vic_start['step'] == 1 || $vic_start['step'] == 2 ){echo'<hr><div align="right">Следующая подсказка через ';}
if($vic_start['step'] == 3){echo'<hr><div align="right">Следующий вопрос через ';}
?>
<div id="link"><? echo ($time - time()); ?></div>
<script>
var link=document.getElementById('link');
var tmt=window.setInterval(function(){
--link.innerHTML||(window.clearInterval(tmt),
link.innerHTML='<img src="/images/reload.gif"> Перезагружаю...');
}, 1000);
</script>
<?
echo'</div>';
}
# Проверяем ответ
function regist_rus($str){
$strold=array("Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х", "Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э", "Я", "Ч", "С", "М", "И", "Т", "Ь", "Б", "Ю", "Ъ"); # что заменять
$strnew=array("й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "ф", "ы", "в", "а", "п", "р", "о", "л", "д", "ж", "э", "я", "ч", "с", "м", "и", "т", "ь", "б", "ю", "ъ"); # на что заменять
$str=str_replace($strold, $strnew, $str);
return $str;
}
function otvet($msg){
$vic_start = DB::run() -> queryFetch("SELECT * FROM vic_vopros ORDER BY id DESC LIMIT 1");
$otvet_user = regist_rus($msg);
$otvet = regist_rus($vic_start['otvet']);
if($otvet_user == $otvet){
#########################################
if($vic_start['step'] == 1){$win = '3 актива, 3 опыта, 3 рубля'; user_live(check($_COOKIE['login']),3,3,3);}
if($vic_start['step'] == 2){$win = '2 актива, 2 опыта, 2 рубля'; user_live(check($_COOKIE['login']),2,2,2);}
if($vic_start['step'] == 3){$win = '1 актив, 1 опыт, 1 рубль'; user_live(check($_COOKIE['login']),1,1,1);}
$us = DB::run() -> queryFetch("SELECT * FROM users WHERE login =?",array(check($_COOKIE['login'])));
$text = 'Молодец, <a href=/profile/'.check($_COOKIE['login']).'>'.check($_COOKIE['login']).'</a>! Правильных ответов: '.($us['vic'] + 1).', вы заработали '.$win.'!';
DB::run()->query("UPDATE `users` SET `vic`=`vic` + ? WHERE `login` = ?",array(1,check($_COOKIE['login'])));
DB::run()->query("INSERT INTO `vic_msg`(`login`, `msg`, `data`) VALUES (?,?,?)",array('Умник',$text,times()));
DB::run()->query("DELETE FROM `vic_vopros` WHERE `id` =?",array($vic_start['id'])); header ('location: ?mode=index');
}
}
?>