-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
127 lines (112 loc) · 3.54 KB
/
config.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* * DB connection config
*/
class Config{
private $DB_SERVER = 'localhost';
private $DB_USER = 'root';
private $DB_PASS = '';
private $DB_NAME = 'test1';
function __construct()
{
$con = mysqli_connect($this->DB_SERVER,$this->DB_USER,$this->DB_PASS,$this->DB_NAME);
$this->dbc=$con;
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
}
/**
* @param mixed $path
* @param mixed $name
*
*
*/
public function insertPath($path,$name){
$date = date('Y-m-d h:i:s');
$result = mysqli_query($this->dbc,"INSERT INTO filepath (`path`,`name`,`created`) VALUES('$path','$name','$date')");
return $result;
}
/**
* @param null $parentid
* @param mixed $filename
* @param mixed $type
*
* @return [type]
*/
public function insertTree($parentid = null,$filename,$type){
$date = date('Y-m-d h:i:s');
if($parentid == '')
$parentid = 'NULL';
$filename = str_replace(' ','',$filename);
mysqli_query($this->dbc,"INSERT INTO doclist (`parent_id`,`name`) VALUES($parentid,'$filename')");
$last_id = $this->dbc->insert_id;
return $last_id;
}
public function truncateData(){
mysqli_query($this->dbc,"TRUNCATE `filepath`");
mysqli_query($this->dbc,"TRUNCATE `doclist`");
}
/**
* @param mixed $search
*
* @return result in array
*/
public function selectData($search){
$sql = "SELECT `path` from filepath WHERE LOWER(`name`) LIKE '%$search%' ";
$result = $this->dbc->query($sql);
return $result;
}
/**
* @param mixed $search
*
* @return result in array
*/
public function getTreeRecord($search){
$sql = "SELECT id, name, getpath(id) AS path FROM doclist HAVING path LIKE '%$search%'";
$result = $this->dbc->query($sql);
return $result;
}
/**
* @param mixed $search
*
* @return array data
*/
public function selectRecord($search){
$sql = "SELECT `file_name`,`parent_id`,`id` from doclist WHERE LOWER(`file_name`) LIKE '%$search%' ";
$result = $this->dbc->query($sql);
$tree = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$pth = $row["file_name"];
//echo "id: " . $row["id"]. " - Name: " . $row["file_name"]." paretn id : ".$row["parent_id"]."<br>";
$tree[$row["id"]] = $this->fetchTreeList($row["parent_id"],$row);
}
} else {
echo "0 results";
}
return $tree;
}
/**
* @param int $parent
* @param string $tree_array
*
* @return array data
*/
function fetchTreeList($parent = 0, $tree_array = '') {
if (!is_array($tree_array))
$tree_array = array();
$sql = "SELECT `file_name`,`parent_id`,`id` from doclist WHERE id='$parent'";
$result = $this->dbc->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$tree_array['aryparent'][] = array('id'=>$row["id"],'parent_id'=>$row["parent_id"],'file_name'=>$row["file_name"]);
//uksort($tree_array,'aryparent');
$tree_array = $this->fetchTreeList($row["parent_id"], $tree_array);
}
}
return $tree_array;
}
}