function addBet($uid, $g_id, $bi_id, $amount, $notify = 0) { global $config; $basedir = $config['basedir']; $now = time(); // insert to coin_deals $q = "INSERT INTO coin_deals (user_id, cd_amount, cd_inout, tx_id, cd_type, cd_tx_date) VALUES ('{$uid}', '{$amount}', 'out', '', 'bet', '{$now}')"; mysql_query($q); $id = mysql_insert_id(); if ($id) { // append all_coin_deals.txt cache $coindeal['cd_id'] = $id; $coindeal['user_id'] = $uid; $coindeal['g_id'] = 0; $coindeal['cd_amount'] = $amount; $coindeal['cd_inout'] = 'out'; $coindeal['tx_id'] = ''; $coindeal['cd_type'] = 'bet'; $coindeal['cd_tx_date'] = $now; $file = $basedir . '/temp/all_coin_deals.txt'; if (file_exists($file)) { $data = json_decode(file_get_contents($file), true); $data[] = $coindeal; unlink($file); file_put_contents($file, json_encode($data)); } //recompute user's coins $user_coins = getUserCoins($uid); updateUserCoins($uid, $user_coins); $activity = 'joinedgame'; $seen = 1; $fieldname = 'g_id'; $fieldvalue = $g_id; addActivity($uid, $activity, $seen, $fieldname, $fieldvalue); // insert to user_bets $q = "INSERT INTO user_bets (user_id, g_id, bi_id, ub_coins, ub_notify, cd_id) VALUES ('{$uid}', '{$g_id}', '{$bi_id}', '{$amount}', '{$notify}', '{$id}')"; mysql_query($q); $insert_id = mysql_insert_id(); // insert data to the cache file $newrec = array('ub_id' => $insert_id, 'user_id' => $uid, 'g_id' => $g_id, 'bi_id' => $bi_id, 'ub_coins' => $amount, 'ub_notify' => $notify, 'cd_id' => $id, 'ub_iswinner' => 0); $cachefile = $config['basedir'] . '/temp/user_bets_active.php'; if (file_exists($cachefile)) { // get the file $uba = json_decode(file_get_contents($cachefile), true); $uba[] = $newrec; file_put_contents($cachefile, json_encode($uba)); // write } } return true; }
$user_bettings = false; $include_bet_status = false; $disable_betting = false; $is_future_game = false; $is_closed = false; $top_winners = false; $bi_id_of_winner = false; $win_item_placed_coins = 0; $game_timer_id = "gameTimer"; $game_timer = false; $user_won = false; $user_congratulations_text = ''; $user_won_after_commission = false; $user_may_earn = 0; $notice = ''; $user_coins = getUserCoins($user_id); // how much coins does the user have? // ex: details.php?game=Ng== // 7: Nw== // 2: Mg== // 8: OA== $game_id = base64_decode($_GET['game']); if (!$game_id) { echo 'no game id. refresh to main page'; //header('Location: ' . $baseurl); exit; } if ($user_id) { $is_liked = checkIsLiked($user_id, $game_id); $is_bookmarked = checkIsBookmarked($user_id, $game_id); } else {