<?php session_start();

include('includes/config/config.php');
include_once("includes/functions.php");
include_once("log_entry.php");
mysqli_query($conn, 'SET character_set_results=utf8');
error_reporting(0);

$query = "select * from company_profile where company_id = 5";
$result = mysqli_query($conn, $query);
$row_for_company = mysqli_fetch_array($result);
@extract($row_for_company);
?>
<!doctype html>
<html lang="en">

<head>
    <title>CANTEEN HYGIENE SURVEILLANCE</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <style>
        .print{
            position: absolute;
            right:11%;
        }
          .space {
        padding-bottom: 10px;
    }
    @media print {
        #printPageButton {
            display: none;
        }
    }
    body {
        font-family: Arial, Helvetica, sans-serif
    }
          .table_sign_2 {
        left: 10%;
        width: 100%;
    }
    .canteen {
        background-color: #008080;
        /* position: relative; */
        left: 20%;
        text-align: center;
        padding-left: 10%;
        padding-right: 10%;
        color: white;
    }

    table {
        border-collapse: collapse;
    }

    .table_2 {
        text-align: center;
        /* font-size: 10px; */
    }

    th,
    td {
        border: 1px solid black;
        height: 20px;
    }

    /*
        td{
            position: relative;
        } */
    .tt {
        text-align: center;
    }

    .head {
        background-color: #008080;
        color: white;
    }
    </style>
</head>

<body>

    <div class="container">
        <div class="container">
            <div class="container">
                <?php
include "pdf_ohc_header.php";
?>
<button id="printPageButton" class="btn btn-success print" onClick="window.print();">Print</button>

