forked from Flame1994/CosmicTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkSystem.php
524 lines (461 loc) · 27.4 KB
/
checkSystem.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<?php
// ============================================================================
// Updates the website if a player enters a new solar system
// ============================================================================
include "php/routes.php";
session_start();
// Check if required parameters are set
if (isset($_SESSION['CharacterID']) && isset($_GET['system'])) {
// update and store neighbouring systems on each solar system a player visits
$conn = connect();
$main_system_id = "".$_GET['system']."";
$prepared = $conn->prepare("SELECT * FROM neighbours WHERE system_id = ?");
$prepared->bind_param('s', $main_system_id);
$prepared->execute();
$result = get_result($prepared);
if ($prepared->num_rows == 0) {
// System not yet in database
// Get information about system
$url = file_get_contents("https://esi.tech.ccp.is/dev/universe/systems/".$_GET['system']."/?datasource=tranquility&language=en-us");
$content = json_decode($url, true);
$const_id = $content['constellation_id'];
$main_system_name = $content['name'];
$url2 = file_get_contents("https://esi.tech.ccp.is/latest/universe/constellations/".$const_id."/?datasource=tranquility&language=en-us");
$content2 = json_decode($url2, true);
$const_name = $content2['name'];
$region_id = $content2['region_id'];
$url3 = file_get_contents("https://esi.tech.ccp.is/latest/universe/regions/".$region_id."/?datasource=tranquility&language=en-us");
$content3 = json_decode($url3, true);
$region_name = $content3['name'];
echo '
<div class="col-xs-12" style="background-color: #333;">
<h2>Current System: <span class="text-primary">';
if (isset($_SESSION["CharacterSystemName"])) {
echo $_SESSION["CharacterSystemName"] ;
echo '<h5 style="color:white;">'.$main_system_name.' <span class="security-status"> '.round($content['security_status'],1).'</span> ‹ '.$const_name.' ‹ '.$region_name.'</h5>';
} else {
echo "Not Found";
}
echo '</span></h2>
</div>
<div class="col-xs-12" style="height: 200px;">
<h6>Add Signatures</h6>
<form id="add-sig" action="signature" enctype="multipart/form-data" method="post">
<textarea id="sigdata" name="sigdata" placeholder="Add signature results" style="width:100%; color:#333333; font-size:12px" rows="4"></textarea>
<button type="submit" name="Submit" id="Submit" class="btn btn-default">Submit</button>
</form>
<script>
$(function () {
$(\'#add-sig\').on(\'submit\', function (e) {
e.preventDefault();
$.ajax({
type: \'POST\',
url: \'/sigadd.php\',
data: $(\'#add-sig\').serialize(),
success: function (data) {
if (data == "false") {
$(\'#sig-report\').html("<div class=\"col-md-2\"></div>\
<div class=\"col-xs-12 col-md-8 notification-container notification-failed\">\
<div class=\"notification-left\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></div>\
<div class=\"notification-right\"><div class=\"notification-note\">A signature failed to add.</div></div>\
</div>");
} else if (data == "true") {
$(\'#sig-report\').html("<div class=\"col-md-2\"></div>\
<div class=\"col-xs-12 col-md-8 notification-container notification-success\">\
<div class=\"notification-left\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></div>\
<div class=\"notification-right\"><div class=\"notification-note\">All Signatures added.</div></div> \
</div>");
$.ajax({
url:\'/getSystemSigs.php\',
type:\'GET\',
beforeSend:function () {
},
success:function (data) {
$(".sys-info-list").html("");
$(".sys-info-list").html(data);
}
});
}
}
});
});
});
</script>
</div>
<div id="sig-report" class="col-xs-12">
</div>
<div class="col-xs-12 signature-list sys-info-list">
<table>
<tr>
<th>System</th>
<th>ID</th>
<th>Type</th>
<th>Signature Name</th>
<th>Explorer</th>
<th>Time</th>
<th></th>
</tr>';
// Display signatures of system
$conn2 = connect();
$prepared2 = $conn2->prepare("SELECT * FROM signatures WHERE system_id = ?");
$prepared2->bind_param('s', $main_system_id);
$prepared2->execute();
$result2 = get_result($prepared2);
$count = 0;
while ($row2 = array_shift($result2)) {
$system = $row2['system'];
$sigID = $row2['sig_id'];
$sigType = $row2['sig_type'];
$sigName = $row2['sig_name'];
$reported = $row2['reported'];
$reportedID = $row2['reported_id'];
$reportTime = $row2['report_time'];
echo '
<tr>
<td>'.$system.'</td>
<td>'.$sigID.'</td>
<td>'.$sigType.'</td>
<td>'.$sigName.'</td>
<td><a href="https://zkillboard.com/character/'.$reportedID.'/">'.$reported.'</a></td>
<td>'.$reportTime.'</td>
<td>
<form id="delete-sig-'.$count.'" class="delete-sig" enctype="multipart/form-data" method="post">
<input type="hidden" name="sig_id" value="'.$sigID.'">
<button id="Submit" type="submit" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="Delete Signature" name="Submit" value="Delete Sig" style="padding-left:6px;">
<span><i class="fa fa-times" aria-hidden="true"></i></span>
</button>
</form>
</td>
</tr>
';
$count = $count + 1;
}
$conn2->close();
echo ' </table>
<script>
$(function () {
$(\'.delete-sig\').on(\'submit\', function (e) {
e.preventDefault();
$.ajax({
type: \'POST\',
url: \'/sigdelete.php\',
data: $(\'#\'+this.id).serialize(),
success: function (data) {
if (data == "false") {
} else if (data == "true") {
$.ajax({
url:\'/getSystemSigs.php\',
type:\'GET\',
beforeSend:function () {
},
success:function (data) {
$(".sys-info-list").html("");
$(".sys-info-list").html(data);
}
});
}
}
});
});
});
</script>
</div>
<div class="col-xs-12 intel">
<h4>Neighbouring Systems</h4>
<hr style="padding: 0; margin: 0;">';
// Get systems intel
$url = file_get_contents("https://esi.tech.ccp.is/dev/universe/systems/".$_GET['system']."/?datasource=tranquility&language=en-us");
$content = json_decode($url, true);
$stargates = $content['stargates'];
foreach ($stargates as $stargate) {
$url2 = file_get_contents("https://esi.tech.ccp.is/dev/universe/stargates/".$stargate."/?datasource=tranquility");
$content2 = json_decode($url2, true);
$destination = $content2['destination']['system_id'];
$url3 = file_get_contents("https://esi.tech.ccp.is/dev/universe/systems/".$destination."/?datasource=tranquility&language=en-us");
$content3 = json_decode($url3, true);
$system_name = $content3['name'];
$system_id = $content3['system_id'];
$sec_status = round($content3['security_status'],1);
$const_id = $content3['constellation_id'];
$url2 = file_get_contents("https://esi.tech.ccp.is/latest/universe/constellations/".$const_id."/?datasource=tranquility&language=en-us");
$content2 = json_decode($url2, true);
$const_name = $content2['name'];
$region_id = $content2['region_id'];
$url3_1 = file_get_contents("https://esi.tech.ccp.is/latest/universe/regions/".$region_id."/?datasource=tranquility&language=en-us");
$content3_1 = json_decode($url3_1, true);
$region_name = $content3_1['name'];
// Insert neighbour systems to database
$conn3 = connect();
$prepared3 = $conn3->prepare("SELECT * FROM neighbours WHERE system_id = ? AND neighbour = ?");
$prepared3->bind_param('ss', $main_system_id, $system_name);
$prepared3->execute();
$result3 = get_result($prepared3);
if ($prepared3->num_rows == 0) {
$prepared3_1 = $conn3->prepare("INSERT INTO `neighbours` (`id`, `system`, `system_id`, `neighbour`, `neighbour_id`, `sec_status`, `const`, `const_id`, `region`, `region_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$entryVal = NULL;
$prepared3_1->bind_param('ssssssssss', $entryVal, $main_system_name, $main_system_id, $system_name, $system_id, $sec_status, $const_name, $const_id, $region_name, $region_id);
$prepared3_1->execute();
}
$conn3->close();
echo '
<div class="col-xs-12 intel-system">
<h5>'.$system_name.' <span class="security-status"> '.$sec_status.'</span> ‹ '.$const_name.' ‹ '.$region_name.'</h5>
<div class="col-xs-6">
<table>';
$conn4 = connect();
$prepared4 = $conn4->prepare("SELECT * FROM signatures WHERE system = ?");
$prepared4->bind_param('s', $content3['name']);
$prepared4->execute();
$result4 = get_result($prepared4);
if ($prepared4->num_rows == 0) {
echo "No Signatures Found";
}
while ($row4 = array_shift($result4)) {
$system = $row4['system'];
$sigID = $row4['sig_id'];
$sigType = $row4['sig_type'];
$sigName = $row4['sig_name'];
$reported = $row4['reported'];
$reportedID = $row4['reported_id'];
$reportTime = $row4['report_time'];
echo '
<tr>
<td>'.$sigID.'</td>
<td>'.$sigType.'</td>
<td>'.$sigName.'</td>
</tr>
';
}
$conn4->close();
echo ' </table>
</div>
<div id="'.$system_id.'-intel" class="col-xs-6">
<button onclick="getIntel('.$system_id.')" class="btn btn-default btn-intel">Get System Intel</button>
</div>
</div>
';
}
echo '
</div>
<script type="text/javascript">
$(".system").css({"background-color":"#fff"});
$("#';echo $_SESSION["CharacterSystemName"]; echo '").css({"background-color":"#337ab7"});
if (queue[queue.length-1] != "'.$_SESSION["CharacterSystemName"].'") {
queue.push("'; echo $_SESSION["CharacterSystemName"]; echo'");
}
</script>
';
} else {
// System is in database
// Get system info
$conn0 = connect();
$prepared0 = $conn->prepare("SELECT * FROM neighbours WHERE neighbour_id = ?");
$prepared0->bind_param('s', $main_system_id);
$prepared0->execute();
$result0 = get_result($prepared0);
while ($row0 = array_shift($result0)) {
$sec_status = $row0['sec_status'];
$main_system_name = $row0['neighbour'];
$const_name = $row0['const'];
$region_name = $row0['region'];
}
$conn0->close();
echo '
<div class="col-xs-12" style="background-color: #333;">
<h2>Current System: <span class="text-primary">';
if (isset($_SESSION["CharacterSystemName"])) {
echo $_SESSION["CharacterSystemName"] ;
echo '<h5 style="color:white;">'.$main_system_name.' <span class="security-status"> '.$sec_status.'</span> ‹ '.$const_name.' ‹ '.$region_name.'</h5>';
} else {
echo "Not Found";
}
echo '</span></h2>
</div>
<div class="col-xs-12" style="height: 200px;">
<h6>Add Signatures</h6>
<form id="add-sig" action="signature" enctype="multipart/form-data" method="post">
<textarea id="sigdata" name="sigdata" placeholder="Add signature results" style="width:100%; color:#333333; font-size:12px" rows="4"></textarea>
<button type="submit" name="Submit" id="Submit" class="btn btn-default">Submit</button>
</form>
<script>
$(function () {
$(\'#add-sig\').on(\'submit\', function (e) {
e.preventDefault();
$.ajax({
type: \'POST\',
url: \'/sigadd.php\',
data: $(\'#add-sig\').serialize(),
success: function (data) {
if (data == "false") {
$(\'#sig-report\').html("<div class=\"col-md-2\"></div>\
<div class=\"col-xs-12 col-md-8 notification-container notification-failed\">\
<div class=\"notification-left\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></div>\
<div class=\"notification-right\"><div class=\"notification-note\">A signature failed to add.</div></div>\
</div>");
} else if (data == "true") {
$(\'#sig-report\').html("<div class=\"col-md-2\"></div>\
<div class=\"col-xs-12 col-md-8 notification-container notification-success\">\
<div class=\"notification-left\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></div>\
<div class=\"notification-right\"><div class=\"notification-note\">All Signatures added.</div></div> \
</div>");
$.ajax({
url:\'/getSystemSigs.php\',
type:\'GET\',
beforeSend:function () {
},
success:function (data) {
$(".sys-info-list").html("");
$(".sys-info-list").html(data);
}
});
}
}
});
});
});
</script>
</div>
<div id="sig-report" class="col-xs-12">
</div>
<div class="col-xs-12 signature-list sys-info-list">
<table>
<tr>
<th>System</th>
<th>ID</th>
<th>Type</th>
<th>Signature Name</th>
<th>Explorer</th>
<th>Time</th>
<th></th>
</tr>';
// Get system signatures
$conn2 = connect();
$prepared2 = $conn2->prepare("SELECT * FROM signatures WHERE system_id = ?");
$prepared2->bind_param('s', $main_system_id);
$prepared2->execute();
$result2 = get_result($prepared2);
$count = 0;
while ($row2 = array_shift($result2)) {
$system = $row2['system'];
$sigID = $row2['sig_id'];
$sigType = $row2['sig_type'];
$sigName = $row2['sig_name'];
$reported = $row2['reported'];
$reportedID = $row2['reported_id'];
$reportTime = $row2['report_time'];
echo '
<tr>
<td>'.$system.'</td>
<td>'.$sigID.'</td>
<td>'.$sigType.'</td>
<td>'.$sigName.'</td>
<td><a href="https://zkillboard.com/character/'.$reportedID.'/">'.$reported.'</a></td>
<td>'.$reportTime.'</td>
<td>
<form id="delete-sig-'.$count.'" class="delete-sig" enctype="multipart/form-data" method="post">
<input type="hidden" name="sig_id" value="'.$sigID.'">
<button id="Submit" type="submit" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="Delete Signature" name="Submit" value="Delete Sig" style="padding-left:6px;">
<span><i class="fa fa-times" aria-hidden="true"></i></span>
</button>
</form>
</td>
</tr>
';
$count = $count +1;
}
$conn2->close();
echo ' </table>
<script>
$(function () {
$(\'.delete-sig\').on(\'submit\', function (e) {
e.preventDefault();
$.ajax({
type: \'POST\',
url: \'/sigdelete.php\',
data: $(\'#\'+this.id).serialize(),
success: function (data) {
if (data == "false") {
} else if (data == "true") {
$.ajax({
url:\'/getSystemSigs.php\',
type:\'GET\',
beforeSend:function () {
},
success:function (data) {
$(".sys-info-list").html("");
$(".sys-info-list").html(data);
}
});
}
}
});
});
});
</script>
</div>';
echo ' <div class="col-xs-12 intel">
<h4>Neighbouring Systems</h4>
<hr style="padding: 0; margin: 0;">';
// Get system intel
while ($row = array_shift($result)) {
$system_name = $row['system'];
$system_id = $row['system_id'];
$neighbour_name = $row['neighbour'];
$neighbour_id = $row['neighbour_id'];
$sec_status = $row['sec_status'];
$const_name = $row['const'];
$const_id = $row['const_id'];
$region_name = $row['region'];
$region_id = $row['region_id'];
echo '
<div class="col-xs-12 intel-system">
<h5>'.$neighbour_name.' <span class="security-status"> '.$sec_status.'</span> ‹ '.$const_name.' ‹ '.$region_name.'</h5>
<div class="col-xs-6">
<table>';
$conn4 = connect();
$prepared4 = $conn4->prepare("SELECT * FROM signatures WHERE system = ?");
$prepared4->bind_param('s', $neighbour_name);
$prepared4->execute();
$result4 = get_result($prepared4);
if ($prepared4->num_rows == 0) {
echo "No Signatures Found";
}
while ($row4 = array_shift($result4)) {
$system = $row4['system'];
$sigID = $row4['sig_id'];
$sigType = $row4['sig_type'];
$sigName = $row4['sig_name'];
$reported = $row4['reported'];
$reportedID = $row4['reported_id'];
$reportTime = $row4['report_time'];
echo '
<tr>
<td>'.$sigID.'</td>
<td>'.$sigType.'</td>
<td>'.$sigName.'</td>
</tr>
';
}
$conn4->close();
echo ' </table>
</div>
<div id="'.$neighbour_id.'-intel" class="col-xs-6">
<button onclick="getIntel('.$neighbour_id.')" class="btn btn-default btn-intel">Get System Intel</button>
</div>
</div>
';
}
echo '
</div>
<script type="text/javascript">
$(".system").css({"background-color":"#fff"});
$("#';echo $_SESSION["CharacterSystemName"]; echo '").css({"background-color":"#337ab7"});
if (queue[queue.length-1] != "'.$_SESSION["CharacterSystemName"].'") {
queue.push("'; echo $_SESSION["CharacterSystemName"]; echo'");
}
</script>
';
}
$conn->close();
}
?>