-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
executable file
·151 lines (133 loc) · 6.11 KB
/
profile.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
<?php
$title = 'Profile';
$page = 'profile';
$header_title = 'Profile';
include 'partials/header.php';
$query = "SELECT user_id, username, user_firstname, user_lastname, user_email, user_image, user_role, user_description FROM users WHERE user_id = ? ";
$stmt = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt, 's', $_SESSION['user_id']);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $user_id, $username, $user_firstname, $user_lastname, $user_email, $user_image, $user_role, $user_description);
confirmQuery($stmt);
mysqli_stmt_fetch($stmt);
if(isset($_POST['edit_user'])) {
$user_firstname = $_POST['user_firstname'];
$user_lastname = $_POST['user_lastname'];
$user_description = $_POST['user_description'];
$user_image = $_FILES['user_image']['name'];
$user_image_temp = $_FILES['user_image']['tmp_name'];
$date = date('m-d-Y');
$microtime = round(microtime(true));
$actual_name = pathinfo($user_image, PATHINFO_FILENAME);
$ext = pathinfo($user_image, PATHINFO_EXTENSION);
$image_path = "./assets/images/profile/";
$prepend_name = 'Img_profile_' . $date . "_" . $microtime;
$full_img_name = $prepend_name . '_' . $actual_name . '.' . $ext;
$dest_file = $image_path . $full_img_name;
move_uploaded_file($user_image_temp, $dest_file);
// move_uploaded_file($user_image_temp, "./assets/images/profile/$user_image");
if(empty($user_image)) {
$query = "SELECT user_image FROM users WHERE user_id = " . $user_id . "";
$select_image = mysqli_query($connection,$query);
while($row = mysqli_fetch_array($select_image)) {
$full_img_name = $row['user_image'];
}
}
$query = "UPDATE users SET ";
$query .="user_firstname = ?, ";
$query .="user_lastname = ?, ";
$query .="user_image = ?, ";
$query .="user_description = ? " ;
$query .= "WHERE user_id = ? ";
$stmt = mysqli_prepare($connection, $query);
confirmQuery($stmt);
mysqli_stmt_bind_param($stmt, 'sssss', $user_firstname, $user_lastname, $full_img_name, $user_description, $_SESSION['user_id']);
mysqli_stmt_execute($stmt);
redirect($baseURL . "/admin/profile.php");
}
?>
<div class="row pt-3">
<div class="col-lg-4">
<div class="card card-small mb-4 pt-3">
<div class="card-body text-center">
<div class="mb-3 mx-auto">
<?php if (empty($user_image)) { ?>
<img class="rounded-circle" src="<?php echo $baseURL; ?>/assets/images/profile/user.png" alt="<?php echo $user_firstname . " " . $user_lastname; ?>" width="110">
<?php } else { ?>
<img class="rounded-circle" src="<?php echo $baseURL; ?>/assets/images/profile/<?php echo($user_image); ?>" alt="<?php echo $user_firstname . " " . $user_lastname; ?>" width="110">
<?php } ?>
</div>
<h4 class="mb-0"><?php echo $user_firstname . " " . $user_lastname; ?></h4>
<span class="text-muted d-block mb-2"><?php echo $user_role; ?></span>
<span class="text-muted d-block mb-2"><?php echo $user_email; ?></span>
<span class="text-left d-block mb-2"><?php echo stripslashes($user_description); ?></span>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card card-small mb-4">
<div class="card-header border-bottom">
<h6 class="m-0">Account Details</h6>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item p-3">
<div class="row">
<div class="col">
<form method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group col-md-6">
<label for="feFirstName">Username</label>
<input type="text" class="form-control" name="username" id="feFirstName" value="<?php echo $username; ?>" disabled>
</div>
<div class="form-group col-md-6">
<label for="fe LastName">User Role</label>
<?php
$query = 'SELECT * FROM user_roles';
$select_categories = query($query);
confirmQuery($select_categories);
while ($row = mysqli_fetch_assoc($select_categories)) {
$role_id = $row['role_id'];
$role_title = $row['role_title'];
if ($role_title == $user_role) {
echo "<input type='text' class='form-control' value='$role_title' disabled>";
}
}
?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="feFirstName">First Name</label>
<input type="text" class="form-control" name="user_firstname" placeholder="First Name" value="<?php echo($user_firstname) ?>">
</div>
<div class="form-group col-md-6">
<label for="feLastName">Last Name</label>
<input type="text" class="form-control" name="user_lastname" id="feLastName" value="<?php echo($user_lastname) ?>">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="feEmailAddress">Email</label>
<input type="email" class="form-control" name="user_email" value="<?php echo($user_email) ?>" disabled>
</div>
<div class="form-group col-md-6">
<label for="fePassword">Profile Image</label>
<input type="file" class="form-control" name="user_image" value="<?php echo($user_image) ?>">
</div>
</div>
<div class="form-row">
<div class="form-group col-12">
<textarea name="user_description" class="form-control" cols="30" rows="5"><?php echo stripslashes($user_description); ?></textarea>
</div>
</div>
<button type="submit" name="edit_user" class="btn btn-accent btn-primary">Update</button>
</form>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<?php include 'partials/footer.php'; ?>