35311-vm/manage_documents.php
2025-10-30 18:38:17 +00:00

119 lines
5.2 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'partner') {
header("Location: index.php");
exit;
}
$resident_id = isset($_GET['resident_id']) ? (int)$_GET['resident_id'] : 0;
if ($resident_id === 0) {
header("Location: partner_dashboard.php");
exit;
}
$pdo = db();
// Fetch resident details
$stmt = $pdo->prepare("SELECT * FROM residents WHERE id = ?");
$stmt->execute([$resident_id]);
$resident = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$resident) {
header("Location: partner_dashboard.php");
exit;
}
// Fetch documents for this resident
$stmt = $pdo->prepare("SELECT * FROM documents WHERE resident_id = ? ORDER BY uploaded_at DESC");
$stmt->execute([$resident_id]);
$documents = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Documents - <?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="partner_dashboard.php">Continuum Nexus</a>
<a href="logout.php" class="btn btn-outline-light">Logout</a>
</div>
</nav>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Manage Documents for <?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></h1>
<a href="partner_dashboard.php" class="btn btn-secondary">← Back to Dashboard</a>
</div>
<div class="row">
<div class="col-md-7">
<div class="card">
<div class="card-header">Uploaded Documents</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>File Name</th>
<th>Description</th>
<th>Uploaded On</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (empty($documents)): ?>
<tr>
<td colspan="4" class="text-center">No documents uploaded yet.</td>
</tr>
<?php else: ?>
<?php foreach ($documents as $doc): ?>
<tr>
<td><?php echo htmlspecialchars($doc['file_name']); ?></td>
<td><?php echo htmlspecialchars($doc['description']); ?></td>
<td><?php echo date("M j, Y", strtotime($doc['uploaded_at'])); ?></td>
<td>
<a href="download_document.php?id=<?php echo $doc['id']; ?>" class="btn btn-sm btn-outline-primary">Download</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-5">
<div class="card">
<div class="card-header">Upload New Document</div>
<div class="card-body">
<form action="upload_document.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="resident_id" value="<?php echo $resident_id; ?>">
<div class="mb-3">
<label for="document" class="form-label">Select File</label>
<input type="file" name="document" id="document" class="form-control" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea name="description" id="description" class="form-control" rows="3" required></textarea>
</div>
<button type="submit" class="btn btn-primary-custom">Upload File</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>