-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_pos.php
61 lines (49 loc) · 2.02 KB
/
update_pos.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
<?php
// Connect to database
$host = 'localhost';
$user = 'root';
$pass = '';
$conn_error = 'Could Not Connect';
$dbname = "trackme";
// Create connection
$conn = mysqli_connect($host, $user, $pass, $dbname);
// Check connection
if ($conn){
// Get data
$phone_id = mysqli_real_escape_string($conn,$_GET["guid"]);
$lat_ = mysqli_real_escape_string($conn,$_GET["lat"]);
$long_= mysqli_real_escape_string($conn,$_GET["lng"]);
// Update user data
$query1 = "UPDATE users SET latitudes = $lat_, longitudes = $long_, last_update = NOW() WHERE id = '$phone_id'";
mysqli_query($conn, $query1) OR die($conn_error);
// Get user channel
$channel = '';
$query2 = "SELECT channel FROM users WHERE id = '$phone_id'";
if($query_run = mysqli_query($conn,$query2)){
// Getting just the first result, no more
if($query_row = mysqli_fetch_assoc($query_run)){
$channel = $query_row['channel'];
}
}
$arr = array();
// Getting all the informtion of users in the same channel
$query3 = "SELECT * FROM users WHERE channel = '$channel' AND id NOT IN ('$phone_id')";
if($query_run = mysqli_query($conn,$query3)){
while($query_row = mysqli_fetch_assoc($query_run)){
$arry = array();
$arry['username'] = $query_row['username'];
$arry['longitudes'] = $query_row['longitudes'];
$arry['latitudes'] = $query_row['latitudes'];
$arry['last_update'] = $query_row['last_update'];
array_push($arr,$arry);
}
}
// Output data depending if it is cross domain call or normal call
if (isset($_GET["callback"])){
echo $_GET["callback"] . '(' . json_encode($arr) . ')';
}
else{
echo json_encode($arr);
}
}
?>