-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutbox.php
61 lines (57 loc) · 2.49 KB
/
outbox.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
<?php
//Variables session
$userName = $_SESSION["username"];
$firstName = $_SESSION["userFirstName"];
//Get the info of the user
$user = get_user_by_userName($pdo, $userName);
// Get the latest sent messages from the logged in user
$stmt = $pdo->prepare('SELECT * FROM messages Where FromUserId = :userid ORDER BY Timestamp DESC ');
$stmt->execute(
array(
'userid' => $_SESSION["userid"]
)
);
//Verify the respond data from DB
if ($stmt == null) {
//Error
$errorMessage = "There was an error in the database, please wait here";
template_error('Error', $errorMessage);
}
$recently_added_messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?= template_header('Outbox', $firstName, $userName, $user['UserAvatar']) ?>
<div class="list-group">
<h2><?= $firstName ?>'s Outbox <i class="fas fa-inbox"></i></h2>
<div class="messages">
<?php foreach ($recently_added_messages as $message) : ?>
<?php
// Get the info of the FromUser
$info_from_user = get_user_by_id($pdo, $message['ToUserId']);
?>
<a href="index.php?page=message&id=<?= $message['MessageId'] ?>" class="list-group-item list-group-item-action d-flex gap-3 py-3" aria-current="true">
<img src="<?= $info_from_user['UserAvatar'] ?>" alt="twbs" width="32" height="32" class="rounded-circle flex-shrink-0" />
<div class="d-flex gap-2 w-100 justify-content-between">
<div>
<h6 class="mb-0"> <?= $info_from_user['UserFirstName'] . " " . $info_from_user['UserLastName'] ?></h6>
<p class="mb-0 opacity-75">
<?= substr($message['Text'], 0, 50) ?>
</p>
</div>
<small class="opacity-50 text-nowrap"><?= $message['Timestamp'] ?></small>
</div>
<?php if ($message['AttachFile'] == null || $message['AttachFile'] == "uploads/") {
$isAttached = "";
} else {
$isAttached = "fas fa-paperclip";
} ?>
<p>
<i class="<?= $isAttached ?>"></i>
</p>
</a>
<?php endforeach; ?>
</div>
<hr class="mb-4">
<a href="index.php?page=new-message" class="btn btn-primary btn-lg btn-block">New message</a>
</div>
<?= template_footer() ?>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>