Initial Commit
This commit is contained in:
101
indexes/user/process/index_.php
Normal file
101
indexes/user/process/index_.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Online Fruit Store</title>
|
||||
<script src="./iframe.js"></script>
|
||||
<link rel="stylesheet" href="./show_item.css" type="text/css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<br><br><br><br><br><br><br>
|
||||
|
||||
<div id="grid">
|
||||
<?php
|
||||
include '../ConnectDB.php';
|
||||
session_start();
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$usertype = $_SESSION['user_type'];
|
||||
if($usertype == "seller"){
|
||||
$a = "seller_availability";
|
||||
$p = "seller_price";
|
||||
}
|
||||
else{
|
||||
$a = "buyer_availability";
|
||||
$p = "buyer_price";
|
||||
}
|
||||
|
||||
//check availability
|
||||
$sql_rownum="SELECT * FROM inventory WHERE $a='1'";
|
||||
$res = mysqli_query($conn, $sql_rownum);
|
||||
if (!$res) {
|
||||
die('Query failed: ' . mysqli_error($conn));
|
||||
}
|
||||
$row = mysqli_num_rows($res);
|
||||
|
||||
//read in and display
|
||||
for ($i = 0; $i < $row; $i++) {
|
||||
while ($goods = mysqli_fetch_array($res)){
|
||||
//if inventory == 0, hide it from buyer
|
||||
if($goods['quantities'] != 0 || $usertype == "seller"){
|
||||
echo '<div id="items">';
|
||||
if (!empty($goods['imgname'])) {
|
||||
$imagePath = "../../img/" . $goods['imgname'];
|
||||
if (file_exists($imagePath)) {
|
||||
echo '<img src="' . $imagePath . '" title="' . $goods['name'] . '" id="' . $goods['name'] . '" onmousedown="details(this)">';
|
||||
}
|
||||
} else {
|
||||
echo '<img src="data:image/jpeg;base64,' . base64_encode($goods['img']) . '" title="' . $goods['name'] . '" id="' . $goods['name'] . '" onmousedown="details(this)">';
|
||||
}
|
||||
echo '<h5 style="margin: 0%; margin-bottom: 3%; margin-top: 3%; font-size: 70%;" id="' . $goods['name'] . '" onclick="details(this)">' . $goods['name'] . '</h5>';
|
||||
echo '<p style="font-size: small; margin: 0%;" id="' . $goods['name'] . '" onclick="details(this)">' . $goods['simpledesc'] . '</p>';
|
||||
echo '<p style="font-size: small; margin: 0%; color: blue;" id="' . $goods['name'] . '" onclick="details(this)">¥' . $goods[$p] . '/kg</p>';
|
||||
echo '<img class="icon_1" src="../../icon/addcart.svg" title="add to cart" id="' . $goods['name'] . '" onclick="addcart(this)">';
|
||||
echo '<img class="icon_2" src="../../icon/checkout.svg" title="buy now" id="' . $goods['name'] . '" onclick="buynow(this)">';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<!--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>
|
||||
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>
|
||||
Reference in New Issue
Block a user