186 lines
8.1 KiB
PHP
186 lines
8.1 KiB
PHP
<?php
|
|
require_once 'auth-check.php';
|
|
require_once 'db/config.php';
|
|
|
|
// Function to execute query and return results
|
|
function get_assets() {
|
|
try {
|
|
$pdo = db();
|
|
// Check if table exists, if not, run migration
|
|
$result = $pdo->query("SHOW TABLES LIKE 'assets'");
|
|
if ($result->rowCount() == 0) {
|
|
$sql = file_get_contents('db/migrations/001_create_assets_table.sql');
|
|
$pdo->exec($sql);
|
|
}
|
|
|
|
$stmt = $pdo->query('SELECT * FROM assets ORDER BY created_at DESC');
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
// In a real app, you'd log this error and show a user-friendly message.
|
|
// For this initial setup, we'll just display the error.
|
|
return ['error' => 'Database error: ' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
$assets = get_assets();
|
|
|
|
function getStatusClass($status) {
|
|
switch (strtolower($status)) {
|
|
case 'in service':
|
|
return 'status-in-service';
|
|
case 'under repair':
|
|
return 'status-under-repair';
|
|
case 'retired':
|
|
return 'status-retired';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>IC-Inventory</title>
|
|
<meta name="description" content="Built with Flatlogic Generator">
|
|
<meta name="keywords" content="asset management, inventory control, company assets, IT inventory, asset tracking, equipment management, Built with Flatlogic Generator">
|
|
<meta property="og:title" content="IC-Inventory">
|
|
<meta property="og:description" content="Built with Flatlogic Generator">
|
|
<meta property="og:image" content="">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="">
|
|
|
|
<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="#" class="nav-link active" aria-current="page">
|
|
<i data-feather="home" class="me-2"></i>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li>
|
|
<a href="#" class="nav-link">
|
|
<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>Asset Dashboard</h1>
|
|
<div>
|
|
<a href="add-asset.php" class="btn btn-primary">Add New Asset</a>
|
|
<div class="theme-switcher" id="theme-switcher">
|
|
<i data-feather="moon"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (isset($_GET['success']) && $_GET['success'] === 'asset_added'): ?>
|
|
<div class="alert alert-success">Asset successfully added!</div>
|
|
<?php elseif (isset($_GET['success']) && $_GET['success'] === 'asset_updated'): ?>
|
|
<div class="alert alert-success">Asset successfully updated!</div>
|
|
<?php elseif (isset($_GET['success']) && $_GET['success'] === 'asset_deleted'): ?>
|
|
<div class="alert alert-success">Asset successfully deleted!</div>
|
|
<?php elseif (isset($_GET['error']) && $_GET['error'] === 'access_denied'): ?>
|
|
<div class="alert alert-danger">You do not have permission to access that page.</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="surface p-4">
|
|
<?php if (isset($assets['error'])): ?>
|
|
<div class="alert alert-danger">
|
|
<?php echo htmlspecialchars($assets['error']); ?>
|
|
</div>
|
|
<?php elseif (empty($assets)): ?>
|
|
<div class="text-center p-5">
|
|
<h4>No assets found.</h4>
|
|
<p>Get started by adding your first company asset.</p>
|
|
<a href="add-asset.php" class="btn btn-primary">Add Asset</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table asset-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Asset Tag</th>
|
|
<th>Status</th>
|
|
<th>Location</th>
|
|
<th>Manufacturer</th>
|
|
<th>Model</th>
|
|
<th>Purchase Date</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($assets as $asset): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($asset['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($asset['asset_tag']); ?></td>
|
|
<td><span class="status <?php echo getStatusClass($asset['status']); ?>"><?php echo htmlspecialchars($asset['status']); ?></span></td>
|
|
<td><?php echo htmlspecialchars($asset['location']); ?></td>
|
|
<td><?php echo htmlspecialchars($asset['manufacturer']); ?></td>
|
|
<td><?php echo htmlspecialchars($asset['model']); ?></td>
|
|
<td><?php echo htmlspecialchars($asset['purchase_date']); ?></td>
|
|
<td>
|
|
<a href="edit-asset.php?id=<?php echo $asset['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
<?php if (in_array($_SESSION['user_role'], ['Admin', 'Asset Manager', 'IT Technician'])): ?>
|
|
<a href="delete-asset.php?id=<?php echo $asset['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this asset?');">Delete</a>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</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>
|