/
detail.php
executable file
·122 lines (118 loc) · 4 KB
/
detail.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
<html>
<head>
<title>Game Detail</title>
</head>
<body>
<?
require_once "util.php";
$con = mysql_connect("localhost", "mikeMike", "1234");
if (!$con) {
print("Cannot connect to database");
return;
}
if (!mysql_select_db('war3')) {
print("Cannot connect to db war3");
return;
}
if (isset($_GET['id'])) {
$id = mysql_real_escape_string($_GET['id']);
} else {
$id = mysql_real_escape_string($_POST['id']);
}
$isAdmin = true; //(isset($_GET['admin']) && $_GET['admin'] == 'abc123');
$canEdit = (isset($_POST['admin']) && $_POST['admin'] == 'xyz890');
if ($canEdit) {
$isAdmin = true;
if (isset($_POST['rating'])) {
$rating = mysql_real_escape_string($_POST['rating']);
$query = "UPDATE game SET rating=$rating WHERE id=$id";
} else if (isset($_POST['bid'])) {
$bid = mysql_real_escape_string($_POST['bid']);
$type = mysql_real_escape_string($_POST['type']);
$start = toSec(mysql_real_escape_string($_POST['start']));
$end = toSec(mysql_real_escape_string($_POST['end']));
$action = mysql_real_escape_string($_POST['action']);
$adv = mysql_real_escape_string($_POST['adv']);
$decisive = isset($_POST['decisive'])? 1 : 0;
if ($bid == 'new') {
$query = "INSERT INTO battle (game_id, type, start, end, advantage, decisive) VALUES ($id, $type, $start, $end, $adv, $decisive)";
} else if ($action == "Update") {
$query = "UPDATE battle SET type=$type, start=$start, end=$end, advantage=$adv, decisive=$decisive WHERE id=$bid";
} else if ($action == "Remove") {
$query = "DELETE FROM battle WHERE id=$bid";
}
} else if (isset($_POST['details'])) {
$details = mysql_real_escape_string($_POST['details']);
$query = "UPDATE game SET detail='$details' WHERE id=".$id;
}
if (mysql_query($query)) print("Edit successful");
else print("Edit failed");
}
$query = "SELECT * FROM game where id=".mysql_real_escape_string($id);
$result = mysql_query($query);
if (!$result) {
print("Something is wrong :(");
return;
}
$row = mysql_fetch_assoc($result);
?>
<h3>Replay details</h3>
<div>Filename: <a href=""><?= $row['name'] ?></a></div>
<div>Map: <?= $row['map'] ?></div>
<div>Version: <?= sprintf("1.%02d", $row['version']) ?></div>
<div>Type: <?= gameType2Str($row['type']) ?></div>
<?
$len = floor($row['length']/1000);
$lenStr = sprintf("%02dmin%02dsec", floor($len/60), $len%60);
$desc = $row['detail'];
?>
<div>Length: <?= $lenStr ?></div>
<div>Date: <?= $row['created'] ?></div>
<br>
<div>Winning Team:</div>
<?
$query2 = "SELECT * FROM player where gameid=".$row['id'];
$result2 = mysql_query($query2);
if (!$result2) {
print("Something is wrong :(");
return;
}
$player = array();
while($row2 = mysql_fetch_assoc($result2)) {
$player[] = $row2;
}
?>
<? foreach($player as $p): ?>
<? if ($p['team'] > 4 && $p['apm'] == 0) continue; ?>
<? if ($p['team'] == $row['winner']): ?>
<div><?= $p['name']." (".race2Str($p['race']).") apm=".$p['apm'] ?></div>
<? endif ?>
<? endforeach ?>
<br>
<div>Losing Team:</div>
<? foreach($player as $p): ?>
<? if ($p['team'] > 4 && $p['apm'] == 0) continue; ?>
<? if ($p['team'] != $row['winner']): ?>
<div><?= $p['name']." (".race2Str($p['race']).") apm=".$p['apm'] ?></div>
<? endif ?>
<? endforeach ?>
<br><br>
<form method="post">
<input type="hidden" name="id" value="<?= $id ?>" />
Rating:
<select name="rating">
<option value=0 <?= ($row['rating'] == 0)? "selected" : ""?>>Not Yet Rated</option>
<option value=1 <?= ($row['rating'] == 1)? "selected" : ""?>>One Sided</option>
<option value=2 <?= ($row['rating'] == 2)? "selected" : ""?>>Ma Ma Hu Hu</option>
<option value=3 <?= ($row['rating'] == 3)? "selected" : ""?>>Competitive</option>
<option value=4 <?= ($row['rating'] == 4)? "selected" : ""?>>Must See</option>
</select>
<? if ($isAdmin): ?>
<input type="hidden" name="admin" value="xyz890" />
<input type="submit" value="Edit" />
<? endif ?>
</form>
<?
mysql_close();
?>
</body>