-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathclass_staff.php
executable file
·192 lines (172 loc) · 5.25 KB
/
class_staff.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/* For licensing terms, see /license.txt */
class staff extends model {
public $columns = array('id', 'user','email', 'password','salt', 'name', 'perms');
public $table_name = 'staff';
/**
* Creates an user staff
*
* @param int User id
* @param float amount
* @param date expiration date
*/
public function create($params) {
global $db, $main;
if (!empty($params['user']) && !empty($params['email'])) {
if ($this->userNameExists($params['user']) == false) {
$params['salt'] = md5(rand(0,9999999));
$params['password'] = md5(md5($params['password']).md5($params['salt']));
$user_id = $this->save($params);
$main->addLog("Staff created: $user_id");
return $user_id;
} else {
//$array['Error'] = "That username already exist!";
$main->errors('That username already exist!');
}
} else {
$main->errors('Please field the username and email');
}
return false;
}
public function edit($id, $params) {
global $order, $main;
$this->setId($id);
if (isset($params['password']) && !empty($params['password']) ) {
$params['salt'] = md5(rand(0,9999999));
$params['password'] = md5(md5($params['password']).md5($params['salt']));
}
$main->addLog("staff::edit Staff updated #$id");
$this->update($params);
}
/**
* Checks if the username is taken or not
* @param string username
* @return bool true if success
*/
public function userNameExists($username) {
global $db;
$username = $db->strip($username);
$query = $db->query("SELECT id FROM ".$this->getTableName()." WHERE user = '$username'");
if($db->num_rows($query) > 0) {
return true;
} else {
return false;
}
}
/**
* Deletes a user
*/
public function delete($id) {
global $main;
//you cant delete yourself
if ($id != $main->getCurrentStaffId()) {
$this->setId($id);
parent::delete();
$main->addLog("Staff User deleted: $id");
return true;
}
return false;
}
/**
* Gets user information by id
* @param int user id
* @param array user information
*/
public function getStaffUserById($user_id) {
global $db, $main;
$query = $db->query("SELECT * FROM ".$this->getTableName()." WHERE id = '{$db->strip($user_id)}'");
$data = array();
if($db->num_rows($query) > 0) {
$data = $db->fetch_array($query,'ASSOC');
}
return $data;
}
/**
* Gets user information by username
* @param int user id
* @param array user information
*/
public function getStaffUserByUserName($username) {
global $db, $main;
$query = $db->query("SELECT * FROM ".$this->getTableName()." WHERE user = '{$db->strip($username)}'");
$data = array();
if($db->num_rows($query) > 0) {
$data = $db->fetch_array($query,'ASSOC');
}
return $data;
}
/**
* Search a user from a keyword (username, email, name)
*/
public function searchStaffUser($query) {
global $db;
$user_list = array();
if (!empty($query)) {
$query = $db->strip($query);
$sql = "SELECT * FROM ".$this->getTableName()."
WHERE user LIKE '%$query%' OR
email LIKE '%$query%' OR
name LIKE '%$query%'";
$result = $db->query($sql);
if($db->num_rows($result) > 0) {
while($data = $db->fetch_array($result,'ASSOC')) {
$user_list[] = $data;
}
}
}
return $user_list;
}
public function gettAllStaff() {
global $db, $main;
$result = $db->query("SELECT * FROM ".$this->getTableName());
$user_list = array();
if($db->num_rows($result) > 0) {
while($data = $db->fetch_array($result,'ASSOC')) {
$user_list[] = $data;
}
}
return $user_list;
}
public function getStaffById($staff_id) {
global $db, $main;
$query = $db->query("SELECT * FROM ".$this->getTableName()." WHERE id = '{$db->strip($staff_id)}'");
$data = array();
if($db->num_rows($query) > 0) {
$data = $db->fetch_array($query,'ASSOC');
}
return $data;
}
/**
* Only changes the system password not the Control Panel password
*
* A more or less centralized function for changing a client's
* password. This updates both the cPanel/WHM and THT password.
* Will return true ONLY on success. Any other returned value should
* be treated as a failure. If the return value happens to be a
* string, it is an error message.
* @todo this function should be moved to the class_user.php file
*
*/
public function changeStaffPassword($staff_id, $newpass) {
global $db, $user;
//Making sure the $clientid is a reference to a valid id.
$user_info = $user->getStaffById($staff_id);
if (is_array($user_info) && !empty($user_info)) {
$this->edit($staff_id, array('password'=>$newpass));
} else {
return "That client does not exist.";
}
return true;
}
/*
public function updateUserStatus($user_id, $status) {
global $main;
$this->setId($user_id);
$user_status_list = array_keys($main->getUserStatusList());
if (in_array($status, $user_status_list)) {
$params['status'] = $status;
$main->addLog("updateUserStatus function called: $user_id");
$this->update($params);
}
}*/
}