function changepass($op, $np1, $np2, $uid) { global $config; $basedir = $config['basedir']; $pass_enc = md5($config['private_key'] . $np1); // encrypt the password if (!_checkoldpass($op, $uid)) { return 'invalid old password'; } if ($np1 != $np2) { return 'no match'; } $q = "UPDATE users SET user_password = '******' WHERE user_id = '{$uid}'"; mysql_query($q); $user_id = $uid; $file = $basedir . '/temp/all_users.txt'; if (file_exists($file)) { $data = json_decode(file_get_contents($file), true); $data[$user_id]['user_password'] = $np1; unlink($file); file_put_contents($file, json_encode($data)); } $activity = 'changepass'; $seen = 1; $fieldname = 'user_id'; $fieldvalue = $uid; addActivity($uid, $activity, $seen, $fieldname, $fieldvalue); return $pass_enc; }
function addBookmark($g_id, $u_id) { global $config; $basedir = $config['basedir']; $file = $basedir . '/temp/all_games.txt'; $cache = array(); $temp = array(); if (file_exists($file)) { $temp = json_decode(file_get_contents($file), true); } foreach ($temp as $d) { $cache[$d['g_id']] = $d; } $q = "SELECT ub_id FROM user_bookmarks WHERE user_id = '{$u_id}' AND g_id = '{$g_id}'"; $result = mysql_query($q); $numrows = mysql_num_rows($result); if ($numrows) { // delete it $q = "DELETE FROM user_bookmarks WHERE user_id = '{$u_id}' AND g_id = '{$g_id}'"; mysql_query($q); $q = "UPDATE games SET g_bookmarks = g_bookmarks - 1 WHERE g_id = '{$g_id}'"; mysql_query($q); $activity = 'unbookmark'; $seen = 1; $fieldname = 'g_id'; $fieldvalue = $g_id; addActivity($u_id, $activity, $seen, $fieldname, $fieldvalue); $cbook = $cache[$g_id]['g_bookmarks']; $cache[$g_id]['g_bookmarks'] = $cbook - 1; $ret = 'deleted'; } else { // insert it $q = "INSERT INTO user_bookmarks (user_id, g_id) VALUES ('{$u_id}', '{$g_id}')"; mysql_query($q); $q = "UPDATE games SET g_bookmarks = g_bookmarks + 1 WHERE g_id = '{$g_id}'"; mysql_query($q); $activity = 'bookmark'; $seen = 1; $fieldname = 'g_id'; $fieldvalue = $g_id; addActivity($u_id, $activity, $seen, $fieldname, $fieldvalue); $cbook = $cache[$g_id]['g_bookmarks']; $cache[$g_id]['g_bookmarks'] = $cbook + 1; $ret = 'success'; } $temp = array(); foreach ($cache as $d) { $temp[] = $d; } if (file_exists($file)) { unlink($file); file_put_contents($file, json_encode($temp)); } return $ret; }
function insertUserWinnings($winners, $coin_div, $total_bet_amt, $game_id) { global $config; $basedir = $config['basedir']; $do_write = false; // get the cache file $cache_file = $config['basedir'] . '/temp/all_users.txt'; if (!file_exists($cache_file)) { return; } $all_users = json_decode(file_get_contents($cache_file), TRUE); $won_users = array(); $file = $basedir . '/temp/all_coin_deals.txt'; if (file_exists($file)) { $data = json_decode(file_get_contents($file), true); } else { $data = array(); } foreach ($winners as $w) { $user_id = $w['user_id']; $total_user_bet = $w['total_bet']; //$total_win_amt = $total_user_bet - ($total_user_bet * ($house_com / 100)); $ration = $total_user_bet / $total_bet_amt * 100; // get the percentage of the user's total take $total_win_amt = $ration * $coin_div; // multiply by coins $now = time(); $won_users[] = $all_users[$w['user_id']]; increaseUserCoins($user_id, $total_win_amt); $q = "INSERT INTO coin_deals (user_id, g_id, cd_amount, cd_inout, tx_id, cd_type, cd_tx_date) VALUES ('{$user_id}', '{$game_id}', '{$total_win_amt}', 'in', '0', 'bet winning', '{$now}')"; mysql_query($q); // append all_coin_deals.txt cache $coindeal['cd_id'] = mysql_insert_id(); $coindeal['user_id'] = $user_id; $coindeal['g_id'] = $game_id; $coindeal['cd_amount'] = $total_win_amt; $coindeal['cd_inout'] = 'in'; $coindeal['tx_id'] = 0; $coindeal['cd_type'] = 'bet winning'; $coindeal['cd_tx_date'] = $now; if ($data) { $data[] = $coindeal; $do_write = true; } $activity = 'won'; $seen = 0; $fieldname = 'g_id'; $fieldvalue = $game_id; addActivity($user_id, $activity, $seen, $fieldname, $fieldvalue); } if ($do_write) { unlink($file); file_put_contents($file, json_encode($data)); } notifyWonUsers($won_users, $game_id); return true; }
function checkInput() { addActivity(); // Add activity confirmAdded(); // Pompt user }