64 lines
3.6 KiB
PHTML
64 lines
3.6 KiB
PHTML
<?php include dirname(__DIR__).'/header.phtml'; ?>
|
|
|
|
<div class="container">
|
|
<?php
|
|
function isLoggedIn() {
|
|
return isset($_SESSION['user_id']);
|
|
}
|
|
|
|
function isAdmin() {
|
|
return isLoggedIn() && isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
|
|
}
|
|
|
|
function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
|
|
return htmlspecialchars((string)$data, $flags, $encoding);
|
|
}
|
|
|
|
$sortBy = $_GET['sort_by'] ?? 'uploaded_at';
|
|
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC'); // Ensure uppercase for comparison
|
|
?>
|
|
<div class="page-header">
|
|
<h2>All Users' Files</h2>
|
|
</div>
|
|
|
|
<?php if (isset($errmsg)): ?>
|
|
<label class="error-message"><?php echo $errmsg; ?></label>
|
|
<?php endif; ?>
|
|
|
|
<table class="notes-table">
|
|
<thead>
|
|
<tr>
|
|
<th data-sort="id">File ID <span class="sort-icon"><?php if($sortBy === 'id') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="original_filename">Original File Name <span class="sort-icon"><?php if($sortBy === 'original_filename') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="stored_filename">Stored File Name <span class="sort-icon"><?php if($sortBy === 'stored_filename') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="note_id">Note ID <span class="sort-icon"><?php if($sortBy === 'note_id') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="owner_username">Owner <span class="sort-icon"><?php if($sortBy === 'owner_username') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="uploaded_at">Uploaded At <span class="sort-icon"><?php if($sortBy === 'uploaded_at') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="file_size">File Size <span class="sort-icon"><?php if($sortBy === 'file_size') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($files as $file): ?>
|
|
<tr>
|
|
<td><?php echo sanitize($file['id']); ?></td>
|
|
<td><a href="<?php echo substr($_SERVER['PHP_SELF'], 0, -9).'Uploads/'.$file['stored_filename']; ?>"><?php echo sanitize($file['stored_filename']); ?></a></td>
|
|
<td><?php echo sanitize($file['stored_filename']); ?></td>
|
|
<td><?php echo sanitize($file['note_id']); ?></td>
|
|
<td><?php echo sanitize($file['owner_username']); ?></td>
|
|
<td><?php echo date("d.m.Y H:i", strtotime($file['uploaded_at'])); ?></td>
|
|
<td><?php echo round(sanitize($file['file_size']) / 1024, 2) . ' KB'; ?></td>
|
|
<td class="actions-cell">
|
|
<form method="POST" action="?controller=Notes&do=deleteFile" onsubmit="return confirm('Are you sure you want to delete this file?');" style="display: inline;">
|
|
<input type="hidden" name="file_id" value="<?php echo $file['id']; ?>">
|
|
<button type="submit" class="button danger">Delete</button>
|
|
<input type="hidden" name="controller" value="Notes">
|
|
<input type="hidden" name="do" value="deleteFile">
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php include dirname(__DIR__).'/footer.phtml'; ?> |