-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.edit.php
More file actions
279 lines (257 loc) · 13 KB
/
user.edit.php
File metadata and controls
279 lines (257 loc) · 13 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
<?php
session_start();
#################### Login & License Validation ####################
require("temp/validate.login.temp.php"); #
$license_path = "license/".$_SESSION['license_username']."/license.json"; #
require("auth/license.validate.functions.php"); #
require("temp/validate.license.temp.php"); #
#################### Login & License Validation ####################
######################## Database Connection #######################
require("auth/config.php"); #
require("auth/functions.php"); #
$conn = conn("localhost", "root", "", "unitySync"); #
######################## Database Connection #######################
################################ Role Validation ################################
if (validationRole($conn, $_SESSION['project'], $_SESSION['role'], "edit-user") != true) {
header("Location: user.all.php?m=user_edit_not_allow");
exit();
}
################################ Role Validation ################################
if (empty($_GET['i'])) {
header("Location: user.all.php?m=not_found");
exit();
}
// $query = "SELECT * FROM `roles` WHERE `project_id` = '".$_SESSION['project']."' AND `name` != 'super-admin';";
// $roles = fetch_Data($conn, $query);
$query = "SELECT * FROM `users` WHERE `u_id` = '".$_GET['i']."' AND `project_id` = '".$_SESSION['project']."' AND `role` != 'super-admin';";
$user = mysqli_fetch_assoc(mysqli_query($conn, $query));
if (empty($user)) {
header("Location: user.all.php?m=no_user");
exit();
}
$prefixes = array(
"Mr.",
"Mrs."
);
$genders = array(
"male",
"female",
"not confirm"
);
$martial_status = array(
"single",
"married",
"engaged"
);
$title = "Edit User - ".$user['f_name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require('temp/head.temp.php'); ?>
</head>
<body>
<?php require('temp/aside.temp.php'); ?>
<main class="content">
<?php require('temp/nav.temp.php'); ?>
<div class="py-3 pb-2 d-flex justify-content-between align-items-center">
<nav aria-label="breadcrumb" class="d-none d-md-flex align-items-center">
<ol class="breadcrumb breadcrumb-dark breadcrumb-transparent mb-0">
<li class="breadcrumb-item">
<a href="#">
<svg class="icon icon-xxs" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6">
</path>
</svg>
</a>
</li>
<li class="breadcrumb-item"><a>Configuration</a></li>
<li class="breadcrumb-item"><a href="user.all.php">User Management</a></li>
<li class="breadcrumb-item active" aria-current="page">Edit User - <?=$user['f_name']?></li>
</ol>
</nav>
<a class="btn btn-outline-gray-600" href="user.all.php">Manage Users</a>
</div>
<div class="card card-body border-0 shadow mb-4">
<h2 class="h5 mb-4">General information</h2>
<form method="POST" action="comp/user.edit.php" id="form-row" autocomplete="off">
<div class="row">
<div class="col-md-2 col-sm-4">
<div class="mb-3">
<label for="prefix">Prefix</label>
<select class="form-select" name="prefix" id="prefix">
<option value="Mr." selected>Mr.</option>
<option value="Mrs.">Mrs.</option>
</select>
</div>
</div>
<div class="col-md-5 col-sm-4">
<div class="mb-3">
<label for="fName">First Name</label>
<input class="form-control" id="fName" name="fName" type="text" value="<?=$user['f_name']?>"
required />
</div>
</div>
<div class="col-md-5 col-sm-4">
<div class="mb-3">
<label for="lName">Last Name</label>
<input class="form-control" id="lName" name="lName" type="text" value="<?=$user['s_name']?>"
required />
</div>
</div>
<div class="col-md-4 col-sm-4">
<div class="mb-3">
<label for="email">Email <span class="text-danger">(<b>Unchangeable</b>)</span></label>
<input class="form-control bg-white" id="email" name="email" type="text"
value="<?=$user['email']?>" readonly />
</div>
</div>
<div class="col-lg-3">
<div class="mb-3">
<label for="phoneNo">Contact No.</label>
<div class="input-group">
<span class="input-group-text text-primary">+92</span>
<input type="text" name="phoneNo" id="phoneNo" class="form-control phone_no_format"
placeholder="(333) 333-3333" value="<?=phone_no_format($user['phone_no'])?>" />
</div>
</div>
</div>
<div class="col-sm-2">
<label for="">Status</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1"
<?=($user['status'] == 1)?"checked":""?> name="status" id="status" />
<label class="form-check-label" for="status">
Is Active ?
</label>
</div>
</div>
</div>
<hr />
<h2 class="h5 mb-4">Roles and Permission</h2>
<div class="row">
<div class="col-lg-3">
<div class="mb-3">
<label for="role">Role</label>
<select class="form-select" name="role" id="role" required>
<option value="<?=$user['role']?>" selected><?=$user['role']?></option>
</select>
</div>
</div>
<div class="col-lg-3 col-md-4 col-sm-6">
<div class="mb-3">
<label for="username">Username <span
class="text-danger">(<b>Unchangeable</b>)</span></label>
<input class="form-control bg-white" type="text" value="<?=$user['username']?>" readonly />
<div id="username_feedback" class="form-text"></div>
</div>
</div>
<div class="col-lg-3 col-md-4 col-sm-3">
<div class="mb-3">
<label for="password">Password</label>
<input class="form-control" id="password" name="password" type="password"
value="<?=$user['password']?>" />
</div>
</div>
<div class="col-lg-3 col-md-4 col-sm-3">
<div class="mb-3">
<label for="confirm_password">Confirm password</label>
<input class="form-control" id="confirm_password" name="confirm_password" type="password"
value="<?=$user['password']?>" />
<div id="confirm_password_feedback" class="form-text"></div>
</div>
</div>
</div>
<hr />
<h2 class="h5 mb-4">Other Details</h2>
<div class="row">
<div class="col-lg-3">
<div class="mb-3">
<label for="dateOfBirth">Birthday</label>
<div class="input-group">
<span class="input-group-text">
<svg class="icon icon-xs" fill="currentColor" viewbox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd"
d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z"
clip-rule="evenodd"></path>
</svg>
</span>
<input data-datepicker class="form-control" id="dateOfBirth" name="dateOfBirth"
type="text" placeholder="dd/mm/yyyy" value="<?=$user['date_of_birth']?>" />
</div>
</div>
</div>
<div class="col-lg-3">
<div class="mb-3">
<label for="gender">Gender</label>
<select class="form-select" name="gender" id="gender">
<?php foreach ($genders as $gender) {
if ($user['gender'] == $gender) {?>
<option value="<?=$gender?>" selected><?=$gender?></option>
<?php } else { ?>
<option value="<?=$gender?>"><?=$gender?></option>
<?php } } ?>
</select>
</div>
</div>
<div class="col-lg-3">
<div class="mb-3">
<label for="martialStatus">Martial Status</label>
<select class="form-select" name="maritalStatus" id="maritalStatus">
<?php foreach ($martial_status as $status) {
if ($user['martial_status'] == $status) {?>
<option value="<?=$status?>" selected><?=$status?></option>
<?php } else { ?>
<option value="<?=$status?>"><?=$status?></option>
<?php } } ?>
</select>
</div>
</div>
<div class="col-lg-3">
<div class="mb-3">
<label for="bloodGroup">Blood Group</label>
<input type="text" name="bloodGroup" id="bloodGroup" class="form-control"
value="<?=$user['blood_group']?>" />
</div>
</div>
<div class="col-12 text-center">
<input type="hidden" name="id" value="<?=$_GET['i']?>" />
<input type="submit" name="submit" value="Edit User" class="btn btn-outline-gray-600 my-3" />
</div>
</div>
</form>
</div>
<?php require('temp/footer.temp.php'); ?>
</main>
<?php require('temp/script.temp.php'); ?>
<script>
$('#form-row').submit(function(e) {
e.preventDefault();
var username = $('#username').val();
var password = $('#password').val();
var confirmPassword = $('#confirm_password').val();
// Validate if the passwords match
if (password !== confirmPassword) {
$('#confirm_password_feedback').text('Password do not match.');
$('#confirm_password_feedback').removeClass('text-success');
$('#confirm_password_feedback').addClass('text-danger');
notify("error", "Password do not match.");
return;
} else {
$('#confirm_password_feedback').text('Password Matches.');
$('#confirm_password_feedback').removeClass('text-danger');
$('#confirm_password_feedback').addClass('text-success');
$('#form-row').off('submit').submit();
}
});
<?php if (isset($_GET['m'])) { ?>
<?php if ($_GET['m'] == 'pass_not_match') { ?>
notify("error", "Password Doesn't Match ...");
<?php } ?>
<?php } ?>
</script>
</body>
</html>