-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathUpdate_Profile.php
More file actions
312 lines (276 loc) · 12.8 KB
/
Update_Profile.php
File metadata and controls
312 lines (276 loc) · 12.8 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
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
<?php
session_start();
function getUserData($username)
{
$array= array();
$con=mysqli_connect('localhost:3306','root','root') or die('sorry unable to connect');
mysqli_select_db($con,"demo") or die("cannot select DB");
$q = mysqli_query($con,"SELECT * FROM loginform WHERE User='".$username."'");
while($r = mysqli_fetch_assoc($q))
{
$array['id'] = $r['ID'];
$array['Username'] = $r['User'];
$array['Name'] = $r['Name'];
$array['Place'] = $r['Place'];
$array['password'] = $r['Password'];
$array['Position'] = $r['Position'];
$array['Email'] = $r['Email'];
$array['Image'] = $r['Image'];
$array['dir'] = $r['Announcement_Global'];
}
return $array;
}
$_SESSION['message1'] = "";
$_SESSION['message'] = "";
$_SESSION['message3'] = "";
$dir = "./Announcements/";
$Userdata = array();
if (isset($_SESSION['Username'])){
$Userdata = getUserData($_SESSION['Username']);
}
else
{
echo "<script>window.location.assign('./login.php?msg=".urlencode(base64_encode('You have been Logged out successfully'))."');</script>";
}
$id = $Userdata['id'];
?>
<?php
$mysqli = new mysqli('localhost','root','root','demo');
if (isset($_POST['Update_data']))
{
$id = $Userdata['id'];
$email = $mysqli->real_escape_string($_POST["email"]);
$name = $mysqli->real_escape_string($_POST["Name"]);
$place = $mysqli->real_escape_string($_POST["Place"]);
$position = $mysqli->real_escape_string($_POST["Designation"]);
$_SESSION['username'] = $username;
$_SESSION['avatar'] = $avatar_path;
$sql = "UPDATE `loginform` SET `Name`='$name',`Place`='$place',`Position`='$position',`Email`='$email' WHERE ID = '$id'";
if ($mysqli->query($sql)===true)
{
$_SESSION['message1'] = "Update Successful!!!";
}
else
{
$_SESSION['message1'] = "Update unsuccessful";
}
}
if (isset($_POST["Update_pass"]))
{
if(md5($_POST['password'])==$Userdata['password']){
//$password = $mysqli->real_escape_string($_POST["passwords"]);
if ($_POST['new_password']==$_POST['confirmpassword'])
{
$pass = md5($_POST['new_password']);
$sql = "UPDATE `loginform` SET Password = '$pass' WHERE ID = '$id'";
if ($mysqli->query($sql)===true)
{
$_SESSION['message'] = "Update Successful!!!";
}
else
{
$_SESSION['message'] = "Update unsuccessful";
}
}
else
{
$_SESSION['message'] = "Password not matching Confirm Password";
}
}
else
$_SESSION['message']="Old password not matching";
}
if (isset($_POST['Update_pic']))
{
$avatar_path = $mysqli->real_escape_string('./Uploads/'.$_FILES['file']['name']);
if (preg_match("!image!", $_FILES['file']['type'])){
if (copy($_FILES['file']['tmp_name'],$avatar_path))
{
$sql = "UPDATE `loginform` SET Image = '$avatar_path' WHERE ID = '$id'";
if ($mysqli->query($sql)===true)
{
$_SESSION['message3'] = "Profile Pic Update Successful!!!";
}
else
{
$_SESSION['message3'] = "Update unsuccessful";
}
}
}
else
{
$_SESSION['message3'] = "Error!! Upload an Image(.jpeg/.png/.jpg format)";
}
}
$Userdata = getUserData($_SESSION['Username']);
?>
<!DOCTYPE html>
<html>
<title>Dashboard</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
html,body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<style type="text/css">
fieldset{
margin-right: 40px;
}
</style>
<link rel="stylesheet" type="text/css" href="Dashboard.css">
<body class="w3-light-grey">
<!-- Top container -->
<div class="w3-bar w3-top w3-black w3-large" style="z-index:4">
<button class="w3-bar-item w3-button w3-hide-large w3-hover-none w3-hover-text-light-grey" onclick="w3_open();"><i class="fa fa-bars"></i> Menu</button>
<span class="w3-bar-item w3-right"><img src= "./Images/logo.jpg" height = "40px" width = "40px"></span>
</div>
<!-- Sidebar/menu -->
<nav class="w3-sidebar w3-collapse w3-white w3-animate-left" style="z-index:3;width:300px;" id="mySidebar"><br>
<div class="w3-bar-block">
<a href="#" class="w3-bar-item w3-button w3-padding-16 w3-hide-large w3-dark-grey w3-hover-black" width="100%" onclick="w3_close()" title="close menu"><i class="fa fa-remove fa-fw"></i> Close Menu</a></div><br>
<div class="w3-container w3-row">
<div class="w3-col s4">
<img src="./Images/avatar.png" class="w3-circle w3-margin-right" style="width:46px">
</div>
<div class="w3-col s8 w3-bar">
<span>Welcome, <strong><?php echo $Userdata['Name']; ?></strong></span><br>
</div>
</div>
<hr>
<div class="w3-bar-block">
<button class="w3-bar-item w3-button w3-padding w3-blue dropdown-btn">Dashboard
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container" >
<a href="./Dash.php" class="w3-bar-item w3-button w3-padding w3-blue"><i class="fa fa-users fa-fw"></i> Overview</a>
<a href="#" class="w3-bar-item w3-button w3-padding active"><i class="fa fa-cog"></i> Update Profile</a>
</div>
<button class="w3-bar-item w3-button w3-padding w3-blue dropdown-btn active"><i class="fa fa-bell"></i> Announcements
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container1" >
<a href="./Dash_announc_global.php" class="w3-bar-item w3-button w3-padding w3-blue"><i class="fa fa-globe"></i> Global</a>
<a href="./Students_Corner/First_Year/Dash_announce.php" class="w3-bar-item w3-button w3-padding w3-blue">First Year</a>
<a href="./Students_Corner/Second_Year/Dash_announce.php" class="w3-bar-item w3-button w3-padding w3-blue">Second Year</a>
<a href="./Students_Corner/Third_Year/Dash_announce.php" class="w3-bar-item w3-button w3-padding w3-blue">Third Year</a>
<a href="./Students_Corner/Fourth_Year/Dash_announce.php" class="w3-bar-item w3-button w3-padding w3-blue">Fourth Year</a>
<a href="./Students_Corner/Fifth_Year/Dash_announce.php" class="w3-bar-item w3-button w3-padding w3-blue">Fifth Year</a>
</div>
<button class="w3-bar-item w3-button w3-padding w3-blue dropdown-btn"><i class="fa fa-book"> Lecture Notes</i>
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container1">
<a href="./Students_Corner/First_Year/Lect.php" class="w3-bar-item w3-button w3-padding w3-blue">First Year</a>
<a href="./Students_Corner/Second_Year/Lect.php" class="w3-bar-item w3-button w3-padding w3-blue">Second Year</a>
<a href="./Students_Corner/Third_Year/Lect.php" class="w3-bar-item w3-button w3-padding w3-blue">Third Year</a>
<a href="./Students_Corner/Fourth_Year/Lect.php" class="w3-bar-item w3-button w3-padding w3-blue">Fourth Year</a>
<a href="./Students_Corner/Fifth_Year/Lect.php" class="w3-bar-item w3-button w3-padding w3-blue">Fifth Year</a>
</div>
<button class="w3-bar-item w3-button w3-padding w3-blue dropdown-btn"><i class="fa fa-pencil"></i> Assignments
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container1">
<a href="./Students_Corner/First_Year/Assignments.php" class="w3-bar-item w3-button w3-padding w3-blue">First Year</a>
<a href="./Students_Corner/Second_Year/Assignments.php" class="w3-bar-item w3-button w3-padding w3-blue">Second Year</a>
<a href="./Students_Corner/Third_Year/Assignments.php" class="w3-bar-item w3-button w3-padding w3-blue">Third Year</a>
<a href="./Students_Corner/Fourth_Year/Assignments.php" class="w3-bar-item w3-button w3-padding w3-blue">Fourth Year</a>
<a href="./Students_Corner/Fifth_Year/Assignments.php" class="w3-bar-item w3-button w3-padding w3-blue">Fifth Year</a>
</div>
<a href="./Events.php" class="w3-bar-item w3-button w3-padding w3-blue"><i class="fa fa-users fa-fw"></i> Events</a>
<a onclick = "return con1()" href="logout.php" class="w3-bar-item w3-button w3-padding w3-blue"><i class="fa fa-power-off"></i> Logout</a>
</div>
<script type="text/javascript">
function con1() {
var r = confirm("Are you sure you want to logout?");
if (r==true)
{
return true;
}
{
return false;
}
}
</script>
</nav>
<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large w3-animate-opacity" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>
<!-- !PAGE CONTENT! -->
<div class="w3-main" style="margin-left:400px;margin-top:43px;">
<!-- Header -->
<header class="w3-container" style="padding-top:22px">
<h5><b><i class="fa fa-dashboard"></i> My Dashboard</b></h5>
</header>
<p class = "heading"><h1><i class = "fa fa-cog"></i>Update Profile</h1><hr>
</p><p><strong><i>Here you can update the details into your profile, by changing thye details of the respective field</i></strong></p><br><br>
<fieldset class = "data">
<i>Kindly change the data you want to update:</i><br><br><center>
<form action = '#' method = "POST" enctype="multipart/form-data"><table><tr><td>
Name:</td><td><input type="text" name="Name" placeholder="Name" value = "<?php echo $Userdata['Name'] ?>"/></td></tr><tr>
<td>Designation:</td><td><input type="text" name="Designation" placeholder="Position" value = "<?php echo $Userdata['Position'] ?>"/></td></tr><tr>
<td>Place:</td><td><input type="text" name="Place" placeholder="Place" value = "<?php echo $Userdata['Place'] ?>"/></td></tr><tr><td>Email:</td>
<td><input type="email" placeholder="Email" name="email" value = "<?php echo $Userdata['Email'] ?>" /></td></tr></table>
<input type="submit" value="Update" name="Update_data" class="btn btn-block btn-primary" /><br><br>
</form></center><br><br>
<center><i>
<? echo $_SESSION['message1'] ?></i></center></fieldset>
<br><br>
<fieldset><i>Kindly change enter password to update:</i><br><br><center>
<form action = '#' method = "POST" enctype="multipart/form-data"><table><tr>
<td>Old Password</td><td><input type = "password" name = "password" placeholder = "Old Password"></td></tr><tr>
<td>New Password</td><td><input type = "password" name = "new_password" placeholder = "New Password"></td></tr><tr>
<td>Confirm New Password</td><td><input type = "password" name = "confirmpassword" placeholder = "Reconfirm New Password"></td></tr></table>
<input type="submit" value="Update" name="Update_pass" class="btn btn-block btn-primary"/><br><br>
</form></center><center><i>
<? echo $_SESSION['message'] ?></i></center></fieldset>
<br><br>
<fieldset><i>Kindly upload new profile pic you want to display:</i><br><br><center>
<form action = '#' method = "POST" enctype="multipart/form-data"><table><tr>
<input type="file" name = "file">
<input type="submit" value="Update" name="Update_pic" class="btn btn-block btn-primary"/><br><br>
</form></center><center><i>
<? echo $_SESSION['message3'] ?></i></center></fieldset>
<br><br>
</div>
<!-- End of Page content-->
<script>
// Get the Sidebar
var mySidebar = document.getElementById("mySidebar");
// Get the DIV with overlay effect
var overlayBg = document.getElementById("myOverlay");
// Toggle between showing and hiding the sidebar, and add overlay effect
function w3_open() {
if (mySidebar.style.display === 'block') {
mySidebar.style.display = 'none';
overlayBg.style.display = "none";
} else {
mySidebar.style.display = 'block';
overlayBg.style.display = "block";
}
}
// Close the sidebar with the close button
function w3_close() {
mySidebar.style.display = "none";
overlayBg.style.display = "none";
}
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
for (i = 0; i < dropdown.length; i++) {
dropdown[i].nextElementSibling.style.display = "none";
}
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
</script>
</body>
</html>