Initial commit
This commit is contained in:
113
indexes/process/checkup_now.php
Normal file
113
indexes/process/checkup_now.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<link rel="stylesheet" href="./cart.css" type="text/css" />
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
|
||||
// Start the session
|
||||
session_start();
|
||||
|
||||
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||
$usertype = mysqli_real_escape_string($conn, $_SESSION['user_type']);
|
||||
|
||||
if ($usertype == "seller") {
|
||||
$a = "seller_availability";
|
||||
$m = "seller_price";
|
||||
}
|
||||
else {
|
||||
$a = "buyer_availability";
|
||||
$m = "buyer_price";
|
||||
}
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET["name"], $_GET["quantity"])) {
|
||||
|
||||
echo '<br><br><br><br>';
|
||||
|
||||
//check availability
|
||||
if($_GET["quantity"] > 100 && $usertype == "seller"){
|
||||
echo "<script type='text/javascript'>
|
||||
alert('You can only sell 100kg/type fruit one time!');
|
||||
window.top.location.href = '../../home.php';
|
||||
</script>";
|
||||
exit();
|
||||
}
|
||||
|
||||
$name = mysqli_real_escape_string($conn, $_GET["name"]);
|
||||
$check_sql = "SELECT $a FROM inventory WHERE name = '$name'";
|
||||
$res = mysqli_query($conn, $check_sql);
|
||||
$avail = mysqli_fetch_array($res);
|
||||
if ($avail[$a] == 0 && $avail[$a] !== null) {
|
||||
$errorMessage = $_GET["name"] . " is currently unavailable";
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = './interfaces/failed.php?why=" . urlencode($errorMessage) . "';
|
||||
</script>";
|
||||
exit();
|
||||
}
|
||||
|
||||
//get image
|
||||
$sql_img = "SELECT img FROM inventory WHERE name='$name'";
|
||||
$picaddress = mysqli_query($conn, $sql_img);
|
||||
$img = mysqli_fetch_array($picaddress);
|
||||
|
||||
//get unit price
|
||||
$sql_price = "SELECT $m FROM inventory WHERE name='$name'";
|
||||
$res = mysqli_query($conn, $sql_price);
|
||||
$price = mysqli_fetch_array($res);
|
||||
//get unit total price
|
||||
$fruitprice = $price[$m] * $_GET["quantity"];
|
||||
|
||||
//display
|
||||
echo '<table id="items" style="align-items: center; width: 98.5%;">';
|
||||
echo '<tr>';
|
||||
echo '<th width="30%">Image</th>';
|
||||
echo '<th width="30%">Fruit</th>';
|
||||
echo '<th width="20%">Order</th>';
|
||||
echo '<th width="20%">Unit-price</th>';
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
|
||||
echo '<table id="items" style="align-items: center; width: 98.5%;">';
|
||||
echo '<tr>';
|
||||
echo '<td width="30%">';
|
||||
echo '<img src="data:image/jpeg;base64,' . base64_encode($img['img']) . '" title="' . $name . '" id="' . $name . '">';
|
||||
echo '</td>';
|
||||
echo '<td width="30%">';
|
||||
echo '<h4 style="margin: 0%;">' . $name . '</h4>';
|
||||
echo '</td>';
|
||||
echo '<td width="20%">';
|
||||
echo '<p style="margin: 0%;" id="' . $name . '">' . $_GET["quantity"] . ' kg</p>';
|
||||
echo '</td>';
|
||||
echo '<td width="20%">';
|
||||
echo '<p style="margin: 0%;">¥'.$price[$m].'/kg</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
|
||||
echo '<br>';
|
||||
|
||||
echo '<table style="text-align: center;" width="100%">';
|
||||
echo '<tr>';
|
||||
echo '<td><h1>Total Price: ¥ '.$fruitprice.'</h1></td>';
|
||||
echo '</tr>';
|
||||
echo '<td>';
|
||||
|
||||
$urlParams = "name=" . urlencode($_GET["name"]) . "&amount=" . urlencode($_GET["quantity"]); // URL-encode the parameters
|
||||
echo '<form action="./ordernow.php?' . $urlParams . '" method="POST">';
|
||||
if ($usertype == 'buyer') {
|
||||
echo '<button type="submit">Order</button>';
|
||||
}
|
||||
else {
|
||||
echo '<button style="align-items: center; width: 98.5%;" type="submit">Sell</button>';
|
||||
}
|
||||
echo '</form>';
|
||||
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
else{
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = './interfaces/failed.php?why=Unknown Error Occurred';
|
||||
</script>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user