-
Notifications
You must be signed in to change notification settings - Fork 0
/
picks.php
267 lines (234 loc) · 12.7 KB
/
picks.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php // Main Pick Selection Page
//--LOAD SITE HEADER
// Load Databases and Common functions
require("mysql.php");
include 'common.php';
include("functions.php"); //Site Functions
//try to guess the current week, function in get_winners
guessCurrentWeek();
include("header.php");
//--END SITE HEADER
//Turn off timer for testing
if($this_group_id == 1) {
$timer_on = FALSE;
} else {
$timer_on = TRUE;
}
// Performing SQL query for correct week
$query = "SELECT * FROM game WHERE season_year='$this_season_year' AND season_type='$this_season_type' AND week='$this_week' ORDER BY start_time ASC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
//Cross-check user's group seasons with this_season
$group_result = mysqli_query($db, "SELECT * FROM g_seasons WHERE group_id='$this_group_id' AND season_year='$this_season_year' AND season_type='$this_season_type'");
if(mysqli_num_rows($group_result) > 0) {
//echo "The user is authorized to pick.";
$can_pick = TRUE;
// Get all of the users picks
$pick_result = mysqli_query($db, "SELECT * FROM picks WHERE user_id='$this_user_id' AND group_id='$this_group_id' AND season_year='$this_season_year' AND season_type='$this_season_type' AND week='$this_week'");
while($user_pick = mysqli_fetch_array($pick_result)) {
$user_picks[] = $user_pick;
}
} else {
echo "The user is NOT authorized to pick.";
$can_pick = FALSE;
}
//echo "<div class=\"row\">\n<div class=\"col-md-12\">\n<table class=\"pickTable\">\n";
//echo "<div>\n<div>\n<table class=\"pickTable\">\n";
if(!$timer_on) {
echo "<div class=\"alert alert-warning\" role=\"alert\">Game Start Timer Inactive</div>\n";
}
echo "<table class=\"pickTable\">\n";
while ($games = pg_fetch_array($result, null, PGSQL_ASSOC)) {
//print_r($games);
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($last_day_of_week) || $this_day_of_week != $last_day_of_week) { //print date row
echo "<tr>\n<td colspan=\"6\" class=\"pickDay\">";
echo date('l, F j Y',strtotime($this_start_time));
echo "</td>\n</tr>\n";
}
$last_day_of_week = $this_day_of_week; //set last day to this day for next iteration
$this_start_time_EST = date("g:iA T", strtotime($this_start_time));
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 diplay winner
$this_winner = $pick['winner'];
if($pick['score']) {
$this_score = $pick['score'];
} else {
$this_score = "";
}
//Selection formatting, remember to change the football.js pickTeam script to match
if($this_away_team == $this_winner) {
$away_style = "picked";
$home_style = "notPicked";
} elseif($this_home_team == $this_winner) {
$home_style = "picked";
$away_style = "notPicked";
}
// 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";
}
break;
} else {
$home_style = "notPicked";
$away_style = "notPicked";
$result_str = "not picked";
$this_score = "";
}
}
} else { //user has made no picks so default to black
$home_style = "notPicked";
$away_style = "notPicked";
$result_str = "not picked";
$this_score = "";
}
if(!$can_pick) {
$onclick_away_str = "onclick=\"alert('Cant pick.')\"";
$onclick_home_str = "onclick=\"alert('Cant pick.')\"";
} elseif($has_started && $timer_on) { // alert the user that it is too late
//$onclick_away_str = "data-toggle=\"popover\" data-trigger=\"focus\" data-content=\"It's too late to turn back now. The game has already started.\"";
//$onclick_home_str = "data-toggle=\"popover\" data-trigger=\"focus\" data-content=\"It's too late to turn back now. The game has already started.\"";
$onclick_away_str = "onclick=\"alert('Cant pick.')\"";
$onclick_home_str = "onclick=\"alert('Cant pick.')\"";
} else { // add pickTeam script to element
$onclick_away_str = "onclick=\"pickTeam(this,'".$this_user_id."','".$this_group_id."','".$this_gsis_id."','".$this_season_year."','".$this_season_type."','".$this_week."','".$this_away_team."')\"";
$onclick_home_str = "onclick=\"pickTeam(this,'".$this_user_id."','".$this_group_id."','".$this_gsis_id."','".$this_season_year."','".$this_season_type."','".$this_week."','".$this_home_team."')\"";
}
if(!isset($result_str)) {
$result_str = "not picked";
}
//$span_str =
switch($result_str) {
case "correct":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"ok","Correct Pick.","green");
break;
case "incorrect":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"remove", "Incorrect Pick.", "red");
break;
case "winning":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"arrow-up", "Your Pick is winning.", "green");
break;
case "losing":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"arrow-down","Your Pick is losing.", "red");
break;
case "tied":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"sort", "The teams are tied.", "blue");
break;
case "not started":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\"></span>",$this_gsis_id,"time", "The game hasn't started yet.", "green");
break;
case "not picked":
$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"%s\" style=\"color:%s;\" onmouseover=\"showTimer('%s_expiresIn')\" onmouseout=\"hideTimer('%s_expiresIn')\"></span>",$this_gsis_id,"exclamation-sign", "You haven't picked a winner for this game yet.", "orange",$this_gsis_id,$this_gsis_id);
//$result_span = sprintf("<span id=\"%s_glyph\" class=\"glyphicon glyphicon-%s\" aria-hidden=\"true\" data-toggle=\"tooltip\" data-placement=\"left\" style=\"color:%s;\" onmouseover=\"startTimer('%s_glyph','%s')\"></span>",$this_gsis_id,"exclamation-sign","orange",$this_gsis_id,date(DATE_RFC2822,strtotime($this_start_time)));
break;
}
//if(!isset($away_style)) { $away_style = 'notPicked'; }
//if(!isset($home_style)) { $home_style = 'notPicked'; }
//Game Row start
echo "<tr>\n"; //start new row in table
//Away Team Cell
echo "<td><div id=\"$this_gsis_id"."_away\" $onclick_away_str class=\"teamCell away $away_style\">$this_away_team</div></td>\n";
//Away Team Score
echo "<td>";
if($has_started) {
echo "<span class=\"badge\">$this_away_score</span>";
}
echo "</td>\n";
echo "<td>at</td>\n";
//Home Team Score
echo "<td>";
if($has_started) {
echo "<span class=\"badge\">$this_home_score</span>";
}
echo "</td>\n";
//Home Team Cell
echo "<td><div id=\"$this_gsis_id"."_home\" $onclick_home_str class=\"teamCell home $home_style\">$this_home_team</div></td>\n";
//Result Cell
echo "<td class=\"glyphCell\">";
if(isset($result_span) && $can_pick) {
echo $result_span;
}
echo "</td>\n";
//Game Date
//echo "<td>at</td>";
//echo "<td class=\"dayCell\">$this_day_of_week</td>";
//echo "<td class=\"timeCell\">";
//echo date('F j Y',strtotime($this_start_time));
// echo "</td>";
echo "<td id=\"$this_gsis_id"."_time\" class=\"dayCell\" onclick=\"showTimer('".$this_gsis_id."_expiresIn')\">at $this_start_time_EST\n";
if(!$has_started) echo "<div id=\"".$this_gsis_id."_expiresIn\" class=\"expiresIn\" style=\"display: none;\">Game Locks Out in <span id=\"".$this_gsis_id."-countdown\"><img src=\"timer.png\" onload=\"startTimer('".$this_gsis_id."-countdown','".date(DATE_RFC2822,strtotime($this_start_time))."')\"></span></div></td><td colspan=\"2\">\n";
echo "</td>\n";
//Pick Result
echo "<td id=\"$this_gsis_id"."_result\" class=\"resultCell\">";
//if(!$has_started) echo "<img src=\"timer.png\" onload=\"startTimer('".$this_gsis_id."_glyph','".date(DATE_RFC2822,strtotime($this_start_time))."','You haven't picked a winner for this game yet.')\">\n";
//if(!$has_started) echo "<div id=\"".$this_gsis_id."_expiresIn\" class=\"alert alert-warning expiresIn\" role=\"alert\"><small>Expires in <span id=\"".$this_gsis_id."-countdown\"><img src=\"timer.png\" onload=\"startTimer('".$this_gsis_id."-countdown','".date(DATE_RFC2822,strtotime($this_start_time))."')\"></span></small></div></td><td colspan=\"2\"></td></tr>\n";
//if(!$has_started) echo "<div id=\"".$this_gsis_id."_expiresIn\" class=\"alert alert-warning expiresIn\" role=\"alert\"><small>Expires in <span id=\"".$this_gsis_id."-countdown\"><img src=\"timer.png\" onload=\"startTimer('".$this_gsis_id."-countdown','".date(DATE_RFC2822,strtotime($this_start_time))."')\"></span></small></div></td><td colspan=\"2\"></td></tr>\n";
echo "</td>\n";
echo "</tr>\n";
//if(!$has_started) echo "<tr><td colspan=\"5\"><div id=\"".$this_gsis_id."-expiresIn\" class=\"alert alert-warning expiresIn\" role=\"alert\"><small>Expires in <span id=\"".$this_gsis_id."-countdown\"><img src=\"timer.png\" onload=\"startTimer('".$this_gsis_id."-countdown','".date(DATE_RFC2822,strtotime($this_start_time))."')\"></span></small></div></td><td colspan=\"2\"></td></tr>\n";
} //End While
echo "</table>\n";
echo "<form class=\"form-inline\">\n";
echo "<div class=\"input-group input-group-sm\">
<span class=\"input-group-addon\" id=\"basic-addon1\">Score of $this_away_team at $this_home_team</span>
<input type=\"text\" id=\"score\" class=\"form-control\" name=\"score\" value=\"$this_score\" size=\"1\" />";
if(isset($this_gsis_id)) {
if($has_started && $timer_on) {
$current_score = $this_home_score + $this_away_score;
$score_diff = $this_score - $current_score;
echo "<span class=\"input-group-addon\" id=\"basic-addon2\">You are off by $score_diff points.</span>";
} else {
echo "<span class=\"input-group-btn\">
<button class=\"btn btn-primary\" type=\"button\" onclick=\"enterScore('$this_user_id','$this_group_id','$this_gsis_id','$this_season_year','$this_season_type','$this_week',score.value)\">Submit</button>
</span>";
}
echo "</div></form>";
} else {
echo "<p>No games this week.</p>";
}
//echo "</div>\n</div>";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($db_nfl);
//--Main Footer
include 'footer.php';
?>