<?php

define('_IN_JOHNCMS', 1);
$textl = 'Yangi o`yin boshlash';
$rootpath = '../../';
require_once ('../../incfiles/core.php');
require_once ('../../incfiles/head.php');
if (!$user_id)
    {
       $error = $lng['access_guest_forbidden'];
       echo functions::display_error($error, '<a href="index.php">' . $lng['back'] . '</a>');
       require_once ('../../incfiles/end.php');
       exit();
       
    }


switch($act)
    {
        case 'add':
            {
                if (!isset($_POST['add']))
                    {
                       $error = 'XATO!';
                        echo functions::display_error($error, '<a href="create_game.php">' . $lng['back'] . '</a>');
                        require_once ('../../incfiles/end.php');
                        exit(); 
                    }

               $suma = abs(intval($_POST['suma']));
			   $my_choice = mysql_real_escape_string(functions::checkin($_POST['my_choice']));
               $sql = mysql_fetch_assoc(mysql_query("select * from `knb_users` where `user_id`='". $user_id ."'"));
			   $userball = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$user_id."'"));
               if ($userball['balans']<$suma)
                {
                    $error = 'Stavka tikishga ballingiz yetmaydi';
                   echo functions::display_error($error, '<a href="create_game.php">' . $lng['back'] . '</a>');
                   require_once ('../../incfiles/end.php');
                   exit();
                } else
                    {
                        mysql_query("insert into `knb_games` set
                            `create_user_id`='".$user_id."',
                            `create_user_name`='".$login."',
                            `stavka`='".$suma."',
                            `choice`='".$my_choice."'");
                        
                        mysql_query("update `users` set `balans`=balans-".$suma." where `id`='". $user_id ."'");
                        
                        echo '<div class="menu">Sizning tanlov: <strong>'.htmlspecialchars(trim($_POST['my_choice'])).'</strong><br />';
                        echo 'Stavka: <strong>'.$suma.'</strong><br />';
                        echo '<a href="index.php">Qaytish</a></div>';
                    }
                
               
            }
            break;
            
        default:
            {
				$userball = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$user_id."'"));
               $sql = mysql_fetch_assoc(mysql_query("select * from `knb_users` where `user_id`='". $user_id ."'"));  
                ?>
                <div class="gmenu">Sizni balingiz: <strong> <?php echo $userball['balans']; ?></strong></div>
                <div class="list1">
                    <strong>Yangi o`yin boshlash<br /></strong>
                    <form action="create_game.php?act=add" method="POST">
                        Tanlovingizni belgilang: <br />
                        <select name="my_choice">
                            <option>Tosh</option>
                            <option>Qaychi</option>
                            <option>Qog`oz</option>
                        </select><br />
                        
                       O`z stavkangizni kiriting:<br />
                        <input type="text" name="suma" /><br />
                        
                        <p><input type="submit" name="add" class="write" value="Jo`natish"/>
                    </form>
                </div>
                <?php    
            }
            
    }

require_once ('../../incfiles/end.php');