-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
187 lines (171 loc) · 6.11 KB
/
index.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
<?php
if (!isSet($error)) {
$error = "";
}
$events = array();
$teams = array();
$inputTeam = false;
$inputEvent = false;
$input = "";
if (isSet($_GET["input"])) {
$input = $_GET["input"];
}
include_once "config.php";
$showHiddenData = isset($_GET["showHiddenData"]);
if (strtolower($input) == $hiddenDataKey && !$showHiddenData) {
$input = "";
$error = "Hidden data now shown.";
$showHiddenData = true;
} else if (strtolower($input) == $hiddenDataKey && $showHiddenData) {
$input = "";
$error = "Hidden data now hidden.";
$showHiddenData = false;
}
if ($error == "" && $input != "") {
$eventDirectories = glob('api/v1/*' , GLOB_ONLYDIR);
foreach($eventDirectories as $fileName) {
if (explode("/", $fileName)[2] == $input) {
$inputTeam = false;
$inputEvent = true;
$teams = glob('api/v1/'.$input.'/*', GLOB_ONLYDIR);
break;
}
$teamDirectories = glob($fileName."/*", GLOB_ONLYDIR);
foreach($teamDirectories as $teamFolder) {
if (explode("/",$teamFolder)[3] == $input) {
$inputEvent = false;
$inputTeam = true;
if (substr(explode("/",$teamFolder)[2],0,4) == $seasonYear) {
array_push($events, $teamFolder);
}
}
}
}
if (count($events) == 0 && count($teams) == 0) {
$error = "Team number or Event data not found for the current season! There may not be scouting data yet!";
}
}
include "config.php";
function getNameEventCode($code) {
global $TBAAuthKey, $TBAApiUrl;
$urlPrefix = $TBAApiUrl.'/event/';
$urlSuffix = '/simple';
$url = $urlPrefix.$code.$urlSuffix;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-TBA-Auth-Key: '.$TBAAuthKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch),true);
if (isSet($result["name"])) {
return $result["name"];
} else {
return $code;
}
curl_close($ch);
}
$teamNameAtEvent = array();
function getNameTeamNumber($teamNumber, $event) {
global $TBAAuthKey, $TBAApiUrl, $teamNameAtEvent;
if (count($teamNameAtEvent) == 0) {
$url = $TBAApiUrl.'/event/'.$event.'/teams/simple';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-TBA-Auth-Key: '.$TBAAuthKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch),true);
curl_close($ch);
foreach ($result as $team) {
$teamNameAtEvent[$team["team_number"]] = $team["nickname"];
}
}
if (isSet($teamNameAtEvent[$teamNumber])) {
return $teamNameAtEvent[$teamNumber];
}
else {
return $teamNumber;
}
}
?>
<head>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<title>ORF Scouter</title>
<style>
body {
background-color: black;
}
img {
width: 25%;
}
p {
font-size: 25;
}
p, h1, h2, h3 {
color: white;
}
div {
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
text-align: center;
}
a {
color: white;
cursor: pointer;
}
a:hover,a.hover { text-decoration: underline; }
</style><script>
function onLoad() {
<?php if ($error == "" && $input != "") {
echo "document.getElementById(\"input\").defaultValue = '".$input."';";
}
?>
}
</script></head><body>
<div>
<img src="logo.png"/>
<?php
if (!(count($events) > 0) && !(count($teams) >0)) {
echo "<script>onLoad();</script><h1>Welcome to ORF's Scouting Data Viewer!</h1><form method=\"get\" action=\"index.php\">
<p>Team Number or Event Key:</p>
<p><input style=\"font-size: 20; text-align:center;\" id=\"input\" name=\"input\" type=\"text\"></input></p>".
(($showHiddenData) ? "<input style=\"display:none\" id=\"showHiddenData\" name=\"showHiddenData\" type=\"text\" value=\"".$hiddenDataKey."\"></input>" : "")
."<p><input style=\"font-size: 20;\" type=\"submit\"></input></p>
</form><br/><p><a href=\"api/v1/exportData.php?exportType=allData\" target=\"_blank\">Download All Data</a>";
}
?>
<p><?php echo $error ?></p>
<?php
if (count($events) > 0 && $error == "" && $inputTeam && !$inputEvent) {
echo "<h1>Team ".$input." has been scouted at these events this season:</h1>";
echo "<form action=\"viewTeam.php\" method=\"get\"> <input type=\"text\" style=\"display:none\" name=\"teamNumber\" value=\"".$input."\"></input>";
if ($showHiddenData) echo "<input type=\"text\" style=\"display:none\" name=\"showHiddenData\" value=\"".$hiddenDataKey."\"></input>";
echo "<select style= \"font-size: 1cm;\" name=\"eventCode\">";
foreach($events as $event) {
$eventCode = explode("/",$event)[2];
if (substr($eventCode,0,4) == $seasonYear) {
echo "<option value=\"".$eventCode."\"'>".getNameEventCode($eventCode)."</option>";
}
}
echo "</select><input style=\"font-size: 0.85cm;margin-left: 50;margin-top: 50;\" type=\"submit\" value=\"View Data\"></input></form><br/>";
echo "<br/><p><button style=\"font-size: 20;\" onClick='window.location.href=\"index.php\"'>Go Back</button><br/>";
echo "<p><a href=\"api/v1/exportData.php?exportType=teamData&teamNumber=".$input."\" target=\"_blank\">Download All Data for ".$input."</a>";
}
if (count($teams) > 0 && $error == "" && !$inputTeam && $inputEvent) {
echo "<h1>These teams have been scouted from the event \"".getNameEventCode($input)."\":</h1>";
echo "<form action=\"viewTeam.php\" method=\"get\"> <input type=\"text\" style=\"display:none\" name=\"eventCode\" value=\"".$input."\"></input>";
if ($showHiddenData) echo "<input type=\"text\" style=\"display:none\" name=\"showHiddenData\" value=\"".$hiddenDataKey."\"></input>";
echo "<select style= \"font-size: 1cm;\" name=\"teamNumber\">";
foreach($teams as $team) {
$teamNumber = explode("/",$team)[3];
if (getNameTeamNumber($teamNumber, $input) != $teamNumber) {
echo "<option value=\"".$teamNumber."\"'>".$teamNumber." - ".getNameTeamNumber($teamNumber, $input)."</option>";
}
}
echo "</select><input style=\"font-size: 0.85cm;margin-left: 50;margin-top: 50;\" type=\"submit\" value=\"View Data\"></input></form><br/>";
echo "<p><button style=\"font-size: 20;\" onClick='window.location.href=\"index.php\"'>Go Back</button><br/>";
echo "<p><a href=\"api/v1/exportData.php?exportType=eventData&eventKey=".$input."\" target=\"_blank\">Download All Data for this Event</a>";
}
?>
</div></body>