-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.php
More file actions
305 lines (270 loc) · 11.1 KB
/
users.php
File metadata and controls
305 lines (270 loc) · 11.1 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
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
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['userlogin'])==0){
header('location:login.php');
}elseif (isset($_GET['delid'])) {
$rid=intval($_GET['delid']);
$sql="DELETE from users where id=:rid";
$query=$dbh->prepare($sql);
$query->bindParam(':rid',$rid,PDO::PARAM_STR);
$query->execute();
echo "<script>alert('User deleted Successfully');</script>";
}elseif(isset($_POST['add_user'])){
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$phone = $_POST['phone'];
$address = $_POST['address'];
// Handle file upload
$pic = $_FILES["image"]["name"];
$extension = substr($pic,strlen($pic)-4,strlen($pic));
$allowed_extensions = array(".jpg",".jpeg",".png",".gif");
if(!in_array($extension,$allowed_extensions)){
echo "<script>alert('Invalid format. Only jpg / jpeg/ png /gif format allowed');</script>";
}else{
$imgnewfile = md5($pic).time().$extension;
move_uploaded_file($_FILES["image"]["tmp_name"],"profiles/".$imgnewfile);
$sql="INSERT INTO users(FirstName,LastName,UserName,Email,Password,Phone,Address,Picture) VALUES(:fname,:lname,:username,:email,:password,:phone,:address,:pic)";
$query = $dbh->prepare($sql);
$query->bindParam(':fname',$fname,PDO::PARAM_STR);
$query->bindParam(':lname',$lname,PDO::PARAM_STR);
$query->bindParam(':username',$username,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':password',$password,PDO::PARAM_STR);
$query->bindParam(':phone',$phone,PDO::PARAM_STR);
$query->bindParam(':address',$address,PDO::PARAM_STR);
$query->bindParam(':pic',$imgnewfile,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId){
echo '<script>alert("User added successfully")</script>';
}else{
echo "<script>alert('Something went wrong. Please try again');</script>";
}
}
}elseif(isset($_POST['edit_user'])){
$user_id = $_POST['user_id'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$username = $_POST['username'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$sql="UPDATE users SET FirstName=:fname,LastName=:lname,UserName=:username,Email=:email,Phone=:phone,Address=:address WHERE id=:id";
$query = $dbh->prepare($sql);
$query->bindParam(':fname',$fname,PDO::PARAM_STR);
$query->bindParam(':lname',$lname,PDO::PARAM_STR);
$query->bindParam(':username',$username,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':phone',$phone,PDO::PARAM_STR);
$query->bindParam(':address',$address,PDO::PARAM_STR);
$query->bindParam(':id',$user_id,PDO::PARAM_STR);
$query->execute();
if($query->rowCount() > 0){
echo '<script>alert("User updated successfully")</script>';
}else{
echo "<script>alert('No changes made or error occurred');</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="Dayflow - HR Management System">
<meta name="keywords" content="admin, estimates, bootstrap, business, corporate, creative, management, minimal, modern, accounts, invoice, html5, responsive, CRM, Projects">
<meta name="author" content="Dayflow - HR Management System">
<meta name="robots" content="noindex, nofollow">
<title>Users - Dayflow HR Management</title>
<!-- Favicon -->
<link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<!-- Fontawesome CSS -->
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<!-- Lineawesome CSS -->
<link rel="stylesheet" href="assets/css/line-awesome.min.css">
<!-- Datatable CSS -->
<link rel="stylesheet" href="assets/css/dataTables.bootstrap4.min.css">
<!-- Select2 CSS -->
<link rel="stylesheet" href="assets/css/select2.min.css">
<!-- Datetimepicker CSS -->
<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css">
<!-- Main CSS -->
<link rel="stylesheet" href="assets/css/style.css"><link rel="stylesheet" href="assets/css/dark-theme.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.min.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Wrapper -->
<div class="main-wrapper">
<!-- Header -->
<?php include_once("includes/header.php");?>
<!-- /Header -->
<!-- Sidebar -->
<?php include_once("includes/sidebar.php");?>
<!-- /Sidebar -->
<!-- Page Wrapper -->
<div class="page-wrapper">
<!-- Page Content -->
<div class="content container-fluid">
<!-- Page Header -->
<div class="page-header">
<div class="row align-items-center">
<div class="col">
<h3 class="page-title">Users</h3>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Users</li>
</ul>
</div>
<div class="col-auto float-right ml-auto">
<a href="#" class="btn add-btn" data-toggle="modal" data-target="#add_user"><i class="fa fa-plus"></i> Add User</a>
</div>
</div>
</div>
<!-- /Page Header -->
<!-- Search Filter -->
<div class="row filter-row">
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus">
<input type="text" class="form-control floating">
<label class="focus-label">Name</label>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus select-focus">
<select class="select floating">
<option>Select Company</option>
<option>Global Technologies</option>
<option>Delta Infotech</option>
</select>
<label class="focus-label">Company</label>
</div>
</div>
<div class="col-sm-6 col-md-3">
<div class="form-group form-focus select-focus">
<select class="select floating">
<option>Select Roll</option>
<option>Web Developer</option>
<option>Web Designer</option>
<option>Android Developer</option>
<option>Ios Developer</option>
</select>
<label class="focus-label">Role</label>
</div>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="btn btn-success btn-block"> Search </a>
</div>
</div>
<!-- /Search Filter -->
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped custom-table datatable">
<thead>
<tr>
<th>Full Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>Created Date</th>
<th class="text-right">Action</th>
</tr>
</thead>
<?php
$sql = "SELECT * FROM users";
$query = $dbh->prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{
?>
<tbody>
<tr>
<td>
<h2 class="table-avatar">
<a href="profile.php" class="avatar"><img src="profiles/<?php echo htmlentities($result->Picture);?>" alt="Profile Pic"></a>
<a href="profile.php"><?php echo htmlentities($result->FirstName).$result->LastName;?>
<span><?php echo htmlentities($result->UserName);?></span></a>
</h2>
</td>
<td><?php echo htmlentities($result->Email);?></td>
<td><?php echo htmlentities($result->Phone);?></td>
<td><?php echo htmlentities($result->Address);?></td>
<td><?php echo htmlentities($result->dateTime);?></td>
<td class="text-right">
<div class="dropdown dropdown-action">
<a href="#" class="action-icon dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="material-icons">more_vert</i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" onclick="editUser(<?php echo $result->id; ?>,'<?php echo $result->FirstName; ?>','<?php echo $result->LastName; ?>','<?php echo $result->UserName; ?>','<?php echo $result->Email; ?>','<?php echo $result->Phone; ?>','<?php echo $result->Address; ?>')" data-toggle="modal" data-target="#edit_user"><i class="fa fa-pencil m-r-5"></i> Edit</a>
<a class="dropdown-item" href="users.php?delid=<?php echo $result->id; ?>" onclick="return confirm('Do you really want to Delete ?');"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
</div>
</div>
</td>
</tr>
</tbody>
<?php $cnt=$cnt+1; }} ?>
</table>
</div>
</div>
</div>
</div>
<!-- /Page Content -->
<!-- Add User Modal -->
<?php include_once("includes/modals/user/add_user.php"); ?>
<!-- /Add User Modal -->
<!-- Edit User Modal -->
<?php include_once("includes/modals/user/edit_user.php"); ?>
<!-- /Edit User Modal -->
<!-- Delete User Modal -->
<?php include_once("includes/modals/user/delete_user.php"); ?>
<!-- /Delete User Modal -->
</div>
<!-- /Page Wrapper -->
</div>
<!-- /Main Wrapper -->
<!-- jQuery -->
<script src="assets/js/jquery-3.2.1.min.js"></script>
<!-- Bootstrap Core JS -->
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- Slimscroll JS -->
<script src="assets/js/jquery.slimscroll.min.js"></script>
<!-- Select2 JS -->
<script src="assets/js/select2.min.js"></script>
<!-- Datetimepicker JS -->
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js"></script>
<!-- Datatable JS -->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/dataTables.bootstrap4.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/app.js"></script>
<!-- Theme Toggle JS -->
<script src="assets/js/theme-toggle.js"></script>
<script>
function editUser(id, fname, lname, username, email, phone, address) {
document.getElementById('edit_user_id').value = id;
document.getElementById('edit_firstname').value = fname;
document.getElementById('edit_lastname').value = lname;
document.getElementById('edit_username').value = username;
document.getElementById('edit_email').value = email;
document.getElementById('edit_phone').value = phone;
document.getElementById('edit_address').value = address;
}
</script>
</body>
</html>