-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriends.php
More file actions
140 lines (125 loc) · 3.7 KB
/
friends.php
File metadata and controls
140 lines (125 loc) · 3.7 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
<?php
require_once("includes/init.php");
// If currentUser is NOT logged in. Return to index.php
if(!$currentUser->isLoggedIn())
{
// GO TO index.php
header("Location: index.php");
die();
}
// Call currentUser function and save result to $friends variable.
$friends = $currentUser->getFriends();
?>
<!DOCTYPE html>
<html>
<head>
<?php require_once("includes/standard_head.php"); ?>
<title>Friends</title>
</head>
<body>
<?php require_once("includes/navbar.php"); ?>
<!-- Content start -->
<div class="container">
<?php displayAlerts(); ?>
<div class="row">
<div class="col-lg-2">
<!-- SIDEBAR USER TITLE -->
<div class="profile-usertitle">
<!-- Display currentUser->username -->
<div class="profile-usertitle-name">
<h1><?php echo $currentUser->username; ?></h1>
</div>
<div class="profile-usertitle-userType">
<!-- Check if currenUser is Admin to display right usertype (Normal user or admin)-->
<?php
if($currentUser->isAdmin())
{
echo "Administrator";
}
else
{
echo "User";
}
?>
</div>
</div>
<!-- END SIDEBAR USER TITLE -->
<!-- SIDEBAR MENU -->
<div class="profile-usermenu">
<ul class="nav">
<li>
<a href="/profile.php">
<i class="glyphicon glyphicon-home"></i>
Overview </a>
</li>
<li>
<a href="#">
<i class="glyphicon glyphicon-user"></i>
Friends </a>
</li>
</ul>
</div>
<!-- END MENU -->
</div>
<!-- FRIENDS LOAD -->
<div class="col-lg-10">
<div class="col-lg-5 profile-comments">
<h3>Friends</h3>
<?php
// If $friends variable is empty the user has no friends
if (empty($friends))
{
echo '<div class="col-lg-12 profile-comment">';
echo '<p>You have no friends... :(</p>';
echo '</div>';
}
else
{ // echo html to show each friend and create link to friends profile page
foreach ($friends as $friends)
{
// create link to friends profile page
echo '<a href="profile.php?user='.htmlspecialchars($friends->username).'">';
echo '<div class="col-lg-12 profile-comment">';
// echo friends username
echo htmlspecialchars($friends->username);
// Show friends since
echo '<br><span class="post-time"> Friends Since: '.date('H:i d/m/y', $currentUser->friendsSince($friends->id)).'</span>';
echo '</div>';
echo '</a>';
}
}
?>
</div>
<div class="col-lg-5 profile-posts">
<h3>Add Friend</h3>
<div class="col-lg-12 profile-comment">
<div class="input-group">
<input id="username" type="text" class="form-control" placeholder="Search User...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" onclick="addUser()">Search</button>
</span>
</div><!-- /input-group -->
</div>
<div id="alertdiv" class="col-lg-12"></div>
</div>
</div>
<!-- FRIENDS LOAD END -->
</div>
</div>
<!-- Content end -->
<?php require_once("includes/standard_footer.php"); ?>
<script>
function addUser(){
var username = $("#username").val();
$.ajax({
url: 'ajax/sendFriendRequest.php',
type: 'post',
data: {username: username},
success: function(output){
$("#alertdiv").html(output);
}
});
}
</script>
</body>
</html>