-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddFriend.php
68 lines (64 loc) · 2.42 KB
/
AddFriend.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
<?php
include_once 'EntityClassLib.php';
include_once('Functions.php');
session_start();
//check whether the user is logged in
if(isset($_SESSION["user"])){
$user = $_SESSION["user"];
} else {
header("Location: Login.php");
exit();
}
$status = 'request';
$friendIdErr = "";
$successMsg = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$friendId = $_POST['friendId'];
if(isset($_POST["submitBtn"])){
$friendIdErr = ValidateFriendId($user->getUserId(), $friendId);
if(empty($friendIdErr)){
try {
$friend = getFriend($friendId);
$friendName = getFriend($friendId)->getFriendName();
$successMsg = sendFriendRequest($user->getUserId(), $friendId, $friendName, $status);
}
catch (Exception $e)
{
die("The system is currently not available, try again later");
}
}
}
}
include("./common/header.php");
?>
<div class="container">
<br>
<h1 class="center">My Friends</h1>
<br>
<p>Welcome <strong><?php echo $user->getName(); ?></strong>! (not you? change user <a href="Logout.php">here</a>)</p>
<br>
<p>Enter the ID of the user you want to be friend with:</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div class="row form-group">
<label for="friendId" class="col-sm-1 col-form-label">ID: </label>
<div class="col-sm-3">
<input type="text" class="form-control" id="friendId" name="friendId" value="<?php echo isset($friendId)? $friendId : ''; ?>">
</div>
<?php
if (!empty($friendIdErr)){
echo "<div class=\"text-danger col-md-5\">
$friendIdErr
</div>";
}
if (!empty($successMsg)){
echo "<div class=\"text-danger col-md-5\">
$successMsg
</div>";
}
?>
</div>
<button type="submit" name="submitBtn" class="btn btn-primary">Send Friend Request</button>
</form>
<br>
</div>
<?php include('./common/footer.php'); ?>