62 lines
2.9 KiB
PHTML
62 lines
2.9 KiB
PHTML
<?php include dirname(__DIR__).'/header.phtml'; ?>
|
|
|
|
<h2>Notes</h2>
|
|
|
|
<div class="container">
|
|
<?php
|
|
$parsedown = new Parsedown();
|
|
$parsedown->setSafeMode(true);
|
|
|
|
function isLoggedIn() {
|
|
return isset($_SESSION['user_id']);
|
|
}
|
|
|
|
function isAdmin() {
|
|
return false;// 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'] ?? 'updated_at';
|
|
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC'); // Ensure uppercase for comparison
|
|
?>
|
|
<table class="notes-table">
|
|
<thead>
|
|
<tr>
|
|
<th data-sort="id">ID <span class="sort-icon"><?php if($sortBy === 'id') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th data-sort="title">Title <span class="sort-icon"><?php if($sortBy === 'title') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<?php if (isAdmin()): ?>
|
|
<th data-sort="owner_username">Owner <span class="sort-icon"><?php if($sortBy === 'owner_username') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<?php endif; ?>
|
|
<th>Content (Preview)</th>
|
|
<th data-sort="updated_at">Last Edited <span class="sort-icon"><?php if($sortBy === 'updated_at') echo $sortOrder === 'ASC' ? '▲' : '▼'; ?></span></th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($notes as $note): ?>
|
|
<tr>
|
|
<td><?php echo sanitize($note['id']); ?></td>
|
|
<td><a href="?controller=Notes&do=showNoteDetails&id=<?php echo $note['id']; ?>"><?php echo sanitize($note['title']); ?></a></td>
|
|
<?php if (isAdmin()): ?>
|
|
<td><?php echo sanitize($note['owner_username']); ?></td>
|
|
<?php endif; ?>
|
|
<td>
|
|
<?php
|
|
$plainTextContent = strip_tags($parsedown->text($note['content'] ?? ''));
|
|
$previewContent = mb_substr($plainTextContent, 0, 70);
|
|
echo sanitize($previewContent) . (mb_strlen($plainTextContent) > 70 ? '...' : '');
|
|
?>
|
|
</td>
|
|
<td><?php echo date("d.m.Y H:i", strtotime($note['updated_at'])); ?></td>
|
|
<td class="actions-cell">
|
|
<a href="index.php?page=edit_note&id=<?php echo $note['id']; ?>" class="button">Edit</a>
|
|
<button class="button danger delete-note-btn" data-note-id="<?php echo $note['id']; ?>">Delete</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php include dirname(__DIR__).'/footer.phtml'; ?> |