-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetting.php
More file actions
233 lines (215 loc) · 9.49 KB
/
Copy pathsetting.php
File metadata and controls
233 lines (215 loc) · 9.49 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
<?php
include 'connection.php';
include 'security.php';
$prof_pic = $_SESSION['Profile_Picture'];
$nm = $_SESSION['Name'];
$em = $_SESSION['Email'];
$u_nm = $_SESSION['Username'];
$institute = $_SESSION['Institute'];
$cfh = $_SESSION['CF_Handle'];
$uh = $_SESSION['UVa_Handle'];
$about = $_SESSION['About'];
$cur_file = "uploads/user/profile_picture/$prof_pic";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upate Profile-Codeware</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="fontawesome/css/all.css">
<link rel="stylesheet" href="css/style.css">
<style>
textarea {
resize: none;
}
</style>
</head>
<body>
<?php include 'nav_bar.php'; ?>
<div class="container-fluid">
<h1 class="text-success text-center mt-5"><b>Update Information</b></h1>
<div class="text-center mt-5">
<?php
if (is_null($prof_pic)) {
echo '<i class="fas fa-user-circle fa-8x"></i>';
}
else {
echo '<img class="image_prof img rounded-circle" src="'.$cur_file.'" alt="">';
}
?>
</div>
<form class="mt-3" action="<?php $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
<div class="justify-content-center d-flex">
<div class="form-group">
<input type="file" name="pic_file" class="form-control-file" id="Xx4">
</div>
</div>
<div class="form-group justify-content-center d-flex">
<button type="submit" name="btn_upd_pic" class="btn btn-success"><b>Update</b></button>
</div>
</form>
<?php
if (isset($_POST['btn_upd_pic'])) {
if (isset($_FILES['pic_file'])) {
$fname = $_FILES['pic_file']['name'];
$ftmp = $_FILES['pic_file']['tmp_name'];
$ftyp = $_FILES['pic_file']['type'];
$fext = strtolower(substr($fname, strrpos($fname, '.') + 1));
echo $fname; echo '<br>'; echo $ftmp;
if ($fext == 'jpg' OR $fext == 'jpeg' OR $fext == 'png') {
//first delete current file
if(!is_null($prof_pic)) {
unlink($cur_file);
}
move_uploaded_file($ftmp, "uploads/profile_picture/" . $fname);
echo $qry_pic = "UPDATE User SET Profile_Picture = '{$fname}' WHERE Id = {$_SESSION['Id']};";
mysqli_query($con, $qry_pic) or die('Picture Update Failed!');
echo '<script>
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
alert("Picture updated successfully!");
</script>';
//session_unset();
session_destroy();
echo '<script>window.location.reload();</script>';
}
else {
echo '<script>
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
alert("Only JPG, JPEG, PNG are allowed to upload!");
window.location.reload();
</script>';
}
}
}
?>
<div class="p-2 mb-5 shadow-lg">
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST">
<div class="row">
<div class="col-md-6 form-group">
<label><b>Full Name:</b></label>
<input type="text" name="name" value="<?php echo ($nm) ?>" class="form-control">
</div>
<div class="col-md-6 form-group">
<label><b>Email Address:</b></label>
<input type="email" name="email" value="<?php echo ($em) ?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<b>Username</b> (<span class="text-danger">changing not allowed</span>)</label>
<input type="text" name="username" value="<?php echo ($u_nm) ?>" class="form-control disabled"
disabled>
</div>
<div class="col-md-6 form-group">
<label><b>Institute:</b></label>
<input type="text" name="inst" value="<?php echo ($institute) ?>" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label><b>UVa Handle:</b></label>
<input type="text" name="uva" value="<?php echo ($uh) ?>" class="form-control">
</div>
<div class="col-md-6 form-group">
<label><b>Codeforces Handle:</b></label>
<input type="text" name="cf" value="<?php echo ($cfh) ?>" class="form-control">
</div>
<div class="col form-group">
<label for="text"><b>About Yourself:</b></label> (<span class="mt-1 " id="count_message"></span>)
<textarea class="form-control" id="text" name="abt" maxlength="255" rows="3"><?php echo $about;?></textarea>
</div>
</div>
<div class="mt-1 justify-content-center justify-content-lg-start">
<button type="submit" name="upd_info" class="btn btn-success"><b>Update</b></button>
</div>
</form>
</div>
<div class="p-2 shadow-lg">
<h3 class="text-primary text-center mb-5"><b>Password Change</b></h3>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST" class="row">
<div class="col-md-5 form-group">
<label><b>Enter the old password</b></label>
<input type="password" name="old_pass" class="form-control" placeholder="*****">
</div>
<div class="col-md-5 form-group">
<label><b>Enter a new password</b></label>
<input type="password" name="new_pass" class="form-control" placeholder="*****">
</div>
<div class="col-md-2 mt-md-4 mt-1 justify-content-center justify-content-lg-start">
<button type="submit" name="upd_pass" class="btn btn-sm btn-success"><b>Update</b></button>
</div>
</form>
</div>
<?php
if (isset($_POST['upd_info'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$inst = $_POST['inst'];
$cf = $_POST['cf'];
$uva = $_POST['uva'];
$abt = $_POST['abt'];
$qry_info = "UPDATE User SET
Name = '{$name}',
Email = '{$email}',
Institute = '{$inst}',
CF_Handle = '{$cf}',
UVa_Handle = '{$uva}',
About = '{$abt}'
WHERE Username = '{$u_nm}';
";
mysqli_query($con, $qry_info);
echo '<script>
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
window.location.reload();
</script>';
session_unset();
session_destroy();
}
if (isset($_POST['upd_pass'])) {
$old_pass = $_POST['old_pass'];
$new_pass = $_POST['new_pass'];
$qry_pass = "SELECT Id FROM User WHERE Username = '{$u_nm}' AND Password = '{$old_pass}';";
$res_pass = mysqli_query($con, $qry_pass) or die("Query Failed!");
if (mysqli_num_rows($res_pass) > 0) {
$qry_pass2 = "UPDATE User SET Password = '{$new_pass}' WHERE Username = '{$u_nm}';";
mysqli_query($con, $qry_pass2);
session_unset();
session_destroy();
echo "<script>
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
window.location.reload();
window.location.href = 'logout.php';
alert('Password updated successfully! Please login again.');
}
</script>";
}
else {
echo '<script>alert("Password not matched!")</script>';
}
}
?>
<?php include 'footer.php'; ?>
</div>
<script src="js/jquery-3.6.0.js" type="text/javascript"></script>
<script src="js/bootstrap.bundle.js" type="text/javascript"></script>
<script src="js/nav_bar.js" type="text/javascript"></script>
<script>
var text_max = 255;
$('#count_message').html('0 / ' + text_max );
$('#text').keyup(function() {
var text_length = $('#text').val().length;
var text_remaining = text_max - text_length;
$('#count_message').html(text_length + ' / ' + text_max);
});
</script>
</body>
</html>