35512-vm/add-asset.php
Flatlogic Bot 53eb27812c v1.1
2025-11-05 22:08:13 +00:00

162 lines
6.6 KiB
PHP

<?php
require_once 'auth-check.php';
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$asset_tag = $_POST['asset_tag'] ?? '';
$status = $_POST['status'] ?? 'In Service';
$location = $_POST['location'] ?? '';
$manufacturer = $_POST['manufacturer'] ?? '';
$model = $_POST['model'] ?? '';
$purchase_date = $_POST['purchase_date'] ?? '';
if (empty($name) || empty($asset_tag) || empty($purchase_date)) {
$error_message = 'Please fill in all required fields: Name, Asset Tag, and Purchase Date.';
} else {
try {
$pdo = db();
$sql = "INSERT INTO assets (name, asset_tag, status, location, manufacturer, model, purchase_date) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $asset_tag, $status, $location, $manufacturer, $model, $purchase_date]);
header("Location: index.php?success=asset_added");
exit;
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Asset - IC-Inventory</title>
<meta name="description" content="Add a new asset to the inventory.">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://unpkg.com/feather-icons"></script>
</head>
<body>
<div class="wrapper">
<nav id="sidebar" class="d-flex flex-column flex-shrink-0 p-3">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-decoration-none">
<span class="fs-4">IC-Inventory</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="index.php" class="nav-link" aria-current="page">
<i data-feather="home" class="me-2"></i>
Dashboard
</a>
</li>
<li>
<a href="index.php" class="nav-link active">
<i data-feather="box" class="me-2"></i>
Assets
</a>
</li>
<?php if ($_SESSION['user_role'] === 'Admin'): ?>
<li>
<a href="users.php" class="nav-link">
<i data-feather="users" class="me-2"></i>
Users
</a>
</li>
<?php endif; ?>
<li>
<a href="#" class="nav-link">
<i data-feather="settings" class="me-2"></i>
Settings
</a>
</li>
</ul>
<hr>
<div>
<span class="d-flex align-items-center text-decoration-none"><strong><?php echo htmlspecialchars($_SESSION['user_name']); ?></strong></span>
<a href="logout.php" class="d-flex align-items-center text-decoration-none">
<i data-feather="log-out" class="me-2"></i>
<strong>Logout</strong>
</a>
</div>
</nav>
<main id="content">
<div class="header">
<h1>Add New Asset</h1>
<div class="theme-switcher" id="theme-switcher">
<i data-feather="moon"></i>
</div>
</div>
<div class="surface p-4">
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="add-asset.php" method="post">
<div class="row">
<div class="col-md-6 mb-3">
<label for="name" class="form-label">Asset Name*</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="col-md-6 mb-3">
<label for="asset_tag" class="form-label">Asset Tag*</label>
<input type="text" class="form-control" id="asset_tag" name="asset_tag" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option>In Service</option>
<option>Under Repair</option>
<option>Retired</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="location" class="form-label">Location</label>
<input type="text" class="form-control" id="location" name="location">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="manufacturer" class="form-label">Manufacturer</label>
<input type="text" class="form-control" id="manufacturer" name="manufacturer">
</div>
<div class="col-md-6 mb-3">
<label for="model" class="form-label">Model</label>
<input type="text" class="form-control" id="model" name="model">
</div>
</div>
<div class="mb-3">
<label for="purchase_date" class="form-label">Purchase Date*</label>
<input type="date" class="form-control" id="purchase_date" name="purchase_date" required>
</div>
<button type="submit" class="btn btn-primary">Add Asset</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
feather.replace();
</script>
</body>
</html>