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

$policy_no_data = new input();
$policy_no_data->type("text");
$policy_no_data->name("guest_no");
$policy_no_data->id("guest_no");

$no_policies_res = $db->query("guest_registration", "SELECT * FROM guest_registration");
$policy_no = $no_policies_res->num_rows;

if ($no_policies_res->num_rows > 0) {
    $policy_no = 1 + $no_policies_res->num_rows;
    $policy_no_data->value($policy_no);
} else {
    $policy_no = 1;
    $policy_no_data->value($policy_no);
}

$name_surname_label = new label();
$name_surname_label->for("name_surname_label");
$name_surname_label->value("NAME & SURNAME");

$name_surname = new input();
$name_surname->type("text");
$name_surname->name("name_surname");
$name_surname->id("name_surname");
$name_surname->placeholder("NAME AND SURNAME");
$name_surname->style("width: 40%;");

$type_label = new label();
$type_label->for("type_label");
$type_label->value("PLEASE SELECT:");

$type = new select();
$type->class("inputs");
$type->id("type");
$type->name("type");
$type->add_option("", "");
$type->add_option("Visitor", "Visitor");
$type->add_option("Contactor", "Contactor");

$company_name_label = new label();
$company_name_label->for("company_name_label");
$company_name_label->value("COMPANY NAME:");

$company_name = new input();
$company_name->type("text");
$company_name->name("company_name");
$company_name->id("company_name");
$company_name->placeholder("COMPANY NAME");
$company_name->style("width: 40%;");

$visit_reason_label = new label();
$visit_reason_label->for("visit_reason_label");
$visit_reason_label->value("REASON FOR VISIT:");

$visit_reason = new input();
$visit_reason->type("text");
$visit_reason->name("visit_reason");
$visit_reason->id("visit_reason");
$visit_reason->placeholder("REASON FOR VISIT");
$visit_reason->style("width: 40%;");

$date_time_label = new label();
$date_time_label->for("date_time_label");
$date_time_label->value("DATE & TIME:");

$date = new input();
$date->type("datetime-local");
$date->id("date_time");
$date->name("date_time");

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

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

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

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

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

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

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

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

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

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

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

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

$q10_info = new input();
$q10_info->type("text");
$q10_info->name("q10_info");
$q10_info->id("q10_info");
$q10_info->placeholder("If yes,Please specify");
$q10_info->style("margin: 1vw auto;");

$q11_info = new input();
$q11_info->type("text");
$q11_info->name("q11_info");
$q11_info->id("q11_info");
$q11_info->placeholder("If yes,Please specify");
$q11_info->style("margin: 1vw auto;");

$submit_btn = new button();
$submit_btn->class("submit_btn");
$submit_btn->value("Submit");
$submit_btn->onclick("registration()");
$submit_btn->id("submit_btn")

    ?>

