This repository has been archived by the owner on Sep 5, 2021. It is now read-only.
forked from avs-code/PREM-Podium-race-E-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraces.php
139 lines (131 loc) · 4.52 KB
/
races.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
<? if(!defined("CONFIG")) exit(); ?>
<? if(!isset($login)) { show_error("You do not have administrator rights\n"); return; } ?>
<?
if(isset($_GET['season'])) $season = $_GET['season'];
else $season = 0;
$query_where = "WHERE r.season='$season'";
if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
$query_where .= " AND (r.name LIKE '%$filter%' OR r.track LIKE '%$filter%')";
}
$query = "SELECT r.*, d.name dname, rs.name rsname, qrs.name qrsname, COUNT(rd.team_driver) drivers FROM race r JOIN division d ON (d.id = r.division) JOIN point_ruleset rs ON (rs.id = r.ruleset) LEFT JOIN point_ruleset qrs ON (qrs.id = r.ruleset_qualifying) LEFT JOIN race_driver rd ON (r.id = rd.race) $query_where GROUP BY r.id ORDER BY r.date DESC";
require_once("functions.php"); // import mysql function
$link = mysqlconnect(); // call mysql function to get the link to the database
$result = mysqli_query($link,$query);
if(!$result) {
show_error("MySQL error: " . mysqli_error($link));
return;
}
$squery = "SELECT s.*, d.name dname, COUNT(r.id) racecount FROM season s JOIN division d ON (d.id = s.division) LEFT JOIN race r ON (r.season = s.id) GROUP BY s.id ORDER BY name ASC, dname ASC";
$sresult = mysqli_query($link,$squery);
if(!$sresult) {
show_error("MySQL error: " . mysqli_error($link));
return;
}
$s2query = "SELECT COUNT(id) racecount FROM race WHERE season = 0";
$s2result = mysqli_query($link,$s2query);
if(!$s2result) {
show_error("MySQL error: " . mysqli_error($link));
return;
}
$s2item = mysqli_fetch_array($s2result);
$noseasonracecount = $s2item['racecount'];
?>
<h1>Races</h1>
<div align="right">
<form action="." method="GET">
<input type="hidden" name="page" value="races">
<input type="text" class="search" name="filter" value="<?=$_GET['filter']?>"><br>
<select name="season" onchange="this.form.submit();">
<option value="0">NO SEASON - <?=$noseasonracecount?> race<?=$noseasonracecount == 1 ? "" : "s"?></option>
<optgroup label="Seasons">
<? while($sitem = mysqli_fetch_array($sresult)) { ?>
<option value="<?=$sitem['id']?>"<?=$season == $sitem['id'] ? " selected" : ""?>><?=$sitem['name']?> - <?=$sitem['dname']?> - <?=$sitem['racecount']?> race<?=$sitem['racecount'] == 1 ? "" : "s"?></option>
<? } ?>
</optgroup>
</select>
<input type="submit" class="button submit" value="ok">
</form>
</div>
<a href=".?page=race_add&season=<?=$season?>">Add race</a>
<? if($season == "0") { ?>
<h2>Seasons</h2>
<div class="w3-container">
<table class="w3-table-all">
<tr class="w3-dark-grey">
<td>Season</td>
<td>Division</td>
<td>Races</td>
</tr>
<?
mysqli_data_seek($sresult, 0);
#$style = "odd";
while($sitem = mysqli_fetch_array($sresult)) {
?>
<tr class="w3-hover-green">
<td><a href="?page=races&season=<?=$sitem['id']?>"><?=$sitem['name']?></a></td>
<td><?=$sitem['dname']?></td>
<td><?=$sitem['racecount']?></td>
</tr>
<?
# $style = $style == "odd" ? "even" : "odd";
} ?>
</table>
<h2>Events</h2>
<? } ?>
<?
if(mysqli_num_rows($result) == 0) {
show_msg("No races found\n");
return;
}
?>
<div class="w3-container">
<table class="w3-table-all">
<tr class="w3-dark-grey">
<td> </td>
<td>Date</td>
<? if ($season == 0) { ?>
<td>Name<br>Track</td>
<td>Division<br>Ruleset</td>
<td align="center">Drivers</td>
<td align="center">Laps</td>
<td align="center">MaxPl</td>
<? } else { ?>
<td>Name</td>
<td>Track</td>
<td align="center">Drivers</td>
<td align="center">Laps</td>
<td align="center">MaxPl</td>
<? } ?>
</tr>
<?
#$style = "odd";
while($item = mysqli_fetch_array($result)) {
$date = strtotime($item['date']);
?>
<tr class="w3-hover-green">
<td>
<a href=".?page=race_results_chg&id=<?=$item['id']?>"><img src="images/properties16.png" alt="props"></a>
<a href=".?page=race_chg&id=<?=$item['id']?>"><img src="images/edit16.png" alt="chg"></a>
<a href=".?page=race_rem&id=<?=$item['id']?>"><img src="images/delete16.png" alt="rem"></a>
</td>
<td><?=date("d/m/y", $date)?></td>
<? if ($season == 0) { ?>
<td><?=$item['name']?><br><?=$item['track']?></td>
<td><?=$item['dname']?><br><?=$item['rsname']?><?=!empty($item['qrsname']) ? " / " . $item['qrsname'] : ""?></td>
<td width="40" align="center"><?=$item['drivers']?></td>
<td width="40" align="center"><?=$item['laps']?></td>
<td width="40" align="center"><?=$item['maxplayers']?></td>
<? } else { ?>
<td><?=$item['name']?></td>
<td><?=$item['track']?></td>
<td align="center"><?=$item['drivers']?></td>
<td align="center"><?=$item['laps']?></td>
<td align="center"><?=$item['maxplayers']?></td>
<? } ?>
</tr>
<?
# $style = $style == "odd" ? "even" : "odd";
}
?>
</table>