-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
248 lines (240 loc) · 9.78 KB
/
Copy pathprofile.php
File metadata and controls
248 lines (240 loc) · 9.78 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
<html>
<head>
<title>Welcome</title>
<script src="jquery-1.12.2.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap.css" rel="stylesheet" type="text/css" />
<link href="bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="profile.css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700italic' rel='stylesheet' type='text/css'>
<script>
window.addEventListener("click",function(e){
document.getElementById("output").style.display="none";
});
</script>
</head>
<body>
<?php
global $row;
$row= new StdClass;
$row->id = null;
$row->pass = "";
$row->image="";
$row->phno="";
$row->gender="";
$row->email="";
$row->name="";
session_start();
if(!isset($_SESSION['user']))
header("Location: index.php");
else
{
include "connect.php";
$sql=$conn->prepare("SELECT username,name,passcode,Image,email,phno,gender from users where username=?");
$sql->bind_param('s',$_SESSION['user']);
$sql->execute();
$sql->store_result();
$sql->bind_result($row->id,$row->name,$row->pass,$row->image,$row->email,$row->phno,$row->gender);
$sql->fetch();
}
?>
<p align="center">Welcome <?php
echo '<br>';
?>  
<span class='glyphicon glyphicon-search'></span>
<input onkeyup="findmatch();" type="text" data-toggle="tooltip" data-placement="right" title="Enter username or Phone number"
id="search" placeholder="Search with username or Phone Number" style="width:280px;"></p>
<div id="img-holder">
<?php
include "connect.php";
echo '<img id="dp" src="data:image/jpeg;base64,'.base64_encode( $row->image ).'"/>';
?></div>
<button class="btn btn-info" id="Edit" onClick="updatedp();">
<span class="glyphicon glyphicon-pencil"></span>
</button>
<div id="output">
</div>
<div id="id01" class="modal">
<div class="modal-content" id="change">
</div>
</div>
<div id="contents">
<h1 style="position:relative;left:25px;top:30px">Contact Information</h1><br>
<hr color="black">
<table>
<div id="name">
<tr>
<td width="30%">Name</td>
<td width="40%" id="valueName"><?php echo $row->name;?></td>
<td width="20%"><button type="button" class="btn btn-default" onclick="updatename();"><span class="glyphicon glyphicon-pencil icon-success"></span> Edit</button></td>
</tr>
</div>
<div id="gender">
<tr>
<td>Gender</td>
<td id="valueGender"><?php echo $row->gender;?></td>
<td><button type="button" class="btn btn-default" onclick="updategender();"><span class="glyphicon glyphicon-pencil icon-success"></span> Edit</button></td>
</tr>
</div>
<div id="email">
<tr>
<td>Email</td>
<td id="valueEmail"><?php echo $row->email;?></td>
<td><button type="button" class="btn btn-default" onclick="updatemail();"><span class="glyphicon glyphicon-pencil icon-success"></span> Edit</button></td>
</tr>
</div>
<div id="phno">
<tr>
<td>Phone number</td>
<td id="valuePhno"><?php echo $row->phno; ?></td>
<td><button type="button" class="btn btn-default" onclick="updatephno();"><span class="glyphicon glyphicon-pencil icon-success"></span> Edit</button></td>
</tr>
</div>
</table>
<br>
<button align="center" style="position:relative;left:25%" onclick="updatepassword();">Change Password</button>
<br>
<br>
<input type="button" onclick="document.location.href='logout.php'" value="Logout" style="position:relative;left:30%">
<br><br><br><br>
<p style="position:absolute;bottom:0;left:25%;font-size:15px">Made with <span style="font-size:150%;color:red;">♥</span> by Nandhini</p>
</div>
<script>
var param="";
function findmatch(){
var search_text = document.getElementById('search').value;
document.getElementById("output").style.display="block";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("output").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','getuser.php?search_text='+search_text,true);
xmlhttp.send();
}
function updatename()
{
param="Name";
document.getElementById("name").style.display="none";
var modal=document.getElementById("id01");
modal.style.display="block";
document.getElementById("change").innerHTML="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center><table><tr><td>Enter Name:</td><td><input type='text' id='changedvalue' autofocus></td><td><button onclick='send()'>Submit</button></td></tr></table></center>";
}
function updategender()
{
param="Gender";
document.getElementById("gender").style.display="none";
var modal=document.getElementById("id01");
modal.style.display="block";
document.getElementById("change").innerHTML="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center><table><tr><td>Gender:</td><td><input type='text' id='changedvalue' autofocus></td><td><button onclick='send()'>Submit</button></td></tr></table></center>";
}
function updatemail()
{
param="Email";
document.getElementById("email").style.display="none";
var modal=document.getElementById("id01");
modal.style.display="block";
document.getElementById("change").innerHTML="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center><table><tr><td>Email Id:</td><td><input type='email' id='changedvalue' autofocus></td><td><button onclick='send()'>Submit</button></td></tr></table></center>";
}
function updatephno()
{
param="Phno";
var modal=document.getElementById("id01");
modal.style.display="block";
document.getElementById("change").innerHTML="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center><table><tr><td>Phone Number:</td><td><input type='text' id='changedvalue' autofocus></td><td><button onclick='send()'>Submit</button></td></tr></table></center>";
}
function updatedp()
{
alert("called");
param="Image";
var modal=document.getElementById("id01");
modal.style.display="block";
document.getElementById("change").innerHTML="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center><form enctype='multipart/form-data' action='upload.php' method='post'><table><tr><td>Profile Picture</td><td><input type='file' id='changedvalue' name='userfile'></td><td><button type='submit' name='submit' value='Submit'>Submit</button></td></tr></table></form></center>";
}
function updatepassword() {
var modal=document.getElementById("id01");
modal.style.display="block";
var text="<button onclick=document.getElementById('id01').style.display='none';><span class='glyphicon glyphicon-remove'></span></button><center>";
text+="<table><tr><td>Enter old Password:</td><td><input type='password' name='oldpass' id='oldpass' autofocus></td></tr>";
text+="<tr><td>Enter New Password:</td><td><input type='password' name='newpass' id='newpass'></td></tr>";
text+="<tr><td>Confirm New Password:</td><td><input type='password' name='confirmpass' id='confirmpass'></td></tr>";
text+="<tr><td></td><td><button onclick='AjaxChangePass();'>Submit</button>";
document.getElementById("change").innerHTML=text;
}
function AjaxChangePass(){
var xmlHttp = new XMLHttpRequest();
var url="updatepassword.php";
var parameters = "oldpass="+document.getElementById('oldpass').value+"&newpass="+document.getElementById('newpass').value+"&confirmpass="+document.getElementById('confirmpass').value;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parameters.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(xmlHttp.responseText);
if(xmlHttp.responseText=="Success.Please Login again")
{
document.location.href='index.php';
document.getElementById("id01").style.display="none";
}
}
}
xmlHttp.send(parameters);
}
function send()
{
var newvalue=document.getElementById("changedvalue").value;
var renumber=/[0-9]/;
var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?~_";
var relower=/[a-z]/;
var reupper=/[A-Z]/;
if(param=="Name")
{
for (var i = 0; i < newvalue.length; i++)
{
if (iChars.indexOf(newvalue.charAt(i)) != -1) {
alert ("Your string has special characters.These are not allowed.");
return false;
}
}
if(renumber.test(newvalue))
{
alert("Name Can only contain letters and spaces");
return;
}
}
else if(param=="Gender")
{
if(newvalue!="M" && newvalue!="F")
{
alert("Gender can be only M/F :M - Male F-Female");
return;
}
}
else if(param=="Phno")
{
if(newvalue.length<8 || relower.test(newvalue) ||reupper.test(newvalue) )
{
alert("Enter valid phone number");
return;
}
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
if(xhttp.responseText=="Given Email/Phone number is already taken")
{
alert("Given Email id/Phone number is already taken");
return;
}
document.getElementById("value"+param).innerHTML=xhttp.responseText;
document.getElementById("id01").style.display="none";
}
};
xhttp.open("GET", "update.php?"+param+"="+newvalue, true);
xhttp.send();
}
</script>
</body>
</html>