<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include "../include/config.php";

if (!isset($_SESSION['studentid'])) {
    header("Location: ../index.php");
    exit();
}

// Get note ID from URL
$note_id = $_GET['id'] ?? '';

if ($note_id == '') {
    echo "Invalid note ID.";
    exit();
}

// Fetch note from database
$query = "SELECT * FROM notes WHERE id = '$note_id' LIMIT 1";
$result = mysqli_query($conn, $query);

if (!$result || mysqli_num_rows($result) == 0) {
    echo "Note not found.";
    exit();
}

$note = mysqli_fetch_assoc($result);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Note</title>
    <link rel="stylesheet" href="../../boostrap/1.css">
    <link rel="stylesheet" href="../../boostrap/2.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css">
</head>
<style>
body { padding:0; margin:0; font-family: 'Montserrat', sans-serif; background:white; }
.content { margin-left:210px; padding:20px; }
.note-card { padding:20px; background:white; border-radius:6px; box-shadow: rgba(0,0,0,0.16) 0px 1px 4px; }
.note-card h3 { color:#d03f4d; }
.note-card p { font-size:16px; line-height:1.6; color:#333; }
.back-btn { margin-bottom:20px; }
</style>
<body>

<?php include "../include/nav.php";?>

<div class="content">
    <a href="notes.php" class="btn btn-secondary back-btn"><i class="fa fa-arrow-left"></i> Back to Notes</a>

    <div class="note-card">
        <h3><?php echo htmlspecialchars($note['title']); ?></h3>
        <p><strong>Course:</strong> <?php echo htmlspecialchars($note['course']); ?></p>
        <p><strong>Program:</strong> <?php echo htmlspecialchars($note['program']); ?></p>
        <hr>
        <p><?php echo nl2br(htmlspecialchars($note['note'])); ?></p>
    </div>
</div>

</body>
</html>
