grublox/catalog.php

161 lines
6.6 KiB
PHP

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<?php
require_once 'core/classes.php';
require_once 'core/classes/user.php';
if (isset($_SESSION['user'])) {
$user = new User($con, $_SESSION['user']);
}
$possibleFilters = [
"hats",
"shirts",
"tshirts",
"pants",
"gears",
"packages",
"heads",
"torso",
"leftarm",
"rightarm",
"leftleg",
"rightleg"
];
if(isset($_GET["filter"])) {
$page = $_GET["filter"];
if(!in_array($page,$possibleFilters)) {
header('location: /error?err=404');
exit;
}
} else {
$page = null;
}
$getitstarted = new PartyStarter;
$getitstarted->header();
?> </head>
<title><?php echo $pagename; ?> | <?php echo $sitename; ?></title>
<body>
<main class="container" style="width: 100%;">
<br>
<br>
<form role="search" class="float-end" style="width: 45%;">
<div class="input-group mb-3 shadow-sm">
<input class="form-control rounded-end-0" type="search" placeholder="Search an item..." name="search" aria-label="Search">
<button id="search" type="submit" class="btn btn-primary rounded-start-0">Search</button>
</div>
</form>
<h2>Catalog</h2>
<hr>
<ul class="list-group float-start shadow-sm" style="width: 12rem;">
<li class="list-group-item text-bg-secondary" aria-current="true">
<small>Browse by</small>
<br>
<h4>Category</h4>
</li>
<a href="/catalog" class="list-group-item<?php if($page == null) { ?> active<?php } ?>" aria-current="true">All categories</a>
<a href="?filter=hats" class="list-group-item<?php if($page == "hats") { ?> active<?php } ?>">Hats</a>
<a href="?filter=shirts" class="list-group-item<?php if($page == "shirts") { ?> active<?php } ?>">Shirts</a>
<a href="?filter=tshirts" class="list-group-item<?php if($page == "tshirts") { ?> active<?php } ?>">T-shirts</a>
<a href="?filter=pants" class="list-group-item<?php if($page == "pants") { ?> active<?php } ?>">Pants</a>
<a href="?filter=gears" class="list-group-item<?php if($page == "gears") { ?> active<?php } ?>">Gears</a>
<a href="?filter=packages" class="list-group-item<?php if($page == "packages") { ?> active<?php } ?>">Packages</a>
<button class="list-group-item text-start<?php if($page == "heads" || $page == "torso" || $page == "leftarm" || $page == "rightarm" || $page == "leftleg" || $page == "rightleg") { ?> active<?php } ?>" type="button" data-bs-toggle="dropdown" aria-expanded="false">Body parts</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item<?php if($page == "heads") { ?> active<?php } ?>" href="?filter=heads">Heads</a>
</li>
<li>
<a class="dropdown-item<?php if($page == "torso") { ?> active<?php } ?>" href="?filter=torso">Torso</a>
</li>
<li>
<a class="dropdown-item<?php if($page == "leftarm") { ?> active<?php } ?>" href="?filter=leftarm">Left arm</a>
</li>
<li>
<a class="dropdown-item<?php if($page == "rightarm") { ?> active<?php } ?>" href="?filter=rightarm">Right arm</a>
</li>
<li>
<a class="dropdown-item<?php if($page == "leftleg") { ?> active<?php } ?>" href="?filter=leftleg">Left leg</a>
</li>
<li>
<a class="dropdown-item<?php if($page == "rightleg") { ?> active<?php } ?>" href="?filter=rightleg">Right leg</a>
</li>
</ul>
<li class="list-group-item">
<h5>Legend</h5>
<span class="badge bg-success" >Limited</span>
<br>
<p class="text-white">Limited Items </p>
<p>Owners of these discontinued items can re-sell them to other users at any price.</p>
<div class="pt-2"></div>
<span class="badge bg-success">Limited <span class="badge bg-warning text-dark">U</span>
</span>
<br>
<p class="text-white">Limited Unique Items</p>
<p>A limited supply originally sold by <?php echo $sitename; ?>. Each unit is labeled with a serial number. Once sold out, owners can re-sell them to other users. </p>
</li>
</ul>
<div class="row row-cols-xl-6 row-cols-lg-4 row-cols-md-3 row-cols-sm-2 g-4" style="margin-left: 200px; margin-top: 1px;">
<?php
$sql = "SELECT allStar FROM catalog";
$q = $con->prepare(str_replace('allStar', 'count(*)', $sql));
$q->execute();
$numberOfItems = $q->fetchColumn();
$sql = "SELECT allStar FROM catalog LIMIT :limit OFFSET :offset";
$page = $_GET['p'] ?? 0;
$limit = 20;
$lpage = $limit*$page;
$q = $con->prepare(str_replace('allStar', '*', $sql));
$q->bindParam(':limit', $limit, PDO::PARAM_INT);
$q->bindParam(':offset', $lpage, PDO::PARAM_INT);
$q->execute();
if ($numberOfItems >= 1) {
foreach ($q->fetchAll() as $item) {
$query = $con->prepare('SELECT COUNT(id) FROM users WHERE id=:id');
$query->bindParam(':id', $_SESSION['user'], PDO::PARAM_INT);
$query->execute();
$userExists = $query->fetchColumn();
if($userExists <= 1) {
$creator = [
"id" => $_SESSION['user'],
"username" => $item["name"]
];
} else {
$creator = [
"id" => 0,
"username" => "[ unknown user ]"
];
}
?>
<div class="position-relative col">
<div class="card shadow-sm h-100 d-inline-block">
<a href="item.php?id=<?php echo (int)htmlspecialchars($item["id"]); ?>">
<div class="d-inline-block card-img-top border border-1">
<img src="<?php if (!empty($item["thumbnail"])) {echo htmlspecialchars($item["thumbnail"]);} else {echo "assets/placeholder.png";} ?>" height=150 width=150></a>
<p class="me-1 mt-1 position-absolute top-0 end-0"><?php if($item['limited'] == 1) { echo '<span class="badge bg-success">Limited</span>'; }; ?></p>
</div>
<span class="fs-6 mt-2 ms-2 opacity-75 position-absolute top-50 start-0 translate-middle-y bg-success badge">$<?php echo (int)htmlspecialchars($item["price"]); ?></span>
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($item["name"]); ?></h5>
<p class="card-text">
By <a href="user.php?id=<?php echo (int)htmlspecialchars($creator["id"]); ?>" class="btn-link"><?php echo htmlspecialchars($creator["username"]); ?></a>
</p>
</div>
</div>
</div>
<?php
} } else {
echo "</div> <h4 class='text-muted text-center'><i class='bi bi-egg-fried' style='font-size: 6rem;'></i><br> Looks like there are no items in the catalog yet...</h4>";} ?>
<br>
</div>
</main>
</body>
</html>