-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_profile_edit.php
394 lines (365 loc) · 11.6 KB
/
user_profile_edit.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<!DOCTYPE html>
<?php
// we will only start the session with session_start() IF the session isn't started yet //
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
?>
<?php
include("conn.php");
?>
<?php
if (isset($_SESSION["user_id"])) {
// do nothing
} else {
ob_start();
// It will return to admin panel automatically //
echo "<script>alert('System Notice: You need to login with an account to access this site, please try again.');";
echo "window.location.href='login.php';</script>";
ob_end_flush();
}
?>
<?php
$username = $_SESSION['username'];
$sql = "SELECT * FROM user WHERE user_username = '$username'";
$result = mysqli_query($db, $sql);
?>
<html lang="en">
<head>
<!-- SITE TITTLE -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Edit Profile | Shoppa </title>
<link href="logo_image/favicon.png" rel="shortcut icon">
<!-- PLUGINS CSS STYLE -->
<!-- <link href="plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet"> -->
<!-- Bootstrap -->
<link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="plugins/bootstrap/css/bootstrap-slider.css">
<!-- Font Awesome -->
<link href="plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<!-- Owl Carousel -->
<link href="plugins/slick-carousel/slick/slick.css" rel="stylesheet">
<link href="plugins/slick-carousel/slick/slick-theme.css" rel="stylesheet">
<!-- Fancy Box -->
<link href="plugins/fancybox/jquery.fancybox.pack.css" rel="stylesheet">
<link href="plugins/jquery-nice-select/css/nice-select.css" rel="stylesheet">
<!-- CUSTOM CSS -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="body-wrapper">
<?php
include_once("navigation_bar.php");
?>
<!--==================================
= User Profile =
===================================-->
<section class="user-profile section">
<div class="container">
<div id="edit-detail" class="row">
<?php while ($rows = mysqli_fetch_array($result)){ ?>
<div class="col-md-10 offset-md-1 col-lg-3 offset-lg-0">
<div class="sidebar">
<!-- User Widget -->
<div class="widget user">
<!-- User Image -->
<div class="image d-flex justify-content-center">
<img src="image/user_profile.png" alt="" class="">
</div>
<!-- User Name -->
<h5 id="editpage-user" class="text-center"><?php echo $rows['user_username'] ?></h5>
</div>
<!-- Dashboard Links -->
<div class="widget dashboard-links">
<ul>
<li style="font-size:18px;"><a class="my-1 d-inline-block" href="user_profile.php">Back to Profile</a></li>
</ul>
</div>
</div>
</div>
<div class="col-md-10 offset-md-1 col-lg-9 offset-lg-0">
<!-- Edit Profile Welcome Text -->
<div class="widget welcome-message">
<h2>Edit profile</h2>
<p>Some of the information on your Shoppa profile will always be public. But you can choose what information you want to include in section. You may edit your password at here as well.</p>
</div>
<!-- Edit Personal Info -->
<div class="row">
<div id="form1" class="col-lg-6 col-md-6">
<div class="widget personal-info">
<h3 class="widget-header user">Edit Personal Information</h3>
<form>
<!-- First Name -->
<div class="form-group">
<label for="first-name">First Name</label>
<input type="text" class="form-control" id="fi_name" value="<?php echo $rows['user_fname'] ?>">
</div>
<!-- Last Name -->
<div class="form-group">
<label for="last-name">Last Name</label>
<input type="text" class="form-control" id="la_name" value="<?php echo $rows['user_lname'] ?>" >
</div>
<!-- IC Number -->
<div class="form-group">
<label for="comunity-name">IC Number</label>
<input type="text" class="form-control" id="ic_numbe" value="<?php echo $rows['user_icnumber'] ?>" maxlength="10">
</div>
<!-- Address -->
<div class="form-group">
<label for="zip-code">Address</label>
<input type="text" class="form-control" id="ad_dress" value="<?php echo $rows['user_address'] ?>">
</div>
<!-- Submit button -->
<button id="btn_Save_Edit_1" class="btn btn-transparent">Save My Changes</button>
</form>
</div>
</div>
<div class="col-lg-6 col-md-6">
<!-- Change Password -->
<div class="widget change-password">
<h3 class="widget-header user">Edit Password</h3>
<form action="#">
<!-- Current Password -->
<div class="form-group">
<label for="current-password">Current Password</label>
<input type="password" class="form-control" id="current_password">
</div>
<!-- New Password -->
<div class="form-group">
<label for="new-password">New Password</label>
<input type="password" class="form-control" id="new_password">
</div>
<!-- Confirm New Password -->
<div class="form-group">
<label for="confirm-password">Confirm New Password</label>
<input type="password" class="form-control" id="confirm_password">
</div>
<!-- Submit Button -->
<button id="btn_Save_Edit_2" class="btn btn-transparent">Change Password</button>
</form>
</div>
</div>
<div class="col-lg-6 col-md-6">
<!-- Change Email Address -->
<div class="widget change-email mb-0">
<h3 class="widget-header user">Edit Email Address</h3>
<form action="#">
<!-- Current Email -->
<div class="form-group">
<label for="current-email">Current Email</label>
<input type="email" class="form-control" id="current_email" value="<?php echo $rows['user_email'] ?>" disabled>
</div>
<!-- New email -->
<div class="form-group">
<label for="new-email">New email</label>
<input type="email" class="form-control" id="new_email">
</div>
<!-- Submit Button -->
<button id="btn_Save_Edit_3" class="btn btn-transparent">Change email</button>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
<?php
include_once("footer.php");
?>
<!-- JAVASCRIPTS -->
<script src="plugins/jQuery/jquery.min.js"></script>
<script src="plugins/bootstrap/js/popper.min.js"></script>
<script src="plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="plugins/bootstrap/js/bootstrap-slider.js"></script>
<!-- tether js -->
<script src="plugins/tether/js/tether.min.js"></script>
<script src="plugins/raty/jquery.raty-fa.js"></script>
<script src="plugins/slick-carousel/slick/slick.min.js"></script>
<script src="plugins/jquery-nice-select/js/jquery.nice-select.min.js"></script>
<script src="plugins/fancybox/jquery.fancybox.pack.js"></script>
<script src="plugins/smoothscroll/SmoothScroll.min.js"></script>
<!-- google map -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCcABaamniA6OL5YvYSpB3pFMNrXwXnLwU&libraries=places"></script>
<script src="plugins/google-map/gmap.js"></script>
<script src="js/script.js"></script>
<!-- JQuery-->
<script>
$("document").ready(function(){
var icnumber_state = false;
var email_state = false;
var password_state = false;
//Check icnumber valid
$("#ic_numbe").blur(function(){
var ic_num = $("#ic_numbe").val();
if(ic_num == ""){
icnumber_state = false;
return;
}
$.ajax({
url: "process_user.php",
type: "POST",
data:{
check_icnumber_update : 1,
ic_number : ic_num
},
success: function(response){
if(response.trim() == "not_available"){
icnumber_state = false;
}
else if(response.trim() == "available"){
icnumber_state = true;
}
}
});
});
//Check password valid
$("#current_password").blur(function(){
var current = $("#current_password").val();
if(current == ""){
password_state = false;
return;
}
$.ajax({
url: "process_user.php",
type: "POST",
data:{
check_password_update : 1,
password : current
},
success: function(response){
if(response.trim() == "not_available"){
password_state = false;
}
else if(response.trim() == "available"){
password_state = true;
}
}
});
});
//Check for email format
function isEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
//Check email valid
$("#new_email").blur(function(){
var e_mail = $("#new_email").val().trim();
var tempBool = false;
if(e_mail == ""){
email_state = false;
return;
}
else if(tempBool == isEmail(e_mail)){
email_state = false;
return;
}
$.ajax({
url: "process_user.php",
type: "POST",
data:{
check_email_update : 1,
email : e_mail
},
success: function(response){
if(response.trim() == "not_available"){
email_state = false;
}
else if(response.trim() == "available"){
email_state = true;
}
}
});
});
//Function for Save My Changes button
$("#edit-detail").find("#btn_Save_Edit_1").click(function () {
var first_name = $("#fi_name").val();
var last_name = $("#la_name").val();
var icnum = $("#ic_numbe").val();
var add_ress = $("#ad_dress").val();
if(first_name.trim() == "" || last_name.trim() == "" || icnum.trim() == "" || add_ress.trim() == ""){
alert("Please make sure the form is filled");
}
else if(icnumber_state == false){
alert("Please check your ic number!");
}
else{
$.ajax({
url : "process_user.php",
type : "POST",
data : {
update_user_normal : 1,
firstname : first_name,
lastname : last_name,
icnumber : icnum,
address : add_ress
},
success: function(respond){
alert(respond);
location.reload();
}
});
}
});
//Function for Change Password button
$("#edit-detail").find("#btn_Save_Edit_2").click(function () {
var latest = $("#new_password").val();
var rlatest = $("#confirm_password").val();
if(latest.trim() == "" || rlatest.trim() == ""){
alert("Please make sure the form is filled");
}
else if(latest != rlatest){
alert("Please make sure the new passwords are matched!");
}
else if(password_state == false){
alert("Please make sure the old password is correct!");
}else{
$.ajax({
url : "process_user.php",
type : "POST",
data : {
update_user_password : 1,
password : latest
},
success: function(respond){
alert(respond);
location.reload();
}
});
}
});
//Function for Change Email button
$("#edit-detail").find("#btn_Save_Edit_3").click(function () {
var e_mail = $("#new_email").val().trim();
if(e_mail.trim() == ""){
alert("Please make sure the form is filled");
}
else if(email_state == false){
alert("The email has been used by someone, or the email format is incorrect!");
}else{
$.ajax({
url : "process_user.php",
type : "POST",
data : {
update_user_email : 1,
email : e_mail
},
success: function(respond){
alert(respond);
location.reload();
}
});
}
});
});
</script>
</body>
</html>