RoamEase/indexes/user/process/item_details.php
2025-06-06 17:31:03 +08:00

166 lines
6.0 KiB
PHP

<html>
<head>
<script src="./iframe.js"></script>
<link rel="stylesheet" href="./show_item.css" type="text/css" />
<style>
#area{
position: absolute;
text-align: center;
width: 95%;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
user-select: none;
font-family: Arial, Helvetica, sans-serif;
}
img{
border-radius: 12px;
margin-top: 2.5%;
width: 65%;
height: 65%;
overflow:hidden;
background-position: center;
background-repeat: no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
background-size:cover;
transition: 0.5s;
}
img:hover{
border-radius: 12px;
margin-top: 2.5%;
width: 70%;
height: 70%;
overflow:hidden;
background-position: center;
background-repeat: no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
background-size:cover;
transition: 0.5s;
}
pre{
white-space:pre-wrap;
user-select: text;
text-align: left;
}
.checkicon{
width: 6%;
height: 6%;
}
.checkicon:hover{
width: 8%;
height: 8%;
}
</style>
</head>
<body>
<!--dialog for adding fruit-->
<dialog class="dialog">
<form method="dialog">
Add <input type="number" id="amount" value="1" placeholder="how many"> kg
<br><br>
<button class="dialogbutton" type="submit" value="add cart">Check</button>
<button class="dialogbutton" id="cancel-button">Cancel</button>
</form>
</dialog>
<script>
// get the value of the 'myParam' query parameter from the URL
var myParamValue = new URLSearchParams(window.location.search).get('myParam');
</script>
<?php
include "../ConnectDB.php";
session_start();
$usertype = mysqli_real_escape_string($conn, $_SESSION['user_type']);
if ($usertype == "seller") {
$p = "seller_price";
} else {
$p = "buyer_price";
}
if (isset($_GET['myParam']) && !empty($_GET['myParam'])) {
$sql = "SELECT * FROM inventory WHERE name = '" . $_GET['myParam'] . "'";
$res = mysqli_query($conn, $sql);
$goods = mysqli_fetch_assoc($res);
if (!empty($goods['imgname'])) {
$imagePath = "../../img/" . $goods['imgname'];
if (file_exists($imagePath)) {
$image = $imagePath;
}
} else {
$image = 'data:image/jpeg;base64,' . base64_encode($goods['img']);
}
} else {
// Handle the case when myParam is not set or is empty
$image = "../../img/default_image_path.jpg";
}
?>
<div id="area">
<table>
<tr>
<td width="50%" style="text-align: right;">
<img src="<?php echo $image; ?>" title="<?php echo $goods['name']; ?>">
</td>
<td width="50%">
<h1><?php echo $goods['name']; ?></h1>
<h3><?php echo $goods['simpledesc']; ?></h3>
<h4 style="color: blue;">Inventory: <?php echo $goods['quantities']; ?>kg &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Price: ¥<?php echo $goods[$p]; ?>/kg</h4>
<?php
if ($usertype == "seller" || $usertype == "buyer") {
echo "<img class='checkicon' src='../../icon/addcart.svg' title='add to cart' id='". $goods['name']."' onclick='addcart(this)'>";
echo "<img class='checkicon' src='../../icon/checkout.svg' title='buy now' id='".$goods['name']."' onclick='buynow(this)'>";
}
?>
</td>
</tr>
</table>
<pre>
<?php echo $goods['fulldesc']; ?>
</pre>
<br><br>
</div>
<script>
function addcart(tag){
var name = tag.id;
var dialog = document.querySelector('dialog');
dialog.showModal();
dialog.addEventListener('close', function(event) {
var amount = document.getElementById("amount").value;
var targetButton = event.target.returnValue;
if (targetButton === "add cart" && amount !== "") {
window.location.href = "addcart.php?name=" + name + "&quantity=" + amount;
}
});
}
function buynow(tag){
var name = tag.id;
var dialog = document.querySelector('dialog');
dialog.showModal();
dialog.addEventListener('close', function(event) {
var amount = document.getElementById("amount").value;
var targetButton = event.target.returnValue;
if (targetButton === "add cart" && amount !== "") {
window.location.href = "checkup_now.php?name=" + name + "&quantity=" + amount;
}
});
}
</script>
</body>
</html>