-
Notifications
You must be signed in to change notification settings - Fork 5
/
contribmap-service.php
57 lines (47 loc) · 1.56 KB
/
contribmap-service.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
<?php
//$ip = $_SERVER['REMOTE_ADDR'];
//echo $ip;
// List points from database
if ($_GET['action'] == 'listpoints') {
$query = "SELECT * FROM location_master INNER JOIN (trees, user_tree_table) ON trees.tree_id=user_tree_table.tree_id AND trees.tree_location_id=location_master.tree_location_id";
$result = map_query($query);
$points = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push($points, array('name' => $row['location_name'], 'lat' => $row['latitude'], 'lng' => $row['longitude']));
}
echo json_encode(array("Locations" => $points));
exit;
}
function map_query($query) {
// Connect
mysql_connect('localhost', 'root', 'root')
OR die(fail('Could not connect to database.'));
mysql_select_db('ncbs_test');
return mysql_query($query);
}
function fail($message) {
die(json_encode(array('status' => 'fail', 'message' => $message)));
}
function success($data) {
die(json_encode(array('status' => 'success', 'data' => $data)));
}
/* // Save a point from our form
if ($_POST['action'] == 'savepoint') {
$name = $_POST['name'];
if(preg_match('/[^\w\s]/i', $name)) {
fail('Invalid name provided.');
}
if(empty($name)) {
fail('Please enter a name.');
}
// Query
$query = "INSERT INTO location_master SET location_name='$_POST[name]', latitude='$_POST[lat]', longitude='$_POST[lng]'";
$result = map_query($query);
if ($result) {
success(array('lat' => $_POST['lat'], 'lng' => $_POST['lng'], 'name' => $name));
} else {
fail('Failed to add point.');
}
exit;
} */
?>