-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathadminProfile.php
357 lines (286 loc) · 12.8 KB
/
adminProfile.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
require_once 'classControllers/init.php';
// include('backend/Admins.php');
if(!isset($_SESSION["role"])) {
header('Location:login');
}
$adminId = $_SESSION["admin_id"];
$admin = new Admins();
$display = $admin->getAdmin($adminId);
if($display["hasPic"] == 0) {
// admin has NO picture, show default
$_SESSION["hasPic"] = "no";
} else {
// admin has picture
$_SESSION["hasPic"] = "yes";
}
if(isset($_POST["update"])) {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$updateResult = $admin->updateProfile($firstname, $lastname, $email, $adminId);
}
if(isset($_POST["uploadPicture"])) {
$fileName = $adminId. ".jpg";
if (move_uploaded_file($_FILES["image"]["tmp_name"], "images/uploads/admin/".$fileName."")) {
$admin->imageUPloaded($adminId);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
if(isset($_POST["changePassword"])) {
$oldPassword = $_POST["oldPassword"];
$newPassword = $_POST["newPassword"];
$confirmNewPassword = $_POST["confirmNewPassword"];
$changePasswordResult = $admin->changePassword($oldPassword, $newPassword, $confirmNewPassword);
}
if(isset($_POST["deleteProfilePicture"])) {
$deletePicRes = $admin->deleteProfilePic();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Admin Profile</title>
<link rel="icon" type="img/png" href="images/hng-favicon.png">
<link rel="stylesheet" href="css/dashboard.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style type="text/css">
.card {
height: 150px;
background: #ccc;
margin: 15px;
padding: 10px;
border-radius: 15px;
}
.col-md-2 {
height: 40px;
}
.col-md-8 {
height: 1px;
padding: 0;
margin: 0;
}
@media (max-width: 400px) {
.heading {
margin-top: 50px !important;
font-size: 18px !important;
}
}
</style>
</head>
<body>
<main class="reg">
<section id="overview-section">
<h1 class="heading">Admin Profile</h1>
<div class="register-container">
<br /><br />
<div class="row" id="table-row">
<div class="col-md-6">
<?php
if(isset($_GET["updated"])) {
echo '
<div class="alert alert-success">
<strong>Done!</strong> Profile updated Successfully
</div>';
}
if(isset($_GET["failed"])) {
echo '
<div class="alert alert-danger">
<strong>Error! Update Failed. </strong> No changes found.
</div>';
}
?>
<form method="post">
<div class="form-group">
<label for="">First Name: </label>
<input type="text" name="firstname" id="fname" required class="form-control" value="<?php echo $display["firstname"]; ?>">
</div>
<div class="form-group">
<label for="">Last Name: </label>
<input type="text" name="lastname" id="name" required class="form-control" value="<?php echo $display["lastname"]; ?>">
</div>
<div class="form-group">
<label for="">Email: </label>
<input type="email" name="email" id="email" required class="form-control" value="<?php echo $display["email"]; ?>">
</div>
<div class="form-group">
<label for="">Role: </label>
<?php
if($display["role"] == 1) {
$role = "Super Admin";
} else if($display["role"] == 2) {
$role = "Admin";
}
?>
<input type="text" name="role" id="role" required class="form-control" value="<?php echo $role; ?>" disabled>
</div>
<input type="submit" class="btn btn-success" id="submit" name="update" value="Save Changes">
</form>
<div class="row" style="margin-top: 20px;">
<div class="container">
<div class="col-md-6">
<?php
if(isset($_GET["shortPassword"])) {
echo '
<div class="alert alert-danger">
<strong>Error! </strong> Your password must have at least 6 characters
</div>';
}
if(isset($_GET["passwordUpdated"])) {
echo '
<div class="alert alert-success">
<strong>Done! </strong> You have successfully updated your password
</div>';
}
if(isset($_GET["passwordUpdateFailed"])) {
echo '
<div class="alert alert-danger">
<strong>Error! </strong> Password Update Failed. Please try again
</div>';
}
if(isset($_GET["matchError"])) {
echo '
<div class="alert alert-danger">
<strong>Error! </strong> Your new passwords do not match
</div>';
}
if(isset($_GET["wrongPassword"])) {
echo '
<div class="alert alert-danger">
<strong>Error! </strong> No account found with the password you entered
</div>';
}
?>
<h3>Change Password</h3>
<form method="post">
<div class="form-group">
<label for="">Old Password </label>
<input type="password" name="oldPassword" id="fname" required class="form-control">
</div>
<div class="form-group">
<label for="">New Password </label>
<input type="password" name="newPassword" id="name" required class="form-control" minlength=6>
</div>
<div class="form-group">
<label for="">Confirm New Password </label>
<input type="password" name="confirmNewPassword" id="email" required class="form-control">
</div>
<input type="submit" class="btn btn-success" id="submit" name="changePassword" value="Change Password">
</form>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php
if(isset($_GET["picSaved"])) {
echo '
<div class="alert alert-success">
<strong>Done!</strong> Profile Picture uploaded Successfully
</div>';
}
if(isset($_GET["changed"])) {
echo '
<div class="alert alert-success">
<strong>Done!</strong> Profile Picture updated Successfully
</div>';
}
?>
<div class="col-md-10" style="margin-bottom: 20px; margin-top: 20px;">
<?php
if($display["hasPic"] == 0) {
// admin has NO picture, show default
echo '<img src="adminProfilePics/default.jpg" />';
} else {
// admin has picture
echo '<img src="images/uploads/admin/'.$adminId.'.jpg" class="img-circle img-responsive" style="height: 200px; width: 200px;"/>';
}
?>
</div>
<div class="row" style="padding-left: 70px;">
<?php
if($display["hasPic"] == 0) {
// admin has NO picture
echo '
<button class="btn btn-warning" data-toggle="modal" data-target="#myModal">Upload Profile Picture</button>';
} else {
// admin has picture
echo '
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal" style="margin: 5px;">Change Profile Picture</button>';
echo '
<button class="btn btn-danger" data-toggle="modal" data-target="#myModal1" style="margin: 5px;">Delete My Profile Picture</button>';
}
?>
</div>
</div>
</div>
</div>
<br /><br />
</section>
</main>
<input type="checkbox" id="mobile-bars-check" />
<label for="mobile-bars-check" id="mobile-bars">
<div class="stix" id="stik1"></div>
<div class="stix" id="stik2"></div>
<div class="stix" id="stik3"></div>
</label>
<?php include('fragments/sidebar.php'); ?>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Select Profile Picture</h4>
</div>
<div class="modal-body">
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="">First Name: </label>
<input type="file" name="image" id="image" required class="form-control">
</div>
<input type="submit" class="btn btn-success" id="submit" name="uploadPicture" value="Submit">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal 1 -->
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Are you sure you want to delete your Profile Picture?</h4>
</div>
<div class="modal-body">
<form method="post" enctype="multipart/form-data">
<input type="button" class="btn btn-primary" id="submit" name="" value="No">
<input type="submit" class="btn btn-danger" id="submit" name="deleteProfilePicture" value="Yes">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript" src="js/sidebar.js"></script>
<script type="text/javascript" src="js/newDashboard.js"></script>