-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
348 lines (305 loc) · 11.8 KB
/
index.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
<!--mbrousseau, Jan, 2014
Entry form for Sound Map, utilizes js location picker by https://github.com/rolos79/locationpicker-->
<?php
//Allow headers in any order
ob_start();
//Grab the database info
require("phpsqlajax_dbinfo.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
//Expiry headers
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//The session cookie from BLTI security code
include '/var/www/html/elearn-admin/functions.php';
// Load up the LTI Support code - from https://code.google.com/p/ims-dev/
require_once 'blti.php';
// Initialize, all secrets are 'secret', do not set session, and do not redirect
$context = new BLTI("%SECRET%", false, false);
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Sound Map Point Entry</title>
<!--The javascript for the location picker-->
<link type="text/css" rel="stylesheet" href="css/locationpicker.css" />
<!--The javascript for the google map-->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<!--JQuery inclusion stuff-->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="css/modal-style.css">
<!--Modal and verification script-->
<script>
$(function() {
var name = $( "#locName" ),
url = $( "#url" ),
username = $( "#userName" ),
latlong = $( "#picker" ),
desc = $( "#desc" ),
allFields = $( [] ).add( name ).add( url ).add( username ).add( latlong ).add( desc ),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 520,
width: 500,
position:['middle',50],
closeOnEscape: false,
modal: true,
buttons: {
"Create a Sound Point": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
//Test output of field information
console.log("Name: "+name.val()+" Length: "+name.val().length);
console.log("Url: "+url.val()+" Length: "+url.val().length);
console.log("Username: "+username.val()+" Length: "+username.val().length);
console.log("Latlong: "+latlong.val()+" Length: "+latlong.val().length);
console.log("Desc: "+desc.val()+" Length: "+desc.val().length);
//allFields = $( [] ).add( name ).add( url ).add( username ).add( latlong ).add( desc ),
bValid = bValid && checkLength( name, "location name", 3, 50 );
bValid = bValid && checkLength( url, "url", 6, 80 );
bValid = bValid && checkLength( username, "name", 3, 50 );
bValid = bValid && checkLength( latlong, "geoLocation", 3, 50 );
bValid = bValid && checkLength( desc, "description", 6, 80 );
if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + url.val() + "</td>" +
"<td>" + username.val() + "</td>" +
"<td>" + latlong.val() + "</td>" +
"<td>" + desc.val() + "</td>" +
"</tr>" );
$( "#soundSubmit" ).click();
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
username.val("");
}
});
$( "#dialog-form-rem" ).dialog({
autoOpen: false,
height: 520,
width: 500,
position:['middle',50],
modal: true});
$( "#picker" ).click(function() {
$( "#lp-search" ).focus();
});
$( "#create-point" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
$( "#remove-point" )
.button()
.click(function() {
$( "#dialog-form-rem" ).dialog( "open" );
});
});
</script>
<!--Script for the location picker-->
<script type="text/javascript">
//<![CDATA[
var customIcons = {
audio: {
icon: 'img/sound_yellow2.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(43.119953, -79.246552),
zoom: 16,
mapTypeId: google.maps.MapTypeId.HYBRID
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var desc = markers[i].getAttribute("desc");
var url = markers[i].getAttribute("url");
var createdby = markers[i].getAttribute("createdby");
//Check if there is a correct protocol selected for the url
var startUrl = url.indexOf("http://");
var startUrls = url.indexOf("https://");
//If there isn't append http
if(startUrl == -1 && startUrls == -1){
url = "http://"+url;
}
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<div style='min-height:180px;'><b>" + name + "</b> <br/><i>Created by: " + createdby + "</i><br /><br/>" + desc + '<br /><a href="' + url + '" target="_blank">' + url + '</a></div>';
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.setOptions({maxWidth: 200});
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
</head>
<body onload="load()">
<!--Wrapper div for padding-->
<div id = "wrapper">
<div style="float:left"><h2>Sound Map</h2></div>
<!--SOUND MAP POINT ENTRY - Add new points on the map-->
<div style="float:right"><button id="remove-point">- Remove Sound Point</button></div>
<div style="float:right"><button id="create-point">+ Create new Sound Point</button></div>
<!--SOUND MAP - The actual sound map-->
<div id="map" style="width: 100%; height: 800px"></div>
<!--Modal for creating new points-->
<div id="dialog-form" title="Add new sound point">
<p class="validateTips">All form fields are required.</p>
<!--Main submission form with loc picker-->
<form action="index.php" id="audioForm" method="POST">
<label for='locName'>Location Name:</label>
<input type='text' name='locName' id='locName'/><br />
<label for='url'>URL to Sound File:</label>
<input type='text' name='url' id='url'/><br />
<label for='userName'>Username:</label>
<input type='text' name='userName' id='userName' value="<?php echo $user['username'];?>" value readonly/><br />
<label for='picker'>geoLocation:</label>
<input class='latlng' type='text' name='picker' id='picker' value readonly/>
<button type="button" value="Close">Close</button><br />
<label for='desc'>Item Description:</label><br />
<textarea rows='8' cols='60' name='desc' id='desc'></textarea><br />
<input style="visibility:hidden" type='submit' value='Add Entry' id ="soundSubmit" name="soundSubmit"/>
</form>
</div>
<!--Modal for removing points-->
<div id="dialog-form-rem" title="Remove a sound point">
<p class="validateTips">This is a listing of all of the sound point you've created. <br />Choose remove on the point you'd like to delete. <br />There is no way to reverse this process.</p>
<!--Main submission form with loc picker-->
<form action="index.php" id="removeForm" name="removeForm" method="POST">
<?php
//Get the sound points the current user has created and present them for potential deletion
$db2 = new PDO('mysql:host=localhost;dbname='.$database.';charset=utf8', $username, $password);
if (!$db2) {
die('Failed to connect to DB : ' . mysql_error());
}
// Select all the rows in the markers table
$stmt2 = $db2->prepare('SELECT * FROM `markers` WHERE `createdby` = "'.$user['username'].'"');
$stmt2->execute();
//Pull out all the points the user has created
while (($row = $stmt2->fetch(PDO::FETCH_ASSOC)) !== false) {
//print_r($row);
echo $row['name'].' - <input style="display:inline" type="checkbox" value="'.$row['id'].'" id ="check-'.$row['id'].'" name="check-'.$row['id'].'">
<br />';
}
?>
<input type='button' value='Remove Item(s)' onclick='$( "#soundRemove" ).click()'/>
<input style="visibility:hidden" type='submit' value='Remove Entry' id ="soundRemove" name="soundRemove"/>
</form>
</div>
<!--Load the location picker javascript-->
<script src="js/jquery.locationpicker.js"></script>
<script>
$('.latlng').locationPicker();
</script>
<?php
//If the user has submitted the form to add a point
if(isset($_POST["soundSubmit"])){
// Opens a connection to a MySQL server using PDO
$db = new PDO('mysql:host=localhost;dbname='.$database.';charset=utf8', $username, $password);
if (!$db) {
die('Failed to connect to DB : ' . mysql_error());
}
//Pull apart the lat and long
$latLong = explode(",", $_POST['picker']);
// Select all the rows in the markers table
$stmt = $db->prepare("INSERT INTO markers(`name`,`lat`,`lng`,`desc`,`url`,`createdby`) VALUES(?,?,?,?,?,?)");
//Try catch the prepared statment or throw the mysql error
try {
$stmt->execute(array($_POST["locName"], $latLong[0], $latLong[1], htmlspecialchars($_POST["desc"], ENT_QUOTES), htmlspecialchars($_POST["url"], ENT_QUOTES), $_POST["userName"], $found_cookie['context_id']));
} catch(PDOException $ex) {
echo "Unable to: "; //user friendly message
echo $ex->getMessage();
}
header("Location: index.php?");
}
//If the user has submitted the form to remove a point
if(isset($_POST["soundRemove"])){
// Opens a connection to a MySQL server using PDO
$db = new PDO('mysql:host=localhost;dbname='.$database.';charset=utf8', $username, $password);
if (!$db) {
die('Failed to connect to DB : ' . mysql_error());
}
//Run through all the submitted items for removal
foreach ($_POST as &$check){
if($check == "Remove Entry"){
break;
}
// Select all the rows in the markers table
$stmt = $db->prepare("DELETE FROM `markers` WHERE `id` = ?");
//Try catch the prepared statment or throw the mysql error
try {
$stmt->execute(array($check));
} catch(PDOException $ex) {
echo "Unable to: "; //user friendly message
echo $ex->getMessage();
}
}
//Push the user to the map with a blank get pass to stop multiple submits/removals
header("Location: index.php?");
}
?>
</div>
</body>
</html>