-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_class.php
154 lines (141 loc) · 4.5 KB
/
admin_class.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
session_start();
Class Action {
private $db;
public function __construct() {
ob_start();
include 'db_connect.php';
$this->db = $conn;
}
function __destruct() {
$this->db->close();
ob_end_flush();
}
function login(){
extract($_POST);
$qry = $this->db->query("SELECT * FROM users where username = '".$username."' and password = '".$password."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'passwors' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
return 1;
}else{
return 2;
}
}
function logout(){
session_destroy();
foreach ($_SESSION as $key => $value) {
unset($_SESSION[$key]);
}
header("location:login.php");
}
function save_folder(){
extract($_POST);
$data = " name ='".$name."' ";
$data .= ", parent_id ='".$parent_id."' ";
if(empty($id)){
$data .= ", user_id ='".$_SESSION['login_id']."' ";
$check = $this->db->query("SELECT * FROM folders where user_id ='".$_SESSION['login_id']."' and name ='".$name."'")->num_rows;
if($check > 0){
return json_encode(array('status'=>2,'msg'=> 'Folder name already exist'));
}else{
$save = $this->db->query("INSERT INTO folders set ".$data);
if($save)
return json_encode(array('status'=>1));
}
}else{
$check = $this->db->query("SELECT * FROM folders where user_id ='".$_SESSION['login_id']."' and name ='".$name."' and id !=".$id)->num_rows;
if($check > 0){
return json_encode(array('status'=>2,'msg'=> 'Folder name already exist'));
}else{
$save = $this->db->query("UPDATE folders set ".$data." where id =".$id);
if($save)
return json_encode(array('status'=>1));
}
}
}
function delete_folder(){
extract($_POST);
$delete = $this->db->query("DELETE FROM folders where id =".$id);
if($delete)
echo 1;
}
function delete_file(){
extract($_POST);
$path = $this->db->query("SELECT file_path from files where id=".$id)->fetch_array()['file_path'];
$delete = $this->db->query("DELETE FROM files where id =".$id);
if($delete){
unlink('assets/uploads/'.$path);
return 1;
}
}
function save_files(){
extract($_POST);
if(empty($id)){
if($_FILES['upload']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['upload']['name'];
$move = move_uploaded_file($_FILES['upload']['tmp_name'],'assets/uploads/'. $fname);
if($move){
$file = $_FILES['upload']['name'];
$file = explode('.',$file);
$chk = $this->db->query("SELECT * FROM files where SUBSTRING_INDEX(name,' ||',1) = '".$file[0]."' and folder_id = '".$folder_id."' and file_type='".$file[1]."' ");
if($chk->num_rows > 0){
$file[0] = $file[0] .' ||'.($chk->num_rows);
}
$data = " name = '".$file[0]."' ";
$data .= ", folder_id = '".$folder_id."' ";
$data .= ", description = '".$description."' ";
$data .= ", user_id = '".$_SESSION['login_id']."' ";
$data .= ", file_type = '".$file[1]."' ";
$data .= ", file_path = '".$fname."' ";
if(isset($is_public) && $is_public == 'on')
$data .= ", is_public = 1 ";
else
$data .= ", is_public = 0 ";
$save = $this->db->query("INSERT INTO files set ".$data);
if($save)
return json_encode(array('status'=>1));
}
}
}else{
$data = " description = '".$description."' ";
if(isset($is_public) && $is_public == 'on')
$data .= ", is_public = 1 ";
else
$data .= ", is_public = 0 ";
$save = $this->db->query("UPDATE files set ".$data. " where id=".$id);
if($save)
return json_encode(array('status'=>1));
}
}
function file_rename(){
extract($_POST);
$file[0] = $name;
$file[1] = $type;
$chk = $this->db->query("SELECT * FROM files where SUBSTRING_INDEX(name,' ||',1) = '".$file[0]."' and folder_id = '".$folder_id."' and file_type='".$file[1]."' and id != ".$id);
if($chk->num_rows > 0){
$file[0] = $file[0] .' ||'.($chk->num_rows);
}
$save = $this->db->query("UPDATE files set name = '".$name."' where id=".$id);
if($save){
return json_encode(array('status'=>1,'new_name'=>$file[0].'.'.$file[1]));
}
}
function save_user(){
extract($_POST);
$data = " name = '$name' ";
$data .= ", username = '$username' ";
$data .= ", password = '$password' ";
$data .= ", type = '$type' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO users set ".$data);
}else{
$save = $this->db->query("UPDATE users set ".$data." where id = ".$id);
}
if($save){
return 1;
}
}
}