<?php

session_start();

require_once __DIR__ . '/../library/config.php';

$page_title = 'Add Homework';

require_once __DIR__ . '/../include/header.php';

require_once __DIR__ . '/../include/sidebar.php';

/*
|--------------------------------------------------------------------------
| FETCH CLASSES
|--------------------------------------------------------------------------
*/

$classStmt = $pdo->prepare("

    SELECT *

    FROM classes

    WHERE school_id = ?

    ORDER BY class_name ASC

");

$classStmt->execute([$_SESSION['school_id']]);

$classes = $classStmt->fetchAll(PDO::FETCH_ASSOC);

/*
|--------------------------------------------------------------------------
| FETCH SUBJECTS
|--------------------------------------------------------------------------
*/

$subjectStmt = $pdo->prepare("

    SELECT *

    FROM subjects

    WHERE school_id = ?

    ORDER BY name ASC

");

$subjectStmt->execute([$_SESSION['school_id']]);

$subjects = $subjectStmt->fetchAll(PDO::FETCH_ASSOC);

?>
<div class="content-wrapper">

<section class="content-header">

    <div class="container-fluid">

        <div class="d-flex justify-content-between align-items-center">

            <div>

                <h1 class="font-weight-bold">

                    Add Homework

                </h1>

                <p class="text-muted mb-0">

                    Create class wise homework

                </p>

            </div>

            <a
                href="index.php"
                class="btn btn-secondary"
            >

                <i class="fas fa-arrow-left mr-1"></i>

                Back

            </a>

        </div>

    </div>

</section>

<section class="content">

    <div class="container-fluid">

        <div class="card shadow-sm border-0">

            <div class="card-body">

                <form
                    action="process.php?action=create"
                    method="POST"
                    enctype="multipart/form-data"
                >

                    <div class="row">

                        <!-- CLASS -->

                        <div class="col-md-6">

                            <div class="form-group">

                                <label>

                                    Class

                                </label>

                                <select
                                    name="class_id"
                                    class="form-control"
                                    required
                                >

                                    <option value="">

                                        Select Class

                                    </option>

                                    <?php foreach($classes as $class): ?>

                                        <option value="<?= $class['id'] ?>">

                                            <?= htmlspecialchars($class['class_name']) ?>

                                        </option>

                                    <?php endforeach; ?>

                                </select>

                            </div>

                        </div>

                        <!-- SECTION -->

                        <div class="col-md-6">

                            <div class="form-group">

                                <label>

                                    Section

                                </label>

                                <input
                                    type="text"
                                    name="section"
                                    class="form-control"
                                    placeholder="Enter Section"
                                >

                            </div>

                        </div>

                        <!-- SUBJECT -->

                        <div class="col-md-6">

                            <div class="form-group">

                                <label>

                                    Subject

                                </label>

                                <select
                                    name="subject_id"
                                    class="form-control"
                                >

                                    <option value="">

                                        Select Subject

                                    </option>

                                    <?php foreach($subjects as $subject): ?>

                                        <option value="<?= $subject['id'] ?>">

                                            <?= htmlspecialchars($subject['name']) ?>

                                        </option>

                                    <?php endforeach; ?>

                                </select>

                            </div>

                        </div>

                        <!-- HOMEWORK DATE -->

                        <div class="col-md-3">

                            <div class="form-group">

                                <label>

                                    Homework Date

                                </label>

                                <input
                                    type="date"
                                    name="homework_date"
                                    class="form-control"
                                    required
                                >

                            </div>

                        </div>

                        <!-- SUBMISSION DATE -->

                        <div class="col-md-3">

                            <div class="form-group">

                                <label>

                                    Submission Date

                                </label>

                                <input
                                    type="date"
                                    name="submission_date"
                                    class="form-control"
                                >

                            </div>

                        </div>

                        <!-- TITLE -->

                        <div class="col-md-12">

                            <div class="form-group">

                                <label>

                                    Homework Title

                                </label>

                                <input
                                    type="text"
                                    name="title"
                                    class="form-control"
                                    placeholder="Enter Homework Title"
                                    required
                                >

                            </div>

                        </div>

                        <!-- DESCRIPTION -->

                        <div class="col-md-12">

                            <div class="form-group">

                                <label>

                                    Description

                                </label>

                                <textarea
                                    name="description"
                                    rows="5"
                                    class="form-control"
                                    placeholder="Enter Homework Description"
                                ></textarea>

                            </div>

                        </div>

                        <!-- ATTACHMENT -->

                        <div class="col-md-12">

                            <div class="form-group">

                                <label>

                                    Attachment

                                </label>

                                <input
                                    type="file"
                                    name="attachment"
                                    class="form-control"
                                >

                            </div>

                        </div>

                    </div>

                    <!-- BUTTON -->

                    <button
                        type="submit"
                        class="btn btn-primary px-4"
                    >

                        <i class="fas fa-save mr-1"></i>

                        Save Homework

                    </button>

                </form>

            </div>

        </div>

    </div>

</section>
</div>
<style>

.card {

    border-radius: 18px;
}

.form-control {

    border-radius: 10px;
    height: 45px;
}

textarea.form-control {

    height: auto;
}

.btn {

    border-radius: 10px;
}

</style>

<?php require_once __DIR__ . '/../include/footer.php'; ?>