<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$maindb = 'visaform';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$zroot = $_SESSION["zdir"];
$compcd = $_SESSION["comp_" . $dbname];
$myyear = $_SESSION[$myyear];
$tourcode = $_SESSION['tourcode'];
$tourname = $_SESSION['tourname'];

mysqli_select_db($conn, $zdb);

$class = $_POST["class"];
$frmregnno = $_POST["frmregnno"];
$toregnno = $_POST["toregnno"];
$frmpaxno = $_POST["frmpaxno"];
$topaxno = $_POST["topaxno"];

$ccond = "";
if (!empty($_POST["class"])) {
    $ccond = " AND b.`batchno`='$class' ";
}


$regnnocond = "";
if (!empty($_POST["frmregnno"]) && !empty($_POST["toregnno"])) {
    $regnnocond = " AND a.`vregnno` BETWEEN '$frmregnno' AND '$toregnno'";
}

$paxcond = "";
if (!empty($_POST["frmpaxno"]) && !empty($_POST["topaxno"])) {
    $paxcond = " AND a.`vouchno` BETWEEN '$frmpaxno' AND '$topaxno'";
}


$sort = $_POST["orderby"];
if ($sort == 'R') {
    $orderby = " ORDER BY a.vregnno,a.vouchno ";
} else {
    $orderby = " ORDER BY a.vouchno ";
}

