grublox/home.php

115 lines
4.5 KiB
PHP

<?php
require_once 'core/classes.php';
require_once 'core/classes/user.php';
headStart();
$user = new User($con, $_SESSION['user'] ?? 0);
if(!$user->isLoggedIn()) {
header('location: /login');
exit;
}
?>
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<?php
$himsgs = [
"Hello",
"What's up",
"How you doing",
"Ayo",
"Hola",
"Welcome",
"Welcome back",
"Hi",
"Hey",
"Heyyo",
"Howdy",
"Hi there",
"Ahoy",
"Ay",
"Sup",
"Wassup"
];
$himsg = array_rand($himsgs);
$himsg = $himsgs[$himsg];
$getitstarted = new PartyStarter;
$getitstarted->header();
?>
</head>
<title><?php echo $pagename; ?> | <?php echo $sitename; ?></title>
<body>
<main class="container" style="height: 90vh;">
<br><br>
<img src="assets/renders/user/headshot?userId=<?php echo (int)htmlspecialchars($user->getID($con, $user->getUsername())); ?>"
class="rounded-circle" width=190 height=190>
<span class="ms-2 fs-1"> <?php echo $himsg; ?>, <?php echo htmlspecialchars($user->getUsername()); ?>!</span>
</img>
<div style="margin-bottom: 50px;"></div>
<div class="d-flex flex-row justify-content-between mb-3">
<h4 class=" card-title">Friends (<?php $q=$con->prepare("SELECT count(*) FROM friendships WHERE user1=:id AND isAccepted=1"); $q->bindParam(':id',$_SESSION['user'],PDO::PARAM_INT); $q->execute(); $numberOfFriends = $q->fetchColumn(); echo $numberOfFriends; ?>)</h4>
<a href="/friends" class="btn btn-link text-decoration-none align-self-end">See all <i class="bi bi-caret-right"></i></a>
</div>
<div class="card mb-3 shadow-sm" style="height: 11.75rem;">
<div class="card-group" style=" margin-left: 10px; margin-top: 10px;">
<?php
if ($numberOfFriends >= 1) {
foreach ($user->getFriends() as $friend) {
$frienduser = new User($con, $friend['friend']);
?>
<div class="card text-white border border-0" style="max-width: 130px;">
<a href="user?id=<?php echo (int)htmlspecialchars($friend['friend']); ?>" style="text-decoration: none; text-align: center; margin-bottom: 9px;">
<div class="card-body">
<img src="assets/renders/user/headshot?userId=<?php echo (int)htmlspecialchars($friend['friend']); ?>" class="rounded-circle" width=100 height=100 alt="<?php echo htmlspecialchars($frienduser->getUsername()); ?>"></img>
</div>
<small class="text-center text-white"><?php echo htmlspecialchars($frienduser->getUsername()); ?></small>
</a>
</div>
<?php }
} else {
echo "</div> <h4 class='text-muted text-center mb-4'><i class='bi bi-egg-fried' style='font-size: 6rem;'></i><br> You have no friends.</h4>";
} ?>
</div>
</div>
<br>
<div class="d-flex flex-row justify-content-between mb-3">
<h4 class="card-title">Recently Played</h4>
<a href="/played" class="btn btn-link text-decoration-none align-self-end">See all <i class="bi bi-caret-right"></i></a>
</div>
<div class="row row-cols-2 row-cols-sm-3 row-cols-lg-4 row-cols-xl-6 g-4">
<?php
$sql = "SELECT allStar FROM games ORDER BY date LIMIT 6 ";
$q = $con->prepare(str_replace('allStar', 'count(*)', $sql));
$q->execute();
$numberOfGames = $q->fetchColumn();
$q = $con->prepare(str_replace('allStar', '*', $sql));
$q->execute();
if ($numberOfGames >= 1) {
while ($game = $q->fetch()) {
$playingCount = $game['players'];
?>
<div class="col">
<div class="card bg-dark border-start rounded shadow-sm" style="min-width: 140px; max-width: 220px; ">
<a href="place?id=<?php echo (int)htmlspecialchars($game["id"]); ?>" style="text-decoration: none; text-align: left; margin-bottom: 9px;">
<img src="<?php if (!empty($game["thumbnail"])) {echo htmlspecialchars($game["thumbnail"]);} else {echo "assets/placeholder.png";} ?>" class="card-img-top rounded-top" alt="<?php echo htmlspecialchars($game["name"]); ?>">
<div class="card-body">
<small class="card-title text-white" style="font-size: 1rem;"><?php echo htmlspecialchars($game["name"]); ?></small>
<br>
<small class="card-text text-muted"><?php echo (int)$playingCount; ?> playing</small> </div>
</a>
</div>
</div>
<?php
}
echo "</div>";
} else {
echo "</div> <h4 class='text-muted text-center'><i class='bi bi-egg-fried' style='font-size: 6rem;'></i><br> You haven't played any games, why not <a class='text-decoration-none text-muted' href='/games'>play</a> one.</h4>";} ?>
<?php $getitstarted->footer(); ?>
</main>
</body>
</html>