-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
479 lines (421 loc) · 19.6 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
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<?php
include("res/php/auth.php");
include("res/php/loadfunc.php");
include("res/php/links.php");
?>
<?php
mysql_connect($mysql_host,$username,$password);
$con = mysql_connect($mysql_host,$username,$password);
if (!$con) {
die("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Error: </strong>" . mysql_error() . "</strong></div>");
}
$db = mysql_select_db($database);
?>
<?php
$sql = 'SELECT * FROM `Buildings` LIMIT 0, 30 ';
$rs = mysql_query($sql);
if (!$rs) { die("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Error: </strong>" . mysql_error() . "</strong></div>"); } ?>
<script type="text/javascript">
window.onkeydown = function(e) {
return !(e.keyCode == 32);
};
/* Functions involved with music BEGIN */
// Global Variables involved in playing music
var playing = false;
var reported = false;
var mid = '';
var ptok = '';
var gData = {};
var bName = 'Building Name';
// API keys and information
var lfmbase = "http://ws.audioscrobbler.com/2.0/";
var lfmkey = "&api_key=b15a0b92b58b210280fa88c5ae3bd038";
var etbase = "http://8tracks.com";
var etkey = "?api_key=efaea88b3f74c64c06351f6e76674f65bcc23ea0&api_version=2";
var loadMix = function (tag, name) {
// encode tags in URL formating
var tags = encodeURIComponent(tag);
// Make sure there are tags
if (tags != null) {
// Build ajax url string
var sear = "&tag=" + tags + "&sort=popular";
var mix = etbase + "/mixes.jsonp" + etkey + sear;
var purl = etbase + "/sets/new.jsonp" + etkey;
$.when(
$.ajax({ // Grab the mix id
url: mix,
dataType: "jsonp",
success: function(data) {
console.log(data);
if (data.total_entries >= 1) {
mid = data.mixes[0].id;
console.log("Grabbed Mix ID: " + data.mixes[0].name + " ("+mid+")");
} else {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>8Tracks Error</strong> Unable to find playlist with those tags.</div>");
}
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
}), $.ajax({ // Grab the play token
url: purl,
dataType: "jsonp",
success: function(data) {
ptok = data.play_token;
console.log("Grabbed Play Token: "+ptok);
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
})
).done(function(a1, a2){ // Make sure both ajax calls complete successfully
// Construct call play url string
var play = etbase+"/sets/"+ptok+"/play.jsonp"+etkey+"&mix_id="+mid;
$.ajax({ // Get current track
url: play,
dataType: "jsonp",
success: function(data) {
gData = data;
$("video").attr("src", data.set.track.url);
$("#player").get(0).play();
playing = true;
bName = name;
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
});
});
}
} // loadMix()
/* Functions involved with music END */
/* Functions involved with voting BEGIN */
var upVote = function (tid) {
$.ajax({
url: "res/php/upvote.php",
data: "tid="+tid,
success: function(data) {
$("#msg").append("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Thank you!</strong> Your vote has been recieved</div>");
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
});
} // upVote()
var dnVote = function (tid) {
$.ajax({
url: "res/php/dnvote.php",
data: "tid="+tid,
success: function(data) {
$("#msg").append("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Thank you!</strong> Your vote has been recieved.</div>");
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
});
} // dnVote()
/* Functions involved with voting END */
var refreshSize = function () {
}
// Add a Building
function addBuilding() {
var name = "name=" + encodeURIComponent($("input#name").val());
var tag1 = "&tag1=" + encodeURIComponent($("input#tag1").val());
var tag2 = "&tag2=" + encodeURIComponent($("input#tag2").val());
var tag3 = "&tag3=" + encodeURIComponent($("input#tag3").val());
var lat = "&lat=" + $("input#lat").val();
var lng = "&lng=" + $("input#lng").val();
$.ajax({
url: "res/php/add.php",
data: name+tag1+tag2+tag3+lat+lng,
success: function(newdata) {
$("#msg").append("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Thank you!</strong> The building has been created.</div>");
console.log("newdata is: " + newdata);
console.log("newdata[4] is: " + newdata[4]);
var lat = newdata[0];
var lng = newdata[1];
var name = newdata[2];
var id = newdata[3];
var tagarr = newdata[4];
var ratingarr = newdata[5];
var tidarr = newdata[6];
var first = true;
var playTags;
var dispTags = "";
for(var tag in tagarr){
if (first) { playTags = tagarr[tag]; first = false; }
else if (tag < 3 ) { playTags += "+" + tagarr[tag]; }
dispTags += "<p><span class='label label-jam'><a href='#' onclick='upVote("+tidarr[tag]+")'><i class='icon-white icon-thumbs-up'></i></a>";
dispTags += " [ " + ratingarr[tag] + " ] ";
dispTags += "<a href='#' onclick='dnVote("+tidarr[tag]+")'><i class='icon-white icon-thumbs-down'></i></a></span>";
dispTags += "<span class='badge badge-jam'>" + tagarr[tag] + "</span></p>";
}
var contentString = "<div>" +
"<button class='btn btn-jam' onclick='loadMix(\""+playTags+"\", \"New Building\")'>" +
"<h3>Play New Building <i class='icon-white icon-chevron-right'></i></h3>" +
"</button></div>";
$("#output").html(contentString);
},
error: function(jqXHR, textStatus, errorThrown) {
$("#msg").append("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>"+textStatus+"</strong> "+errorThrown+"</div>");
},
open: function() { $("#brand").addClass( "ui-autocomplete-loading" ); },
close: function() { $("#brand").removeClass( "ui-autocomplete-loading" ); }
});
} // addBuilding()
/* Start of map code */
/* Find where user is, specifically ask for it */
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success);
} else {
error('Geo Location is not supported');
}
var usrLat;
var usrLng;
var usrLatLng;
var geocoder;
var geoAddress;
function success(position) {
usrLat = position.coords.latitude;
usrLng = position.coords.longitude;
usrLatLng = new google.maps.LatLng(usrLat, usrLng);
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': usrLatLng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
geoAddress = results[0].formatted_address;
initialize();
}
} else {
console.log("Geocoder failed due to: " + status + "\n usrLat: " + usrLat +"\n usrLng: " + usrLng);
}
});
}
/* End of user geolocation*/
var map;
function initialize() {
// Init map options
var mapOptions = {
zoom: 16,
center: new google.maps.LatLng(usrLat, usrLng),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
// Markers
var id;
var markers = {};
var infowindow = new google.maps.InfoWindow();
// Add Init markers
var addInitMarker = function (alatlng, name, id, tagarr, ratingarr, tidarr) {
var image = "play.png";
marker = new google.maps.Marker({
position: alatlng,
map: map,
icon: image,
animation: google.maps.Animation.DROP
});
var first = true;
var playTags;
var dispTags = "";
for(var tag in tagarr){
if (first) { playTags = tagarr[tag]; first = false; }
else if(ratingarr[tag] > 0) { playTags += "+" + tagarr[tag]; }
if (ratingarr[tag] > 0){
dispTags += "<p><span class='label label-jam'><a href='#' onclick='upVote("+tidarr[tag]+")'><i class='icon-white icon-thumbs-up'></i></a>";
dispTags += " [ " + ratingarr[tag] + " ] ";
dispTags += "<a href='#' onclick='dnVote("+tidarr[tag]+")'><i class='icon-white icon-thumbs-down'></i></a></span>";
dispTags += "<span class='badge badge-jam'>" + tagarr[tag] + "</span></p>";
}
}
var contentString = "<div>" +
"<button class='btn btn-jam' onclick='loadMix(\""+playTags+"\", \""+name+"\")'>" +
"<h3>" + name + "<i class='icon-white icon-chevron-right'></i></h3>" +
"</button></div>";
contentString += dispTags;
makeInfoWindowEvent(map, infowindow, contentString, marker);
id = marker.__gm_id
markers[id] = marker;
google.maps.event.addListener(marker, "dblclick", function (point) {
id = this.__gm_id;
delMarker(id);
});
google.maps.event.addListener(marker, 'click', function(point) {
id = this.__gm_id;
infowindow.open(map, markers[id]);
});
var circleSize = 1;
// Circle size proportional to ratings
for(var tag in tagarr){ circleSize += Number(ratingarr[tag]); }
var circleOptions = {
strokeColor: "#8800CC",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#8800CC",
fillOpacity: 0.35,
map: map,
center: alatlng,
radius: 50 * circleSize
};
musicCircle = new google.maps.Circle(circleOptions);
} // addInitMarker()
// Add markers
var addMarker = function (alatlng) {
var image = "play.png";
marker = new google.maps.Marker({
position: alatlng,
map: map,
draggable: false,
icon: image,
animation: google.maps.Animation.DROP
});
var geocoder = new google.maps.Geocoder();
var geoAddress;
geocoder.geocode({'latLng': alatlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
geoAddress = results[0].formatted_address;
var contentString = "<div id='output'>" +
"<h2>When you're at...</h2>"+
"<input type='text' name='name' id='name' value='"+ geoAddress + "' autofocus='autofocus'/><br/>" +
"<p class='lead'>...what does it remind you of?</p>"+
"<input type='text' name='tag1' id='tag1' placeholder='mood, genre, or artist' required='required'/><br/>" +
"<input type='text' name='tag2' id='tag2' placeholder='mood, genre, or artist'/><br/>" +
"<input type='text' name='tag3' id='tag3' placeholder='mood, genre, or artist'/><br/>" +
"<input type='text' name='lat' id='lat' value='"+alatlng.lat()+"' style='display:none;'/><br/>" +
"<input type='text' name='lng' id='lng' value='"+alatlng.lng()+"' style='display:none;'/>" +
"<button type='submit' onclick='addBuilding()' class='btn btn-jam'>Save</button></div>";
makeInfoWindowEvent(map, infowindow, contentString, marker);
}
} else {
console.log("Geocoder failed in addMarker due to: " + status);
}
});
//map.panTo(alatLng);
id = marker.__gm_id
markers[id] = marker;
google.maps.event.addListener(marker, "rightclick", function (point) { id = this.__gm_id; delMarker(id) });
google.maps.event.addListener(marker, 'click', function(point) {
id = this.__gm_id;
infowindow.open(map, markers[id]);
});
} // addMarker()
function makeInfoWindowEvent(map, infowindow, contentString, marker) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
} // makeInfoWindowEvent()
// Right click handler
google.maps.event.addListener(map, "dblclick", function(event) {
var lat = event.latLng.lat();
var lng = event.latLng.lng();
var myLatlng = new google.maps.LatLng(lat, lng);
addMarker(myLatlng);
});
// Retrieve information to be displayed in infopane from database. Gets lat, long, name, id, and the related tags (and their ratings)
<?php while($row = mysql_fetch_array($rs)) { ?>
<?php $sql2 = "SELECT * FROM `Tags` WHERE `building` = '".$row['id']."'";
$rs2 = mysql_query($sql2);
if (!$rs2) { die("<div class='alert alert-error fade in'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Error: </strong>" . mysql_error() . "</strong></div>"); }
?>
var tagarr = [];
var ratingarr = [];
var tidarr = [];
var i = 0;
<?php while($row2 = mysql_fetch_array($rs2)) { ?>
tagarr[i] = "<?=$row2['tag']?>";
ratingarr[i] = "<?=$row2['rating']?>";
tidarr[i] = "<?=$row2['id']?>";
i++;
<?php } ?>
addInitMarker(new google.maps.LatLng(<?=$row['lat']?>, <?=$row['lng']?>), "<?=$row['name']?>", <?=$row['id']?>, tagarr, ratingarr, tidarr);
<?php } ?>
/* Assign map to be entirty of window */
$("#map_canvas").css("height", window.innerHeight - 40);
$("#map_canvas").css("width", window.innerWidth);
$(document).ready(function() {
// Add user's marker
console.log("Adding user location" + usrLatLng);
addMarker(usrLatLng);
});
} // initialize()
/* Assign map to be entirty of window on resize BEGIN */
window.onresize = function() {
$("#map_canvas").css("height", window.innerHeight - 40);
$("#map_canvas").css("width", window.innerWidth);
}
/* Assign map to be entirty of window on resize END */
google.maps.event.addDomListener(window, 'load', initialize);
var toggleMusic = function (){
if (playing) {
$("#player").get(0).pause();
playing = false;
}
else {
$("#player").get(0).play();
playing = true;
}
}
</script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<!-- Button to trigger modal -->
<div class="row-fluid">
<div class="span3 track">
<button onclick="toggleMusic()" class="btn btn-jam control-conatiner pull-left " style="height:40px;width:40px;">
<i id="control" class="icon-white" ></i>
</button>
<div class="progress progress-jam progress-striped active" style="height:20px;">
<div class="bar" id="time"><span id="current" class="badge badge-jam">0:00</span></div>
</div>
</div>
<div class="span6 info" id="info">
<i class="icon-music icon-white"></i> Track Name <i class="icon-user icon-white"></i> Artist <i class="icon-volume-up icon-white"></i> You're listening to the sounds of <strong>Building Name</strong>
</div>
<div class="span3">
<!--a href="#help" role="button" class="btn btn-jam" data-toggle="modal" id="helpBtn">Need Help?</a-->
<div class="pull-right"><a class="brand" id="brand" href="./index.php">JamWalkr</a></div>
</div>
</div>
</div>
</div>
</div>
<span id="msg"></span>
<video id="player" class="data"></video>
<div id="map_canvas"></div>
<!-- Modal -->
<div id="help" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Welcome to JamWalkr</h3>
</div>
<div class="modal-body">
<p class="lead">What is JamWalkr?</p>
<p>JamWalkr is a music tagging application. Users are encouraged to tag buildings with moods, genres or artists. As the number of tagged buildings grow, we can see how the citizens of a city thinks their city sounds.</p>
<p class="lead">How do I participate?</p>
<p>To add a point, simiply right click and fill out the form. You can view already tagged buildings by clicking on their markers. Please also vote on whether you agree with the tags by voting up or down the specific tags.</p>
</div>
<div class="modal-footer">
<button class="btn btn-jam" data-dismiss="modal" aria-hidden="true">Start Jammin'</button>
</div>
</div>
<a href="http://www.000webhost.com/" target="_blank" class="host"><img src="http://www.000webhost.com/images/80x15_powered.gif" alt="Web Hosting" width="80" height="15" border="0" /></a>
</body>
</html>