<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$inspector_label = new label();
$inspector_label->for("inspector_name");
$inspector_label->value("Name of person doing the inspection:");

$inspector_name = new input();
$inspector_name->type("text");
$inspector_name->id("inspector_name");
$inspector_name->name("inspector_name");
$inspector_name->class("inputs");
$inspector_name->style("margin: 1vw auto; width: 25vw;");

$date_label = new label();
$date_label->for("date");
$date_label->value("Date of inspection:");

$date = new input();
$date->type("datetime-local");
$date->id("date");
$date->name("date");
$date->class("inputs");
$date->style("margin: 1vw auto;width: 25vw;");

$jobcard_id_label = new label();
$jobcard_id_label->for("jobcard_id");
$jobcard_id_label->value("Jobcard ID:");

$jobcard_id = new input();
$jobcard_id->type("text");
$jobcard_id->id("jobcard_id");
$jobcard_id->name("jobcard_id");
$jobcard_id->class("inputs");
// $jobcard_id->value($_GET["jobcard_id"]);
$jobcard_id->style("margin: 1vw auto; width: 25vw;");

$date_requested_label = new label();
$date_requested_label->for("date_requested");
$date_requested_label->value("Date requested:");

$date_requested = new input();
$date_requested->type("datetime-local");
$date_requested->id("date_requested");
$date_requested->name("date_requested");
$date_requested->class("inputs");
// $date_requested->value_from_db("maintenance_request", "date_requested","jobcard_id = {$_GET["jobcard_id"]}");
$date_requested->style("margin: 1vw auto; width: 25vw;");

$requested_by_label = new label();
$requested_by_label->for("requested_by");
$requested_by_label->value("Requested by:");

$requested_by = new input();
$requested_by->type("text");
$requested_by->id("requested_by");
$requested_by->name("requested_by");
$requested_by->class("inputs");
// $requested_by->value_from_db("maintenance_request", "requested_by","jobcard_id = {$_GET["jobcard_id"]}");
$requested_by->style("margin: 1vw auto; width: 25vw;");

$equipment_name_label = new label();
$equipment_name_label->for("equipment_name");
$equipment_name_label->value("Name of equipment:");

$equipment_name = new input();
$equipment_name->type("text");
$equipment_name->id("equipment_name");
$equipment_name->name("equipment_name");
$equipment_name->class("inputs");
// $equipment_name->value_from_db("maintenance_request", "equipment_name","jobcard_id = {$_GET["jobcard_id"]}");
$equipment_name->style("margin: 1vw auto; width: 25vw;");

$equipment_id_label = new label();
$equipment_id_label->for("equipment_id");
$equipment_id_label->value("Equipment ID:");

$equipment_id = new input();
$equipment_id->type("text");
$equipment_id->id("equipment_id");
$equipment_id->name("equipment_id");
$equipment_id->class("inputs");
// $equipment_id->value_from_db("maintenance_request", "equipment_id","jobcard_id = {$_GET["jobcard_id"]}");
$equipment_id->style("margin: 1vw auto; width: 25vw;");

$location_label = new label();
$location_label->for("location");
$location_label->value("Location:");

$location = new input();
$location->type("text");
$location->id("location");
$location->name("location");
$location->class("inputs");
// $location->value_from_db("maintenance_request", "location","jobcard_id = {$_GET["jobcard_id"]}");
$location->style("margin: 1vw auto; width: 25vw;");

$fault_reported_label = new label();
$fault_reported_label->for("fault_reported");
$fault_reported_label->value("Fault reported:");

$fault_reported = new input();
$fault_reported->type("text");
$fault_reported->id("fault_reported");
$fault_reported->name("fault_reported");
$fault_reported->class("inputs");
// $fault_reported->value_from_db("maintenance_request", "fault_reported","jobcard_id = {$_GET["jobcard_id"]}");
$fault_reported->style("margin: 1vw auto; width: 25vw;");

$tagout_required_label = new label();
$tagout_required_label->for("tagout_required");
$tagout_required_label->value("Tagout required:");

$tagout_required = new input();
$tagout_required->type("text");
$tagout_required->id("tagout_required");
$tagout_required->name("tagout_required");
$tagout_required->class("inputs");
// $tagout_required->value_from_db("maintenance_request", "tagout_required","jobcard_id = {$_GET["jobcard_id"]}");
$tagout_required->style("margin: 1vw auto; width: 25vw;");

$sanitation_requirements_label = new label();
$sanitation_requirements_label->for("sanitation_requirements");
$sanitation_requirements_label->value("Sanitation requirements:");

