-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests.php
More file actions
89 lines (75 loc) · 3.54 KB
/
requests.php
File metadata and controls
89 lines (75 loc) · 3.54 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
<?php
//Get logged in user. If no user is logged in, redirect to login page.
session_start();
if (!isset($_SESSION["loggedInUser"])){
header("Location:login.php");}
else{
$loggedInUser = $_SESSION["loggedInUser"];}
//Connect to database
$serverName = "localhost\sqlexpress";
$connectionInfo = array("Database"=>"social_network", "UID"=>"ben", "PWD"=>"password123");
$conn = sqlsrv_connect($serverName, $connectionInfo);
//Get userID of loggedinUser
$getCurrentUserIDQuery = "SELECT id FROM users WHERE username = '$loggedInUser'";
$getCurrentUserID = sqlsrv_query($conn, $getCurrentUserIDQuery, array());
$currentUserID = sqlsrv_fetch_array($getCurrentUserID);
$currentUserID = $currentUserID[0];
//Get received pending friend invites of loggedInUser
$getCurrentUserReceivedPendingInvitesQuery = "SELECT userid FROM friends WHERE friendid = '$currentUserID' AND accepted = 'False'";
$currentUserReceivedPendingInvites = sqlsrv_query($conn, $getCurrentUserReceivedPendingInvitesQuery, array(), array( "Scrollable" => 'static' ));
$pendingRequestsCount = sqlsrv_num_rows($currentUserReceivedPendingInvites); //Count pending invites
//Convert pending friend invites of loggedInUser to array of user IDs
$currentUserReceivedPendingInvitesArray = array();
for ($x = 1; $x < $pendingRequestsCount + 1; $x++){
$currentUserReceivedPendingInvitesRow = sqlsrv_fetch_array($currentUserReceivedPendingInvites, SQLSRV_FETCH_NUMERIC); //Select next row
array_push($currentUserReceivedPendingInvitesArray, $currentUserReceivedPendingInvitesRow[0]);}
//Convert currentUserReceivedPendingInvitesArray from user IDs to usernames
foreach ($currentUserReceivedPendingInvitesArray as &$value){
$convertQuery = " SELECT username FROM users WHERE id = '$value' ";
$convert = sqlsrv_query($conn, $convertQuery);
$convert = sqlsrv_fetch_array($convert);
$value = $convert[0];}
?>
<html>
<head>
<title>Social Network</title>
<link rel="stylesheet" type="text/css" href="default.css">
</head>
<body>
<center>
<!--Logo-->
<div class="header" id="header">
<h1><a href="index.php">Social Network</a></h1>
</div>
<!--Options bar-->
<div id="options">
<span id="search">
<?php echo '<form action="?" method="post"style="display: inline;"><input type="text" name="search" placeholder="Search"><input type="submit" value="Submit" name="submitSearch"></form>'; ?>
</span>
<span id="userOptions">
<?php if (!isset($_SESSION["loggedInUser"])){echo '<a href="register.php">Register</a> ';} ?>
<?php if (!isset($_SESSION["loggedInUser"])){echo '<a href="login.php"44>Log in</a> ';} ?>
<?php if (isset($_SESSION["loggedInUser"])){echo '<a href="logout.php">Log out</a>';} ?>
<?php if (isset($_SESSION["loggedInUser"])){echo 'Welcome, <a href="profile.php?selectedUser=' . $loggedInUser . '">' .$loggedInUser. '</a>';}
?>
</span>
</div>
<div class="contents">
<div id="searchResults">
<?php
echo nl2br("Friend requests\n\n");
if ($pendingRequestsCount > 0){
for ($x = 1; $x < $pendingRequestsCount + 1; $x++){
//Display a user
echo nl2br("<font color='#0080ff'><b><a href='profile.php?selectedUser=".$currentUserReceivedPendingInvitesArray[$x-1]."'>".$currentUserReceivedPendingInvitesArray[$x-1]."</a></b></font>\n\n");
}
}
else {
echo "No friend reqests";
}
?>
</div>
</div>
</center>
</body>
</html>