Example #1
0
 // pass this_winner to a script that checks the actual_winner for the jesus_id in the nfl_db
 // if it returns true, print correct or add to score,,,,
 // if false, print LOSER and don't ++score
 if ($has_started) {
     if (getGameWinner($this_gsis_id) == $this_winner) {
         if ($has_finished) {
             $result_str = "correct";
             //echo "<span style=\"color:green;\">Correct</span>";
             // add point to picks table for user and gsis_id
             addPoint($db, $pick['pick_id'], 1, false);
             updatePoints($db, $this_user_id, $this_group_id, $this_season_year, $this_season_type, $this_week, false);
         } else {
             $result_str = "winning";
             //echo "<span style=\"color:green;\">Winning</span>";
         }
     } elseif (getGameWinner($this_gsis_id) == "tied") {
         $result_str = "tied";
         //echo "<span style=\"color:blue;\">Tied</span>";
     } else {
         if ($this_finished == "t") {
             $result_str = "incorrect";
             //echo "<span style=\"color:red;\">Loser</span>";
             addPoint($db, $pick['pick_id'], 0, false);
             updatePoints($db, $this_user_id, $this_group_id, $this_season_year, $this_season_type, $this_week, false);
         } else {
             $result_str = "losing";
             //echo "<span style=\"color:red;\">Losing</span>";
         }
     }
 } else {
     $result_str = "not started";
Example #2
0
function reconcileWeeklyPoints($db, $group_id, $season_year, $season_type, $week)
{
    // get users from mysql db that belong to the group
    $users = getUsers($db, $group_id);
    foreach ($users as $user) {
        $this_user_id = $user['user_id'];
        echo "<p>User " . $user['user_name'] . "(id {$this_user_id})</p>";
        // Get all of the users picks for the season year type week
        //$pick_result = mysqli_query($db, "SELECT * FROM picks WHERE user_id='$this_user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'");
        //$sql = "SELECT * FROM picks WHERE user_id='$this_user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
        $sql = "SELECT picks.pick_id, picks.game_id, picks.winner, points.reconciled\n" . "FROM picks \n" . "LEFT JOIN points \n" . "ON points.user_id=picks.user_id\n" . "WHERE picks.user_id='{$this_user_id}' AND picks.group_id='{$group_id}' AND picks.season_year='{$season_year}' AND picks.season_type='{$season_type}' AND picks.week='{$week}' AND points.reconciled is NULL";
        echo "<p>{$sql}</p>";
        $pick_result = mysqli_query($db, $sql) or die(mysqli_error($db));
        while ($user_pick = mysqli_fetch_array($pick_result)) {
            $user_picks[] = $user_pick;
        }
        // Performing SQL query for all games
        $query = "SELECT * FROM game WHERE season_year='{$season_year}' AND season_type='{$season_type}' AND week='{$week}'";
        $result = pg_query($query) or die('Query failed: ' . pg_last_error());
        while ($games = pg_fetch_array($result, null, PGSQL_ASSOC)) {
            extract($games, EXTR_PREFIX_ALL, "this");
            //load all game variables from db_array
            if (strtotime($this_start_time) < time()) {
                $has_started = true;
            } else {
                $has_started = false;
            }
            if ($this_finished == "t") {
                $has_finished = true;
            } else {
                $has_finished = false;
            }
            if (isset($user_picks)) {
                //at least some picks in db
                foreach ($user_picks as $pick) {
                    if ($pick['game_id'] == $this_gsis_id) {
                        //user has already picked game so set winner
                        $this_winner = $pick['winner'];
                        // pass this_winner to a script that checks the actual_winner for the jesus_id in the nfl_db
                        // if it returns true, print correct or add to score,,,,
                        // if false, print LOSER and don't ++score
                        if (strtotime($this_start_time) < time()) {
                            //game started
                            if (getGameWinner($this_gsis_id) == $this_winner) {
                                if ($this_finished == "t") {
                                    //echo "<span style=\"color:green;\">Correct</span>";
                                    // add point to picks table for user and gsis_id
                                    addPoint($db, $pick['pick_id'], 1, true);
                                    reconcilePoints($db, $this_user_id, $group_id, $this_season_year, $this_season_type, $this_week, true);
                                }
                            } else {
                                if ($this_finished == "t") {
                                    //echo "<span style=\"color:red;\">Loser</span>";
                                    addPoint($db, $pick['pick_id'], 0, true);
                                    reconcilePoints($db, $this_user_id, $group_id, $this_season_year, $this_season_type, $this_week, true);
                                }
                            }
                        }
                    }
                }
                //End Foreach pick
            }
        }
        //End While
    }
    //End User Foreach
}