$sanitation_requirements = new input();
$sanitation_requirements->type("text");
$sanitation_requirements->id("sanitation_requirements");
$sanitation_requirements->name("sanitation_requirements");
$sanitation_requirements->class("inputs");
// $sanitation_requirements->value_from_db("maintenance_request", "sanitation_requirements","jobcard_id = {$_GET["jobcard_id"]}");
$sanitation_requirements->style("margin: 1vw auto; width: 25vw;");

$allergen_contamination_risk_label = new label();
$allergen_contamination_risk_label->for("allergen_contamination_risk");
$allergen_contamination_risk_label->value("Allergen contamination risk:");

$allergen_contamination_risk = new input();
$allergen_contamination_risk->type("text");
$allergen_contamination_risk->id("allergen_contamination_risk");
$allergen_contamination_risk->name("allergen_contamination_risk");
$allergen_contamination_risk->class("inputs");
// $allergen_contamination_risk->value_from_db("maintenance_request", "allergen_contamination_risk","jobcard_id = {$_GET["jobcard_id"]}");
$allergen_contamination_risk->style("margin: 1vw auto; width: 25vw;");

$technician_assigned_label = new label();
$technician_assigned_label->for("technician_assigned");
$technician_assigned_label->value("Technician assigned:");

$technician_assigned = new input();
$technician_assigned->type("text");
$technician_assigned->id("technician_assigned");
$technician_assigned->name("technician_assigned");
$technician_assigned->class("inputs");
// $technician_assigned->value_from_db("maintenance_request", "technician_assigned","jobcard_id = {$_GET["jobcard_id"]}");
$technician_assigned->style("margin: 1vw auto; width: 25vw;");

$work_performed_label = new label();
$work_performed_label->for("work_performed");
$work_performed_label->value("Work performed:");

$work_performed = new input();
$work_performed->type("text");
$work_performed->id("work_performed");
$work_performed->name("work_performed");
$work_performed->class("inputs");
// $work_performed->value_from_db("maintenance_request", "work_performed","jobcard_id = {$_GET["jobcard_id"]}");
$work_performed->style("margin: 1vw auto; width: 25vw;");

$parts_used_label = new label();
$parts_used_label->for("parts_used");
$parts_used_label->value("Parts used:");

$parts_used = new input();
$parts_used->type("text");
$parts_used->id("parts_used");
$parts_used->name("parts_used");
$parts_used->class("inputs");
// $parts_used->value_from_db("maintenance_request", "parts_used","jobcard_id = {$_GET["jobcard_id"]}");
$parts_used->style("margin: 1vw auto; width: 25vw;");

$chemicals_lubricants_used_label = new label();
$chemicals_lubricants_used_label->for("chemicals_lubricants_used");
$chemicals_lubricants_used_label->value("Chemicals and lubricants used:");

$chemicals_lubricants_used = new input();
$chemicals_lubricants_used->type("text");
$chemicals_lubricants_used->id("chemicals_lubricants_used");
$chemicals_lubricants_used->name("chemicals_lubricants_used");
$chemicals_lubricants_used->class("inputs");
// $chemicals_lubricants_used->value_from_db("maintenance_request", "chemicals_lubricants_used","jobcard_id = {$_GET["jobcard_id"]}");
$chemicals_lubricants_used->style("margin: 1vw auto; width: 25vw;");

$food_contact_surfaces_worked_label = new label();
$food_contact_surfaces_worked_label->for("food_contact_surfaces_worked");
$food_contact_surfaces_worked_label->value("Food contact surfaces worked:");

$food_contact_surfaces_worked = new input();
$food_contact_surfaces_worked->type("text");
$food_contact_surfaces_worked->id("food_contact_surfaces_worked");
$food_contact_surfaces_worked->name("food_contact_surfaces_worked");
$food_contact_surfaces_worked->class("inputs");
// $food_contact_surfaces_worked->value_from_db("maintenance_request", "food_contact_surfaces_worked","jobcard_id = {$_GET["jobcard_id"]}");
$food_contact_surfaces_worked->style("margin: 1vw auto; width: 25vw;");

$equipment_cleaning = new select();
$equipment_cleaning->id("equipment_cleaning");
$equipment_cleaning->name("equipment_cleaning");
$equipment_cleaning->class("inputs");
$equipment_cleaning->add_option("Yes", "Yes");
$equipment_cleaning->add_option("No", "No");
$equipment_cleaning->style("margin: 1vw auto;");

$contact_surfaces_sanitized = new select();
$contact_surfaces_sanitized->id("contact_surfaces_sanitized");
$contact_surfaces_sanitized->name("contact_surfaces_sanitized");
$contact_surfaces_sanitized->class("inputs");
$contact_surfaces_sanitized->add_option("Yes", "Yes");
$contact_surfaces_sanitized->add_option("No", "No");
$contact_surfaces_sanitized->style("margin: 1vw auto;");