$cmain = mysqli_query($conn, "SELECT  a.*,b.tel,b.mobile,b.add1,b.add2,b.add3,b.city,b.pin,b.state  FROM `visaform` a, `bookform` b  
                              WHERE  a.vregnno = b.regnno AND a.tour = b.tourno AND a.`name` != ''  AND b.tourno = '$tourcode'  $regnnocond $paxcond
                              $ccond $orderby ") or die(mysqli_error($conn));

$paxno = mysqli_num_rows($cmain);

$getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code`= '$compcd'") or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);

if (mysqli_num_rows($cmain) <= 0) {
    browse('Record Not Found');
    echo "<script>"
        . "window.close();"
        . "</script>;";
}

if (isset($_POST["view"])) {

    include("includes/linkshead.php");
?>
    <style>
        body {
            font-size: 10px;
            width: 100%;
        }

        .mtable {
            border: 1px solid black;
            border-collapse: collapse;
        }

        .mtd {
            border: 1px solid black;
            border-collapse: collapse;
            text-align: right;
        }

        .fsize {
            font-size: 10px;
        }

        td,
        th {
            padding: 0px;
            font-size: 15px;
        }

        .border {
            border-top-style: solid;
            border-right-style: solid;
            border-left-style: solid;
            border-bottom-style: none;
            border-width: 1px;
        }

        .border2 {
            border-top-style: solid;
            border-right-style: solid;
            border-left-style: solid;
            border-bottom-style: solid;
            border-width: 1px;
        }

        .center {
            text-align: center;
        }

        .left {
            text-align: left;
        }

        .right {
            text-align: right;
        }

        .page {
            width: 297mm;
            /* width: ; */
            /* size: A4 landscape; */
            /* min-height: 210mm; */
            padding: 5px 0;
            /* margin: 10mm auto; */
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;
            margin-top: 0px;
            margin-bottom: 0px;
        }

        .h13 {
            height: 13px;
        }

        .h12 {
            height: 12px
        }


        @media print {
            .mtable {
                border: 1px solid black;
                border-collapse: collapse;
            }

            .mtd {
                border: 1px solid black;
                border-collapse: collapse;
                text-align: right;
            }

            .fsize {
                font-size: 13px;
            }

            td,
            th {
                padding: 0px;
                font-size: 20px;
            }

            /* .padd{
            padding:8px;
        }
        .padd5{
            padding:6px;
        } */
            .border {
                border-top-style: solid;
                border-right-style: solid;
                border-left-style: solid;
                border-bottom-style: none;
                border-width: 1px;
            }

            .border2 {
                border-top-style: solid;
                border-right-style: solid;
                border-left-style: solid;
                border-bottom-style: solid;
                border-width: 1px;
            }

            table {
                width: 100%;
                /* height: 70vh; */
                /*border : 1px solid black;*/
            }

            .center {
                text-align: center;
            }

            .left {
                text-align: left;
            }

            .right {
                text-align: right;
            }

            .page {
                width: 297mm;
                /* width: ; */
                size: A4 landscape;
                /* min-height: 210mm; */
                padding: 10px 0;
                /* margin: 10mm auto; */
                border: 1px #D3D3D3 solid;
                border-radius: 5px;
                background: white;
                margin-top: 0px;
                margin-bottom: 0px;
            }

            .h13 {
                height: 13px;
            }

            .h12 {
                height: 12px
            }
        }
    </style>
    </head>

    <body>
        <div class="book ">

            <?php
            $ctr = 0;
            $status = '';
            while ($pax = mysqli_fetch_assoc($cmain)) {
                $ctr++;

                $gender = $pax['cmbgender'];
                if ($gender == 'M') {
                    $sex = 'MALE';
                } else {
                    $sex = 'FEMALE';
                }
                
                $mstatus = $pax['mstatus'];

                //                calculating age
                if ($pax['dob'] != '0000-00-00') {
                    $dob = strtotime($pax['dob']);
                    $tdate = strtotime(date('Y-m-d'));

                    $diff = abs($tdate - $dob);

                    $years = floor($diff / (365 * 60 * 60 * 24));
                    $month = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
                }

                $lblctr++;

                if ($lblctr == 1) {
                    echo "<div class='page' style=''>";
                }
            ?>
                <? if ($ctr == 1) { ?>
                    <table width="100% ">

                        <tr>
                            <td style="width:7%; "></td>
                            <td style="width:37%;  border: 1px solid black;padding-left: 15px; padding-top:1%;">
                            <? } else { ?>
                            <td style="width:7%; "></td>
                            <td style="width:37%; border: 1px solid black;padding-left: 15px; padding-top:1%;">
                            <? } ?>

                            <!--<div style="border:1px solid black;">-->

                            <!--<h4 align="center"><b style="text-align:center"><u>HEALTH & OPD BOOKLET</u></b></h4>-->
                            <table style="width:65%;float:left;height:25vh;">
                                <tr>
                                    <td class="padd fsize">PAX NO.: <?= $pax['vouchno'] ?>
                                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;REGN. NO.: <?= $pax['vregnno']; ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">PASSPORT NUMBER: <?= $pax['redypass'] ?></td>
                                </tr>

                                <tr>
                                    <td class="padd fsize">NAME: <?= $pax['name']; ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize" style="height: 24px;">GUARDIAN / ACCOMPANYING<br>
                                        PERSON'S NAME:<br>
                                        <?= $pax['surname']. " ". $pax['fhname']; ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">AGE: <?= $years . $months; ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">GENDER: <?= $sex ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">BLOOD GROUP: <?= $pax['bloodgrp']; ?></td>
                                </tr>

                                <tr>
                                    <td class="padd fsize">MARITAL STATUS: <?= $mstatus; ?></td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">CONTACT NUMBER: <?= $pax['tel'] ?>
                                        <?php if ($pax['mobile'] != "") { ?>
                                            / <?= $pax['mobile']; ?>
                                        <?php } ?></td>
                                </tr>
                            </table>

                            <table style="width:24%;float:right;height:25vh;margin-right:10px;">
                               
                                <tr style="height:95px;">
                                    <?php if ($pax["image"] != '') { ?>
                                        <td><img src="<?= $pax["image"] . "?a=" . mt_rand(); ?>" alt="Pilgrim Image" height="95px" width="93px"></td>
                                    <? } else { ?>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;Photograph</td>
                                    <? } ?>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr style="border:1px solid black;height:85px;">
                                    <td><img src=""></td>
                                </tr>
                            </table>
                            
                            <br>

                            <table>
                                <tr>
                                    <td class="padd fsize">ADDRESS OF CORRESPONDENCE: <br>
                                        <?= $pax["add1"] .  " " . $pax["add2"] .  " " . $pax["add3"] .  ", " . $pax["city"] . " - " . $pax["pin"] . ", " . $pax["state"]; ?></td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="padd fsize">EMERGENCY CONTACT DETAILS<br>
                                        (NAME & NUMBER):<br><br>
                                        <?= strtoupper($comp['compname']); ?><br>
                                        <?= $comp['emgcontact'] ?><br>
                                    </td>
                                </tr>
                            </table>

                            <table>
                                <tr>
                                    <td style="width:200px;"></td>
                                    <td style="width:200px; border: 1px solid black;padding-top:50px;float:right; ">
                                      <span style="float: right;">Authorized Signature</span>
                                    </td>
                                </tr>
                            </table>
                            <!--</div>-->
                            </td>


                            <?
                            if ($ctr == 2) {
                                echo "<td>";
                                echo "&nbsp;";
                                echo "</td>";
                                echo "</tr>";
                                echo "</table>";
                                //                                echo "<br>";
                                $ctr = 0;
                            }
                            if ($lblctr == 2) {
                                $lblctr = 0;
                                echo "</div>";
                            }
                            ?>
                            <br>
                        <?php
                        $status = '';
                    }
                    if (($paxno % 2) == 1) {
                        ?>

                            <!--                    <td style="width:10%"></td>
                            <td style="width:35%;">&nbsp;</td>-->
                        <?
                    }
                    echo "</div>";
                        ?>
        </div>
        <?php include("includes/linksfoot.php"); ?>
    </body>

    </html>
<?php
}
?>