Файл: football/index.php
Строк: 187
<?
define('_IN_JOHNCMS', 1);
$textl = 'Угадай футболиста';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");
$user = functions::get_user($user);
if (!$user) {
require('../incfiles/head.php');
echo functions::display_error($lng['user_does_not_exist']);
require('../incfiles/end.php');
exit;
}
function letter($letters = array(), $array = array()) {
$abc = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','щ','ш','ь','ы','ъ','э','ю','я');
$rand = $abc[array_rand($abc)];
if(in_array($rand, $letters) || in_array($rand, $array)) {
return letter($letters, $array);
} else {
return $rand;
}
}
?>
<style type="text/css">
.b2 { padding:0px;
border-radius: 4px;
margin: 2px 0;}
.b2 a{color:#000000;padding:6px;
border-bottom:1px solid #d2c9c9;
font-weight:bold;
border-radius: 4px;
line-height:32px; display:inline !important;
background: #badbad;}
.b23 { padding:0px;
border-radius: 4px;
margin: 2px 0;}
.b23 a{color:#000000;padding:6px;
border-bottom:1px solid #000000;
font-weight:bold;
border-radius: 4px;
line-height:32px; display:inline !important;
background: #3caa3c;}
.neverno {padding-top:8px;padding-bottom:8px;
border-top:1px dotted #348EDD;
border-bottom:1px dotted #348EDD;
font-weight:bold;
}
</style>
<?
// даем вопрос
$add = mysql_num_rows(mysql_query("SELECT * FROM `my_football` WHERE `id_user` = '".$user['id']."' and `otvet` = '0'"));
$count = mysql_num_rows(mysql_query("SELECT * FROM `my_football` WHERE `id_user` = '".$user['id']."' and `otvet` = '1'"));
$next=$count+1;
$id = mysql_fetch_array(mysql_query("SELECT * FROM `football` WHERE `id` = '".$next."' LIMIT 1"));
$sko=mysql_result(mysql_query("SELECT COUNT(*) FROM `football` "),0);
$sko2=mysql_result(mysql_query("SELECT COUNT(*) FROM `my_football` WHERE `id_user` = '".$user['id']."' and `otvet` = '1'"),0);
if($add == 0 and $sko != $sko2 ){
unset($_SESSION['bukva']);
unset($_SESSION['podskazka']);
unset($_SESSION['schet']);
unset($_SESSION['uid'], $_SESSION['reply'], $_SESSION['string']);
mysql_query("insert into `my_football` set
`id_user` = '".$user['id']."',
`otvet` = '0',
`id_football` = '$id[id]'
");
header('location: ?');
}
$count_football = mysql_num_rows(mysql_query("select * from `football`"));
if($count_football == 0){
echo '<div class="neverno"><font color="red">Нет заданий!</font></div><br>';
} else {
// Увеличение изображения
if(isset($_GET['big1'])){
$b1_h = 400;
} else {
$b1_h = 200;
}
$my = mysql_fetch_assoc(mysql_query("select * from `my_football` where `id_user` = '$user[id]' and `otvet` = '0' limit 1"));
$football = mysql_fetch_assoc(mysql_query("select * from `football` where `id` = '$my[id_football]' limit 1"));
$letters = preg_split('//u', $football['football'], -1, PREG_SPLIT_NO_EMPTY);
$count = count($letters);
if(!isset($_SESSION['uid'])) {
// Получаем массив из рандомных букв, не входящих в исходное слово
$array = array();
for($i = 0; $i < (14 - $count); $i++) {
$array[$i] = letter($letters, $array);
}
// Соединяем два массива в один и рандомно перемешиваем
$_SESSION['uid'] = array_merge($letters, $array );
shuffle($_SESSION['uid']);
}
// Слово - ответ
if(!isset($_SESSION['reply'])) {
$_SESSION['reply'] = array();
for($i = 0; $i < $count; $i++) {
$_SESSION['reply'][$i] = '_';
}
}
// Подстановка буквы
if(isset($_GET['letter']) && in_array('_', $_SESSION['reply'])) {
$_GET['letter'] = abs(intval($_GET['letter']));
if(isset($_SESSION['uid'][$_GET['letter']])) {
$k = false;
for($i = 0; $i <= $count; $i++) {
if($_SESSION['reply'][$i] == '_' && !$k) {
$k = true;
$_SESSION['reply'][$i] = $_SESSION['uid'][$_GET['letter']];
}
}
unset($_SESSION['uid'][$_GET['letter']]);
header('location: ?');
exit;
}
}
// Удаление буквы
if(isset($_GET['delete'])) {
$_GET['delete'] = abs(intval($_GET['delete']));
if(isset($_SESSION['reply'][$_GET['delete']])) {
if($_SESSION['reply'][$_GET['delete']] != '_') {
$_SESSION['uid'][] = $_SESSION['reply'][$_GET['delete']];
$_SESSION['reply'][$_GET['delete']] = '_';
header('location: ?');
exit;
}
}
}
$sko=mysql_result(mysql_query("SELECT COUNT(*) FROM `football` "),0);
$sko2=mysql_result(mysql_query("SELECT COUNT(*) FROM `my_football` WHERE `id_user` = '$user[id]' and `otvet` = '1'"),0);
if($sko == $sko2 ){
echo '<div class="neverno"><font color="red">Вы прошли игру! Мы в любой момент добавим новые задания, следите за игрой!</font></div>';
}
else {
$myB = mysql_fetch_assoc(mysql_query("select * from `users` where `id` = '$user[id]' limit 1"));
echo "<center><div class='nav2'>Баллы: <b>".$myB['balans']."</b></div>
<a href='".(isset($_GET['big1']) ? "?" : "?big1")."'><img src='../files/foot/$football[img]' style='height: ".$b1_h."px; width: ".$b1_h."px;' alt=''/></a>
";
}
if(mysql_num_rows(mysql_query("select * from `my_football` where `id_user` = '$user[id]' and `otvet` = '0'")) == 0){
}
else {
echo "<div class='nav2'>Слово состоит из $count букв</div><br/>";
}
if(isset($user['id'])) {
if(in_array('_', $_SESSION['reply']) == false) {
$text = NULL;
for($frf = 0; $frf < $count; $frf++){
$text .= $_SESSION['reply'][$frf];
}
if($football['football'] == $text) {
$ballz = mysql_fetch_assoc(mysql_query("select * from `football_settings` limit 1"));
mysql_query("update `users` set `users` = `balans` + '$ballz[otvet]' where `id` = '$user[id]'");
mysql_query("update `my_football` set `otvet` = '1' where `id_football` = '$football[id]' and `id` = '$my[id]'");
unset($_SESSION['bukva']);
unset($_SESSION['podskazka']);
unset($_SESSION['schet']);
unset($_SESSION['uid'], $_SESSION['reply'], $_SESSION['string']);
if(!empty($text)){
echo "<div class='nav1'>Это был <b>".$text."</b></div>";
echo "<div class='nav1'>Вы заработали <b>".$ballz['otvet']."</b> баллов</div>";
echo '<span class="b2"><a href="?">Далее</a></span>';
}
} else {
echo '<div class="neverno"><font color="red">Не правильно!</font></div><br>';
}
header("location: ");
}
if(isset($_SESSION['reply'])){
foreach($_SESSION['reply'] as $key=>$reply) {
echo '<span class="b2"><a href="?delete='.$key.'"><b>'.$reply.'</b></a></span> ';
}
echo "<br/>";
}
if(isset($_SESSION['uid'])){
foreach($_SESSION['uid'] as $key=>$letter) {
echo '<span class="b23"><a href="?letter='.$key.' ">'.$letter.'</a></span> ';
}
echo "<br/>";
}
}else{
echo '<div class="neverno"><font color="red">Для того, чтобы ответить, вам необходимо зарегистрироваться!</font></div><br>';
}
}
// Пропустить слово
$ballz = mysql_fetch_assoc(mysql_query("select * from `football_settings` limit 1"));
$balls_next = $ballz['propusk'];
if(isset($_GET['next'])){
if($user['balans'] >= $balls_next){
mysql_query("update `my_football` set `otvet` = '1' where `id_user` = '$user[id]' and `id_football` = '$my[id_football]'");
mysql_query("update `users` set `balans` = `balans` - '$balls_next' where `id` = '$user[id]'");
unset($_SESSION['bukva']);
unset($_SESSION['podskazka']);
unset($_SESSION['schet']);
unset($_SESSION['uid'], $_SESSION['reply'], $_SESSION['string']);
for($s = 1; $s <= $strlen; $s++){
unset($_SESSION['bukva_'.$s]);
}
header("location: ?");
} else {
echo'<div class="neverno"><font color="red">У вас недостаточно баллов для использования данной функции!</font></div>';
}
}
// подсказка
$balls_pods = $ballz['pods'];
if(isset($_GET['pods'])){
if($_SESSION['podskazka'] == NULL){
if($user['balans'] >= $balls_pods ){
$_SESSION['podskazka'] = 1;
mysql_query("update `users` set `balans = `balans` - '$balls_pods' where `id` = '$user[id]'");
header("location: ?");
} else {
echo'<div class="neverno"><font color="red">У вас недостаточно баллов для использования данной функции!</font></div>';
}
} else {
echo '<div class="neverno"><font color="red">Вы уже использовали подсказку!</font></div>';
}
}
echo '</center><br /><hr>';
if(isset($_SESSION['podskazka'])){
echo "<br/><center><div class='neverno'>Клуб: <font color='green'>$football[pods]</font></div></center><br/>";
}
if(mysql_num_rows(mysql_query("select * from `my_football` where `id_user` = '$user[id]' and `otvet` = '0'")) == 0){
}
else {
echo "
<div class='main_menu'><img src='pods.png'> <a href='?pods'> Узнать клуб</a> (".$ballz['pods']." баллов)</div>
<div class='main_menu'><img src='skip.png'> <a href='?next'> Пропустить </a> (".$ballz['propusk']." баллов) </div>";
}
if ($user[id]==1){
echo "<div class='main'>n";
echo "<img src='settings.png' alt='S' /> <a href='settings.php'>Настройки игры</a> ";
echo "</div>";
echo "<div class='main'>n";
echo "<img src='adm.png' alt='S' /> <a href='admin.php'>Админка игры</a> ";
echo "</div>";
}
require_once ("../incfiles/end.php");
?>