forked from jmonclard/MopScreens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aj_refreshstart.php
executable file
·225 lines (207 loc) · 11 KB
/
aj_refreshstart.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
<?php
/*
Copyright 2014-2015 Metraware
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
include_once('functions.php');
include_once('lang.php');
session_start();
$_SESSION['CurrentLanguage'] = isset($_SESSION['CurrentLanguage']) ? $_SESSION['CurrentLanguage'] : autoSelectLanguage(array('fr','en','sv'),'en');
header('Content-type: text/html;charset=utf-8');
$PHP_SELF = $_SERVER['PHP_SELF'];
$link = ConnectToDB();
$cls = ((isset($_GET['cls'])) ? $_GET['cls'] : "0");
$cmpId = ((isset($_GET['cmpId'])) ? $_GET['cmpId'] : "0");
$leg = ((isset($_GET['leg'])) ? $_GET['leg'] : "0");
$ord = ((isset($_GET['ord'])) ? $_GET['ord'] : "0");
$radio = ((isset($_GET['radio'])) ? $_GET['radio'] : "finish");
$rcid = ((isset($_GET['rcid'])) ? $_GET['rcid'] : "0");
$sid = ((isset($_GET['sid'])) ? $_GET['sid'] : "0");
$sql = 'UPDATE resultscreen SET panel1lastrefresh='.time().' WHERE rcid='.$rcid.' AND sid='.$sid;
mysqli_query($link,$sql);
$numlegs = null; //JM 2017-07-23 non testé
//date_default_timezone_set('Europe/Paris');
date_default_timezone_set('UTC');
if ((!is_null($numlegs)) && ($numlegs > 1)) { //JM 2017-07-23 non testé
for ($k = 1; $k <= $numlegs; $k++) {
$sql = "SELECT max(ord) FROM mopteammember tm, mopteam t WHERE t.cls = '$cls' AND tm.leg=$k AND ".
"tm.cid = '$cmpId' AND t.cid = '$cmpId' AND tm.id = t.id";
$res = mysqli_query($link,$sql);
$r = mysqli_fetch_array($res);
$numparallel = $r[0];
if ($numparallel == 0) {
selectLegRadio($cls, $k, 0);
}
}
if ($radio!='') {
if ($radio == 'finish') {
$sql = "SELECT t.id AS id, cmp.name AS name, t.name AS team, cmp.rt AS time, cmp.st, cmp.stat AS status, ".
"cmp.it+cmp.rt AS tottime, cmp.tstat AS totstat ".
"FROM mopteammember tm, mopcompetitor cmp, mopteam t ".
"WHERE t.cls = '$cls' AND t.id = tm.id AND tm.rid = cmp.id ".
"AND t.cid = '$cmpId' AND tm.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"AND tm.leg='$leg' AND tm.ord='$ord' ORDER BY cmp.st ASC, cmp.stat, cmp.rt ASC, t.id";
$sql2 = "SELECT t.id AS id, cmp.name AS name, t.name AS team, cmp.rt AS time, cmp.st, cmp.stat AS status, ".
"cmp.it+cmp.rt AS tottime, cmp.tstat AS totstat ".
"FROM mopteammember tm, mopcompetitor cmp, mopteam t ".
"WHERE t.cls = '$cls' AND t.id = tm.id AND tm.rid = cmp.id ".
"AND t.cid = '$cmpId' AND tm.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"AND tm.leg='$leg' AND tm.ord='$ord' ORDER BY cmp.name ASC, cmp.st ASC, cmp.stat, cmp.rt ASC, t.id";
$rname = "Finish";
}
else {
$rid = (int)$radio;
$sql = "SELECT name FROM mopcontrol WHERE cid='$cmpId' AND id='$rid'";
$res = mysqli_query($link,$sql);
$rinfo = mysqli_fetch_array($res);
$rname = $rinfo['name'];
$sql = "SELECT team.id AS id, cmp.name AS name, team.name AS team, radio.rt AS time, 1 AS status, ".
"cmp.it+radio.rt AS tottime, cmp.st, cmp.tstat AS totstat ".
"FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND m.rid = radio.id ".
"AND m.id = team.id ".
"AND m.leg='$leg' AND m.ord='$ord' ".
"AND cmp.cls='$cls' ".
"AND team.cid = '$cmpId' AND m.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"ORDER BY cmp.st ASC, radio.rt ASC ";
$sql2 = "SELECT team.id AS id, cmp.name AS name, team.name AS team, radio.rt AS time, 1 AS status, ".
"cmp.it+radio.rt AS tottime, cmp.st, cmp.tstat AS totstat ".
"FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND m.rid = radio.id ".
"AND m.id = team.id ".
"AND m.leg='$leg' AND m.ord='$ord' ".
"AND cmp.cls='$cls' ".
"AND team.cid = '$cmpId' AND m.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"ORDER BY cmp.name ASC, cmp.st ASC, radio.rt ASC ";
}
$res = mysqli_query($link,$sql);
$results = calculeStart($res);
$res2 = mysqli_query($link,$sql2);
$results2 = calculeStart($res2);
$results3 = null;
foreach($results as $i => $v)
{
$results3[] = array($results[$i]['start_time'], $results[$i]['name'], $results[$i]['team'], $results2[$i]['name'], $results2[$i]['team'], $results2[$i]['start_time']);
}
formatResultScreen($results3);
}
}
else {
if (is_null($numlegs)) {
//No teams;
//$radio = selectRadio($cls);
if ($radio!='') {
if ($radio == 'finish') {
$sql = "SELECT cmp.id AS id, cmp.name AS name, org.name AS team, cmp.st, cmp.rt AS time, cmp.stat AS status ".
"FROM mopcompetitor cmp LEFT JOIN moporganization AS org ON cmp.org = org.id AND cmp.cid = org.cid ".
"WHERE cmp.cls = '$cls' ".
"AND cmp.cid = '$cmpId' ORDER BY cmp.st ASC, cmp.id";
$sql2 = "SELECT cmp.id AS id, cmp.name AS name, org.name AS team, cmp.st, cmp.rt AS time, cmp.stat AS status ".
"FROM mopcompetitor cmp LEFT JOIN moporganization AS org ON cmp.org = org.id AND cmp.cid = org.cid ".
"WHERE cmp.cls = '$cls' ".
"AND cmp.cid = '$cmpId' ORDER BY cmp.name ASC, cmp.st ASC, cmp.id";
$rname = "Finish";
}
else {
$rid = (int)$radio;
$sql = "SELECT name FROM mopcontrol WHERE cid='$cmpId' AND id='$rid'";
$res = mysqli_query($link,$sql);
$rinfo = mysqli_fetch_array($res);
$rname = $rinfo['name'];
$sql = "SELECT cmp.id AS id, cmp.name AS name, cmp.st, org.name AS team, radio.rt AS time, 1 AS status ".
"FROM mopradio AS radio, mopcompetitor AS cmp ".
"LEFT JOIN moporganization AS org ON cmp.org = org.id AND cmp.cid = org.cid ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND cmp.cls='$cls' ".
"AND cmp.cid = '$cmpId' AND radio.cid = '$cmpId' ".
"ORDER BY cmp.st ASC, radio.st ASC ";
$sql2 = "SELECT cmp.id AS id, cmp.name AS name, cmp.st, org.name AS team, radio.rt AS time, 1 AS status ".
"FROM mopradio AS radio, mopcompetitor AS cmp ".
"LEFT JOIN moporganization AS org ON cmp.org = org.id AND cmp.cid = org.cid ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND cmp.cls='$cls' ".
"AND cmp.cid = '$cmpId' AND radio.cid = '$cmpId' ".
"ORDER BY cmp.name ASC, cmp.st ASC, radio.st ASC ";
}
$res = mysqli_query($link,$sql);
$results = calculeStart($res);
$res2 = mysqli_query($link,$sql2);
$results2 = calculeStart($res2);
$results3 = null;
foreach($results as $i => $v)
{
$results3[] = array($results[$i]['start_time'], $results[$i]['name'], $results[$i]['team'], $results2[$i]['name'], $results2[$i]['team'], $results2[$i]['start_time']);
}
formatResultScreen($results3);
}
}
else {
// Single leg (patrol etc)
//$radio = selectRadio($cls);
if ($radio!='') {
if ($radio == 'finish') {
$sql = "SELECT t.id AS id, cmp.name AS name, cmp.st, t.name AS team, t.rt AS time, t.stat AS status ".
"FROM mopteammember tm, mopcompetitor cmp, mopteam t ".
"WHERE t.cls = '$cls' AND t.id = tm.id AND tm.rid = cmp.id AND tm.leg=1 ".
"AND t.cid = '$cmpId' AND tm.cid = '$cmpId' AND cmp.cid = '$cmpId' ORDER BY cmp.st ASC, t.stat, t.rt ASC, t.id";
$sql2 = "SELECT t.id AS id, cmp.name AS name, cmp.st, t.name AS team, t.rt AS time, t.stat AS status ".
"FROM mopteammember tm, mopcompetitor cmp, mopteam t ".
"WHERE t.cls = '$cls' AND t.id = tm.id AND tm.rid = cmp.id AND tm.leg=1 ".
"AND t.cid = '$cmpId' AND tm.cid = '$cmpId' AND cmp.cid = '$cmpId' ORDER BY cmp.name ASC, cmp.st ASC, t.stat, t.rt ASC, t.id";
$rname = "Finish";
}
else {
$rid = (int)$radio;
$sql = "SELECT name FROM mopcontrol WHERE cid='$cmpId' AND id='$rid'";
$res = mysqli_query($link,$sql);
$rinfo = mysqli_fetch_array($res);
$rname = $rinfo['name'];
$sql = "SELECT team.id AS id, cmp.name AS name, cmp.st, team.name AS team, radio.rt AS time, 1 AS status ".
"FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND m.rid = radio.id ".
"AND m.id = team.id ".
"AND m.leg=1 ".
"AND cmp.cls='$cls' ".
"AND radio.cid = '$cmpId' AND m.cid = '$cmpId' AND team.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"ORDER BY cmp.st ASC, radio.rt ASC ";
$sql2 = "SELECT team.id AS id, cmp.name AS name, cmp.st, team.name AS team, radio.rt AS time, 1 AS status ".
"FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp ".
"WHERE radio.ctrl='$rid' ".
"AND radio.id=cmp.id ".
"AND m.rid = radio.id ".
"AND m.id = team.id ".
"AND m.leg=1 ".
"AND cmp.cls='$cls' ".
"AND radio.cid = '$cmpId' AND m.cid = '$cmpId' AND team.cid = '$cmpId' AND cmp.cid = '$cmpId' ".
"ORDER BY cmp.name ASC, cmp.st ASC, radio.rt ASC ";
}
$res = mysqli_query($link,$sql);
$results = calculeStart($res);
$res2 = mysqli_query($link,$sql2);
$results2 = calculeStart($res2);
$results3 = null;
foreach($results as $i => $v)
{
$results3[] = array($results[$i]['start_time'], $results[$i]['name'], $results[$i]['team'], $results2[$i]['name'], $results2[$i]['team'], $results2[$i]['start_time']);
}
formatResultScreen($results3);
}
}
}
?>