Initial commit
This commit is contained in:
115
indexes/manage/admin.php
Normal file
115
indexes/manage/admin.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Online Fruit Store</title>
|
||||
<link rel="shortcut icon" href="../../icon/favicon/favicon.ico" type="image/x-icon" />
|
||||
<link rel="icon" href="../../icon/favicon/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" href="../../index.css" type="text/css" />
|
||||
<script src="../../home.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="dynamic-background"></div>
|
||||
<table id="banner">
|
||||
<tr>
|
||||
<td width="3%"></td>
|
||||
<td style="text-align: right" width="6%">
|
||||
<img class="banner_img" src="../../icon/icon.svg" onmousedown="changetohome()">
|
||||
</td>
|
||||
<td width="70%">
|
||||
<p onmousedown="changetohome()">Online Fruit Store</p>
|
||||
</td>
|
||||
<td width="6%">
|
||||
<img title="Search" id="search_icon" class="banner_img" src="../../icon/search.svg" alt="Search"
|
||||
onclick="search()">
|
||||
</td>
|
||||
<td width="6%">
|
||||
<img title="Edit" class="banner_img" id="edit" src="../../icon/edit.svg" alt="Cart"
|
||||
onmousedown="edit()">
|
||||
</td>
|
||||
<td width="6%">
|
||||
<img title="User" class="banner_img" src="../../icon/user.svg" alt="User"
|
||||
onmousedown="makeIFrame('../../login/login.php', 'login', 'overlay')">
|
||||
</td>
|
||||
<td width="3%"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
// Start the session
|
||||
session_start();
|
||||
if(isset($_SESSION['user_type'])) {
|
||||
$type = $_SESSION['user_type'];
|
||||
}
|
||||
else{
|
||||
echo "<script type='text/javascript'>
|
||||
window.top.location.href = '../../index.html';
|
||||
</script>";
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
var existence = document.getElementById("customerpage");
|
||||
if (!existence) {
|
||||
// Create the iframe and add it to the overlay div
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.setAttribute("src", "./overview.php");
|
||||
iframe.id = "customerpage";
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
function changetohome(){
|
||||
window.top.location.href = '../../home.php';
|
||||
}
|
||||
|
||||
function edit(){
|
||||
if(document.getElementById("edit").title == "Edit"){
|
||||
document.getElementById("edit").src = "../../icon/discard.svg";
|
||||
iframe.setAttribute("src", "./edit.php");
|
||||
document.getElementById("edit").title = "Discard";
|
||||
}
|
||||
else{
|
||||
overview();
|
||||
}
|
||||
}
|
||||
|
||||
function overview(){
|
||||
document.getElementById("edit").src = "../../icon/edit.svg";
|
||||
iframe.setAttribute("src", "./overview.php");
|
||||
document.getElementById("edit").title = "Edit";
|
||||
}
|
||||
|
||||
function addfruit(){
|
||||
makeIFrame("./fruit_add.php", "login", "overlay");
|
||||
}
|
||||
|
||||
//function override
|
||||
function search(){
|
||||
var existence = document.getElementById("search");
|
||||
if(!existence){
|
||||
makeSearchFrame('../search/search.php', 'search', 'search_overlay');
|
||||
document.getElementById("search_icon").src="../../icon/del.svg";
|
||||
}
|
||||
else{
|
||||
document.getElementById("search_icon").src="../../icon/search.svg";
|
||||
closeSearchFrame();
|
||||
}
|
||||
}
|
||||
|
||||
function closeSearchFrame() {
|
||||
loginID = "search";
|
||||
overlayID = "search_overlay";
|
||||
var iframe = document.getElementById(loginID);
|
||||
if (iframe) {
|
||||
iframe.parentNode.removeChild(iframe);
|
||||
var overlay = document.getElementById(overlayID);
|
||||
if (overlay) {
|
||||
overlay.parentNode.removeChild(overlay);
|
||||
}
|
||||
}
|
||||
document.getElementById("search_icon").src="../../icon/search.svg";
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
76
indexes/manage/changeimg.php
Normal file
76
indexes/manage/changeimg.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<link rel="stylesheet" href="../../index.css" type="text/css" />
|
||||
<script src="../../home.js"></script>
|
||||
<html>
|
||||
<head>
|
||||
<title>Change img</title>
|
||||
<style>
|
||||
body{
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 99%;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
background-image: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Change img</h1>
|
||||
|
||||
<?php
|
||||
// Check if the form was submitted
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Include the database connection file
|
||||
include '../ConnectDB.php';
|
||||
|
||||
$name = $_GET['name'];
|
||||
// Read the uploaded image file
|
||||
$image = $_FILES["image"]["tmp_name"];
|
||||
$imageData = file_get_contents($image);
|
||||
|
||||
// Check if the uploaded file is an image
|
||||
$mime = mime_content_type($image);
|
||||
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif'];
|
||||
if (!in_array($mime, $allowedMimeTypes)) {
|
||||
die("Invalid file format. Only JPEG, PNG, and GIF images are allowed.");
|
||||
}
|
||||
|
||||
// Check if the file size is within limits
|
||||
$maxFileSize = 1024 * 1024; // 1 MB
|
||||
if ($_FILES["image"]["size"] > $maxFileSize) {
|
||||
die("File size exceeds the limit. Maximum allowed size is 1 MB.");
|
||||
}
|
||||
|
||||
// Create a connection to the database
|
||||
$conn = new mysqli($servername, $username, $password, $db);
|
||||
|
||||
// Check for connection errors
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Prepare the SQL statement to update the image
|
||||
$stmt = $conn->prepare("UPDATE inventory SET img = ? WHERE name = ?");
|
||||
$stmt->bind_param("ss", $imageData, $name);
|
||||
|
||||
// Execute the SQL statement
|
||||
if ($stmt->execute()) {
|
||||
echo "Image uploaded successfully.";
|
||||
} else {
|
||||
echo "Error uploading image.";
|
||||
}
|
||||
|
||||
// Close the statement
|
||||
$stmt->close();
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
<label for="img">Img:</label>
|
||||
<input type="file" name="image" accept="image/*" required>
|
||||
<br><br>
|
||||
<button type="submit">Change</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
169
indexes/manage/edit.php
Normal file
169
indexes/manage/edit.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<link rel="stylesheet" href="../../index.css" type="text/css" />
|
||||
<script src="../../home.js"></script>
|
||||
<style>
|
||||
body{
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
|
||||
// Start the session
|
||||
session_start();
|
||||
|
||||
// Check if the user is already logged in
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'admin') {
|
||||
|
||||
$sql = "SELECT * FROM inventory";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$row = mysqli_num_rows($result);
|
||||
|
||||
if ($row <= 0) {
|
||||
echo '<h3>Nothing Here</h3>';
|
||||
}
|
||||
|
||||
//buttons
|
||||
echo '<br><br><br><br><br><br><br><br>';
|
||||
echo '<div id="grid">';
|
||||
|
||||
echo '<table style="text-align: left;">';
|
||||
echo '<tr>';
|
||||
echo "<td><button id='addfruit' onclick='addfruit()'>ADD</button></td>";
|
||||
|
||||
echo "<td width='20px'></td>";
|
||||
|
||||
echo '<form action="update.php" method="POST">';
|
||||
echo "<td><button id='update' type='submit' style='text-align: center;'>SAVE</button></td>";
|
||||
echo '</tr>';
|
||||
|
||||
echo '</table>';
|
||||
|
||||
//modify area
|
||||
while ($row_data = mysqli_fetch_array($result)) {
|
||||
echo '<table id="items" style="text-align: center;">';
|
||||
echo '<tr>';
|
||||
echo '<th>Image </th>';
|
||||
echo '<td colspan="2">';
|
||||
echo '<img src="data:image/jpeg;base64,' . base64_encode($row_data['img']) . '" title="' . $row_data['name'] . '" id="' . $row_data['name'] . '" style="width:30%" onclick="changeimg(this)">';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th width="40%">Name </th>';
|
||||
echo '<td width="60%" colspan="2">';
|
||||
echo '<input name="data['.$row_data['name'].'][name]" value="'.$row_data['name'].'" style="width: 90%;">';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Short description </th>';
|
||||
echo '<td colspan="2">';
|
||||
echo '<textarea name="data['.$row_data['name'].'][simpledesc]">'.$row_data['simpledesc'].'</textarea>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Full description </th>';
|
||||
echo '<td style="overflow: auto;" colspan="2">';
|
||||
echo '<textarea name="data['.$row_data['name'].'][fulldesc]">'.$row_data['fulldesc'].'</textarea>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Inventory </th>';
|
||||
echo '<td width="max-content">';
|
||||
echo '<input name="data['.$row_data['name'].'][quantities]" value="'.$row_data['quantities'].'">';
|
||||
echo '</td>';
|
||||
echo '<td>kg</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Buyer price </th>';
|
||||
echo '<td>¥</td>';
|
||||
echo '<td width="max-content">';
|
||||
echo '<input name="data['.$row_data['name'].'][buyer_price]" id="buyer_price" value="'.$row_data['buyer_price'].'">';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Seller price </th>';
|
||||
echo '<td>¥</td>';
|
||||
echo '<td width="max-content">';
|
||||
echo '<input name="data['.$row_data['name'].'][seller_price]" id="seller_price" value="'.$row_data['seller_price'].'">';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>buyer availability </th>';
|
||||
echo '<td><input type="radio" name="data['.$row_data['name'].'][buyer_availability]" value="1" '.($row_data['buyer_availability'] == '1' ? 'checked' : '').'></td>';
|
||||
echo '<td><input type="radio" name="data['.$row_data['name'].'][buyer_availability]" value="0" '.($row_data['buyer_availability'] == '0' ? 'checked' : '').' ></td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<td></td>';
|
||||
echo '<td>available</td>';
|
||||
echo '<td>not available</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th>Seller availability </th>';
|
||||
echo '<td><input type="radio" name="data['.$row_data['name'].'][seller_availability]" value="1" '.($row_data['seller_availability'] == '1' ? 'checked' : '').' ></td>';
|
||||
echo '<td><input type="radio" name="data['.$row_data['name'].'][seller_availability]" value="0" '.($row_data['seller_availability'] == '0' ? 'checked' : '').' ></td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<td></td>';
|
||||
echo '<td>available</td>';
|
||||
echo '<td>not available</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<td colspan="3" id="' . $row_data['name'] . '" onclick="deletefruit(this)" style="cursor: hand; text-align: center; color: white; background-color: red; border-radius: 10px">DELETE</td>';
|
||||
echo '</tr>';
|
||||
echo '<input type="hidden" name="data['.$row_data['name'].'][id]" value="'.$row_data['name'].'">';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
else {
|
||||
echo "<script type='text/javascript'>
|
||||
alert('Only admin can visit!');
|
||||
</script>";
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = '../../index.html';
|
||||
</script>";
|
||||
}
|
||||
|
||||
echo '<dialog class="dialog">';
|
||||
echo'<form method="dialog">';
|
||||
echo'<p>Are you sure to delete this fruit?</p>';
|
||||
echo'<br>';
|
||||
echo'<button class="dialogbutton" type="submit" value="Yes">Yes</button>';
|
||||
echo'   ';
|
||||
echo'<button class="dialogbutton" id="cancel-button">No</button>';
|
||||
echo'</form>';
|
||||
echo'<br>';
|
||||
echo'</dialog>';
|
||||
|
||||
mysqli_close($conn);
|
||||
?>
|
||||
|
||||
<script>
|
||||
function addfruit(){
|
||||
makeIFrame("./fruit_add.php", "login", "overlay");
|
||||
}
|
||||
|
||||
function deletefruit(tag){
|
||||
var name = tag.id;
|
||||
var dialog = document.querySelector('dialog');
|
||||
dialog.showModal();
|
||||
dialog.addEventListener('close', function(event) {
|
||||
var targetButton = event.target.returnValue;
|
||||
if (targetButton === "Yes") {
|
||||
window.location.href = "fruit_del.php?name=" + name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function changeimg(tag) {
|
||||
var name = tag.id;
|
||||
makeIFrame("./changeimg.php?name=" + name, "login", "overlay");
|
||||
}
|
||||
|
||||
</script>
|
||||
131
indexes/manage/fruit_add.php
Normal file
131
indexes/manage/fruit_add.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<link rel="stylesheet" href="../../index.css" type="text/css" />
|
||||
<script src="../../home.js"></script>
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Fruit</title>
|
||||
<style>
|
||||
body {
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 99%;
|
||||
z-index: 1;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-image: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Add Fruit</h1>
|
||||
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Check if the form was submitted
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Include the database connection file
|
||||
include '../ConnectDB.php';
|
||||
|
||||
// Read the uploaded image file
|
||||
$image = $_FILES["image"]["tmp_name"];
|
||||
$imageData = addslashes(file_get_contents($image));
|
||||
|
||||
// Check if the uploaded file is an image
|
||||
$mime = mime_content_type($image);
|
||||
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif'];
|
||||
if (!in_array($mime, $allowedMimeTypes)) {
|
||||
die("Invalid file format. Only JPEG, PNG, and GIF images are allowed.");
|
||||
}
|
||||
|
||||
// Check if the file size is within limits
|
||||
$maxFileSize = 1024 * 1024; // 1 MB
|
||||
if ($_FILES["image"]["size"] > $maxFileSize) {
|
||||
die("File size exceeds the limit. Maximum allowed size is 1 MB.");
|
||||
}
|
||||
|
||||
// Sanitize user input
|
||||
$name = mysqli_real_escape_string($conn, $_POST["name"]);
|
||||
$simpledesc = mysqli_real_escape_string($conn, $_POST["simpledesc"]);
|
||||
$fulldesc = mysqli_real_escape_string($conn, $_POST["fulldesc"]);
|
||||
$quantities = mysqli_real_escape_string($conn, $_POST["quantities"]);
|
||||
$buyer_price = mysqli_real_escape_string($conn, $_POST["buyer_price"]);
|
||||
$seller_price = mysqli_real_escape_string($conn, $_POST["seller_price"]);
|
||||
$buyer_availability = mysqli_real_escape_string($conn, $_POST["buyer_availability"]);
|
||||
$seller_availability = mysqli_real_escape_string($conn, $_POST["seller_availability"]);
|
||||
|
||||
// Insert data into the database
|
||||
$sql_add_inventory = "INSERT INTO `inventory` (`name`, `img`, `simpledesc`, `fulldesc`, `quantities`, `buyer_price`, `seller_price`, `buyer_availability`, `seller_availability`) VALUES ('$name', '$imageData', '$simpledesc', '$fulldesc', '$quantities', '$buyer_price', '$seller_price', '$buyer_availability', '$seller_availability')";
|
||||
$sql_add_buyer = "ALTER TABLE `buyer` ADD `$name` INT NOT NULL DEFAULT '0'";
|
||||
$sql_add_seller = "ALTER TABLE `seller` ADD `$name` INT NOT NULL DEFAULT '0'";
|
||||
|
||||
// Execute the SQL statements
|
||||
$res_1 = mysqli_query($conn, $sql_add_inventory);
|
||||
$res_2 = mysqli_query($conn, $sql_add_buyer);
|
||||
$res_3 = mysqli_query($conn, $sql_add_seller);
|
||||
|
||||
// Check if any query failed
|
||||
if ($res_1 && $res_2 && $res_3) {
|
||||
echo "Inventory added successfully!";
|
||||
} else {
|
||||
echo "Error adding inventory. Please try again.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="POST" action="" enctype="multipart/form-data" onsubmit="return checkprice()">
|
||||
<table style="text-align: right;">
|
||||
<tr>
|
||||
<td><label for="name">Name:</label></td>
|
||||
<td colspan="3"><input type="text" id="name" name="name" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="img">Img:</label></td>
|
||||
<td width="0%"><input type="file" name="image" accept="image/*" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="simpledesc">Simple Description:</label></td>
|
||||
<td colspan="3"><textarea id="simpledesc" name="simpledesc" required></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="fulldesc">Full Description:</label></td>
|
||||
<td colspan="3"><textarea id="fulldesc" name="fulldesc" required></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="quantities">Quantities (kg):</label></td>
|
||||
<td colspan="3"><input type="number" id="quantities" name="quantities" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="buyer_price">Buyer Price:</label></td>
|
||||
<td colspan="3"><input type="number" id="buyer_price" name="buyer_price" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="seller_price">Seller Price:</label></td>
|
||||
<td colspan="3"><input type="number" id="seller_price" name="seller_price" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="buyer_availability">Buyer Availability (available: 1, not available: 0):</label></td>
|
||||
<td colspan="3"><input type="number" id="buyer_availability" name="buyer_availability" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="seller_availability">Seller Availability (available: 1, not available: 0):</label></td>
|
||||
<td colspan="3"><input type="number" id="seller_availability" name="seller_availability" required></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><button type="submit">Add Inventory</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function checkprice() {
|
||||
var buyPrice = parseInt(document.getElementById("buyer_price").value);
|
||||
var sellPrice = parseInt(document.getElementById("seller_price").value);
|
||||
if (buyPrice < sellPrice) {
|
||||
alert("Buyer price cannot be lower than seller price!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
<html>
|
||||
39
indexes/manage/fruit_del.php
Normal file
39
indexes/manage/fruit_del.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
include '../ConnectDB.php';
|
||||
|
||||
if(isset($_GET["name"])) {
|
||||
$name = $_GET["name"];
|
||||
|
||||
// Delete from the inventory table
|
||||
$sql_clear_inventory = "DELETE FROM inventory WHERE name='$name'";
|
||||
$res_1 = mysqli_query($conn, $sql_clear_inventory);
|
||||
if(!$res_1){
|
||||
echo "<br><br><br><br><br><br><br><br>";
|
||||
echo "Error deleting from inventory: " . mysqli_error($conn);
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop the column from the buyer table
|
||||
$sql_clear_buyer = "ALTER TABLE buyer DROP COLUMN `$name`";
|
||||
$res_2 = mysqli_query($conn, $sql_clear_buyer);
|
||||
if(!$res_2){
|
||||
echo "<br><br><br><br><br><br><br><br>";
|
||||
echo "Error dropping column from buyer table: " . mysqli_error($conn);
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop the column from the seller table
|
||||
$sql_clear_seller = "ALTER TABLE seller DROP COLUMN `$name`";
|
||||
$res_3 = mysqli_query($conn, $sql_clear_seller);
|
||||
if(!$res_3){
|
||||
echo "<br><br><br><br><br><br><br><br>";
|
||||
echo "Error dropping column from seller table: " . mysqli_error($conn);
|
||||
return;
|
||||
}
|
||||
|
||||
echo "<script type='text/javascript'>
|
||||
alert('Successfully deleted!');
|
||||
window.location.href = './edit.php';
|
||||
</script>";
|
||||
}
|
||||
?>
|
||||
17
indexes/manage/interfaces/instruct.css
Normal file
17
indexes/manage/interfaces/instruct.css
Normal file
@@ -0,0 +1,17 @@
|
||||
#area{
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
width: 300px;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
user-select: none;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
img{
|
||||
width: 45%;
|
||||
height: 45%;
|
||||
margin: none;
|
||||
}
|
||||
16
indexes/manage/interfaces/success.php
Normal file
16
indexes/manage/interfaces/success.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Success</title>
|
||||
<link rel="stylesheet" href="./instruct.css" type="text/css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="area">
|
||||
<img src="../../../icon/check.svg">
|
||||
<h1>Success</h1>
|
||||
<script type='text/javascript'>
|
||||
setTimeout(function() {window.top.location.href = '../admin.php';}, 600);
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
135
indexes/manage/overview.php
Normal file
135
indexes/manage/overview.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<link rel="stylesheet" href="../../index.css" type="text/css" />
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
textarea{
|
||||
background-color: #00000000;
|
||||
border: none;
|
||||
border-radius: 12px;
|
||||
outline: none;
|
||||
font-size: 75%;
|
||||
width: 100%;
|
||||
height: max-content;
|
||||
}
|
||||
textarea:focus{
|
||||
border: none;
|
||||
}
|
||||
body{
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
|
||||
// Start the session
|
||||
session_start();
|
||||
|
||||
// Check if the user is already logged in
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'admin') {
|
||||
|
||||
echo '<br><br><br><br><br><br><br>';
|
||||
|
||||
//check cashflow
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||
$sql_sell_out = "SELECT details FROM buyer_receipt WHERE name='sell_out'";
|
||||
$result = mysqli_query($conn, $sql_sell_out);
|
||||
$sell_out = mysqli_fetch_array($result);
|
||||
|
||||
$sql_buy_in = "SELECT details FROM seller_receipt WHERE name='buy_in'";
|
||||
$result = mysqli_query($conn, $sql_buy_in);
|
||||
$buy_in = mysqli_fetch_array($result);
|
||||
$profit = $sell_out['details'] - $buy_in['details'];
|
||||
|
||||
echo "<h2 style='text-align: center; color: white;'>Cash Flow: ¥".$profit."</h2>";
|
||||
|
||||
$sql = "SELECT * FROM inventory";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
$row = mysqli_num_rows($result);
|
||||
if($row <= 0){
|
||||
echo '<h2>Nothing Here</h2>';
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div id="grid">';
|
||||
|
||||
for ($i = 0; $i < $row; $i++) {
|
||||
//get number of columns
|
||||
$fields = mysqli_num_fields($result);
|
||||
//Get each row data and display
|
||||
while ($row_data = mysqli_fetch_array($result)){
|
||||
echo '<table id="items" style="text-align: left;">';
|
||||
echo '<tr>';
|
||||
echo '<th>Image </th>';
|
||||
echo '<td colspan="2">
|
||||
<img src="data:image/jpeg;base64,' . base64_encode($row_data['img']) . '" title="' . $row_data['imgname'] . '" id="' . $row_data['name'] . '" onclick="details(this)"
|
||||
style="width:30%"></td>';
|
||||
echo '</tr>';
|
||||
echo "<tr>";
|
||||
echo "<th width='40%'>Name </th>";
|
||||
echo "<td width='60%' colspan='2'>".$row_data['name']."</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th>Short description </th>";
|
||||
echo "<td colspan='2'>".$row_data['simpledesc']."</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th width='40%'>Full description </th>";
|
||||
echo "<td width='60%' style='overflox: auto;' colspan='2'><textarea readonly>"
|
||||
.$row_data['fulldesc']."</textarea></td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th width='40%'>Inventory </th>";
|
||||
echo "<td windth='max-content'>".$row_data['quantities']." kg</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th width='40%'>Buyer price </th>";
|
||||
echo "<td windth='max-content'>¥ ".$row_data['buyer_price']."</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th>Seller price </th>";
|
||||
echo "<td windth='max-content'>¥ ".$row_data['seller_price']."</td>";
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th>buyer availability </th>";
|
||||
if($row_data['buyer_availability'] == '1'){
|
||||
echo "<td>available</td>";
|
||||
}
|
||||
else{
|
||||
echo "<td>not available</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
echo "<th>Seller availability </th>";
|
||||
if($row_data['seller_availability'] == '1'){
|
||||
echo "<td>available</td>";
|
||||
}
|
||||
else{
|
||||
echo "<td>not available</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
else{
|
||||
echo "<script type='text/javascript'>
|
||||
alert('Only admin can visit!');
|
||||
</script>";
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = '../../index.html';
|
||||
</script>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
63
indexes/manage/update.php
Normal file
63
indexes/manage/update.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
|
||||
// Check if the form is submitted
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
// Get the submitted form data
|
||||
$formData = $_POST['data'];
|
||||
|
||||
// Process each item's form data
|
||||
foreach ($formData as $itemName => $itemData) {
|
||||
$id = $itemData['id'];
|
||||
$name = $itemData['name'];
|
||||
$simpledesc = $itemData['simpledesc'];
|
||||
$fulldesc = $itemData['fulldesc'];
|
||||
$quantities = $itemData['quantities'];
|
||||
$buyer_price = $itemData['buyer_price'];
|
||||
$seller_price = $itemData['seller_price'];
|
||||
$buyer_availability = $itemData['buyer_availability'];
|
||||
$seller_availability = $itemData['seller_availability'];
|
||||
|
||||
if($buyer_price < $seller_price){
|
||||
echo "<br><br><br><br><br><br>";
|
||||
echo "<h1>The buyer price of $id cannot be lower than its seller price!</h1>";
|
||||
echo "<script type='text/javascript'>
|
||||
setTimeout(function() {window.location.href = './edit.php';}, 1000);
|
||||
</script>";
|
||||
exit();
|
||||
}
|
||||
|
||||
// Prepare and execute the update query
|
||||
$stmt = mysqli_prepare($conn, "UPDATE inventory SET name=?, simpledesc=?, fulldesc=?, quantities=?, buyer_price=?, seller_price=?, buyer_availability=?, seller_availability=? WHERE name=?");
|
||||
mysqli_stmt_bind_param($stmt, "sssssssss", $name, $simpledesc, $fulldesc, $quantities, $buyer_price, $seller_price, $buyer_availability, $seller_availability, $id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$sql_buyer_name = "ALTER TABLE `buyer` CHANGE `$id` `$name` INT(11) NOT NULL DEFAULT '0'";
|
||||
$res_1 = mysqli_query($conn, $sql_buyer_name);
|
||||
|
||||
$sql_seller_name = "ALTER TABLE `seller` CHANGE `$id` `$name` INT(11) NOT NULL DEFAULT '0'";
|
||||
$res_2 = mysqli_query($conn, $sql_seller_name);
|
||||
|
||||
// Check if the update was successful
|
||||
if (mysqli_stmt_affected_rows($stmt) > 0 && $res_1 && $res_2) {
|
||||
//echo "Data updated successfully.";
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = './interfaces/success.php';
|
||||
</script>";
|
||||
} else {
|
||||
if(mysqli_stmt_error($stmt) || !$res_1 || !$res_2){
|
||||
echo "<script type='text/javascript'>
|
||||
alert('Failed to update data.');
|
||||
window.location.href = './edit.php';
|
||||
</script>";
|
||||
}
|
||||
}
|
||||
echo "<script type='text/javascript'>
|
||||
window.location.href = './interfaces/success.php';
|
||||
</script>";
|
||||
|
||||
// Close the statement
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user