<div class="form_down">

    <h1>Visitor Hygiene Policy</h1>
    <?php
    $policy_no_data->add();
    $name_surname_label->add();
    $name_surname->add();
    $type_label->add();
    $type->add();
    $company_name_label->add();
    $company_name->add();
    $visit_reason_label->add();
    $visit_reason->add();

    ?>

    <style>
        table,
        th,
        td {
            border: 2px solid black;
            border-collapse: collapse;
            padding: 5px;
        }
    </style>

    <br>
    <table style="width:90%">
        <tr>
            <td>
                1. Purpose & Scope<br>

                The purpose of this document is providing clarity and details on actions for staff and visitors with
                specific requirements and rules with regards to personnel hygiene and related activities.
            </td>
        </tr>
        <tr>
            <td>
                2. Definitions & Abbreviations
                <ul>
                    <li>2.1 QA- Quality Assurance</li>
                    <li>2.2 CPAR- Corrective & Preventative Action Report</li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                3. Roles & Responsibility

                <ul>
                    <li>
                        3.1 It is the responsibility of the QA Manager to maintain and enforce the procedure throughout
                        Lowveld Nuts (Pty.) Ltd.
                    </li>
                    <li>
                        3.2 It is the responsibility of the Hygiene Officer to monitor & maintain this procedure.
                    </li>
                    <li>
                        3.3 It is managements responsibility to ensure that any deviation from this procedure is
                        addressed
                        correctly.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4. Policy

                4.1 Policy
                <ul>
                    <li>Your safety on site is of paramount importance to us. For this reason, we've prepared this
                        short induction brochure explaining some of the hazards and rules on this site. Some production
                        areas require personal protective equipment. This equipment will be provided should it be
                        required. Pay strict attention and obey all warning and danger signs.
                        We ask that you do not take photographs while on the premises. Should you desire to take
                        photographs please consult with the Production Manager.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4.2 Emergency situations:
                <ul>
                    <li>
                        Should an evacuation be required in the event of fire, bomb threat or any suchlike, the
                        evacuation alarm will sound.
                    </li>
                    <li>
                        In this event please proceed to the nearest assembly area [please see safety boards for
                        evacuation routs and emergency exits]. For assistance in this regard, you may ask anyone from
                        the management team.
                    </li>
                </ul>
                <p style="color: red; text-align: center;"><i>PLEASE, DO NOT PANIC. WE HAVE WELL TRAINED FIRE FIGHTERS
                        AND EVACUATION
                        MARSHALLS</i></p>
            </td>
        </tr>
        <tr>
            <td>
                4.3 Entry to site and production areas:
                <ul>
                    <li>
                        Visitors / Customers/ Contractors are NOT permitted into the production facility/ area unless
                        accompanied by a representative from Lowveld Nuts.
                    </li>
                    <li>
                        No children are allowed in the warehouse/ production facility unless approved by the Operations
                        Management and accompanied by a representative from Lowveld Nuts.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4.4 Forklifts/ other vehicles and moving equipment:

                <ul>
                    <li>
                        • Remember that this is a functioning facility and forklifts are in use. Please be vigilant,
                        watch and listen for forklifts moving material in and around the premises.
                    </li>
                    <li>
                        • Please ensure that forklift drivers are aware of your presence before you approach them.
                        Forklift and trucks are to be operated by authorised personnel only.
                    </li>
                    <li>
                        • Never walk under any raised load.
                    </li>
                    <li>
                        • Beware of forklifts and heavy vehicles especially when they are moving backwards.
                    </li>
                    <li>
                        • Drivers of delivery vehicles are requested to ensure that they check behind their vehicles
                        before proceeding backwards.
                    </li>
                    <li>
                        • Secure your load before leaving the site.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4.5 General Hygiene rules for storage, production and staff areas on site:
                <ul>
                    <li>
                        No jewellery is allowed in the processing area (no rings, or studs in exposed parts of the body)
                    </li>
                    <li>
                        No watches should be worn.
                    </li>
                    <li>
                        Fingernails should be kept short, clean and unvarnished. No false fingernails may be worn.
                    </li>
                    <li>
                        Wash hands, according to entrance procedure after use of toilets and when entering the factory.
                    </li>
                    <li>
                        Cuts, abrasions, grazes on exposed skin etc. must be reported to the first aid person/person
                        being visited and must be covered by a blue metal detectable plasters supplied by the company.
                    </li>
                    <li>
                        No cell phones are allowed into the Production Area.
                    </li>
                    <li>
                        If you are suffering, or have recently been exposed to an infectious disease, you must declare
                        so to the person to whom you report to.
                    </li>
                    <li>
                        No food or drink may be consumed, and no gum chewed. Eating and drinking in canteen/kitchen and
                        indicated outside area.
                    </li>
                    <li>
                        Do not starts work if you have an infectious disease, an upset stomach, or a discharge from
                        eyes, nose or ears.
                    </li>
                    <li>
                        No smoking is permitted in offices and/or the building- only permitted outside in the smoking
                        area.
                    </li>
                    <li>
                        The wearing of make-up, strong perfume or aftershave is prohibited, inside the factory.
                    </li>
                    <li>
                        Personal medicine can only be stored in the lockers in the change room, none inside the factory
                        – this is to minimize the risk of contamination.
                    </li>
                    <li>
                        No wood is allowed inside the factory
                    </li>
                    <li>
                        No glass or glass products allowed inside the factory there are exceptions made, refer to Glass
                        policy, no metal staples and paperclips allowed in the factory.
                    </li>
                    <li>
                        All food and packaging materials shall be stored on pallets (store about 45cm from the wall) or
                        on shelves no food and packaging materials shall be stored on the floor at any time.
                    </li>
                    <li>
                        All machine lubricants, cleaning chemicals, sanitizers shall be stored away from materials and
                        packaging materials in designated storage areas to prevent possible cross contamination.
                    </li>
                    <li>
                        Do not hold any objects such as pencils, pens behind your ear at any time.
                    </li>
                    <li>
                        No high care staff [cracking and sorting] are allowed in high-risk areas [post pasteurization]
                        or in low-risk areas such as nuts receiving. When people enter the warehouse area it must be
                        with clean protective clothing, following the normal entrance procedure.
                    </li>
                    <li>
                        No smoking is permitted in building, only in designated areas.
                    </li>
                    <li>
                        No employee shall enter the premises under the influence of or in the possession of any alcohol
                        or chemical substance, whether legal or illegal.
                    </li>
                    <li>
                        Under no circumstances may any firearm or weapon be brought onto company property.
                    </li>
                    <li>
                        Please ensure that you observe all safety rules and regulations.
                    </li>
                    <li>
                        Do not operate any fire or emergency equipment unless trained to do so.
                    </li>
                </ul>
                <p style="text-align: center;">
                    <i>
                        IF IN DOUBT PLEASE ASK.
                    </i>
                </p>
                <p style="text-align: center;">
                    <i>
                        SAFETY IS OUR NUMBER ONE CONCERN FOR OUR EMPLOYEES
                    </i>
                </p>


            </td>
        </tr>
        <tr>
            <td>
                4.6 Protective Clothing:
                <ul>
                    <li>
                        It is not permitted to enter the factory without the protective clothing specified, issued in
                        the change room:
                    </li>
                    <li>
                        Hairnet
                    </li>
                    <li>
                        Protective shoes
                    </li>
                    <li>
                        Beard cover [if needed]
                    </li>
                    <li>
                        Protective clothing – Trousers and T-shirt and/or Jacket and apron; wash and cleaned internally
                    </li>
                    <li>
                        Separate storage of personal items and work wear, as supplied by Lowveld Nuts.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4.7 Entrance Procedure:
                4.7.1 Factory Staff:
                <ul>
                    <li>
                        It is not permitted to enter process areas without following the entrance procedure.
                    </li>
                    <li>
                        Place on hairnet to cover hair/ears, beard snoots for beards.
                    </li>
                    <li>
                        Place on protective clothing and do all fasteners.
                    </li>
                    <li>
                        Wash hands with hand soap and dry hands.
                    </li>
                    <li>
                        Place on apron
                    </li>
                    <li>
                        Sanitize hands with alcohol.
                    </li>
                    <li>
                        Enter the factory.
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                4.7.2 Visitors:
                <ul>
                    <li>
                        It is not permitted to enter process areas without following the entrance procedure.
                    </li>
                    <li>
                        Place on hairnet to cover hair/ears, beard snoots for beards.
                    </li>
                    <li>
                        Ensure all jewellery is removed
                    </li>
                    <li>
                        Wash hands with hand soap and dry hands.
                    </li>
                    <li>
                        Place on provided company dust coat
                    </li>
                    <li>
                        Sanitize hands with alcohol.
                    </li>
                    <li>
                        Enter the factory.
                    </li>
                </ul>
                These items will be issued to you before you enter the factory. It is not permitted to enter the process
                areas unless the entrance procedure is followed.
            </td>
        </tr>
        <tr>
            <td>
                4.8 Allergen awareness:
                <ul>
                    The following allergens are handled on site: Tree Nuts
                </ul>
                <ul>
                    Please inform the accompanying manager should you be allergic to tree nuts.
                </ul>
                <ul>
                    You may not bring any allergen containing products on site. If you have handled allergen
                    containing products in the last three hours, please ensure you wash your hands thoroughly before
                    entering the site.
                </ul>

                We respectfully ask you NOT to handle any of the food products or surfaces where food is being prepared
                or transferred unless given permission to do so. You may also be refused access to some or our entire
                food factory if you are affected by some of the above.
            </td>
        </tr>
        <tr>
            <td>
                Emergency Contact details:

                <ul>
                    <li>Ambulance/ ER24: 084124</li>
                    <li>Fire Brigade: 013-7533331</li>
                    <li>Police Station: 013-7500888</li>
                    <li>Operations Manager:</li>
                    <li>Operations Manager:</li>
                    <li>Health & Safety Manager: </li>
                    <li>Health & Safety Manager: </li>
                    <li>Environmental Incident reporting: 0800 205 005</li>
                </ul>
            </td>
        </tr>
    </table>

    <br>

    <table style="width:90%">
        <tr>
            <th>Please kindly tick the applicable box:</th>
            <th>Yes</th>
            <th>No</th>
        </tr>
        <tr>
            <td>6.1. Have you recently suffered any Sickness, Diarrhoea or stomach disorder over the last 3 months?</td>
            <td colspan="2">
                <?php
                $q6_1->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.2. Have you been in contact with anyone with the above symptoms?</td>
            <td colspan="2">
                <?php
                $q6_2->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.3. Have you any history of, or contact with Typhoid, Paratyphoid?</td>
            <td colspan="2">
                <?php
                $q6_3->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.4. Have you any history, or contact with Hepatitis or Jaundice?</td>
            <td colspan="2">
                <?php
                $q6_4->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.5. Have you any history of skin conditions, Eczema, Dermatitis, boils or septic fingers?</td>
            <td colspan="2">
                <?php
                $q6_5->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.6. Have you any history of disease of, or discharge from the ears, nose or eyes?</td>
            <td colspan="2">
                <?php
                $q6_6->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.7. Have you any history of dental hygiene issues?</td>
            <td colspan="2">
                <?php
                $q6_7->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.8. Have you any history of bronchitis or productive cough?</td>
            <td colspan="2">
                <?php
                $q6_8->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.9. What was your means of transportation (Airplane/ car/ public transport (bus)</td>
            <td colspan="2">
                <?php
                $q6_9->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.10. In the past two weeks, have you been outside of the RSA border?</td>
            <td colspan="2">
                <?php
                $q6_10->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>If yes, where?</td>
            <td colspan="2">
                <?php
                $q10_info->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.11. Have you been in physical contact with someone who have been outside of the RSA borders in the
                past two weeks?</td>
            <td colspan="2">
                <?php
                $q6_11->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>If yes, what was the destination?</td>
            <td colspan="2">
                <?php
                $q11_info->add();
                ?>
            </td>
        </tr>
        <tr>
            <td>6.12. Have you experience any of the following symptoms the past 2 weeks: Fever, shortness of breath/
                struggle to breath, coughing, sneezing, flu-like discharge from ears, eyes or nose? </td>
            <td colspan="2">
                <?php
                $q6_12->add();
                ?>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <b>
                    If the answer is YES to any of the questions numbered 1-12, you must see the Occupational Health
                    Advisor
                    before entering the food factory.
                </b>
            </td>
        </tr>
    </table>
    <br>

    <table style="width:90%">
        <tr>
            <td>
                I have read and understand all the hygiene and safety requirements for the site [Please sign]. I hereby
                sign in agreement of this policy:
            </td>
            <td colspan="2">
                <canvas id="visitor_signature" name="visitor_signature" class="signature-pad" width=400 height=100
                    style='background-color:lightgrey;border-radius:20px;'></canvas>
            </td>
        </tr>
        <tr>
            <td>
                Signed off on behalf of Lowveld Nuts:
            </td>
            <td colspan="2">
                <canvas id="lowveld_nut_standin_signature" name="lowveld_nut_standin_signature" class="signature-pad"
                    width=400 height=100 style='background-color:lightgrey;border-radius:20px;'></canvas>
            </td>
        </tr>
    </table>
    <br>
    <table style="width:90%">
        <tr>
            <td>
                7 Non-Conformance & Corrective Action
                <ul>
                    <li>7.1 Non-conformance & corrective action procedure</li>
                    <li>7.2 Handling of potentially unsafe product procedure</li>
                    <li>7.3 Traceability procedure</li>
                    <li>7.4 CPAR record.</li>
                    <li>7.5 Emergency preparedness procedure</li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                8 Training & Competence

                As per schedule and competence procedure to meet the following requirements:
                ISO 22000:2018 Clause: 5.3.2; 7.2; 7.3; 7.4; & 10.3.
            </td>
        </tr>
        <tr>
            <td>
                8 Reference
                ISO 22000:2018
                ISO 22002-1:2009 TS
                FSSC 22 000 Additional Requirements
            </td>
        </tr>
    </table>

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

<script src="https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js"></script>

<script>
    var visitor_canvas = document.getElementById('visitor_signature');
    var visitor_pad = new SignaturePad(visitor_canvas);

    var lowveld_nut_standin_canvas = document.getElementById('lowveld_nut_standin_signature');
    var lowveld_nut_standin_pad = new SignaturePad(lowveld_nut_standin_canvas);

    var policy_no = document.getElementById('policy_no_data').value;

    document.getElementById('submit_btn').addEventListener('click', function () {
        if (lowveld_nut_standin_pad.isEmpty()) {
            alert("Please provide signature");
        } else {
            var dataURL = lowveld_nut_standin_pad.toDataURL('image/png');
            var blob = dataURLToBlob(dataURL);
            var formData = new FormData();
            formData.append('file', blob, 'signature.png');
            formData.append('type', 'lowveld_nut_standin');
            formData.append('standin_no', policy_no);

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "../policy/upload_signature.php", true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    // alert(xhr.responseText); // Handle the server response
                    if (xhr.responseText.indexOf("OK") > 1) {
                        // repload page
                        // location.reload();
                        console.log("Signature saved successfully.");

                    } else {
                        alert(xhr.responseText);
                    }
                }
            };
            xhr.send(formData);
        }
    });

    document.getElementById('submit_btn').addEventListener('click', function () {
        if (visitor_pad.isEmpty()) {
            alert("Please provide signature");
        } else {
            var dataURL = visitor_pad.toDataURL('image/png');
            var blob = dataURLToBlob(dataURL);
            var formData = new FormData();
            formData.append('file', blob, 'signature.png');
            formData.append('type', 'visitor');
            formData.append('visitor_no', policy_no);

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "../policy/upload_signature.php", true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    // alert(xhr.responseText); // Handle the server response
                    if (xhr.responseText.indexOf("OK") > 1) {
                        // repload page
                        // location.reload();
                        console.log("Signature saved successfully.");

                    } else {
                        alert(xhr.responseText);
                    }
                }
            };
            xhr.send(formData);
        }
    });

    function dataURLToBlob(dataURL) {
        var binary = atob(dataURL.split(',')[1]);
        var array = [];
        for (var i = 0; i < binary.length; i++) {
            array.push(binary.charCodeAt(i));
        }
        return new Blob([new Uint8Array(array)], {
            type: dataURL.split(',')[0].split(':')[1].split(';')[0]
        });
    }
</script>

<?php

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

$visitor_ajax = new js_ajax();
$visitor_ajax->function_name("registration");
$visitor_ajax->insert("guest_registration");
$visitor_ajax->on_success("GUEST INFORMATION SAVED");
$visitor_ajax->redirect("");