<?php
session_start();
require_once "db_connection.php";

// Check if the user is logged in
if (!isset($_SESSION['username'])) {
    header("Location: login.php");
    exit;
}

// Connect to the database
$conn = new mysqli("localhost", "anreoalb_archive", "Shahrooz@2681", "anreoalb_archive");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get file_id from POST request
$file_id = $_POST['file_id'];

// Prepare the SQL statement to fetch the temporary notes
$stmt = $conn->prepare("SELECT temporary_note FROM files WHERE file_id = ?");
$stmt->bind_param("i", $file_id);
$stmt->execute();
$stmt->bind_result($temporary_note);
$stmt->fetch();
$stmt->close();
$conn->close();

// Return the temporary notes as a JSON response
echo json_encode(['temporary_note' => $temporary_note]);
?>
