83 lines
4.2 KiB
PHTML
83 lines
4.2 KiB
PHTML
<?php include dirname(__DIR__).'/header.phtml'; ?>
|
|
|
|
<div class="container">
|
|
<?php
|
|
$parsedown = new Parsedown();
|
|
$parsedown->setSafeMode(true);
|
|
|
|
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'] ?? 'updated_at';
|
|
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC'); // Ensure uppercase for comparison
|
|
?>
|
|
<div class="page-header">
|
|
<h2><?php echo isAdmin() ? "All Users' Notes" : "My Notes"; ?></h2>
|
|
<a href="?controller=Notes&do=createNote" class="button">Create New Note</a>
|
|
</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">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 data-sort="priority">Priority<span class="sort-icon"><?php if($sortBy === 'priority') 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>
|
|
<?php
|
|
if($note['priority'] === 'LOW') echo ('<td class="style_low";>');
|
|
elseif($note['priority'] === 'MID') echo ('<td class="style_mid";>');
|
|
elseif($note['priority'] === 'HIGH') echo ('<td class="style_high";>');
|
|
echo sanitize($note['priority']);
|
|
echo ('</td>')
|
|
?>
|
|
<td class="actions-cell">
|
|
<a href="?controller=Notes&do=editNote&id=<?php echo $note['id']; ?>" class="button">Edit</a>
|
|
<form method="POST" action="?controller=Notes&do=deleteNote" onsubmit="return confirm('Are you sure you want to delete this note?');" style="display: inline;">
|
|
<input type="hidden" name="note_id" value="<?php echo $note['id']; ?>">
|
|
<button type="submit" class="button danger">Delete</button>
|
|
<input type="hidden" name="controller" value="Notes">
|
|
<input type="hidden" name="do" value="deleteNote">
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php include dirname(__DIR__).'/footer.phtml'; ?> |