} else { $points_leaderboard_score = $point_leaderboard['total_points'] + $total_points; $current_point = $point_leaderboard['current_point'] + $total_points; updatePointLeaderBoard($user_id, $points_leaderboard_score, $current_point); } if ($game_leaderboard['leader_board_id'] > 0) { $game_leaderboard_score = $game_leaderboard['leader_board_score'] + $game_score; updateGameScoreLeaderBoard($user_id, $game_leaderboard_score); } else { $game_leaderboard_score = $game_score; addNewGameScoreLeaderBoard($user_id, $game_leaderboard_score); } if ($game_user_point['user_point_id'] > 0) { $user_total_points = $game_user_point['total_points'] + $total_points; $user_overall_points = $game_user_point['over_all_points'] + $user_total_points; updateUserPoints($user_id, $game_id, $user_total_points, $user_overall_points); $createdAt = date("Y-m-d H:i:s"); $updatedAt = date("Y-m-d H:i:s"); $game_scores = getGameScoreByUser($user_id, $game_id); $score_game = mysql_fetch_array($game_scores); if ($score_game['game_score'] == "") { $result = mysql_query("insert into game_scores(game_id,user_id,game_score,createdAt,updateAt,isgarbeg) values({$game_id},{$user_id},{$game_score},'{$createdAt}','{$updatedAt}','no')"); if ($result) { echo json_encode("Score Saved in Leaderboard!"); } else { echo json_encode("Score Saved in Leaderboard!"); } } else { if ($game_score > $score_game['game_score']) { $result = mysql_query("update game_scores set game_score={$game_score} where game_id={$game_id} and user_id={$user_id}"); if ($result) {
if ($_FILES['file_01']['tmp_name']) { $f = handleUpload('file_01'); if(!$f){ message('Error occur when uploading the image!'); return redirect('upload.php'); } }else{ $f = ''; } $db = getDBInstance(); $name = $_REQUEST['name']; $desc = $_REQUEST['description']; $short_desc = $_REQUEST['short_description']; $point = 1; $create_by = $_SESSION['user']->id; addBook($db, $name, $desc, $short_desc, $f, $point, $create_by); // add the point once the user upload the book updateUserPoints($db, $_SESSION['user']->id, $point); $new_points = $_SESSION['user']->points + $point; $_SESSION['use']->points = $new_points; $db->debug(); message('Upload successfully!'); redirect('index.php'); ?>
if(!isUserLogin()){ redirect('login.php'); } $db = getDBInstance(); $id = $_REQUEST['id']; $download_book = getDownloadBook($db, $_SESSION['user']->id, $id); $book = $db->get_row("select * from books where id=$id"); if($download_book){ download($book->name,$book->path); }else{ $new_point = $_SESSION['user']->points - $book->points; if($new_point < 0){ message('Your points is not enough to download this book!'); redirect("book.php?id=$id"); } //minus the user's points updateUserPoints($db, $_SESSION['user']->id, $book->points*-1); $_SESSION['user']->points = $new_point; //add the download history addDownloadHistory($db, $_SESSION['user']->id, $id, $book->points); //update the book's download times addDownloadTime($db,$id); download($book->name,$book->path); } ?>
$query2 = "SELECT * FROM user_tournaments"; $result2 = mysqli_query($db_connect, $query2); //loopar igenom varje rad i user_tournaments while ($row = mysqli_fetch_assoc($result2)) { $user_id = $row["user_id"]; $user_name = $row["user_name"]; $tournament_id = $row["tournament_id"]; echo $user_name; //sparar returvärdet från funktionen userPoints $points = userPoints($user_id, $tournament_id); //sparar returvärdet från winnerExtraPoints $extra_points = winnerExtraPoints($user_id, $tournament_id); //sparar returvärdet från slutspelPoints $slutspel_points = slutspelPoints($user_id, $tournament_id); //hämtar funktionen som updaterar personens aktuella poäng updateUserPoints($points, $extra_points, $slutspel_points, $user_id, $tournament_id); } //skickar tillbaka till admin_dash header("Location: ../admin_dash.php"); /* **************************************** */ /* ************* FUNKTIONER *************** */ /* **************************************** */ //funktionen updaterar lagets poäng function insertTeamPoints($points, $team_id) { global $db_connect; mysqli_query($db_connect, "UPDATE teams SET team_points = {$points} WHERE team_id = '{$team_id}' "); } //funktionen räknar ut lagets aktuella poäng. function teamPoints($team_id) {