$all_bets = getAllBets($game_id);
$game_placed_coins = getGameCoins($all_bets);
// get total placed coins for this game
$total_joined = getTotalUsersJoined($all_bets);
// count all users who played
$bet_items = getBetItems($game_id);
$disable_betting = time() > $game['g_schedTo'] ? true : false;
// disabled betting when game ended
foreach ($bet_items as $bi) {
    $bet_items2[$bi['bi_id']] = $bi['bi_description' . $suffix];
    // assign bi_id as key and bi_description as value
    $bi_id_of_winner = $bi['bi_winner'] ? $bi['bi_id'] : $bi_id_of_winner;
}
$info_per_bet_item = getInfoPerBetItem($all_bets);
// get placed coins, bet users, and ratio
$user_may_earn = getUserMayEarn($info_per_bet_item, $game['g_houseCom']);
// if game is already closed
if ($game['g_isClosed']) {
    $is_closed = true;
    $display_uri = $user_bettings ? "?q=yourgame&cat={$game_cat}&sort=time" : "?q=results&cat={$game_cat}&sort=time";
    $notice .= $lang[254];
    // "This game already closed"
    $notice_display = "block";
    $notice_class = "gameclosed";
    $user_bettings = getUserBets($game_id, $user_id);
    $user_won = checkUserWon($user_id, $game_id);
    $top_winners = getTopWinners($info_per_bet_item, $bet_items2, $bi_id_of_winner);
    // get maximum of 10 top winners
    if ($user_won) {
        //$user_won_after_commission = $user_won - ($user_won * ($game['g_houseCom'] / 100));
        $user_congratulations_text = str_replace('$COIN_VARIABLE', $user_won_after_commission, $lang[257]);
}
// check if this game is already closed
if (checkGameisClosed($g_id)) {
    // return with message
    echo json_encode(array('error' => '0', 'status' => 'closed'));
    exit;
}
$bet_items = array();
// get all active bet items
$betitems_cache = $basedir . '/temp/bet_items_active.php';
if (file_exists($betitems_cache)) {
    $bet_items = json_decode(file_get_contents($betitems_cache), TRUE);
} else {
    $bet_items = getAllBetItemsNoWinnerAndWriteToCache();
}
$user_bets = array();
// get all active bet items
$userbets_cache = $basedir . '/temp/user_bets_active.php';
if (file_exists($userbets_cache)) {
    $user_bets = json_decode(file_get_contents($userbets_cache), TRUE);
} else {
    $user_bets = getAllUserBetsNoWinnerAndWriteToCache();
}
$all_bets = getAllBetsFromCache2($bet_items, $user_bets, $g_id);
$info_per_bet_item = getInfoPerBetItem($all_bets);
$user_may_earn = getUserMayEarn($info_per_bet_item, $comm);
if ($info_per_bet_item) {
    echo json_encode(array('error' => '0', 'status' => 'success', 'data' => array(0 => $info_per_bet_item, 1 => $user_may_earn)));
    //echo json_encode(array('error' => '0', 'status' => 'success', 'data' => $info_per_bet_item));
    exit;
}