36432-vm/index.php
Flatlogic Bot 4ff4f98255 Basic
2025-11-28 15:28:25 +00:00

76 lines
2.8 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (isset($_SESSION['user_id'])) {
try {
$db = db();
$stmt = $db->prepare('SELECT * FROM notes WHERE user_id = ? ORDER BY created_at DESC');
$stmt->execute([$_SESSION['user_id']]);
$notes = $stmt->fetchAll();
} catch (PDOException $e) {
// For now, just show an empty array on DB error
$notes = [];
}
} else {
// Sample Data for Notes for non-logged-in users
$notes = [
[
'title' => 'Biology Lesson Plan',
'content' => 'Introduction to cell theory. Discuss Hooke and Leeuwenhoek...',
'tags' => 'science,lesson-plan,10th-grade',
'color' => '#D4EDDA',
],
[
'title' => 'Student Study Notes - History',
'content' => 'Key dates for the American Revolution: 1765 Stamp Act, 1770 Boston Massacre...',
'tags' => 'history,student-notes,exam-prep',
'color' => '#F8D7DA',
],
];
}
$note_created_success = isset($_GET['note_created']);
?>
<?php require_once 'header.php'; ?>
<main class="container py-5">
<h1 class="mb-4">Your Notes</h1>
<?php if ($note_created_success): ?>
<div class="alert alert-success">Note created successfully!</div>
<?php endif; ?>
<?php if (empty($notes)): ?>
<div class="text-center">
<p>You don't have any notes yet. <a href="create_note.php">Create your first one!</a></p>
</div>
<?php else: ?>
<div class="notes-grid">
<?php foreach ($notes as $note): ?>
<div class="card note-card">
<div class="color-label" style="background-color: <?php echo htmlspecialchars($note['color']); ?>;"></div>
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($note['title']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($note['content']); ?></p>
</div>
<div class="card-footer">
<?php
$tags = !empty($note['tags']) ? explode(',', $note['tags']) : [];
foreach ($tags as $tag):
?>
<span class="badge bg-secondary bg-opacity-10 text-secondary-emphasis rounded-pill">
<?php echo htmlspecialchars(trim($tag)); ?>
</span>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</main>
<?php require_once 'footer.php'; ?>