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

$maindb = "passimage";
$formname = "Passport Images";
$file = "passimgreg.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];
mysqli_select_db($conn,$zdb);

if (isset($_POST["view"])) {
    $passno     = $_POST[passno];
    $name       = $_POST[name];
    $lastname   = $_POST[lastname];
    
    $namecond = "";
    if (!empty($name)) {
        $namecond = " AND `name` LIKE '%$name%' ";
    }
    $lastcond = "";
    if (!empty($lastname)) {
        $lastcond = " AND `lastname` LIKE '%$lastname%' ";
    }
    $passcond = "";
    if (!empty($passno)) {
        $passcond = " AND `passno` LIKE '%$passno%' ";
    }

    $getpmain = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `passno`!='' $passcond $namecond $lastcond GROUP BY `passno` ORDER BY `passno`")or die(mysqli_error($conn));

    include("includes/linkshead.php");
    ?>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <table class="table">
                    <tr>
                        <td>
                            <label class="label-control marg">Date - </label>
                            <label class="label-control marg"><?php Echo Date("d-m-Y"); ?></label>
                        </td>
                        <td>
                            <label class="label-control marg">Print - </label>
                            <label class="label-control marg"><?php Echo $formname; ?></label>
                        </td>
                        <td>
                            <a onclick="window.close()" class="btn btn-primary">GO Back</a>
                        </td>
                    </tr>  
                </table>
            </div>
            <div class="col-lg-12 pad">
                <table style="width:100%;background: white" class="table-condensed table-hover table-bordered">
                    <thead>
                        <tr style="height:10px;background-color: #64CCFC">                            
                            <th>Name</th>                                                       
                            <th>Last Name</th>                                                       
                            <th>Passport No.</th>                                                       
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $ctr = 0;
                        while ($pmain = mysqli_fetch_array($getpmain)) {
                            $ctr++;
                            Echo "<tr>";
                            Echo "<td>$pmain[name]</td>";
                            Echo "<td>$pmain[lastname]</td>";
                            Echo "<td>$pmain[passno]</td>";
                            Echo "</tr>";


                            Echo "<tr style='height:10px;'>";
                            Echo "<td colspan='25'>";
                            Echo "<table style='width:100%;' class='table table-condensed table-hover'>";
                            Echo "<th style='background-color: #cccccc;width:10%;'>Type</th>";
                            Echo "<th style='background-color: #cccccc;width:10%;'>Image</th>";
                            Echo "<tr>";

                            $ctr2 = 0;
                            $getpdtl = mysqli_query($conn,"SELECT * FROM `passimage` WHERE `passno`='$pmain[passno]'") or die(mysqli_error($conn));

                            while ($pdtl = mysqli_fetch_array($getpdtl)) {
                                $type = "";
                                if ($pdtl[type] == "F") {
                                    $type = "Front";
                                } elseif ($pdtl[type] == "B") {
                                    $type = "Back";
                                } elseif ($pdtl[type] == "M") {
                                    $type = "Miscellaneous";
                                }

                                $ctr2++;
                                Echo "<tr>";
                                Echo "<td>$type</td>";
                                Echo "<td><img style='width: 150px; height:150px;' src='$pdtl[imgpath]'></td>";
                                Echo "</tr>";
                            }
                            Echo "</table>";
                            Echo "</td>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
        <?php include("includes/linksfoot.php"); ?>
    </body>
    </html>
    <?php
}

if (isset($_POST["excel"])) {
    $name = $_POST[name];
    $gtype = $_POST[gtype];


    $staffcond = "";
    $mtypecond = "";
//    browse($gtype);
    if (!empty($name)) {
        $staffcond = " AND `username`='$name' ";
    }

    if (!empty($gtype)) {
        $mtypecond = " AND `status`='$gtype' ";
    }




    if (empty($_POST["frmdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; leadreg.php");
    }
    $mfrmdate = trim($_POST["frmdt"]);
    $mtodate = trim($_POST["todt"]);



// print "SELECT * FROM `$maindb` WHERE `vouchno`!='' $partyname $broker $transpor $item $godown $mtype";
    $getpmain = mysqli_query($conn,"SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM $maindb where `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate'
             $staffcond $mtypecond")or die(mysqli_error($conn));

    $contents.="Sr,Book No ,Enq Date,Name,Last Name,Destination,Travel Date,Status,Que to Visa,Remark,New Remark\n";

    $ctr = 0;


    while ($pmain = mysqli_fetch_array($getpmain)) {


        $ctr++;

        $exctr = $ctr;
        $exvouchno = $pmain[vouchno];
        $exvouchdt = $pmain[vouchdt];
        $exname = $pmain[name];
        $exlastname = $pmain[lastname];
        $exdestination = $pmain[destination];
        $exdeptdate = $pmain[deptdate];
        $exstatus = $pmain[status];
        $exquotvisa = $pmain[quotvisa];
        $exremarks = $mqty[remarks];
        $exremarks1 = $pmain[remarks1];

        $contents.=$exctr . ",";
        $contents.=$exvouchno . ",";
        $contents.=$exvouchdt . ",";
        $contents.=$exname . ",";
        $contents.=$exlastname . ",";
        $contents.=$exdestination . ",";
        $contents.=$exdeptdate . ",";
        $contents.=$exstatus . ",";
        $contents.=$exquotvisa . ",";
        $contents.=$exremarks . ",";
        $contents.=$exremarks1 . "\n";
    }


    $contents = strip_tags($contents);

//if ($_POST["dtype"] == 1) {
    header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
    print $contents;
//}
}
?>

