119 lines
4.7 KiB
PHP
119 lines
4.7 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
start_secure_session();
|
|
require_login();
|
|
|
|
$message = '';
|
|
$item = null;
|
|
|
|
if (isset($_GET['id'])) {
|
|
$item = get_inventory_item_by_id($_GET['id']);
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = $_POST['id'];
|
|
$item_name = $_POST['item_name'];
|
|
$quantity = $_POST['quantity'];
|
|
$price = $_POST['price'];
|
|
|
|
if (update_inventory_item($id, $item_name, $quantity, $price)) {
|
|
header("Location: inventory.php?message=Item+updated+successfully");
|
|
exit;
|
|
} else {
|
|
$message = "Failed to update item.";
|
|
}
|
|
}
|
|
|
|
if (!$item) {
|
|
header("Location: inventory.php?error=Item+not+found");
|
|
exit;
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Inventory Item - Flatlogic</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
|
|
</head>
|
|
<body class="d-flex">
|
|
|
|
<div class="sidebar d-flex flex-column p-3">
|
|
<a href="index.php" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
|
|
<i class="bi bi-buildings me-2"></i>
|
|
<span class="fs-4">Flatlogic</span>
|
|
</a>
|
|
<hr>
|
|
<ul class="nav nav-pills flex-column mb-auto">
|
|
<li class="nav-item">
|
|
<a href="index.php" class="nav-link text-white" aria-current="page">
|
|
<i class="bi bi-speedometer2 me-2"></i>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="reports.php" class="nav-link text-white">
|
|
<i class="bi bi-bar-chart-line me-2"></i>
|
|
Reports
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="inventory.php" class="nav-link text-white active">
|
|
<i class="bi bi-box-seam me-2"></i>
|
|
Inventory
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
<hr>
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<main class="main-content flex-grow-1 p-4">
|
|
<header class="header">
|
|
<h1>Edit Inventory Item</h1>
|
|
<a href="inventory.php" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-2"></i> Back to Inventory</a>
|
|
</header>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-danger"><?php echo $message; ?></div>
|
|
<?php endif; ?>
|
|
<form action="edit_inventory_item.php?id=<?php echo $item['id']; ?>" method="POST">
|
|
<input type="hidden" name="id" value="<?php echo $item['id']; ?>">
|
|
<div class="mb-3">
|
|
<label for="item_name" class="form-label">Item Name</label>
|
|
<input type="text" class="form-control" id="item_name" name="item_name" value="<?php echo htmlspecialchars($item['item_name']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="quantity" class="form-label">Quantity</label>
|
|
<input type="number" class="form-control" id="quantity" name="quantity" value="<?php echo htmlspecialchars($item['quantity']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="price" class="form-label">Price</label>
|
|
<input type="text" class="form-control" id="price" name="price" value="<?php echo htmlspecialchars($item['price']); ?>" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|