function calculateStats()
{
    global $mysqli, $weekStats, $playerTotals, $possibleScoreTotal;
    //get latest week with all entered scores
    $lastCompletedWeek = getLastCompletedWeek();
    //loop through weeks
    for ($week = 1; $week <= $lastCompletedWeek; $week++) {
        //get array of games
        $games = array();
        $sql = "select * from " . DB_PREFIX . "schedule where weekNum = " . $week . " order by gameTimeEastern, gameID";
        $query = $mysqli->query($sql);
        while ($row = $query->fetch_assoc()) {
            $games[$row['gameID']]['gameID'] = $row['gameID'];
            $games[$row['gameID']]['homeID'] = $row['homeID'];
            $games[$row['gameID']]['visitorID'] = $row['visitorID'];
            if ((int) $row['homeScore'] > (int) $row['visitorScore']) {
                $games[$row['gameID']]['winnerID'] = $row['homeID'];
            }
            if ((int) $row['visitorScore'] > (int) $row['homeScore']) {
                $games[$row['gameID']]['winnerID'] = $row['visitorID'];
            }
        }
        $query->free;
        //get array of player picks
        $playerPicks = array();
        $playerWeeklyTotals = array();
        $sql = "select p.userID, p.gameID, p.pickID, p.points, u.firstname, u.lastname, u.userName ";
        $sql .= "from " . DB_PREFIX . "picks p ";
        $sql .= "inner join " . DB_PREFIX . "users u on p.userID = u.userID ";
        $sql .= "inner join " . DB_PREFIX . "schedule s on p.gameID = s.gameID ";
        $sql .= "where s.weekNum = " . $week . " and u.userName <> 'admin' ";
        $sql .= "order by u.lastname, u.firstname, s.gameTimeEastern";
        $query = $mysqli->query($sql);
        while ($row = $query->fetch_assoc()) {
            $playerPicks[$row['userID'] . $row['gameID']] = $row['pickID'];
            $playerWeeklyTotals[$row['userID']][week] = $week;
            $playerTotals[$row['userID']][wins] += 0;
            $playerTotals[$row['userID']][name] = $row['firstname'] . ' ' . $row['lastname'];
            $playerTotals[$row['userID']][userName] = $row['userName'];
            if (!empty($games[$row['gameID']]['winnerID']) && $row['pickID'] == $games[$row['gameID']]['winnerID']) {
                //player has picked the winning team
                $playerWeeklyTotals[$row['userID']][score] += 1;
                $playerTotals[$row['userID']][score] += 1;
            } else {
                $playerWeeklyTotals[$row['userID']][score] += 0;
                $playerTotals[$row['userID']][score] += 0;
            }
        }
        $query->free;
        //get winners & highest score for current week
        $highestScore = 0;
        arsort($playerWeeklyTotals);
        foreach ($playerWeeklyTotals as $playerID => $stats) {
            if ($stats[score] > $highestScore) {
                $highestScore = $stats[score];
            }
            if ($stats[score] < $highestScore) {
                break;
            }
            $weekStats[$week][winners][] = $playerID;
            $playerTotals[$playerID][wins] += 1;
        }
        $weekStats[$week][highestScore] = $highestScore;
        $weekStats[$week][possibleScore] = getGameTotal($week);
        $possibleScoreTotal += $weekStats[$week][possibleScore];
    }
}
Exemple #2
0
 $sql .= "group by s.weekNum ";
 $sql .= "order by s.weekNum;";
 $query = mysql_query($sql);
 $i = 0;
 $rowclass = '';
 while ($result = mysql_fetch_array($query)) {
     $rowclass = $i % 2 == 0 ? ' class="altrow"' : '';
     echo '		<tr' . $rowclass . '>' . "\n";
     echo '			<td>Week ' . $result['weekNum'] . '</td>' . "\n";
     echo '			<td>' . date('n/j g:i a', strtotime($result['firstGameTime'])) . '</td>' . "\n";
     echo '			<td>' . date('n/j g:i a', strtotime($result['cutoffTime'])) . '</td>' . "\n";
     if ($result['expired']) {
         //if week is expired, show score (if scores are entered)
         if ($lastCompletedWeek >= (int) $result['weekNum']) {
             //scores entered, show score
             $weekTotal = getGameTotal($result['weekNum']);
             //get player score
             $userScore = getUserScore($result['weekNum'], $user->userID);
             echo '			<td class="lighter" style="color: #000;">Score: ' . $userScore . '/' . $weekTotal . ' (' . number_format($userScore / $weekTotal * 100, 2) . '%)</td>' . "\n";
         } else {
             //scores not entered, show ???
             echo '			<td class="lighter" style="color: #000;">week closed, scores not entered.</td>' . "\n";
         }
     } else {
         //week is not expired yet, check to see if all picks have been entered
         $picks = getUserPicks($result['weekNum'], $user->userID);
         if (sizeof($picks) < (int) $result['gamesTotal']) {
             //not all picks were entered
             $tmpStyle = '';
             if ((int) $currentWeek == (int) $result['weekNum']) {
                 //only show in red if this is the current week
}
if ($_POST['action'] == 'Select' && isset($_POST['cannedMsg'])) {
    $cannedMsg = $_POST['cannedMsg'];
    $sql = "select * from " . DB_PREFIX . "email_templates where email_template_key = '" . $cannedMsg . "'";
    $query = $mysqli->query($sql);
    $row = $query->fetch_assoc();
    $subjectTemplate = $row['subject'];
    $messageTemplate = $row['message'];
    //replace variables
    $template_vars = array('{week}', '{first_game}', '{site_url}', '{rules_url}', '{winners}', '{previousWeek}', '{winningScore}', '{possibleScore}', '{currentLeaders}', '{bestPickRatios}');
    $replacement_values = array($week, date('l F j, g:i a', strtotime($firstGameTime)), SITE_URL, SITE_URL . 'rules.php', $winners, $prevWeek, $weekStats[$prevWeek][highestScore], getGameTotal($prevWeek), $currentLeaders, $bestPickRatios);
    $subject = stripslashes(str_replace($template_vars, $replacement_values, $subjectTemplate));
    $message = stripslashes(str_replace($template_vars, $replacement_values, $messageTemplate));
}
if ($_POST['action'] == 'Send Message') {
    $totalGames = getGameTotal($week);
    //get users to send message to
    if ($_POST['cannedMsg'] == 'WEEKLY_PICKS_REMINDER') {
        //select only users missing picks for the current week
        $sql = "select u.firstname, u.email,";
        $sql .= "(select count(p.pickID) from nflp_picks p inner join nflp_schedule s on p.gameID = s.gameID where userID = u.userID and s.weekNum = " . $week . ") as userPicks ";
        $sql .= "from " . DB_PREFIX . "users u ";
        $sql .= "where u.`status` = 1 and u.userName <> 'admin' ";
        $sql .= "group by u.firstname, u.email ";
        $sql .= "having userPicks < " . $totalGames;
    } else {
        //select all users
        $sql = "select firstname, email from " . DB_PREFIX . "users where `status` = 1 and userName <> 'admin'";
    }
    $query = $mysqli->query($sql);
    if ($query->num_rows > 0) {
Exemple #4
0
 $sql .= "order by s.weekNum;";
 $query = $mysqli->query($sql);
 $i = 0;
 $rowclass = '';
 while ($row = $query->fetch_assoc()) {
     //$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
     echo '		<div class="row-week">' . "\n";
     echo '			<p><b>Week ' . $row['weekNum'] . '</b><br />' . "\n";
     echo '			First game: ' . date('n/j g:i a', strtotime($row['firstGameTime'])) . '<br />' . "\n";
     echo '			Cutoff: ' . date('n/j g:i a', strtotime($row['cutoffTime'])) . '</p>' . "\n";
     //echo '		</tr>'."\n";
     if ($row['expired']) {
         //if week is expired, show score (if scores are entered)
         if ($lastCompletedWeek >= (int) $row['weekNum']) {
             //scores entered, show score
             $weekTotal = getGameTotal($row['weekNum']);
             //get player score
             $userScore = getUserScore($row['weekNum'], $user->userID);
             echo '			<div class="bg-info"><b>Score: ' . $userScore . '/' . $weekTotal . ' (' . number_format($userScore / $weekTotal * 100, 2) . '%)</b><br /><a href="results.php?week=' . $row['weekNum'] . '">See Results &raquo;</a></div>' . "\n";
         } else {
             //scores not entered, show ???
             echo '			<div class="bg-info">Week is closed,</b> but scores have not yet been entered.<br /><a href="results.php?week=' . $row['weekNum'] . '">See Results &raquo;</a></div>' . "\n";
         }
     } else {
         //week is not expired yet, check to see if all picks have been entered
         $picks = getUserPicks($row['weekNum'], $user->userID);
         if (sizeof($picks) < (int) $row['gamesTotal']) {
             //not all picks were entered
             $tmpStyle = '';
             if ((int) $currentWeek == (int) $row['weekNum']) {
                 //only show in red if this is the current week