-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.php
453 lines (383 loc) · 20.7 KB
/
session.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
<?php
ini_set('memory_limit', '100000');
require_once ("creds.php");
require_once ("auth_user.php");
require_once ("del_session.php");
require_once ("merge_sessions.php");
require_once ("get_sessions.php");
require_once ("get_columns.php");
require_once ("plot.php");
$_SESSION['recent_session_id'] = strval(max($sids));
echo($_SESSION['recent_session_id']);
// Connect to Database
$con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name, $con) or die(mysql_error());
if (isset($_POST["id"])) {
$session_id = preg_replace('/\D/', '', $_POST['id']);
}
elseif (isset($_GET["id"])) {
$session_id = preg_replace('/\D/', '', $_GET['id']);
}
if (isset($session_id)) {
//For the merge function, we need to find out, what would be the next session
$idx = array_search( $session_id, $sids);
if($idx>0) {
$session_id_next = $sids[$idx-1];
} else {
$session_id_next = false;
}
// Get GPS data for session
$sessionqry = mysql_query("SELECT kff1006, kff1005
FROM $db_table
WHERE session=$session_id
ORDER BY time DESC", $con) or die(mysql_error());
$geolocs = array();
while($geo = mysql_fetch_array($sessionqry)) {
if (($geo["0"] != 0) && ($geo["1"] != 0)) {
$geolocs[] = array("lat" => $geo["0"], "lon" => $geo["1"]);
}
}
// Create array of Latitude/Longitude strings in Google Maps JavaScript format
$mapdata = array();
foreach($geolocs as $d) {
$mapdata[] = "new google.maps.LatLng(".$d['lat'].", ".$d['lon'].")";
}
$imapdata = implode(",\n ", $mapdata);
// Don't need to set zoom manually
$setZoomManually = 0;
mysql_free_result($sessionqry);
mysql_close($con);
}
else {
// Define these so we don't get an error on empty page loads. Instead it
// will load a map of Area 51.
$session_id = "";
$imapdata = "new google.maps.LatLng(37.235, -115.8111)";
$setZoomManually = 1;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Open Torque Viewer</title>
<meta name="description" content="Open Torque Viewer">
<meta name="author" content="Matt Nicklay">
<!--<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">-->
<link rel="stylesheet" href="static/css/bootstrap.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.min.css">
<link rel="stylesheet" href="static/css/torque.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
if("<?php echo $timezone; ?>".length==0){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
var timezoneurl = $(location).attr('href').split('?')[0].replace('session', 'timezone');
$.ajax({
type: "GET",
url: timezoneurl,
data: 'time='+ visitortimezone,
success: function(){
location.reload();
}
});
}
});
</script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.peity.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">
function initialize() {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
poistion: google.maps.ControlPosition.TOP_RIGHT,
mapTypeIds: [google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.HYBRID,
google.maps.MapTypeId.SATELLITE]
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
},
scaleControl: true,
disableDoubleClickZoom: false,
draggable: true,
streetViewControl: true,
draggableCursor: 'move'
});
// The potentially large array of LatLng objects for the roadmap
var path = [<?php echo $imapdata; ?>];
// Create a boundary using the path to automatically configure
// the default centering location and zoom.
var bounds = new google.maps.LatLngBounds();
for (i = 0; i < path.length; i++) {
bounds.extend(path[i]);
}
map.fitBounds(bounds);
// If required/desired, set zoom manually now that bounds have been set
<?php if ($setZoomManually === 1) { ?>
zoomChange = google.maps.event.addListenerOnce(map, 'bounds_changed',
function(event) {
if (this.getZoom()){
this.setZoom(16);
}
});
setTimeout(function(){
google.maps.event.removeListener(zoomChange)
}, 1000);
var contentString = '<div>'+
'<div class="alert alert-info">'+
' <p class="lead" align="center">'+
" You're seeing this window because "+
'<br>'+
"you haven't selected a session. "+
'<br><br>'+
" Select one from the dropdown menu."+
' </p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: <?php echo $imapdata; ?>,
map: map,
title: 'Area 51'
});
setTimeout(function() {
infowindow.open(map, marker)
}, 2000);
<?php } ?>
var line = new google.maps.Polyline({
path: path,
strokeColor: '#800000',
strokeOpacity: 0.75,
strokeWeight: 4
});
line.setMap(map);
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<?php if ($setZoomManually === 0) { ?>
<!-- Flot Javascript files -->
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.axislabels.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.hiddengraphs.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.multihighlight-delta.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.selection.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.time.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.tooltip.min.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.updater.js"></script>
<script language="javascript" type="text/javascript" src="static/js/jquery.flot.resize.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
var s1 = [<?php foreach($d1 as $b) {echo "[".$b[0].", ".$b[1]."],";} ?>];
var s2 = [<?php foreach($d2 as $d) {echo "[".$d[0].", ".$d[1]."],";} ?>];
var flotData = [
{ data: s1, label: <?php echo $v1_label; ?> },
{ data: s2, label: <?php echo $v2_label; ?>, yaxis: 2 }
];
function doPlot(position) {
$.plot("#placeholder", flotData, {
xaxes: [ {
mode: "time",
timezone: "browser",
axisLabel: "Time",
timeformat: "%I:%M%p",
twelveHourClock: true
} ],
yaxes: [ { axisLabel: <?php echo $v1_label; ?> }, {
alignTicksWithAxis: position == "right" ? 1 : null,
position: position,
axisLabel: <?php echo $v2_label; ?>
} ],
legend: {
position: "nw",
hideable: true,
backgroundOpacity: 0.1,
margin: 0
},
//selection: { mode: "xy" },
grid: {
hoverable: false,
clickable: true
},
//multihighlightdelta: { mode: 'x' },
tooltip: false,
tooltipOpts: {
content: "%s at %x: %y",
xDateFormat: "%I:%M:%S%p",
twelveHourClock: true,
onHover: function(flotItem, $tooltipEl) {
// console.log(flotItem, $tooltipEl);
}
}
}
)}
doPlot("right");
$("button").click(function () {
doPlot($(this).text());
});
});
</script>
<script language="javascript" type="text/javascript" src="static/js/torquehelpers.js"></script>
<?php } else { ?>
<script language="javascript" type="text/javascript" src="static/js/torquehelpers.js"></script>
<?php } ?>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="session.php">Open Torque Viewer</a>
</div>
</div>
</div>
<div id="map-container" class="col-md-7 col-xs-12">
<div id="map-canvas"></div>
</div>
<div id="right-container" class="col-md-5 col-xs-12">
<div id="right-cell">
<h4>Select Session</h4>
<div class="row center-block" style="padding-bottom:4px;">
<form method="post" class="form-horizontal" role="form" action="url.php">
<select id="seshidtag" name="seshidtag" class="form-control chosen-select" onchange="this.form.submit()" data-placeholder="Select Session..." style="width:100%;">
<option value=""></option>
<?php
foreach ($seshdates as $dateid => $datestr) { ?>
<option value="<?php echo $dateid; ?>"<?php if ($dateid == $session_id) echo ' selected'; ?>><?php echo $datestr; if ($show_session_length) {echo $seshsizes[$dateid];} ?></option>
<?php } ?>
</select>
<noscript><input type="submit" id="seshidtag" name="seshidtag" class="input-sm"></noscript>
</form>
<?php if(isset($session_id) && !empty($session_id)){ ?>
<div class="btn-group btn-group-justified">
<table style="width:100%"><tr>
<td><form method="post" class="form-horizontal" role="form" action="session.php?mergesession=<?php echo $session_id; ?>&mergesessionwith=<?php echo $session_id_next; ?>" id="formmerge">
<div align="center" style="padding-top:6px;"><input class="btn btn-info btn-sm" type="submit" id="formmerge" name="merge" value="Merge" title="Merge this session (<?php echo $seshdates[$session_id]; ?>) with the next session (<?php echo $seshdates[$session_id_next]; ?>)." <?php if(!$session_id_next){ echo 'disabled="disabled"';} ?> /></div>
</form></td>
<script type="text/javascript">
//Adding a confirmation dialog to above forms
$('#formmerge').submit(function() {
var c = confirm("Click OK to merge sessions (<?php echo $seshdates[$session_id]; ?>) and (<?php echo $seshdates[$session_id_next]; ?>).");
return c; //you can just return c because it will be true or false
});
</script>
<td><form method="post" class="form-horizontal" role="form" action="session.php?deletesession=<?php echo $session_id; ?>" id="formdelete">
<div align="center" style="padding-top:6px;"><input class="btn btn-info btn-sm" type="submit" id="formdelete" name="delete" value="Delete" title="Delete this session (<?php echo $seshdates[$session_id]; ?>)." /></div>
</form></td>
<script type="text/javascript">
$('#formdelete').submit(function() {
var c = confirm("Click OK to delete session (<?php echo $seshdates[$session_id]; ?>).");
return c; //you can just return c because it will be true or false
});
</script>
</tr></table>
</div>
<?php } /* END: if(isset($session_id) && !empty($session_id)) */?>
</div> <!-- END: Select Session -->
<br>
<?php if ($setZoomManually === 0) { ?>
<h4>Select 2 Variables to Plot</h4>
<div class="row center-block" style="padding-top:3px;">
<form method="post" role="form" action="url.php?makechart=y&seshid=<?php echo $session_id; ?>" id="formplotdata">
<select data-placeholder="Choose OBD2 data..." multiple class="chosen-select" size="<?php echo $numcols; ?>" style="width:100%;" id="plot_data" onsubmit="onSubmitIt" name="plotdata[]">
<option value=""></option>
<?php foreach ($coldata as $xcol) { if ( !(($coldataempty[$xcol['colname']]==1) && ($hide_empty_variables))) {?>
<option value="<?php echo $xcol['colname']; ?>" <?php echo ($coldataempty[$xcol['colname']]?"class='dataempty'":"") ?>><?php echo $xcol['colcomment'].($coldataempty[$xcol['colname']]?" [empty]":""); ?></option>
<?php }} ?>
</select>
<div align="center" style="padding-top:6px;"><input class="btn btn-info btn-sm" type="submit" id="formplotdata" name="plotdata[]" value="Plot!"></div>
</form>
</div>
<?php } else { ?>
<h4>Plot</h4>
<div align="center" style="padding-top:10px;">
<h5><span class="label label-warning">Select a session first!</span></h5>
</div>
<?php } ?>
<br>
<h4>Chart</h4>
<div class="row center-block" style="padding-bottom:5px;">
<?php if ($setZoomManually === 0) { ?>
<div class="demo-container">
<div id="placeholder" class="demo-placeholder" style="height:300px;"></div>
</div>
<?php } else { ?>
<div align="center" style="padding-top:10px;">
<h5><span class="label label-warning">Select a session first!</span></h5>
</div>
<?php } ?>
</div>
<br>
<h4>Data Summary</h4>
<div class="row center-block">
<?php if ($setZoomManually === 0) { ?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Min/Max</th>
<th>25th Pcnt</th>
<th>75th Pcnt</th>
<th>Mean</th>
<th>Sparkline</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong><?php echo substr($v1_label, 1, -1); ?></strong></td>
<td><?php echo $min1.'/'.$max1; ?></td>
<td><?php echo $pcnt25data1; ?></td>
<td><?php echo $pcnt75data1; ?></td>
<td><?php echo $avg1; ?></td>
<td><span class="line"><?php echo $sparkdata1; ?></span></td>
</tr>
<tr>
<td><strong><?php echo substr($v2_label, 1, -1); ?></strong></td>
<td><?php echo $min2.'/'.$max2; ?></td>
<td><?php echo $pcnt25data2; ?></td>
<td><?php echo $pcnt75data2; ?></td>
<td><?php echo $avg2; ?></td>
<td><span class="line"><?php echo $sparkdata2; ?></span></td>
</tr>
</tbody>
</table>
</div>
<?php } else { ?>
<div align="center" style="padding-top:5px;">
<h5><span class="label label-warning">Select a session first!</span></h5>
</div>
<?php } ?>
</div>
<br>
<h4>Export Data</h4>
<div class="row center-block" style="padding-bottom:18px;">
<?php if ($setZoomManually === 0) { ?>
<div class="btn-group btn-group-justified">
<a class="btn btn-default" role="button" href="<?php echo './export.php?sid='.$session_id.'&filetype=csv'; ?>">CSV</a>
<a class="btn btn-default" role="button" href="<?php echo './export.php?sid='.$session_id.'&filetype=json'; ?>">JSON</a>
</div>
<?php } else { ?>
<div align="center" style="padding-top:10px;">
<h5><span class="label label-warning">Select a session first!</span></h5>
</div>
<?php } ?>
</div>
</div>
</div>
</body>
</html>