-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_account.php
183 lines (179 loc) · 9.44 KB
/
manage_account.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
<?php
$user = $conn->query("SELECT s.*,d.name as department, c.name as curriculum,CONCAT(lastname,', ',firstname,' ',middlename) as fullname FROM student_list s inner join department_list d on s.department_id = d.id inner join curriculum_list c on s.curriculum_id = c.id where s.id ='{$_settings->userdata('id')}'");
foreach($user->fetch_array() as $k =>$v){
$$k = $v;
}
?>
<style>
.student-img{
object-fit:scale-down;
object-position:center center;
height:200px;
width:200px;
}
</style>
<div class="content py-4">
<div class="card card-outline card-primary shadow rounded-0">
<div class="card-header rounded-0">
<h5 class="card-title">Update Details</h5>
</div>
<div class="card-body rounded-0">
<div class="container-fluid">
<form action="" id="update-form">
<input type="hidden" name="id" value="<?= $_settings->userdata('id') ?>">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="firstname" class="control-label text-navy">FirstName</label>
<input type="text" name="firstname" id="firstname" autofocus placeholder="Firstname" class="form-control form-control-border" value="<?= isset($firstname) ?$firstname : "" ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="middlename" class="control-label text-navy">MiddleName</label>
<input type="text" name="middlename" id="middlename" placeholder="Middlename (optional)" class="form-control form-control-border" value="<?= isset($middlename) ?$middlename : "" ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="lastname" class="control-label text-navy">LastName</label>
<input type="text" name="lastname" id="lastname" placeholder="Lastname" class="form-control form-control-border" value="<?= isset($lastname) ?$lastname : "" ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-auto">
<label for="" class="control-label text-navy">Gender</label>
</div>
<div class="form-group col-auto">
<div class="custom-control custom-radio">
<input class="custom-control-input" type="radio" id="genderMale" name="gender" value="Male" required <?= isset($gender) && $gender == "Male" ? "checked" : "" ?>>
<label for="genderMale" class="custom-control-label">Male</label>
</div>
</div>
<div class="form-group col-auto">
<div class="custom-control custom-radio">
<input class="custom-control-input" type="radio" id="genderFemale" name="gender" value="Female" <?= isset($gender) && $gender == "Female" ? "checked" : "" ?>>
<label for="genderFemale" class="custom-control-label">Female</label>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="email" class="control-label text-navy">Email</label>
<input type="email" name="email" id="email" placeholder="Email" class="form-control form-control-border" required value="<?= isset($email) ?$email : "" ?>">
</div>
<div class="form-group">
<label for="password" class="control-label text-navy">New Password</label>
<input type="password" name="password" id="password" placeholder="Password" class="form-control form-control-border">
</div>
<div class="form-group">
<label for="cpassword" class="control-label text-navy">Confirm New Password</label>
<input type="password" id="cpassword" placeholder="Confirm Password" class="form-control form-control-border">
</div>
<small class='text-muted'>Leave the New Password and Confirm New Password Blank if you don't wish to change your password.</small>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="img" class="control-label text-muted">Choose Image</label>
<input type="file" id="img" name="img" class="form-control form-control-border" accept="image/png,image/jpeg" onchange="displayImg(this,$(this))">
</div>
<div class="form-group text-center">
<img src="<?= validate_image(isset($avatar) ? $avatar : "") ?>" alt="My Avatar" id="cimg" class="img-fluid student-img bg-gradient-dark border">
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="oldpassword">Please Enter your Current Password</label>
<input type="password" name="oldpassword" id="oldpassword" placeholder="Current Password" class="form-control form-control-border" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group text-center">
<button class="btn btn-default bg-navy btn-flat"> Update</button>
<a href="./?page=profile" class="btn btn-light border btn-flat"> Cancel</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function displayImg(input,_this) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#cimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}else{
$('#cimg').attr('src', "<?= validate_image(isset($avatar) ? $avatar : "") ?>");
}
}
$(function(){
// Update Form Submit
$('#update-form').submit(function(e){
e.preventDefault()
var _this = $(this)
$(".pop-msg").remove()
$('#password, #cpassword').removeClass("is-invalid")
var el = $("<div>")
el.addClass("alert pop-msg my-2")
el.hide()
if($("#password").val() != $("#cpassword").val()){
el.addClass("alert-danger")
el.text("Password does not match.")
$('#password, #cpassword').addClass("is-invalid")
$('#cpassword').after(el)
el.show('slow')
return false;
}
start_loader();
$.ajax({
url:_base_url_+"classes/Users.php?f=save_student",
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
dataType:'json',
error:err=>{
console.log(err)
el.text("An error occured while saving the data")
el.addClass("alert-danger")
_this.prepend(el)
el.show('slow')
end_loader()
},
success:function(resp){
if(resp.status == 'success'){
location.href= "./?page=profile"
}else if(!!resp.msg){
el.text(resp.msg)
el.addClass("alert-danger")
_this.prepend(el)
el.show('show')
}else{
el.text("An error occured while saving the data")
el.addClass("alert-danger")
_this.prepend(el)
el.show('show')
}
end_loader();
$('html, body').animate({scrollTop: 0},'fast')
}
})
})
})
</script>