<br><br>
<h4 class="canteen">CANTEEN HYGIENE SURVEILLANCE</h4>
                <?php
    $patient_id = $_POST['patient_id'];
    $response_id = $_POST['response_id'];
    $chs_no = $_POST['chs_no'];

    error_log("patient_id" . $patient_id . "  response_id " . $response_id . "  chs_no  " . $chs_no);

    $sql_patient = "select a.*,b.question_id,b.question_remarks,b.question_answer,c.patient_name, c.dob , c.gender, c.doj from questionaire_master_response a left join questionaire_master_response_details b on a.response_id = b.response_id left join patient_master c on a.patient_id = c.id where a.patient_id='" . $_REQUEST['patient_id'] . "' and a.response_id='" . $response_id . "' and a.medical_examination_no='" . $chs_no . "' ";
    error_log("query " . $sql_patient);

    $result_patient = mysqli_query($conn, $sql_patient);

    $row_patient = mysqli_fetch_assoc($result_patient);


    @extract($row_patient);
    if ($row_patient['gender'] == 'M' || $row_patient['gender'] == 'm') {
        $gender = "MALE";
    } else if ($row_patient['gender'] == 'F' || $row_patient['gender'] == 'f') {
        $gender = "FEMALE";
    }
    ?>
                <table>
                    <tr>
                        <td width="10%" colspan="2">
                            Canteen Location:
                            &nbsp;
                            <?= $row_patient['canteen_location'];
                                ?>

                        </td>
                        <td width="5%">
                            Manpower:
                            &nbsp;
                            <?= $row_patient['manpower'];
                            ?>
                        </td>
                        <td width="5%">
                            Daily Caterer No:
                            &nbsp;
                            <?= $row_patient['daily_caterer'];
                            ?>
                        </td>
                        
                    </tr>

                    <tr>
                        <td>
                             Supervisor:
                            &nbsp;
                            <?= $row_patient['supervisor'];
                            ?>
                            
                        </td>
                        <td>
                           Daily Catering No:
                            &nbsp;
                            <?= $row_patient['daily_catering'];
                            ?>
                        </td>
                        <td class="tt">
                            Date:

                        </td>
                        <td>
                            <?= $row_patient['screen_date'];
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td height="20px">
                            Previous Survellance Date:
                            &nbsp;
                            <?= $row_patient['previous_survellance'];
                            ?>
                        </td>
                        <td>
                            Observation:
                            &nbsp;
                            <?= $row_patient['observation'];
                            ?>
                        </td>
                        <td class="tt">
                            Open / Total :

                        </td>
                        <td>
                            &nbsp;
                            <?= $row_patient['open_total'];
                            ?>
                        </td>
                    </tr>
                </table>
                <br>
                <table class="table_2">
                    <?php
            $sql_sub_section = "select sub_section_order,section_name from questionaire_master where sub_section_available IN ('','Y') and question_type='chs' group by sub_section_order";
            $result_sub_section = mysqli_query($conn, $sql_sub_section);

            $i = 0;
            if (mysqli_num_rows($result_sub_section) > 0) {
                while ($row_sub_section = mysqli_fetch_assoc($result_sub_section)) {
                    $section_name = $row_sub_section['section_name'];?>
                    <thead>

                        <tr class="head">
                            <?php
                            $sql_config = "select value from config where key_name = 'QUESTIONNAIRE_LANGUAGE'";
                            $result_config = @mysqli_query($conn, $sql_config);

                            $row_config = @mysqli_fetch_array($result_config);



                            if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>

                            <th width="2%">क्रमांक</th>
                            <th width="20%"><?= $section_name ?></th>

                            <th width="10%">हां/नहीं</th>

                            <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>


                            <th width="2%">Sr.No</th>
                            <th width="20%"><?= $section_name ?></th>

                            <th width="10%">Yes/No</th>
                            <th>Observation and remark</th>

                            <?php } else { ?>

                            <th width="2%">क्रमांक / Sr.No</th>
                            <th width="20%"><?= $section_name ?></th>
                            <th width="10%">हां/नहीं / Yes/No</th>
                            <th width="20%">Observation and remark</th>
                            <?php } ?>

                        </tr>
                    </thead>

                    <tbody>
                        <?php

                        $row = null;

                        $sql = "select * from questionaire_master where question_type='chs' and sub_section_order='" . $row_sub_section['sub_section_order'] . "'  ";
                        $result = @mysqli_query($conn, $sql);
                        $num_rows = @mysqli_num_rows($result);
                        $row = @mysqli_fetch_array($result);

                        do {

                        ?>


                        <tr>

                            <td style="width:5%"><?php echo $i + 1; ?></td>

                            <td style="width: 60%; text-align: left;" >
                                <?php

                                    if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>


                                <?php echo $row['question_hindi'] ?>

                                <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>


                                <?php echo $row['question'] ?>

                                <?php } else { ?>

                                <?php echo $row['question'] ?> / <?php echo $row['question_local_lang'] ?>

                                <?php } ?>
                            </td>
                            <?php
                                $sql_r = "select question_id, question_remarks,question_answer from questionaire_master_response_details a left join questionaire_master_response b on a.response_id = b.response_id where b.patient_id='" . $_REQUEST['patient_id'] . "' and a.question_id='" . $row['question_id'] . "' and b.medical_examination_no='".$chs_no . "'";
                                error_log("remarks sql " . $sql_r);
                                $result_r = mysqli_query($conn, $sql_r);
                                $row_r = mysqli_fetch_assoc($result_r);
                                ?>

                            <td style="width: 20%">
                                <?php
                                    if ($row_r['question_answer'] == 'Y') {
                                    ?>
                                Yes
                                <?php
                                    } else {
                                    ?>
                                No
                                <?php
                                    }
                                    ?>

                            </td>

                            <td style="width: 30%;">
                                <?php echo $row_r['question_remarks']?>
                            </td>
                        </tr>
                        <?php
                            $i++;
                        } while ($row = @mysqli_fetch_array($result));
                    }}
                    ?>
                    </tbody>
                </table>
                <br>
                <table>
                    <tr class="head">
                        <th style="text-align: center;" width="20%">Observation of consern</th>
                        <th width="20%" style="text-align: center;">Capa</th>
                        <th width="10%" style="text-align: center;">Communication Notes</t>
                    </tr>
                    <td style="text-align: center;"><?php echo $row_patient['observation_of_consern'] ?></td>
                    <td style="text-align: center;"><?php echo $row_patient['capa'] ?></td>
                    <td style="text-align: center;"><?php echo $row_patient['communication_notes'] ?></td>
                </table>
                <br>
                <table width="100%">
                    <tr class="head" >
                        <th  style="text-align: center;">Responsibility</th>
                        <th style="text-align: center;" >Completion Date</th>
                        <th width="30%" style="text-align: center;" width="20%">Status and closing remarks</th>
                    </tr>
                    <td style="text-align: center;"><?php echo $row_patient['responsibility'] ?></td>
                    <td style="text-align: center;"><?php echo $row_patient['completion'] ?></td>
                    <td style="text-align: center;">
                        <?php echo $row_patient['status_and_losing']?>
                </td>
                </table>
                <br>
             
                <table class="table_sign_2" style="text-align: center;">
                     <tr>
                   <?php
                                if ($row_patient['survellance'] == null || $row_patient['survellance'] == '' ) {?>
                    <td style="height: 100px;" width="30%">
                            <span
                                style="position: relative; text-align: center; top: 30%; width: fit-content;">Signature of Survellance  :</span>
                        </td>
                         <?php   }else{

                                    $survellance = "select b.*,c.patient_name , a.user_name from tbl_users a left join employee_signature b on a.emp_id = b.emp_id left join patient_master c on a.emp_id = c.id  where a.user_id='"  . $row_patient['medical_attend'] . "'";
                                    $sign_survellance = @mysqli_query($conn, $survellance);
                                    error_log('pdf khs '. $survellance);
                                    $sign_survellance_officer = @mysqli_fetch_assoc($sign_survellance);
                                    @extract($sign_survellance_officer);
                                    ?>
                        <td>

                            <center><img style=" width:150px; height:80px;" class="card-img-bottm"
                                    src="data:<?= $sign_survellance_officer['image_type']; ?>;base64,<?= base64_encode($sign_survellance_officer['emp_sign']) ?>">
                            </center>
                            <br>
                            <span><?= $sign_survellance_officer['user_name'];?></span>
                            <br>
                            <span class="" style="position: relative; text-align: left;">Signature of Survellance 
                                :</span>
                            <?php
                                } ?>
                                <br>
                        </td>
                        <td style="height: 100px;">
                            <span style="position: relative; top: 30%; text-align: center;">Sign of Canteen
                                Supervisor/Admin Head :</span>
                        </td>
                        <?php
                                if ($row_patient['approval_user'] == null || $row_patient['approval_user'] == '' ) {?>
                        <td style="height: 100px;">

                            <span class="" style="position: relative; top: 30%;">Signature of Medical Officer :</span>
                        </td>

                        <?php   }else{

                                    $medical_officer =  "select b.*,a.user_name from tbl_users a left join employee_signature b on a.emp_id = b.emp_id left join patient_master c on a.emp_id = c.id  where a.user_id='"  . $row_patient['approval_user'] . "'";
                                    error_log("PDF EMPI ". $row_patient['approval_user']."--". $medical_officer);
                                    $sign_medical = @mysqli_query($conn, $medical_officer);
                                    $sign_medical_officer = @mysqli_fetch_assoc($sign_medical);
                                    @extract($sign_medical_officer);
                                    ?>
                        <td>

                            <center><img style=" width:150px; height:80px;" class="card-img-bottm"
                                    src="data:<?= $sign_medical_officer['image_type']; ?>;base64,<?= base64_encode($sign_medical_officer['emp_sign']) ?>">
                            </center>
                            <br>
                            <span><?= $sign_medical_officer['user_name'];?></span>
                            <br>

                            <span class="" style="position: relative; text-align: left;">Signature of Medical Officer
                                :</span>
                            <?php
                                } ?>
                        </td>
                        
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div class="space"></div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous">
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
    </script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
    </script>
</body>

</html>