-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscouter.php
357 lines (306 loc) · 11.9 KB
/
scouter.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
// 1) Include DB connection.
include 'php/database_connection.php';
// 2) Get distinct event names from active_event.
$eventQuery = "SELECT DISTINCT event_name FROM active_event";
$eventStmt = $pdo->prepare($eventQuery);
$eventStmt->execute();
$events = $eventStmt->fetchAll(PDO::FETCH_ASSOC);
// 3) Get last event + next match.
$activeventQuery = "
SELECT
event_name,
match_no + 1 AS match_number
FROM scouting_submissions
WHERE event_name = (
SELECT event_name
FROM scouting_submissions
ORDER BY id DESC
LIMIT 1
)
ORDER BY match_no DESC
LIMIT 1
";
$activeventStmt = $pdo->prepare($activeventQuery);
$activeventStmt->execute();
// Option A: fetch() since we're only expecting one row
$row = $activeventStmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
$activeEventName = $row['event_name'];
$activeMatch = $row['match_number'];
// Do something with $activeEventName and $activeMatch...
//echo "Next Match: $activeMatch<br>";
} else {
// If there's no row returned, handle the case
//echo "No row found for the last event!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>the Scout Owl</title>
<style>
/* Responsive design: Adjust form gap for screens narrower than 330px */
@media (max-width: 800px) {
form {
gap: 8px; /* Reduces the gap between form elements for small screens */
}
}
@font-face {
font-family: 'Roboto';
src: url('/../stat_goblin/fonts/roboto/Roboto-Regular.ttf') format('ttf'),
url('/../stat_goblin/fonts/roboto/Roboto-Regular.ttf') format('ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Griffy';
src: url('/../stat_goblin/fonts/Griffy/Griffy-Regular.ttf') format('ttf'),
url('/../stat_goblin/fonts/Griffy/Griffy-Regular.ttf') format('ttf');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Comfortaa';
src: url('/../stat_goblin/fonts/Comfortaa/Comfortaa-VariableFont_wght.ttf') format('ttf'),
url('/../stat_goblin/fonts/Comfortaa/Comfortaa-VariableFont_wght.ttf') format('ttf');
font-weight: normal;
font-style: normal;
}
/* Global Styles */
body, html {
font-family: 'Comfortaa', sans-serif;
margin: 0;
padding: 0;
background: #222;
color: #eee;
line-height: 1.5;
text-align: center;
}
/* Styling for the main heading (h1) */
h1 {
text-align: left; /* Aligns the text to the left */
font-size: 1.2rem; /* Sets the font size */
margin-top: -10px; /* Adjusts the top margin */
margin-left: 12px; /* Adds left margin for positioning */
}
/* Styling for the form element */
form {
padding: 10px; /* Adds padding inside the form */
display: flex; /* Uses flexbox layout */
flex-direction: column; /* Arranges children in a column */
gap: 10px; /* Adds space between form elements */
}
/* Styling for form labels */
label {
font-size: 0.9rem; /* Sets the font size */
margin-bottom: 5px; /* Adds space below the label */
}
/* Styling for select elements and buttons */
select, button {
font-size: 0.9rem; /* Sets the font size */
padding: 10px; /* Adds padding inside the elements */
border-radius: 5px; /* Rounds the corners */
width: 100%; /* Sets the width to 100% of the container */
box-sizing: border-box; /* Includes padding and border in the element's total width and height */
}
/* Additional styling for buttons */
button {
padding: 1.5rem; /* Increases padding for larger clickable area */
cursor: pointer; /* Changes cursor to pointer on hover */
}
/* Styling for the submit button */
.submit-button {
background-color: #FFF; /* Sets background color to white */
color: #111; /* Sets text color to dark */
font-size: 1rem; /* Sets font size */
border: 1px solid #fff; /* Adds a white border */
}
/* Hover effect for the submit button */
.submit-button:hover {
background-color: #111; /* Changes background color on hover */
color: #FFF; /* Changes text color on hover */
border: 1px solid #fff; /* Maintains border on hover */
}
/* Styling for the logo image */
.logo {
width: 400px;
display: block;
margin: 0 auto 1rem auto;
}
/* Class to hide elements */
.hidden {
display: none; /* Hides the element */
}
/* Focus state for select elements */
select:focus {
outline: none; /* Removes default outline */
border-color: #ccc; /* Changes border color on focus */
}
.containerOuter {
background-color: #333;
border-bottom: 1px solid #444;
width: 100%;
padding: 1rem;
box-sizing: border-box;
}
.container {
max-width: 800px;
margin: auto;
}
</style>
<link rel="stylesheet" href="css/select.css">
</head>
<body>
<div class="containerOuter">
<!-- <?php
echo "Event Name: $activeEventName<br>";
echo "Next Match: $activeMatch<br>";
?>-->
<div class="container">
<a href="."><img src="images/thescoutowl.png" class="logo"> </a>
<form id="scoutingForm">
<label for="eventDropdown">Event:</label>
<select id="eventDropdown" name="event" required>
<option value="">Select Event</option>
<?php foreach ($events as $event):?>
<option value="<?= htmlspecialchars($event['event_name'])?>"><?= htmlspecialchars($event['event_name'])?></option>
<?php endforeach;?>
</select>
<label for="matchNumberDropdown">Match Number:</label>
<select id="matchNumberDropdown" name="match_number" required>
<option value="">Select Match Number</option>
</select>
<label for="robotDropdown">Robot:</label>
<select id="robotDropdown" name="robot" required>
<option value="">Select Robot</option>
</select>
<input type="text" id="allianceDisplay" class="hidden" name="alliance" readonly>
<button type="button" class="submit-button" id="submitForm">Submit</button>
</form>
<script src="js/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function() {
// 1) Keep a reference to these values
let activeEventName = "<?php echo $activeEventName; ?>";
let activeMatch = "<?php echo $activeMatch; ?>";
// 2) On change for #eventDropdown
$('#eventDropdown').change(function() {
var eventName = $(this).val();
if (eventName) {
console.log('Selected Event:', eventName);
$.ajax({
type: 'POST',
url: 'php/fetch_data.php',
data: {
event: eventName,
action: 'fetchMatches'
},
success: function(response) {
console.log('AJAX Response for fetchMatches:', response);
$('#matchNumberDropdown').html(response); // Populate matchNumberDropdown
$('#robotDropdown').html('<option value="">Select Robot</option>');
$('#allianceDisplay').val('');
// ***** Now that matchNumberDropdown is populated, set it here! *****
if (activeMatch) {
$('#matchNumberDropdown').val(activeMatch).trigger('change');
}
},
error: function(xhr, status, error) {
console.error('AJAX Error in fetchMatches:', status, error);
}
});
} else {
$('#matchNumberDropdown').html('<option value="">Select Match Number</option>');
$('#robotDropdown').html('<option value="">Select Robot</option>');
$('#allianceDisplay').val('');
}
});
// 3) On change for #matchNumberDropdown
$('#matchNumberDropdown').change(function() {
var eventName = $('#eventDropdown').val();
var matchNumber = $(this).val();
if (eventName && matchNumber) {
console.log('Selected Event:', eventName);
console.log('Selected Match Number:', matchNumber);
$.ajax({
type: 'POST',
url: 'php/fetch_data.php',
data: {
event: eventName,
match_number: matchNumber,
action: 'fetchRobots'
},
success: function(response) {
console.log('AJAX Response for fetchRobots:', response);
$('#robotDropdown').html(response);
$('#allianceDisplay').val('');
},
error: function(xhr, status, error) {
console.error('AJAX Error in fetchRobots:', status, error);
}
});
} else {
$('#robotDropdown').html('<option value="">Select Robot</option>');
$('#allianceDisplay').val('');
}
});
// 4) On change for #robotDropdown
$('#robotDropdown').change(function() {
var eventName = $('#eventDropdown').val();
var matchNumber = $('#matchNumberDropdown').val();
var robot = $(this).val();
if (eventName && matchNumber && robot) {
console.log('Selected Robot:', robot);
$.ajax({
type: 'POST',
url: 'php/fetch_data.php',
data: {
event: eventName,
match_number: matchNumber,
robot: robot,
action: 'fetchAlliance'
},
success: function(response) {
console.log('AJAX Response for fetchAlliance:', response);
$('#allianceDisplay').val(response);
if (response == 'Red') {
$('#robotDropdown').css('background-color', '#C0392B');
} else {
$('#robotDropdown').css('background-color', '#2C3E50');
}
},
error: function(xhr, status, error) {
console.error('AJAX Error in fetchAlliance:', status, error);
}
});
} else {
$('#allianceDisplay').val('');
}
});
// 5) On form submit
$('#submitForm').click(function() {
var event = $('#eventDropdown').val();
var matchNumber = $('#matchNumberDropdown').val();
var robot = $('#robotDropdown').val();
var alliance = $('#allianceDisplay').val();
if (event && matchNumber && robot && alliance) {
window.location.href = `scouter/index.php?event=${encodeURIComponent(event)}&match=${encodeURIComponent(matchNumber)}&robot=${encodeURIComponent(robot)}&alliance=${encodeURIComponent(alliance)}`;
} else {
alert('Please fill all fields.');
}
});
// 6) Finally: set the #eventDropdown if we have activeEventName
// That will trigger the .change(), which will fetch the matches,
// which will then (in success callback) set #matchNumberDropdown.
if (activeEventName) {
$('#eventDropdown').val(activeEventName).trigger('change');
}
});
</script>
</div>
</div>
</body>
</html>