This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfriend-requests.php
88 lines (77 loc) · 3.28 KB
/
friend-requests.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
<?php
require_once "pdo.php";
require_once "head.php";
date_default_timezone_set('Asia/Taipei');
if (!isset($_SESSION["email"])) {
include 'head.php';
echo "<p align='center'>PLEASE LOGIN</p>";
echo "<br />";
echo "<p align='center'>Redirecting in 3 seconds</p>";
header("refresh:3;url=login.php");
die();
}
if (isset($_SESSION['email'])) {
$stmt = $pdo->query("SELECT * FROM account");
$accounts = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = $pdo->prepare("SELECT * FROM account WHERE user_id=?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetchAll(PDO::FETCH_ASSOC);
$pfpsrc_default = './assets/images/default-user-square.png';
if ($user[0]['pfp'] != null) {
$userpfp = $user[0]['pfp'];
} else {
$userpfp = $pfpsrc_default;
}
$stmt = $pdo->prepare("SELECT * FROM friendship_status where addressee_id =?");
$stmt->execute([$_SESSION['user_id']]);
$friendship_requests = $stmt->fetchAll();
// print_r($friendship_requests);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>G4o2 Chat</title>
</head>
<body>
<main>
<?php
require_once "navbar.php";
echo "<h1>Friend requests</h1>";
if (!$friendship_requests) {
echo "<p>no friend requests</p>";
echo "<span>Send one <a href='./users.php'>here</a></span>";
} else {
foreach ($friendship_requests as $friendship_request) {
$stmt = $pdo->prepare("SELECT * FROM account WHERE user_id=?");
$stmt->execute([$friendship_request['requester_id']]);
$friendship_requester = $stmt->fetch(PDO::FETCH_ASSOC);
$last_online = $friendship_request['specified_date_time'];
$current_date_time = date(DATE_RFC2822);
$last_online = new DateTime($last_online);
$current_date_time = new DateTime($current_date_time);
$diff = $current_date_time->diff($last_online)->format("last online %a days %h hours and %i minutes ago");
$exploded = explode(" ", $diff);
if ($exploded[2] == "1") {
$diff = "<p class='text-primary'>$exploded[2] day ago</p>";
} elseif ($exploded[4] == "1") {
$diff = "<p class='text-primary'>$exploded[4] hour ago</p>";
} elseif ($exploded[7] == "1") {
$diff = "<p class='text-primary'>$exploded[7] minute ago</p>";
} elseif ($exploded[2] !== "0") {
$diff = "<p class='text-primary'>$exploded[2] days ago</p>";
} elseif ($exploded[4] !== "0") {
$diff = "<p class='text-primary'>$exploded[4] hours ago</p>";
} elseif ($exploded[7] !== "0") {
$diff = "<p class='text-primary'>$exploded[7] minutes ago</p>";
} else {
$diff = "<p class='text-primary'>Just now</p>";
}
echo "<h6>New friend request from <a href='profile.php?id=".$friendship_requester['user_id']."'>{$friendship_requester['username']}</a></h6>";
echo $diff;
}
}
?>
</main>
</body>
</html>