grublox/item.php

73 lines
1.8 KiB
PHP

<?php
session_start();
require_once 'core/classes.php';
require_once 'core/classes/user.php';
$user = new User($con, $_SESSION['user']);
if(!isset($_GET["id"])) {
header("Location: ?id=".$_SESSION['user']);
} else {
$id = (int)$_GET["id"];
}
function getMoney($money) {
if ($money < 1000000) {
// Anything less than a million
return number_format($money);
} else if ($money < 1000000000) {
// Anything less than a billion
return number_format($money / 1000000, 1) . 'M';
} else {
// At least a billion
return number_format($money / 1000000000, 1) . 'B';
}
}
$q = $con->prepare("SELECT * FROM catalog WHERE id = :id");
$q->bindParam(':id',$id,PDO::PARAM_INT);
$q->execute();
$item = $q->fetch();
if(!$item) {
header('location: /error?err=404');
exit;
}
?>
<!DOCTYPE html>
<html data-bs-theme="dark">
<head>
<?php
$getitstarted = new PartyStarter;
$getitstarted->header();
?>
</head>
<title><?php echo htmlspecialchars($item["name"]); ?> | <?php echo $sitename; ?></title>
<body>
<main class="container d-flex justify-content-center">
<h1 class="mt-3"><?php echo htmlspecialchars($item["name"]); ?></h1>
<div class="d-flex flex-row mb-3">
<img src="<?php if (!empty($item["thumbnail"])) {echo htmlspecialchars($item["thumbnail"]);} else {echo "assets/placeholder.png";} ?>">
<div>
sdasdas
</div>
<div class="border border-2 bg-light-subtle" style="width: 13rem; height: 8.4rem;">
<div class="mx-auto text-center p-2">
<p>Price: <span class="text-success"><span class="grufont fs-5">@ </span><?php echo getMoney(htmlspecialchars($item["price"]))." (".htmlspecialchars($item["price"]).")"; ?></span></p>
<button class="btn btn-success" style="width: 10rem;">Buy with <span class="grufont fs-5">@</span></button>
<p>(0 sold)</p>
</div>
</div>
</div>
</div>
</main>
</body>
</html>