<?session_start();
header( 'Content-type: text/html; charset=windows-1251' );

$usid=intval($_SESSION["user_id"]);
if(empty($usid)){  exit;}
# Автоподгрузка классов
function __autoload($name){ include($_SERVER['DOCUMENT_ROOT']."/classes/_class.".$name.".php");}

# Класс конфига 
$config = new config;

# Функции
$func = new func;

# База данных
$db = new db($config->HostDB, $config->UserDB, $config->PassDB, $config->BaseDB);

$db->Query("SELECT money_b FROM db_users_b WHERE id=$usid");
$money = $db->FetchRow();
if(isset($_GET['bet'])){ 
$bet=intval($_GET['bet']);
if($bet==1){ $bet=100;}
elseif($bet==2){ $bet=500;}
else{ $bet=1000;}
$bet2=$bet*2;
$bank=$bet/100*80; // 20% от ставки идет админу
if($money < $bet){ exit;}
$db->Query("UPDATE db_config SET gamebank = gamebank + '$bank' WHERE id =1");
$db->Query("UPDATE db_users_b SET money_b = money_b - $bet WHERE id = $usid");
$db->Query("SELECT gamebank FROM db_config WHERE id = 1");
$gamebank = $db->FetchRow();
if($gamebank>$bet2){ 
$rand=mt_rand(1,2);
if ($rand==1) {
$db->Query("UPDATE db_config SET gamebank = gamebank - '$bet2' WHERE id =1");
$db->Query("UPDATE db_users_b SET money_b = money_b + $bet2 WHERE id = $usid");
$db->Query("SELECT money_b FROM db_users_b WHERE id=$usid");
$money = $db->FetchRow();
$db->Query("INSERT INTO orel (user,date,stavka,win) VALUES ('$_SESSION[user]','".time()."','$bet','$bet2')");
echo "WIN!!$money";
exit;
}
}
$db->Query("INSERT INTO orel (user,date,stavka) VALUES ('$_SESSION[user]','".time()."','$bet')");
$db->Query("SELECT money_b FROM db_users_b WHERE id=$usid");
$money = $db->FetchRow();
echo "LOSE!!$money";
}else{
echo $money;}



?>