-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.php
More file actions
56 lines (47 loc) · 1.97 KB
/
tree.php
File metadata and controls
56 lines (47 loc) · 1.97 KB
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
<?php
// set headers
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET POST');
header('Content-Type: application/json');
// add necessary files
include("config/database.php");
include("utilities/db.php");
include("utilities/tree.php");
if($_SERVER['REQUEST_METHOD'] == "GET") {
if(isset($_GET['treeid'])) {
if($_GET['treeid'] < 0) {
echo json_encode(array("status" => "Error", "message" => "treeid cannot be negative"));
} else {
$tree = fetch_tree($conn, $_GET['treeid']);
echo json_encode(array("status" => "Success", "data" => $tree));
}
} else {
echo json_encode(array("status" => "Error", "message" => "Tree details not found" ));
}
}
if($_SERVER['REQUEST_METHOD'] == "POST") {
// create the array
$tree = array();
$tree['TREEID'] = $_POST['treeid'];
$tree['TreeTag'] = $_POST['treetag'];
$tree['TreeType'] = $_POST['treetype'];
$tree['SpeciesType'] = $_POST['speciestype'];
$tree['Species'] = $_POST['species'];
$tree['Age'] = $_POST['age'];
$tree['TreeSurround'] = $_POST['treesurround'];
$tree['Vigour'] = $_POST['vigour'];
$tree['Condition'] = $_POST['condition'];
$tree['Longitude'] = $_POST['longitude'];
$tree['Latitude'] = $_POST['latitude'];
$tree['Height'] = $_POST['height'];
$tree['Description'] = $_POST['description'];
$tree['SpreadRadius'] = $_POST['spreadradius'];
$tree['Diameter'] = $_POST['diameter'];
$result = updateTree($conn, $tree);
if($result['status'] == "Success") {
echo json_encode(array("status" => "Success", "data" => $result['tree']));
} else {
echo json_encode(array("status" => "Error", "message" => $result['error']));
}
}
?>