-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfound.js
executable file
·56 lines (55 loc) · 1.79 KB
/
found.js
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
var config = {
apiKey: "AIzaSyDa2Jw2AY8rKjEOHjC3zpSr5o6uxOzKbI0",
authDomain: "lost-and-found-e04ad.firebaseapp.com",
databaseURL: "https://lost-and-found-e04ad.firebaseio.com",
storageBucket: "lost-and-found-e04ad.appspot.com",
messagingSenderId: "404142438505"
};
firebase.initializeApp(config);
var uuid;
function determineUID(){
var finalLocation;
var urlvars = document.URL.match(/(\?|\&)([^=]+)\=([^&]+)/g);
//console.log(urlvars);
var uuidtemp = urlvars[0];
uuid = uuidtemp.substring(5);
//console.log(uuid);
}
function storeloc(lat,long){
console.log(lat);
console.log(long);
}
function updateTime(time){
return time.getHours()+":"+time.getMinutes()+":"+time.getSeconds()+" on "+(time.getMonth()+1)+"-"+time.getDate()+"-"+time.getFullYear();
}
function storeaddressandtime(add){
var uid;
var address = add.formatted_address;
var time = new Date();
//console.log(time.getMonth());
time = updateTime(time);
var itemname;
//console.log(time);
firebase.database().ref('/Items').once('value').then(function(snapshot){
uid = snapshot.val()[uuid];
console.log(uid);
//console.log(uid);
//console.log(uuid);
firebase.database().ref('/Users/'+uid + '/items/' + uuid).once('value').then(function(snapshot2){
console.log(snapshot2.val());
itemname = snapshot2.val()["name"];
var updates = {};
//console.log(itemname);
var postData = {
name: itemname,
location: address,
time: time
};
updates['/Users/'+uid + '/items/'+uuid] = postData;
firebase.database().ref().update(updates).then(function(){
console.log("updates pushed");
alert("Thank you! The location was transmitted. I'm sure the person you just help will be grateful. You may close this site if you like.");
});
});
});
}