-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrutas.php
373 lines (342 loc) · 12.2 KB
/
rutas.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
<?php
session_start();
$userid = @$_SESSION["uid"];
if($userid==""){
header("Location: /");
exit;
}
if(!isset($_POST["fi"])){
$_POST["fi"]=date("Y-m-d",time()-3600);
}
if(!isset($_POST["ft"])){
$_POST["ft"]=date("Y-m-d");
}
if(!isset($_POST["ht"])){
$_POST["ht"]=date("H:i:s");
}
if(!isset($_POST["hi"])){
$_POST["hi"]=date("H:i:s",time()-3600);
}
?><!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Rutas Servitrans</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
#map-container { min-height: 700px; height: 100%;}
.panel-fullscreen {
display: block;
z-index: 9999;
position: fixed;
width: 98%;
/*height: 98%;*/
top: 1%;
right: 1%;
left: 1%;
/*bottom: 1%;*/
overflow: auto;
}
.panel-actions {
margin-top: -17px;
margin-bottom: 0;
text-align: right;
margin-right: -6px;
}
.panel-actions a {
color:#333;
}
</style>
</head>
<body>
<!-- Fixed navbar -->
<!--<nav class="navbar navbar-default navbar-fixed-top" style="background-color:#008175;color:#97BE0D;">-->
<?php include("menu.php"); ?>
<div class="container">
<div class="page-header" style="margin-top:0;">
<h3 style="margin-top:0;">Rutas <small>Despliegue de Recorridos</small></h3>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="btn-group pull-right">
<!--<a href="#" class="btn btn-default btn-sm">Ver Detalle</a>-->
</div>
<!--<h3 class="panel-title" style="padding-top:5px;">-->
<h3 class="panel-title">
Filtros
</h3>
</div>
<div class="panel-body">
<form method="post">
<div class="row">
<div class="col-md-2">
Vehículo
</div>
<div class="col-md-2">
Fecha Inicio
</div>
<div class="col-md-2">
Hora Inicio
</div>
<div class="col-md-2">
Fecha Término
</div>
<div class="col-md-2">
Hora Término
</div>
<div class="col-md-2">
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<select name="vid" class="form-control">
<?php
$username="root";
$password="r1r7C1h6ZG4ZVWF";
$database="traccar";
$locations = array();
//mysql_connect("cohorte.cvssq77sdkiq.sa-east-1.rds.amazonaws.com",$username,$password);
$link = mysql_connect("sscl-db-instance.chapmhehekr9.us-east-1.rds.amazonaws.com",$username,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$q = "SELECT device_group.id, device_group.name FROM user_group_assign, device_group WHERE user_group_assign.user_id = $userid AND user_group_assign.device_group_id = device_group.id;";
$resultado = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($resultado)) {
?>
<optgroup label="<?php echo $row["name"];?>">
<?php
$q = "SELECT devices.id, devices.name FROM device_group_assign, devices WHERE device_group_assign.device_group_id = {$row["id"]} AND device_group_assign.device_id = devices.id;";
$resultado2 = mysql_query($q) or die(mysql_error());
while ($row2 = mysql_fetch_array($resultado2)) {
?>
<option value="<?php echo $row2["id"];?>"<?php echo (@$_POST["vid"]==$row2["id"]) ? " selected=\"selected\"" : "";?>><?php echo $row2["name"];?></option>
<?php
}
?>
</optgroup>
<?php }
mysql_close($link);
?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="date" name="fi" class="form-control" value="<?php echo @$_POST["fi"];?>" max="<?php echo date("Y-m-d");?>" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="time" class="form-control" name="hi" value="<?php echo $_POST["hi"];?>" step="1">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="date" name="ft" class="form-control" value="<?php echo @$_POST["ft"];?>" max="<?php echo date("Y-m-d");?>" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="time" class="form-control" name="ht" value="<?php echo $_POST["ht"];?>" step="1">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="submit" name="btn-submit" class="btn btn-primary pull-right">Aceptar</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php if(isset($_POST["btn-submit"])){ ?>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="info-recorrido"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body" style="padding:0;">
<div id="map-container"></div>
</div>
</div>
</div>
</div>
<?php } ?>
</div> <!-- /container -->
<footer class="footer">
<div class="container">
<p class="text-muted" style="color: #008175;">Sistema de Rastreo 1.0 / Servitrans / 2016 © Todos los derechos reservados / <?php echo date("d/m/Y h:i:s A");?></p>
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="http://maps.google.com/maps/api/js?key=AIzaSyAr_-4pxrC16Ii95y8KeviDojtob5kgTiU&libraries=geometry"></script>
<script>
var map;
var var_location;
function init_map() {
<?php
if(isset($_POST["btn-submit"])){
$did=$_POST["vid"];
$fi = strtotime($_POST["fi"]." ".$_POST["hi"])+10800;
$fi = date("YmdHis",$fi);
$ft = strtotime($_POST["ft"]." ".$_POST["ht"])+10800;
$ft = date("YmdHis",$ft);
$username="root";
$password="r1r7C1h6ZG4ZVWF";
$database="traccar";
$locations = array();
//mysql_connect("cohorte.cvssq77sdkiq.sa-east-1.rds.amazonaws.com",$username,$password);
$link = mysql_connect("sscl-db-instance.chapmhehekr9.us-east-1.rds.amazonaws.com",$username,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$q = "SELECT name, id FROM devices where id = $did;";
$resultado2 = mysql_query($q) or die(mysql_error());
while ($row2 = mysql_fetch_array($resultado2)) {
$q = "SELECT location_report.latitude, location_report.longitude, location_report.speed, location_report.utc, location_report.heading FROM location_report WHERE location_report.latitude!=0 and location_report.longitude!=0 and location_report.device_id={$row2["id"]} and location_report.utc >= '$fi' and location_report.utc <= '$ft' ORDER BY location_report.utc DESC";
$resultado = mysql_query($q) or die(mysql_error());
while ($row = mysql_fetch_array($resultado)) {
$utc = date("d/m/Y h:i:s A",strtotime($row[3])-10800);
$locations[] = "['{$row2["name"]}',{$row[0]},{$row[1]},{$row[2]}, '$utc', {$row[4]}]";
}
}
mysql_close($link);
?>
var bounds = new google.maps.LatLngBounds();
var locations = [<?php echo implode(",",$locations);?>];
var_location = new google.maps.LatLng(-33.3266167,-70.7164856);
var var_mapoptions = {
center: var_location,
zoom: 14
};
//var var_marker = new google.maps.Marker({
//position: var_location,
//map: var_map,
//title:""});
map = new google.maps.Map(document.getElementById("map-container"),var_mapoptions);
var recorridoCoor = [];
for (i = 0; i < locations.length; i++) {
var icono = google.maps.SymbolPath.FORWARD_CLOSED_ARROW;
var color = 'grey';
var scale = 3;
if (i==0||i+1==locations.length){
icono = google.maps.SymbolPath.FORWARD_CLOSED_ARROW;
color = 'green';
scale = 3;
if (i==0){
color = 'red';
}
}
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: {
path: icono,
scale: scale,
strokeColor: color,
rotation: locations[i][5]
},
});
marker.setMap(map);
bounds.extend(marker.position);
map.fitBounds(bounds);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var contentString = '<div style="font-size:90%;">'+
'<h4>Vehículo '+locations[i][0]+'</h4>'+
'<h5>Fecha</h5>'+
locations[i][4]+
'<h5>Velocidad</h5>'+
locations[i][3]+' Km/h'+
'</div>';
var infowindow = new google.maps.InfoWindow({ });
infowindow.setContent(contentString);
infowindow.open(map, marker);
}
})(marker, i));
recorridoCoor.push({lat: locations[i][1], lng: locations[i][2]});
}
// Linea de recorrido
var recorrido = new google.maps.Polyline({
path: recorridoCoor,
geodesic: true,
strokeColor: 'grey',
strokeOpacity: 1,
strokeWeight: 3
});
recorrido.setMap(map);
var path = recorrido.getPath();
var distancia = google.maps.geometry.spherical.computeLength(path.getArray()); // em metros
if(distancia > 0){
distancia = Math.round(distancia/1000);
$(".info-recorrido").text("El recorrido desplegado tiene una longitud de " +distancia+ " kilómetros.");
}
//console.log(distancia/1000);
//var_marker.setMap(var_map);
<?php } ?>
}
google.maps.event.addDomListener(window, 'load', init_map);
$(document).ready(function () {
//Toggle fullscreen
$("#panel-fullscreen2").click(function (e) {
var full_screen_height = window.innerHeight - 100;
e.preventDefault();
var $this = $(this);
if ($this.children('i').hasClass('glyphicon-resize-full'))
{
$this.children('i').removeClass('glyphicon-resize-full');
$this.children('i').addClass('glyphicon-resize-small');
document.getElementById("map-container").style.width = "100%";
document.getElementById("map-container").style.height = full_screen_height+"px";
}
else if ($this.children('i').hasClass('glyphicon-resize-small'))
{
$this.children('i').removeClass('glyphicon-resize-small');
$this.children('i').addClass('glyphicon-resize-full');
document.getElementById("map-container").style.width = "100%";
document.getElementById("map-container").style.height = "500px"
}
$(this).closest('.panel').toggleClass('panel-fullscreen');
google.maps.event.trigger(var_map,"resize");
var_map.setCenter(var_location);
});
});
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
$('.vehiculos').each(function() {
var $this = $(this);
$this.popover({
trigger: 'hover',
placement: 'right',
html: true,
content: $this.find('.vehiculoInfo').html()
});
});
});
</script>
</body>
</html>