$chemicals_removed = new select();
$chemicals_removed->id("chemicals_removed");
$chemicals_removed->name("chemicals_removed");
$chemicals_removed->class("inputs");
$chemicals_removed->add_option("Yes", "Yes");
$chemicals_removed->add_option("No", "No");
$chemicals_removed->style("margin: 1vw auto;");

$floors_cleaned = new select();
$floors_cleaned->id("floors_cleaned");
$floors_cleaned->name("floors_cleaned");
$floors_cleaned->class("inputs");
$floors_cleaned->add_option("Yes", "Yes");
$floors_cleaned->add_option("No", "No");
$floors_cleaned->style("margin: 1vw auto;");

$tools_removed = new select();
$tools_removed->id("tools_removed");
$tools_removed->name("tools_removed");
$tools_removed->class("inputs");
$tools_removed->add_option("Yes", "Yes");
$tools_removed->add_option("No", "No");
$tools_removed->style("margin: 1vw auto;");

$waste_disposed = new select();
$waste_disposed->id("waste_disposed");
$waste_disposed->name("waste_disposed");
$waste_disposed->class("inputs");
$waste_disposed->add_option("Yes", "Yes");
$waste_disposed->add_option("No", "No");
$waste_disposed->style("margin: 1vw auto;");

$cleaner_name = new select();
$cleaner_name->id("cleaner_name");
$cleaner_name->name("cleaner_name");
$cleaner_name->class("inputs");
$cleaner_name->add_option("Cleaner 1", "Cleaner 1");
$cleaner_name->add_option("Cleaner 2", "Cleaner 2");
$cleaner_name->add_option("Cleaner 3", "Cleaner 3");
$cleaner_name->add_option("Cleaner 4", "Cleaner 4");
$cleaner_name->add_option("Cleaner 5", "Cleaner 5");
$cleaner_name->style("margin: 1vw auto;");

$visual_inspection_conducted = new select();
$visual_inspection_conducted->id("visual_inspection_conducted");
$visual_inspection_conducted->name("visual_inspection_conducted");
$visual_inspection_conducted->class("inputs");
$visual_inspection_conducted->add_option("Yes", "Yes");
$visual_inspection_conducted->add_option("No", "No");
$visual_inspection_conducted->style("margin: 1vw auto;");

$swab_description = new input();
$swab_description->type("text");
$swab_description->id("swab_description");
$swab_description->name("swab_description");
$swab_description->class("inputs");

$area_sanitized = new select();
$area_sanitized->id("area_sanitized");
$area_sanitized->name("area_sanitized");
$area_sanitized->class("inputs");
$area_sanitized->add_option("Yes", "Yes");
$area_sanitized->add_option("No", "No");
$area_sanitized->style("margin: 1vw auto;");

$additional_comments = new textarea();
$additional_comments->id("additional_comments");
$additional_comments->name("additional_comments");
$additional_comments->class("inputs");
$additional_comments->style("margin: 1vw auto; width: 25vw;");

$cleaned_by_label = new label();
$cleaned_by_label->for("cleared_by");
$cleaned_by_label->value("Cleaner Signature:");

$cleared_by = new signature();
$cleared_by->id("cleared_by");
$cleared_by->name("cleared_by");
$cleared_by->send_file_path("../maintenance/upload_signature.php");
$cleared_by->submit_btn_id("submit_btn");
$cleared_by->style("height: 150px;");

$production_manager_signature_label = new label();
$production_manager_signature_label->for("production_manager");
$production_manager_signature_label->value("Production Manager Signature:");

$production_manager_signature = new signature();
$production_manager_signature->id("production_manager");
$production_manager_signature->name("production_manager");
$production_manager_signature->send_file_path("../maintenance/upload_signature.php");
$production_manager_signature->submit_btn_id("submit_btn");
$production_manager_signature->style("height: 150px;");

$job_done_label = new label();
$job_done_label->for("job_done");
$job_done_label->value("Jobcard Done:");

$job_done = new button();
$job_done->class("submit_btn");
$job_done->value("JOBCARD DONE");
$job_done->onclick("open_popup()");

$submit_btn = new input();
$submit_btn->class("submit_btn");
$submit_btn->value("Submit");
$submit_btn->onclick("post_maintenance");
$submit_btn->id("submit_btn");

?>

