// 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]);
    }
}
// if game has ended but not yet closed or judged
if (time() > $game['g_schedTo'] and !$game['g_isClosed']) {
    $display_uri = $user_bettings ? "?q=yourgame&cat={$game_cat}&sort=time" : "?q=results&cat={$game_cat}&sort=time";
    $notice = $lang[556];
    $notice_display = "block";
    $notice_class = "judgement";
} else {
    // if this is a trial game and game is not yet closed
function currentBettingAndResultsGame($user_id)
{
    global $config;
    $data = array();
    $temp = array();
    $file = $config['basedir'] . '/temp/all_games.txt';
    if (file_exists($file)) {
        $temp = json_decode(file_get_contents($file), true);
    } else {
        $temp = getAllGames();
    }
    foreach ($temp as $t) {
        $all_games[$t['g_id']] = $t;
    }
    $all_bets = getAllBetsByUserId($user_id);
    $temp = array();
    foreach ($all_bets as $ab) {
        $g_id = $ab['g_id'];
        $game = $all_games[$g_id];
        $suffix = getSuffix($game);
        if (!isset($temp[$g_id])) {
            $temp[$g_id] = getBetItems($g_id);
            foreach ($temp[$g_id] as $t) {
                $bet_items[$t['bi_id']] = $t;
            }
            if ($game['g_isClosed'] and !$game['g_isCancelled']) {
                $key = 'results';
            } else {
                $key = 'current';
            }
            $data[$key][$g_id]['won'] = false;
            $data[$key][$g_id]['earned'] = 0;
            $data[$key][$g_id]['game_id'] = $g_id;
            $data[$key][$g_id]['title'] = $game['g_title' . $suffix];
            $data[$key][$g_id]['image'] = $game['g_image'];
            $data[$key][$g_id]['from'] = $game['g_schedFrom'];
            $data[$key][$g_id]['to'] = $game['g_schedTo'];
            $data[$key][$g_id]['your_placed'] = 0;
            $data[$key][$g_id]['housecom'] = $game['g_houseCom'];
            $data[$key][$g_id]['total_placed'] = getGameTotalPlacedCoins($g_id);
        }
        if ($ab['ub_iswinner']) {
            $data[$key][$g_id]['won'] = true;
            $data[$key][$g_id]['earned'] = checkUserWon($user_id, $g_id);
        }
        if (!isset($data[$key][$g_id]['your_items'][$ab['bi_id']]['placed_coins'])) {
            $data[$key][$g_id]['your_items'][$ab['bi_id']]['placed_coins'] = 0;
        }
        $data[$key][$g_id]['your_placed'] += $ab['ub_coins'];
        $data[$key][$g_id]['your_items'][$ab['bi_id']]['placed_coins'] += $ab['ub_coins'];
        $data[$key][$g_id]['your_items'][$ab['bi_id']]['name'] = $bet_items[$ab['bi_id']]['bi_description' . $suffix];
        $data[$key][$g_id]['your_items'][$ab['bi_id']]['winner'] = $ab['ub_iswinner'];
    }
    return $data;
}
 $my_total_bet = 0;
 $is_cancelled = false;
 $my_game = false;
 if (isset($is_yourgame) and $is_yourgame) {
     $my_game = true;
     $won_amount = '---';
 }
 if ($d['g_schedFrom'] < time() and $d['g_schedTo'] > time() and !$d['g_isClosed']) {
     // live game
     $is_live_data = true;
 } elseif ($d['g_schedTo'] < time()) {
     // results game
     $my_total_bet = getUserBetsTotal($d['g_id'], $user_id);
     if ($d['g_isClosed']) {
         $was_closed = 1;
         $user_has_won = checkUserWon($user_id, $d['g_id']);
         if ((string) $user_has_won != 'nowin') {
             $won_amount = $user_has_won;
             $bet_end_time_text = $lang[417];
         } else {
             $won_amount = 0;
             if ($my_total_bet != 'nobet') {
                 // if user has a bet, then user has lost
                 $bet_end_time_text = $lang[418];
             }
         }
     } else {
     }
 } elseif ($d['g_schedFrom'] > time()) {
     // upcoming
     $is_upcoming = true;