-
Notifications
You must be signed in to change notification settings - Fork 57
/
results.php
220 lines (209 loc) · 7.13 KB
/
results.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
require('includes/application_top.php');
$week = (int)$_GET['week'];
if (empty($week)) {
//get current week
$week = (int)getCurrentWeek();
}
$cutoffDateTime = getCutoffDateTime($week);
$weekExpired = ((date("U", time()+(SERVER_TIMEZONE_OFFSET * 3600)) > strtotime($cutoffDateTime)) ? 1 : 0);
include('includes/header.php');
//include('includes/column_right.php');
//display week nav
$sql = "select distinct weekNum from " . DB_PREFIX . "schedule order by weekNum;";
$query = $mysqli->query($sql);
$weekNav = '<div class="navbar3"><b>Go to week:</b> ';
$i = 0;
while ($row = $query->fetch_assoc()) {
if ($i > 0) $weekNav .= ' | ';
if ($week !== (int)$row['weekNum']) {
$weekNav .= '<a href="results.php?week=' . $row['weekNum'] . '">' . $row['weekNum'] . '</a>';
} else {
$weekNav .= $row['weekNum'];
}
$i++;
}
$query->free;
$weekNav .= '</div>' . "\n";
echo $weekNav;
//get array of games
$allScoresIn = true;
$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'];
$homeScore = (int)$row['homeScore'];
$visitorScore = (int)$row['visitorScore'];
if ($homeScore + $visitorScore > 0) {
if ($homeScore > $visitorScore) {
$games[$row['gameID']]['winnerID'] = $row['homeID'];
}
if ($visitorScore > $homeScore) {
$games[$row['gameID']]['winnerID'] = $row['visitorID'];
}
} else {
$games[$row['gameID']]['winnerID'] = '';
$allScoresIn = false;
}
}
$query->close();
//get array of player picks
$playerPicks = array();
$playerTotals = array();
$sql = "select p.userID, p.gameID, p.pickID, p.points ";
$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 p.userID, s.gameTimeEastern, s.gameID";
$query = $mysqli->query($sql);
$i = 0;
while ($row = $query->fetch_assoc()) {
$playerPicks[$row['userID']][$row['gameID']] = $row['pickID'];
if (!empty($games[$row['gameID']]['winnerID']) && $row['pickID'] == $games[$row['gameID']]['winnerID']) {
//player has picked the winning team
$playerTotals[$row['userID']] += 1;
} else {
$playerTotals[$row['userID']] += 0;
}
$i++;
}
$query->free;
?>
<script type="text/javascript">
$(document).ready(function(){
$(".table tr").mouseover(function() {
$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");
});
$(".table tr").click(function() {
if ($(this).attr('class').indexOf('overPerm') > -1) {
$(this).removeClass("overPerm");
} else {
$(this).addClass("overPerm");
}
});
//$( "#table1" ).draggable({ containment: "#table1-container", scroll: false })
});
</script>
<style type="text/css">
.pickTD { width: 24px; font-size: 9px; text-align: center; }
</style>
<h1>Results - Week <?php echo $week; ?></h1>
<?php
if (!$allScoresIn) {
echo '<p style="font-weight: bold; color: #DBA400;">* Not all scores have been updated for week ' . $week . ' yet.</p>' . "\n";
}
$hideMyPicks = hidePicks($user->userID, $week);
if ($hideMyPicks && !$weekExpired) {
echo '<p style="font-weight: bold; color: green;">* Your picks are currently hidden to other users.</p>' . "\n";
}
if (sizeof($playerTotals) > 0) {
?>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr><th align="left">Player</th><th colspan="<?php echo sizeof($games); ?>">Week <?php echo $week; ?></th><th align="left">Score</th></tr>
</thead>
<tbody>
<?php
$i = 0;
arsort($playerTotals);
foreach($playerTotals as $userID => $totalCorrect) {
$hidePicks = hidePicks($userID, $week);
if ($i == 0) {
$topScore = $totalCorrect;
$winners[] = $userID;
} else if ($totalCorrect == $topScore) {
$winners[] = $userID;
}
$tmpUser = $login->get_user_by_id($userID);
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
//echo ' <tr' . $rowclass . '>' . "\n";
echo ' <tr>' . "\n";
switch (USER_NAMES_DISPLAY) {
case 1:
echo ' <td>' . trim($tmpUser->firstname . ' ' . $tmpUser->lastname) . '</td>' . "\n";
break;
case 2:
echo ' <td>' . trim($tmpUser->userName) . '</td>' . "\n";
break;
default: //3
echo ' <td><abbr title="' . trim($tmpUser->firstname . ' ' . $tmpUser->lastname) . '">' . trim($tmpUser->userName) . '</abbr></td>' . "\n";
break;
}
//loop through all games
foreach($games as $game) {
$pick = '';
$pick = $playerPicks[$userID][$game['gameID']];
if (!empty($game['winnerID'])) {
//score has been entered
if ($playerPicks[$userID][$game['gameID']] == $game['winnerID']) {
$pick = '<span class="winner">' . $pick . '</span>';
}
} else {
//mask pick if pick and week is not locked and user has opted to hide their picks
$gameIsLocked = gameIsLocked($game['gameID']);
if (!$gameIsLocked && !$weekExpired && $hidePicks && (int)$userID !== (int)$user->userID) {
$pick = '***';
}
}
echo ' <td class="pickTD">' . $pick . '</td>' . "\n";
}
echo ' <td nowrap><b>' . $totalCorrect . '/' . sizeof($games) . ' (' . number_format(($totalCorrect / sizeof($games)) * 100, 2) . '%)</b></td>' . "\n";
echo ' </tr>' . "\n";
$i++;
}
//if all scores entered, display winner
if ($allScoresIn) {
foreach($winners as $winnerID) {
$winner = $login->get_user_by_id($winnerID);
if (strlen($winnersHtml) > 0) $winnersHtml .= ', ';
switch (USER_NAMES_DISPLAY) {
case 1:
$winnersHtml .= trim($winner->firstname . ' ' . $winner->lastname);
break;
case 2:
$winnersHtml .= trim($winner->userName);
break;
default: //3
$winnersHtml .= '<abbr title="' . trim($winner->firstname . ' ' . $winner->lastname) . '">' . $winner->userName . '</abbr>';
break;
}
}
echo ' <tr><th colspan="' . (sizeof($games) + 2) . '" align="left">Winner: ' . $winnersHtml . '</th></tr>' . "\n";
}
?>
</tbody>
</table>
</div>
<?php
//display list of absent players
$sql = "select * from " . DB_PREFIX . "users where `status` = 1 and userID not in(" . implode(',', array_keys($playerTotals)) . ") and userName <> 'admin'";
$query = $mysqli->query($sql);
if ($query->num_rows > 0) {
$absentHtml = '<p><b>Absent Players:</b> ';
$i = 0;
while ($row = $query->fetch_assoc()) {
if ($i > 0) $absentHtml .= ', ';
switch (USER_NAMES_DISPLAY) {
case 1:
$absentHtml .= trim($row['firstname'] . ' ' . $row['lastname']);
break;
case 2:
$absentHtml .= $row['userName'];
break;
default: //3
$absentHtml .= '<abbr title="' . trim($row['firstname'] . ' ' . $row['lastname']) . '">' . $row['userName'] . '</abbr>';
break;
}
$i++;
}
echo $absentHtml;
}
$query->free;
}
include('includes/comments.php');
include('includes/footer.php');