-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
291 lines (212 loc) · 7.32 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
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
<?php include "inc/header.php";
$db = new Database();
$format = new Format();
$user = $format->Stext(isset($_REQUEST['user']));
if (!(isset($_REQUEST['user']) || isset($_SESSION['login']))){
header("location: login.php?msg=Login First");
}
?>
<?php
//for other users
if($user){
$OtherUsername = $format->Stext($_REQUEST['user']);
$queryOther = "SELECT * FROM register WHERE user_name='$OtherUsername'";
$GetDataPr =$db->select($queryOther);
if($GetDataPr){
$GetDataPr = $GetDataPr->fetch_assoc();
}else{
header("location: index.php?error=profile not found");
}
}
else{
//Get data
$username = $_SESSION['name'];
$userlogin = $_SESSION['login'];
$queryPr = "SELECT * FROM register WHERE user_name='$username' AND user_login='$userlogin'";
$GetDataPr =$db->select($queryPr)->fetch_assoc();
// </>
}
//end that
if(isset($_POST['submit'])){
if(isset($userlogin)){
$userip=$_SERVER['REMOTE_ADDR'];
//$passmd5 =md5($pass);
$usertype='user';
$status='active';
$egt = $GetDataPr['user_email'];
$city =$format->Stext($_POST['city']);
$state =$format->Stext($_POST['state']);
$country =$format->Stext($_POST['country']);
$bio =$format->Stext($_POST['bio']);
$date =$format->Stext($_POST['dob']);
$query = "UPDATE register SET
user_city='$city',user_state='$state',
user_country='$country',
user_bio='$bio',
user_date='$date',
ipadd='$userip'
where user_email='$egt'";
$read =$db->update($query);
if($read)
{
Format::jumpTo("profile.php","Profile Info Save Successfully.");
}
}
else{
header("Location: profile.php?user=$OtherUsername&msg=".urlencode('Login First'));
}
}
//for updating photo
if(isset($_POST['savephoto'])){
if(isset($userlogin)){
//upload photo
$photoname = $_FILES['photo']['name'];
$tmp_name = $_FILES['photo']['tmp_name'];
$location="img/profile/$photoname";
$new_name = $location.time()."-".rand(1000, 9999)."-".$photoname;
move_uploaded_file($tmp_name, $new_name);
$dbs = new Database();
$querys = "UPDATE register SET user_image='$new_name' WHERE user_name='$username' AND user_login='$userlogin'";
$reads =$dbs->update($querys);
if($reads)
{
header("Location: profile.php?msg=".urlencode('Profile Photo Save Successfully.'));
}
}else{
header("Location: profile.php?user=$OtherUsername&msg=".urlencode('Login First'));
}
}
//</>}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-2">
<p><img id="profile_img" class="left-block img-thumbnail" src="<?php echo $GetDataPr['user_image']?>" alt=""></p>
<?php
if($user){
}else if($userlogin){
?>
<label class="btn btn-primary" for="profile_input">Browse...</label>
<input type="file" class="m-hidden" name="photo" id="profile_input"/>
<label class="btn btn-info" for="savebtn">Update Photo</label>
<input class="btn btn-info m-hidden" value="Save" type="submit" name="savephoto" id="savebtn"/>
<?php
}
?>
<?php
if($user){
}else if($userlogin){
?>
<div class="card">
<div class="card-header">
Your Stats
</div>
<div class="card-body">
Points : <?php
//getting sensitive data
if(isset($userlogin)){
$querys = "SELECT * FROM register WHERE user_login = '$userlogin'";
$GetDatas = $db->select($querys)->fetch_assoc();
$user_id = $GetDatas['user_id'];
$points = $db->select("SELECT * FROM leaderboard WHERE user_id='$user_id'");
if($points){
$getPoint = $points->fetch_assoc();
echo $getPoint['points'];
}
}
//end getting sensitive data
?> <br>
</div>
</div>
<?php
}
?>
</div>
</form>
<div class="col-xs-12 col-md-10 container-fluid bg-secondary text-white rounded" style="padding-top:70px;padding-bottom:70px">
<h2><?php echo $GetDataPr['user_name']?>'s profile</h2>
<form action="" method="post" enctype="multipart/form-data">
<div class="m-input-group">
<input <?php
if($user){
echo "disabled='disabled'";
}else{
echo "enabled";
}
?> type="date" class="m-form-control" id="dob" name="dob" value="<?php echo $GetDataPr['user_date']?>" class="hasDatepicker">
<label>Date</label>
</div>
<div class="m-input-group">
<input <?php
if($user){
echo "disabled='disabled'";
}else{
echo "enabled";
}
?> type="text" class="m-form-control" name="city" id="city" value="<?php echo $GetDataPr['user_city']?>">
<label>City</label>
</div>
<div class="m-input-group">
<input <?php
if($user){
echo "disabled='disabled'";
}else{
echo "enabled";
}
?> type="text" class="m-form-control" name="state" id="region" value="<?php echo $GetDataPr['user_state']?>">
<label>State/Province</label>
</div>
<div class="m-input-group">
<input <?php
if($user){
echo "disabled='disabled'";
}else{
echo "enabled";
}
?> type="text" class="m-form-control" name="country" id="country" value="<?php echo $GetDataPr['user_country']?>">
<label>Country</label>
</div>
<div class="m-input-group">
<textarea <?php
if($user){
echo "disabled='disabled'";
}else{
echo "enabled";
}
?> class="m-form-control" rows="8" cols="50" id="mytextarea" name="bio"><?php echo $GetDataPr['user_bio']?></textarea>
<label>About</label>
</div>
<p></p>
<p></p>
<?php
if($user){
}else if($userlogin){
?>
<input type="submit" name="submit" value="Update" class="btn btn-primary" name="update_bio">
<button class="btn btn-info" href="profile.php">Cancel</button>
<?php
}
?>
</form>
</div>
</div>
</div>
<script>
//handling image view
$(document).on('change', '#profile_input', function(){
var file = $('#profile_input')[0].files[0];
if(file){
var reader = new FileReader();
reader.onload = function(e){
//set value of the input for profile picture
$('#profile_input').attr('value', file.name);
//display the image
$('#profile_img').attr('src', e.target.result);
};
reader.readAsDataURL(file);
}
});
//end handling image view
</script>
<?php include "inc/footer.php"; ?>