-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathscores.php
112 lines (108 loc) · 4.73 KB
/
scores.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
<?php
require('includes/application_top.php');
require('includes/classes/team.php');
if (!$user->is_admin) {
header('Location: ./');
exit;
}
if ($_POST['action'] == 'Update') {
foreach($_POST['game'] as $game) {
$homeScore = ((strlen($game['homeScore']) > 0) ? $game['homeScore'] : 'NULL');
$visitorScore = ((strlen($game['visitorScore']) > 0) ? $game['visitorScore'] : 'NULL');
$overtime = ((!empty($game['OT'])) ? '1' : '0');
$sql = "update " . DB_PREFIX . "schedule ";
$sql .= "set homeScore = " . $homeScore . ", visitorScore = " . $visitorScore . ", overtime = " . $overtime . " ";
$sql .= "where gameID = " . $game['gameID'];
$mysqli->query($sql) or die('Error updating score: ' . $mysqli->error);
}
header('Location: ./');
exit;
}
$week = (int)$_GET['week'];
if (empty($week)) {
//get current week
$week = (int)getCurrentWeek();
}
include('includes/header.php');
?>
<h1>Enter Scores - Week <?php echo $week; ?></h1>
<?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="scores.php?week=' . $row['weekNum'] . '">' . $row['weekNum'] . '</a>';
} else {
$weekNav .= $row['weekNum'];
}
$i++;
}
$query->free;
$weekNav .= '</div>' . "\n";
echo $weekNav;
?>
<script type="text/javascript">
function getScores(weekNum) {
$.get("getHtmlScores.php", {week: weekNum}, function(data) {
for(var item in data) {
visitorScoreField = document.getElementById('game[' + data[item].gameID + '][visitorScore]');
homeScoreField = document.getElementById('game[' + data[item].gameID + '][homeScore]');
OTField = document.getElementById('game[' + data[item].gameID + '][OT]');
if (visitorScoreField.value !== data[item].visitorScore) {
visitorScoreField.value = data[item].visitorScore;
visitorScoreField.className="fieldLoaded";
}
if (homeScoreField.value !== data[item].homeScore) {
homeScoreField.value = data[item].homeScore;
homeScoreField.className="fieldLoaded";
}
if (data[item].overtime == '1') {
OTField.checked = true;
}
}
},'json');
}
</script>
<p><input type="button" value="Load Scores" onclick="return getScores(<?php echo $week; ?>);" class="btn btn-info" /></p>
<form id="scoresForm" name="scoresForm" action="scores.php" method="post">
<input type="hidden" name="week" value="<?php echo $week; ?>" />
<div class="table-responsive">
<?php
$sql = "select s.*, ht.city, ht.team, ht.displayName, vt.city, vt.team, vt.displayName ";
$sql .= "from " . DB_PREFIX . "schedule s ";
$sql .= "inner join " . DB_PREFIX . "teams ht on s.homeID = ht.teamID ";
$sql .= "inner join " . DB_PREFIX . "teams vt on s.visitorID = vt.teamID ";
$sql .= "where weekNum = " . $week . " ";
$sql .= "order by gameTimeEastern";
$query = $mysqli->query($sql);
if ($query->num_rows > 0) {
echo '<table class="table table-striped">' . "\n";
echo ' <tr><th colspan="6" align="left">Week ' . $week . '</th></tr>' . "\n";
$i = 0;
while ($row = $query->fetch_assoc()) {
$homeTeam = new team($row['homeID']);
$visitorTeam = new team($row['visitorID']);
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '>' . "\n";
echo ' <td><input type="hidden" name="game[' . $row['gameID'] . '][gameID]" value="' . $row['gameID'] . '" />' . date('D n/j g:i a', strtotime($row['gameTimeEastern'])) . ' ET</td>' . "\n";
echo ' <td align="right"><input type="hidden" name="gameID[' . strtolower($visitorTeam->team) . ']" value="' . $row['gameID'] . '" />' . $visitorTeam->teamName . '</td>' . "\n";
echo ' <td><input type="text" name="game[' . $row['gameID'] . '][visitorScore]" id="game[' . $row['gameID'] . '][visitorScore]" value="' . $row['visitorScore'] . '" size="3" /></td>' . "\n";
echo ' <td align="right"><input type="hidden" name="gameID[' . strtolower($homeTeam->team) . ']" value="' . $row['gameID'] . '" />at ' . $homeTeam->teamName . '</td>' . "\n";
echo ' <td><input type="text" name="game[' . $row['gameID'] . '][homeScore]" id="game[' . $row['gameID'] . '][homeScore]" value="' . $row['homeScore'] . '" size="3" /></td>' . "\n";
echo ' <td>OT <input type="checkbox" name="game[' . $row['gameID'] . '][OT]" id="game[' . $row['gameID'] . '][OT]" value="1"' . (($row['overtime']) ? ' checked="checked"' : '') . '" /></td>' . "\n";
echo ' </tr>' . "\n";
$i++;
}
echo '</table>' . "\n";
}
$query->free;
?>
</div>
<input type="submit" name="action" value="Update" class="btn btn-info" />
</form>
<?php
include('includes/footer.php');