<?php
// Include database connection
include('db_connection.php');

// Fetch homework assignments with subject names
$sql = "SELECT h.homework_id, s.subject_name, h.description, h.due_date 
        FROM homework h
        INNER JOIN subject s ON h.subject_id = s.subject_id";
$result = $conn->query($sql);

// Check if there are any assignments
if ($result->num_rows > 0) {
    echo "<h2>Homework</h2>";
    echo "<div class='homework-list'>";
    echo "<table>";
    echo "<tr><th>Subject</th><th>Description</th><th>Deadline</th></tr>";
    
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>{$row['subject_name']}</td>"; // Display subject name
        echo "<td>{$row['description']}</td>";
        echo "<td>{$row['due_date']}</td>";
        echo "</tr>";
    }
    
    echo "</table>";
    echo "</div>";
} else {
    echo "No homework found.";
}

// Close database connection
$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Homework list and Submission</title>
    <link rel="stylesheet" href="styles.css"> <!-- Link your CSS file here -->
    <style type="text/css">
        /* General styles */
body {
    font-family: Arial, sans-serif;
    background-color: #f2f2f2;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 800px;
    margin: 20px auto;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
    color: #333;
}

p {
    color: #666;
}

/* Table styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

table th, table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

table th {
    background-color: #f2f2f2;
}

/* Form styles */
form {
    margin-bottom: 20px;
}

label {
    font-weight: bold;
}

input[type="text"], input[type="email"], select, textarea {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

input[type="file"] {
    margin-top: 5px;
}

button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

button:hover {
    background-color: #45a049;
}

/* Notification styles */
.notification {
    background-color: #f0f0f0;
    padding: 15px;
    margin-bottom: 10px;
    border-left: 6px solid #4CAF50;
}

.notification h4 {
    color: #333;
    margin-top: 0;
}

.notification p {
    color: #666;
}

/* Link styles */
a {
    color: #4CAF50;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

    </style>
</head>
<body>
<div class="homework-submission">
    <h3>Submit Homework</h3>
    <form action="submit_homework.php" method="POST" enctype="multipart/form-data">
        <label for="assignment_id">Select Assignment:</label>
        <select name="assignment_id" id="assignment_id">
            <?php
            // Include database connection
            include('db_connection.php');

            // Fetch assignments from homework table with subject names
            $sql = "SELECT h.homework_id, h.subject_id, h.title, h.description, s.subject_name
                    FROM homework h
                    INNER JOIN subject s ON h.subject_id = s.subject_id";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<option value=\"{$row['homework_id']}\">{$row['title']} - {$row['subject_name']}</option>";
                }
            } else {
                echo "<option value=\"\">No assignments found</option>";
            }

            // Close database connection
            $conn->close();
            ?>
        </select>
        <br><br>
        <label for="submission">Upload File:</label>
        <input type="file" name="submission" id="submission" required>
        <br><br>
        <button type="submit">Submit</button>
    </form>
</div>
</body>
</html>