-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow.php
392 lines (317 loc) · 17 KB
/
follow.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
include 'session_login.php';
$url1 = 'http://localhost/UniWebProject/processFollowers.php?id='.$id;
$url2 = 'http://localhost/UniWebProject/processFollowings.php?id='.$id;
$json1 = json_decode(file_get_contents($url1));
$json2 = json_decode(file_get_contents($url2));
$isFollowed = false;
$isFriend = false;
$friendButtonText = 'Friend';
if(isset($_GET['user'])){
$username = $_GET['user'];
$query = 'SELECT user.user_id FROM webprojectdatabase.user WHERE user.user_name = :username';
$values = array(':username' => $username);
try {
$res = $pdo->prepare($query);
$res->execute($values);
}catch (PDOException $e){
throw new Exception('Database query error');
}
$thisId = $res->fetch()['user_id'];
$query = "SELECT follow.date_since FROM webprojectdatabase.follow WHERE follow.followed = :followed AND follow.follower = :follower";
$values = array(':followed'=>$thisId, ':follower'=>$account->getId());
try {
$res = $pdo->prepare($query);
$res->execute($values);
}catch (PDOException $e){
throw new Exception('Database query error');
}
if($res->rowCount() > 0) {$isFollowed = true;}
$query = "SELECT friend.pending FROM webprojectdatabase.friend WHERE friend.requestee = :requestee AND friend.requestor = :requestor";
$values = array(':requestee'=>$thisId, ':requestor'=>$account->getId());
try {
$res = $pdo->prepare($query);
$res->execute($values);
}catch (PDOException $e){
throw new Exception('Database query error');
}
if($res->rowCount() > 0) {
$isFriend = true;
$row = $res->fetch();
if($row['pending']===1){
$friendButtonText = 'pending';
}else{
$friendButtonText = 'Friend';
}
}else{
$isFriend = false;
$friendButtonText = 'Friend';
}
}else{
$thisId = $account->getId();
$query = 'SELECT user.user_name FROM webprojectdatabase.user WHERE user.user_id = :user_id';
$values = array(':user_id' => $thisId);
try {
$res = $pdo->prepare($query);
$res->execute($values);
}catch (PDOException $e){
throw new Exception('Database query error');
}
$username = $res->fetch()['user_name'];
}
$query = 'SELECT * FROM webprojectdatabase.user WHERE (user_id=:id)';
$values = array(':id'=>$thisId);
try
{
$res = $pdo->prepare($query);
$res->execute($values);
}
catch (PDOException $e)
{
throw new Exception('Database query error');
}
$row = $res->fetch(PDO::FETCH_ASSOC);
$fname = $row['f_name'];
$lname = $row['l_name'];
$self_description = $row['self_description'];
$dob = $row['DOB'];
$education = $row['education'];
$profile_pic = $row['profile_pic'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?php echo $fname.' '.$lname; ?></title>
<link rel="stylesheet" href="userProfile.css">
<link rel="stylesheet" href="tab.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://kit.fontawesome.com/e279e577b6.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<?php include 'navbar.php';?>
<div class="super-main">
<?php include 'side_column.php';?>
<div class="main">
<div id="reload-twPc-div"><div id="twPc-div" class="twPc-div" style="border: 1px solid black; width:95%;">
<div id="cover" class="twPc-bg twPc-block" ><img id="coverPic" src='<?php echo "$cover_pic";?>'></div>
<div id="profile"><img id="profilePic" src='<?php echo "$profile_pic";?>' alt="" class="twPc-avatarImg" style="border: 3px solid black;"></div>
<div id="twPc-divUser" class="twPc-divUser" >
<div class="twPc-divName">
<a href="user_profile.php?user=<?php echo $username;?>"><?php echo $fname;?> <?php echo $lname;?></a>
</div>
<span style="margin-left:30%;">
@<?php echo "$username";?>
</span>
<?php if($thisId!=$account->getId()){ ?>
<button id="friendButton" class="<?php if($isFriend){echo 'in-relation-button';}else{echo 'relation-button';} ?>" <?php if($login){?> onclick="processFriend()" <?php } ?> ><?php echo $friendButtonText ?></button>
<?php }else{} ?>
<?php if($thisId!=$account->getId()){ ?>
<button id="followButton" class="<?php if($isFollowed){echo 'in-relation-button';}else{echo 'relation-button';} ?>" <?php if($login){?> onclick="processFollow()" <?php } ?>><?php if($isFollowed){echo 'Following';}else{echo 'Follow';} ?></button>
<?php }else{} ?>
<script>
function processFollow(){
var unique = new Date().getUTCMilliseconds();
var xhr = new XMLHttpRequest();
var params = "followed=<?php echo $thisId; ?>&follower=<?php echo $account->getId(); ?>";
xhr.open('POST', 'processFollow.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
document.getElementById('followButton').outerHTML=this.responseText;
//$("#followButton").load("#followButton");
}
xhr.send(params);
}
function processFriend(){
var unique = new Date().getUTCMilliseconds();
var xhr = new XMLHttpRequest();
var params = "requestee=<?php echo $thisId; ?>&requestor=<?php echo $account->getId(); ?>";
xhr.open('POST', 'processFriend.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
document.getElementById('friendButton').outerHTML=this.responseText;
//$("#friendButton").load(" #friendButton");
}
xhr.send(params);
}
</script>
</div>
<div class="twPc-divStats">
<br>
<ul class="twPc-Arrange">
<li class="twPc-ArrangeSizeFit">
<span class="twPc-StatLabel twPc-block">Date of Birth</span>
<span id="dateOfBirth" class="twPc-StatValue"><?php echo "$dob";?></span>
</li>
<li class="twPc-ArrangeSizeFit">
<span class="twPc-StatLabel twPc-block">Education</span>
<span id="educ" class="twPc-StatValue"><?php echo "$education";?></span>
</li>
<li class="twPc-ArrangeSizeFit">
<span class="twPc-StatLabel twPc-block">About myself</span>
<span id="self" class="twPc-StatValue"><?php echo "$self_description";?></span>
</li>
<!-- Trigger the modal with a button -->
<?php if($login && $thisId==$id){ ?><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal1">Edit Profile</button><?php } ?>
</ul>
</div>
</div></div>
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Profile</h4>
</div>
<div class="modal-body">
<form id="updateProfile">
<div class="form-group">
<label>Cover Picture:</label>
<input id="cover-image-upload" value = <?php echo $cover_pic;?> type="file" name="coverImage"/>
<img src='<?php echo "$cover_pic";?>' id="cover-image" alt="" class="twPc-avatarImg" style="border-radius: 20%;height:70px;width:70px;margin-top:4%;">
</div>
<div class="form-group">
<label>Profile Picture:</label>
<input id="profile-image-upload" value = <?php echo $profile_pic;?> type="file" name="profileImage"/>
<img src='<?php echo "$profile_pic";?>' id="profile-image" alt="" class="twPc-avatarImg" style="border-radius: 20%;height:70px;width:70px;margin-top:4%;">
</div>
<div class="form-group">
<label>First Name:</label>
<input type="text" id="firstName" name="firstName" class="form-control" value=<?php echo $fname;?>>
</div>
<div class="form-group">
<label>Last Name:</label>
<input type="text" id="lastName" name="lastName" class="form-control" value=<?php echo $lname;?>>
</div>
<div class="form-group">
<label>Date of Birth:</label>
<input type="date" id="dob" name="dob" class="form-control" value=<?php echo "$dob";?>>
</div>
<div class="form-group">
<label>Education:</label>
<textarea id="education" name="education" class="md-textarea form-control" rows="4" cols="20"><?php echo "$education";?></textarea>
</div>
<div class="form-group">
<label>Self-Description:</label>
<textarea id="description" name="selfDescription" class="md-textarea form-control" placeholder="About You" rows="4" cols="20" ><?php echo "$self_description";?></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="update" class="btn btn-primary pull-right" >Update</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<script>
$(document).ready(function(){
//issue with internet, ajax wasn't working, test feature once internet resolved
$("button#update").on('click', function(){
let formData = new FormData();
formData.append('firstName', $("#firstName").val());
formData.append('lastName', $("#lastName").val());
formData.append('dob', $("#dob").val());
formData.append('education', $("#education").val());
formData.append('selfDescription', $("#description").val());
if($('#cover-image-upload').get(0).files.length !== 0){
console.log("Cover picture exists!");
formData.append('coverImage', $("#cover-image-upload")[0].files[0], $("#cover-image-upload").val().split('\\').pop());
}
if($('#profile-image-upload').get(0).files.length !== 0){
console.log("Profile picture exists!");
formData.append('profileImage', $("#profile-image-upload")[0].files[0], $("#profile-image-upload").val().split('\\').pop());
}
$.ajax({
url:"edit_user_profile.php",
data: formData,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function(response){
alert("Olryte");
console.log(response);
$("#reload-twPc-div").load(location.href + " #twPc-div");
}
})
});
$("#profile-image").click(function(){
$("#profile-image-upload").click();
});
$("#cover-image").click(function(){
$("#cover-image-upload").click();
});
});
</script>
</div>
</div>
<div style="width:100%; dsplay:flex;">
<div class="tabinator" style="float:left; width:75%;">
<!-- <h2>CSS tabs with shadow</h2> -->
<input type="radio" id="tab1" name="tabs" checked>
<label for="tab1">Follower</label>
<input type="radio" id="tab2" name="tabs">
<label for="tab2">Followings</label>
<div id="content1">
<?php
if($json1){
foreach($json1 as $follower){
$followerfname = $follower->f_name;
$followerlname = $follower->l_name;
$followerPicture = $follower->profile_pic;
$followerDate = $follower->date_since;
$followerUsername = $follower->user_name;
echo '<div style="background-color:lightgrey; border-radius: 5px; border: 3px solid black; height:100px; overflow:hidden">';
echo '<table>';
echo '<tr>';
echo '<td rowspan="2"><a href="user_profile.php?user='.$followerUsername.'" class="generic-btn"><img src="'.$followerPicture.'" alt="" style="height:50px"></a></td>';
echo '<td><a class="generic-btn anchor-list-item" href="user_profile.php?user='.$followerUsername.'"><p>'.$followerfname.' '.$followerlname.'</p></a></td>';
echo '</tr>';
echo '<tr>';
echo "<td>".$followerDate."</td>";
echo '</tr>';
echo '</table>';
echo '</div>';
echo '<br><br>';
}}
?>
</div>
<div id="content2">
<?php
if($json2){
foreach($json2 as $following){
$followingfname = $following->f_name;
$followinglname = $following->l_name;
$followingPicture = $following->profile_pic;
$followingDate = $following->date_since;
$followingUsername = $following->user_name;
echo '<div style="background-color:lightgrey; border-radius: 5px; border: 3px solid black; height:100px; overflow:hidden">';
echo '<table>';
echo '<tr>';
echo '<td rowspan="2"><a href="user_profile.php?user='.$followingUsername.'" class="generic-btn"><img src="'.$followingPicture.'" alt="" style="height:50px"></a></td>';
echo '<td><a class="generic-btn anchor-list-item" href="user_profile.php?user='.$followingUsername.'"><p>'.$followingfname.' '.$followinglname.'</p></a></td>';
echo '</tr>';
echo '<tr>';
echo "<td>".$followingDate."</td>";
echo '</tr>';
echo '</table>';
echo '</div>';
echo '<br><br>';
}}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer.php';?>
</body>
</html>