-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_users.php
325 lines (279 loc) · 8.68 KB
/
system_users.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
/*
HEZECOM UltimateSpeed PHP CODE GENERATOR
Author: Hezecom Technologies (http://hezecom.com) info@hezecom.net
COPYRIGHT 2014 ALL RIGHTS RESERVED
You must have purchased a valid license from CodeCanyon.com in order to have
access this file.
You may only use this file according to the respective licensing terms
you agreed to when purchasing this item.
*/
if(!defined('VALID_DIR')) die('You are not allowed to execute this file directly');
class admin_users_model{
public $userid;
public $name;
public $email;
public $phone;
public $username;
public $password;
public $membership;
public $user_status;
public $user_position;
public $user_avarta;
public $access_level;
public $date_created;
//Constructor
public function __construct()
{
$this->userid = isset($userid);
$this->name = isset($name);
$this->email = isset($email);
$this->phone = isset($phone);
$this->username = isset($username);
$this->password = isset($password);
$this->membership = isset($membership);
$this->user_status = isset($user_status);
$this->user_position = isset($user_position);
$this->user_avarta = isset($user_avarta);
$this->date_created = isset($date_created);
}
// SELECT ALL
public function SelectAll($limit=null)
{
if($limit){
$startpg = pageparam($limit);
return HDB::hus()->Hselect(H_SYSTEM_ACCESS." LIMIT {$startpg} , {$limit}");
}else{
return HDB::hus()->Hselect(H_SYSTEM_ACCESS." category");
}
}
//Select Count for Pagination
public function CountRow()
{
return HDB::hus()->Hcount(H_SYSTEM_ACCESS);
}
// SELECT ONE
public function SelectOne($id)
{
$bind = array(":id" =>$id);
return HDB::hus()->Hone(H_SYSTEM_ACCESS,"userid=:id",$bind);
}
// SELECT ONE
public function SelectUserID($id)
{
$bind = array(":id" =>$id);
return HDB::hus()->Hone(H_SYSTEM_ACCESS,"username=:id",$bind);
}
// DELETE
public function Delete($id,$redirect_to)
{
$bind = array(":id" =>$id);
HDB::hus()->Hdelete(H_SYSTEM_ACCESS," userid=:id",$bind);
send_to($redirect_to);
}
// INSERT
public function Insert($name,$email,$phone,$username,$password,$membership,$user_status,$user_position,$date_created)
{
$newupload = new UploadControl;
$uploadname=$newupload->ImageUplaodResize('user_avarta',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90);
if($uploadname==''){
$values = array(array( 'name'=>$name,'email'=>$email,'phone'=>$phone,'username'=>$username,'password'=>$password,'membership'=>$membership,'user_status'=>$user_status,'user_position'=>$user_position,'date_created'=>$date_created));
}else{
$values = array(array( 'user_avarta'=>$uploadname,'name'=>$name,'email'=>$email,'phone'=>$phone,'username'=>$username,'password'=>$password,'membership'=>$membership,'user_status'=>$user_status,'user_position'=>$user_position,'date_created'=>$date_created));
}
HDB::hus()->Hinsert(H_SYSTEM_ACCESS, $values);
}
// UPDATE
public function Update($name,$email,$phone,$membership,$user_status,$user_position,$date,$id)
{
$newupload = new UploadControl;
$uploadname=$newupload->ImageUplaodResize('user_avarta',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90);
if($uploadname==''){
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET name ='$name',email ='$email',phone ='$phone',membership ='$membership',user_status ='$user_status',user_position ='$user_position',last_updated ='$date' WHERE userid = :id ";
}else{
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET user_avarta='$uploadname',name ='$name',email ='$email',phone ='$phone',membership ='$membership',user_status ='$user_status',user_position ='$user_position',last_updated ='$date' WHERE userid = :id ";
}
$stmt=HDB::hus()->prepare($sql);
$stmt->bindParam(':id',$id, PDO::PARAM_INT);
$stmt->execute();
}
// UPDATE
public function UpdatePassword($password,$date,$id)
{
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET password ='$password', last_updated ='$date' WHERE email = :email ";
$stmt=HDB::hus()->prepare($sql);
$stmt->bindParam(':email',$id);
try{
if($stmt->execute()){;
return true;
}
}catch(PDOException $e){
die($e->getMessage());
}
}
// LAST LOGIN
public function UpdateLastLogin($date,$ip,$id)
{
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET last_login_date ='$date', last_login_ip ='$ip' WHERE userid = :id ";
$stmt=HDB::hus()->prepare($sql);
$stmt->bindParam(':id',$id, PDO::PARAM_INT);
try{
$stmt->execute();
}catch(PDOException $e){
die($e->getMessage());
}
}
// UPDATE EXEMPT
public function UpdateExempt($name,$email,$phone,$date,$id)
{
$newupload = new UploadControl;
$uploadname=$newupload->ImageUplaodResize('user_avarta',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90);
if($uploadname==''){
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET name ='$name',email ='$email',phone ='$phone',last_updated ='$date' WHERE userid = :id ";
}
else{
$sql = " UPDATE ".H_SYSTEM_ACCESS." SET user_avarta='$uploadname',name ='$name',email ='$email',phone ='$phone' ,last_updated ='$date' WHERE userid = :id ";
}
try{
$stmt=HDB::hus()->prepare($sql);
$stmt->bindParam(':id',$id, PDO::PARAM_INT);
$stmt->execute();
} catch (PDOException $e) {
$this->error = $e->getMessage();
}
}
//LOGIN
public function HezeLogin($username,$password,$table) {
$query = HDB::hus()->prepare("SELECT `password`, `username` FROM `$table` WHERE `username` = ?");
$query->bindValue(1, $username);
try{
$query->execute();
$data = $query->fetch();
$my_password = $data['password'];
$username = $data['username'];
$hash = hezecom_crypt($password);
if ($hash == hezecom_crypt($password, $my_password)) {
return $username;
}else{
return false;
}
}catch(PDOException $e){
die($e->getMessage());
}
}
//USER CHECK
public function user_exist_checker($username,$table) {
$query = HDB::hus()->prepare("SELECT COUNT(`username`) FROM `$table` WHERE `username`= ?");
$query->bindValue(1, $username);
try{
$query->execute();
$rows = $query->fetchColumn();
if($rows == 1){
return true;
}else{
return false;
}
} catch (PDOException $e){
die($e->getMessage());
}
}
public function account_activation($username,$table) {
$query = HDB::hus()->prepare("SELECT COUNT(`username`) FROM `$table` WHERE `username`= ? AND `user_status`= ?");
$query->bindValue(1, $username);
$query->bindValue(2, 1);
try{
$query->execute();
$rows = $query->fetchColumn();
if($rows == 1){
return true;
}else{
return false;
}
} catch(PDOException $e){
die($e->getMessage());
}
}
//CHANGE PASSWORD
public function current_password($password,$table,$field,$value) {
$query = HDB::hus()->prepare("SELECT `password` FROM `$table` WHERE `$field` = ?");
$query->bindValue(1, $value);
try{
$query->execute();
$data = $query->fetch();
$my_password = $data['password'];
$hash = hezecom_crypt($password);
if ($hash == hezecom_crypt($password, $my_password)) {
return true;
}else{
return false;
}
}catch(PDOException $e){
die($e->getMessage());
}
}
//UserID
function UserID()
{
$id=$_SESSION[H_USER_SESSION];
$stmt=HDB::hus()->prepare("SELECT userid FROM ".H_SYSTEM_ACCESS." WHERE username=:id");
$stmt->bindParam(':id',$id);
$stmt->execute();
$row= $stmt->fetch(PDO::FETCH_OBJ);
return $row->userid;
}
//access level
function UserAccess()
{
if(isset($_SESSION[H_USER_SESSION]))
$id=$_SESSION[H_USER_SESSION];
$stmt=HDB::hus()->prepare("SELECT * FROM ".H_SYSTEM_ACCESS." WHERE username=:id");
$stmt->bindParam(':id',$id);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_OBJ);
}
//Login Checker
public function logged_in_user () {
return(isset($_SESSION[H_USER_SESSION]) and $this->UserAccess()->user_status==1) ? true : false;
}
public function logged_in_protect($login) {
if ($this->logged_in_user() === false) {
send_to($login);
exit();
}
}
//logout
public function log_out_access($url) {
if ($this->logged_in_user() === true) {
unset($_SESSION[H_USER_SESSION]);
session_destroy();
send_to($url);
exit();
}
}
//RETRIEVE PASSWORD
public function LostPassword($table,$username) {
$query = HDB::hus()->prepare("SELECT `email` FROM `$table` WHERE `email` = ?");
$query->bindValue(1, $username);
try{
$query->execute();
$data = $query->fetch();
$email = $data['email'];
if ($email == $username) {
return $email;
}else{
return false;
}
}catch(PDOException $e){
die($e->getMessage());
}
}
// QUICK SEARCH
public function AutoSearch($qstring,$limit,$where)
{
$stmt=HDB::hus()->prepare("SELECT * FROM ".H_SYSTEM_ACCESS." WHERE $where LIKE :svalue LIMIT $limit");
$stmt->bindValue(':svalue',"%{$qstring}");
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
} // end class
?>