-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversionTreeLoader.php
More file actions
57 lines (44 loc) · 1.66 KB
/
Copy pathversionTreeLoader.php
File metadata and controls
57 lines (44 loc) · 1.66 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
57
<?php
session_start();
require('db.php');
if (isset($_SESSION['username'])){
$data2 = array();
$username = $_SESSION['username'];
$username = stripslashes($username);
$data = array();
$projectID = $_POST['projectID'];
$query="SELECT * FROM versions WHERE projectID='$projectID' ORDER BY parent ASC";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$rows = mysqli_num_rows($result);
if($rows>=1){
while($row = mysqli_fetch_array($result)) {
$inData = array();
$inData['versionID'] = $row[1];
$inData['title'] = $row[2];
$inData['description'] = $row[3];
$inData['parent'] = $row[4];
$inData['projectID'] = $row[0];
array_push($data,$inData);
}
$new = array();
foreach ($data as $a){
$new[$a['parent']][] = $a;
}
function createTree(&$list, $parent){
$tree = array();
foreach ($parent as $k=>$l){
if(isset($list[$l['versionID']])){
$l['children'] = createTree($list, $list[$l['versionID']]);
}
$tree[] = $l;
}
return $tree;
}
$tree = createTree($new, array($data[0]));
$data = $tree;
}else{
$data['success'] = false;
}
echo json_encode($data);
}
?>