<form action="save_post_main.php" method="post">
    <div class="form_down">
        <h1>POST MAINTENANCE</h1>
        <style>
            table,
            th,
            td {
                border: 2px solid black;
                border-collapse: collapse;
                padding: 5px;
            }
        </style>
        <div style="display:flex; flex-direction: row; justify-content: space-between; width: 55%;">
            <div style="display: flex; flex-direction: column;">
                <?php
                $inspector_label->add();
                $inspector_name->add();
                ?>
            </div>
            <div style="display: flex; flex-direction: column;">
                <?php
                $date_label->add();
                $date->add();
                ?>
            </div>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: space-between; width: 80%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $jobcard_id_label->add();
                $jobcard_id->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $date_requested_label->add();
                $date_requested->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $requested_by_label->add();
                $requested_by->add();
                ?>
            </div>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: space-between; width: 80%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $equipment_name_label->add();
                $equipment_name->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $equipment_id_label->add();
                $equipment_id->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $location_label->add();
                $location->add();
                ?>
            </div>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: space-between; width: 55%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $fault_reported_label->add();
                $fault_reported->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $tagout_required_label->add();
                $tagout_required->add();
                ?>
            </div>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: space-between; width: 55%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $sanitation_requirements_label->add();
                $sanitation_requirements->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $allergen_contamination_risk_label->add();
                $allergen_contamination_risk->add();
                ?>
            </div>
        </div>

        <div style="display: flex;flex-direction: row; justify-content: space-between; width: 80%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $technician_assigned_label->add();
                $technician_assigned->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $work_performed_label->add();
                $work_performed->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $parts_used_label->add();
                $parts_used->add();
                ?>
            </div>
        </div>

        <div style="display: flex;flex-direction: row; justify-content: space-between; width: 55%;">
            <div style="display:flex; flex-direction: column;">
                <?php
                $chemicals_lubricants_used_label->add();
                $chemicals_lubricants_used->add();
                ?>
            </div>
            <div style="display:flex; flex-direction: column;">
                <?php
                $food_contact_surfaces_worked_label->add();
                $food_contact_surfaces_worked->add();
                ?>
            </div>
        </div>

        <br>

        <table style="width: 60%">
            <tr>
                <th colspan="2">
                    Cleaning Inspection:
                </th>
            </tr>
            <tr>
                <td>
                    Equipment cleaned of all debris and residue:
                </td>
                <td>
                    <?php
                    $equipment_cleaning->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Food contact surfaces sanitized:
                </td>
                <td>
                    <?php
                    $area_sanitized->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Cleaning chemicals removed or rinsed:
                </td>
                <td>
                    <?php
                    $chemicals_removed->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Floors and surrounding area cleaned:
                </td>
                <td>
                    <?php
                    $floors_cleaned->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    PPE and tools removed from area:
                </td>
                <td>
                    <?php
                    $tools_removed->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Waste disposed of appropriately:
                </td>
                <td>
                    <?php
                    $waste_disposed->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Please indicate who did the cleaning:
                </td>
                <td>
                    <?php
                    $cleaner_name->add();
                    ?>
                </td>
            </tr>
        </table>

        <br><br>

        <table style="width: 60%">
            <tr>
                <th colspan="2">
                    Clearance for production to continue:
                </th>
            </tr>
            <tr>
                <td>
                    Visual Inspection Conducted:
                </td>
                <td>
                    <?php
                    $visual_inspection_conducted->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Swab / Test Conducted:
                </td>
                <td>

                    <select name="swab_test_conducted" id="swab_test_conducted" onchange="swab_change()" class="inputs">
                        <option value=""></option>
                        <option value="Yes">Yes</option>
                        <option value="No">No</option>
                    </select>
                    <div id="swab_descrip" style="display: none;">
                        <?php
                        $swab_description->add();
                        ?>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    Area Sanitized and safe for Food Contact:
                </td>
                <td>
                    <?php
                    $area_sanitized->add();
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    Additional Comments:
                </td>
                <td>
                    <?php
                    $additional_comments->add();
                    ?>
                </td>
            </tr>
        </table>
        <br>

        <div style="display: flex; flex-direction: row;">
            <div style="display: flex; flex-direction: column;">
                <?php
                $cleaned_by_label->add();
                $cleared_by->add();
                ?>
            </div>
            <div style="display: flex; flex-direction: column;">
                <?php
                $production_manager_signature_label->add();
                $production_manager_signature->add();
                ?>
            </div>
        </div>

        <?php
        $submit_btn->add();
        ?>
    </div>
</form>

<script>
    function open_popup() {
        //redirect to another page
        window.location.href = "post_maintenance.pdf.php";
    }

    function swab_change() {
        if (document.getElementById("swab_test_conducted").value == "No") {
            document.getElementById("swab_descrip").style.display = "block";
        } else {
            document.getElementById("swab_descrip").style.display = "none";
        }
    }
</script>

<?php

$date = date("Y-m-d H:i", strtotime("+2 Hours"));

$ajax = new js_ajax();
$ajax->function_name("post_maintenance");
$ajax->insert("");
$ajax->on_success("");
$ajax->redirect("");