-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin-map.php
More file actions
102 lines (84 loc) · 3.33 KB
/
admin-map.php
File metadata and controls
102 lines (84 loc) · 3.33 KB
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
<?php
include_once 'header.php';
include_once 'locations_model.php';
?>
<div id="map"></div>
<!------ Include the above in your HEAD tag ---------->
<script>
var map;
var marker;
var infowindow;
var red_icon = 'http://maps.google.com/mapfiles/ms/icons/red-dot.png' ;
var purple_icon = 'http://maps.google.com/mapfiles/ms/icons/purple-dot.png' ;
var locations = <?php get_all_locations() ?>;
function initMap() {
var france = {lat: 46.87916, lng: -3.32910};
infowindow = new google.maps.InfoWindow();
map = new google.maps.Map(document.getElementById('map'), {
center: france,
zoom: 7
});
var i ; var confirmed = 0;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon : locations[i][4] === '1' ? red_icon : purple_icon,
html: document.getElementById('form')
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
confirmed = locations[i][4] === '1' ? 'checked' : 0;
$("#confirmed").prop(confirmed,locations[i][4]);
$("#id").val(locations[i][0]);
$("#description").val(locations[i][3]);
$("#form").show();
infowindow.setContent(marker.html);
infowindow.open(map, marker);
}
})(marker, i));
}
}
function saveData() {
var confirmed = document.getElementById('confirmed').checked ? 1 : 0;
var id = document.getElementById('id').value;
var url = 'locations_model.php?confirm_location&id=' + id + '&confirmed=' + confirmed ;
downloadUrl(url, function(data, responseCode) {
if (responseCode === 200 && data.length > 1) {
infowindow.close();
window.location.reload(true);
}else{
infowindow.setContent("<div style='color: purple; font-size: 25px;'>Inserting Errors</div>");
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
</script>
<div style="display: none" id="form">
<table class="map1">
<tr>
<input name="id" type='hidden' id='id'/>
<td><a>Description:</a></td>
<td><textarea disabled id='description' placeholder='Description'></textarea></td>
</tr>
<tr>
<td><b>Confirm Location ?:</b></td>
<td><input id='confirmed' type='checkbox' name='confirmed'></td>
</tr>
<tr><td></td><td><input type='button' value='Save' onclick='saveData()'/></td></tr>
</table>
</div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?language=en&key=AIzaSyA-AB-9XZd-iQby-bNLYPFyb0pR2Qw3orw&callback=initMap">
</script>