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

$formname = 'Visa Entry';
$maindb = 'visamain';
$trandb = 'visatran';
$printfile = "";
$file = 'visaedit.php';
$trandbexist = 0;
$grid = 'visa.php';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
$mgrpcode = '009';

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

mysqli_select_db($conn,$zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["exit"])) {
//    header("location:javascript://history.go(-1)");
    header("refresh: 1; $grid?mode=last");
}
if (isset($_POST["submit"])) {

    $a = 1;
    $vouchdt = $_POST["vouchdt"];
    IF (!empty($_POST["leadvouch"])) {
        $leadvouch = $_POST["leadvouch"];
    } ELSE {
        $leadvouch = 0;
    }

    $name = mysqli_real_escape_string($conn,$_POST["name"]);
    $lastname = mysqli_real_escape_string($conn,$_POST["lastname"]);
    $destination = $_POST["destination"];
    $mob = $_POST["mobile"];
    $email = $_POST["email"];
    $travdate = $_POST["travdate"];
    $package = $_POST["package"];
    $adult = $_POST["adult"];
    $child = $_POST["child"];
    $infant = $_POST["infant"];
    $semiinf = $_POST["semiinf"];
    $totpax = $_POST["totpax"];
    $remarks = $_POST["remarks"];
    $status = $_POST["status"];
    $imagetkn = $_POST["imagetkn"];
    $visadone = $_POST["visadone"];
    $nopass = $_POST["nopass"];
    $visasts = $_POST["visasts"];
    $passcopy = $_POST["passcopy"];
    $passorig = $_POST["passorig"];
    $username = $_SESSION["username_" . $dbname];
    $cancresn = $_REQUEST["cancresn"];
    $okboard  = $_REQUEST["okboard"];
    $count = $_POST["items"];

    mysqli_query($conn,"DELETE FROM `$trandb` WHERE vouchno='$qvouch'") or die(mysqli_error($conn));

    $cnt = 0;
    $cntamt = 0;

    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $mgivename = $_POST["givename_$i"];
        $mlastname = $_POST["lastname_$i"];
        $passport = $_POST["passport_$i"];
        $passorig = $_POST["passorig_$i"];
        switch ($passorig) {
            case '0':
                $pastatus = 1;
                break;
            case '1':
                $pastatus = 0;
                break;
            case '2':
                $pastatus = 1;
                break;
            case '3':
                $pastatus = 1;
                break;
            case '4':
                $pastatus = 2;
                break;
            default:
                break;
        }
//        $pastatus = $_POST["pastatus_$i"];
        if (!empty($mgivename)) {
            mysqli_query($conn,"INSERT INTO `$trandb`(`vouchno`, `vouchdt`, leadvouch, srno, `givename`, `lastname`, `passport`, `passorig`, `pastatus`)
                                        VALUES('$qvouch', '$vouchdt', $leadvouch, '$msrno', '$mgivename', '$mlastname', '$passport', '$passorig', '$pastatus')") or die(mysqli_error($conn));
        }
    }

    if (!empty($cancresn)) {
        mysqli_query($conn,"UPDATE `visamain` SET `cancresn`='$cancresn',`status`='$status' WHERE `vouchno`='$qvouch'")or die(mysqli_error($conn));
    }

    if (!empty($okboard)) {
        mysqli_query($conn,"UPDATE `visamain` SET `okboard`='$okboard',`status`='$status'  WHERE `vouchno`='$qvouch'")or die(mysqli_error($conn));
    }

    if ($a == 1) {
        if ($addflag == 1) {
            mysqli_query($conn,"INSERT INTO `$maindb`(vouchno, `vouchdt`, `name`, `lastname`, `destination`, `mobile`, `deptdate`, `adult`, `child`, `infant`
                                              , `semiinf`, `totpax`, `remarks`, `status`, `imagetkn`, `visadone`, `username`, `nopass`,
                                              `package`, `visasts`, `passcopy`, `email` )
                                        VALUES('$qvouch', '$vouchdt', '$name', '$lastname', '$destination', '$mob', '$travdate', '$adult', '$child', '$infant'
                                              , '$semiinf', '$totpax', '$remarks', '$status', '$imagetkn', '$visadone', '$username', '$nopass',
                                              '$package', '$visasts', '$passcopy', '$email')") or die(mysqli_error($conn));
            insmess();
            header("refresh: 1; $grid?mode=last");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn,"UPDATE `$maindb` SET `vouchdt`='$vouchdt', `name`='$name',  `lastname`='$lastname', `destination`='$destination', mobile= '$mob', 
                        `deptdate`='$travdate', `adult`='$adult', `child`='$child', infant='$infant', `semiinf`='$semiinf', `totpax`='$totpax', 
                        `remarks`='$remarks', `status`='$status', `imagetkn`='$imagetkn', `leadvouch`='$leadvouch', `visadone`='$visadone', 
                        `nopass`='$nopass', `email`='$email', `package`='$package', `visasts`='$visasts', `passcopy`='$passcopy'
                         where vouchno = '$mvouch' ") or die(mysqli_error($conn));

            updmess();
//        header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
//            header("refresh: 1; $grid");
        }
    }
}

if ($addflag != 1) {

    $rowvouch = '';
    if ($addflag == 0) {
        $rowvouch = $_GET[$keyfld];
    } else {
        $rowvouch = $qvouch;
    }

    $result = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE $keyfld='$rowvouch' ") or die(mysqli_error($conn));
    $row = mysqli_fetch_array($result);
}

$senable = "";
$cenable = "";


if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("includes/linkshead.php");
?>
<script type="text/javascript" src="MyScript/webcam.js"></script>
<script src="MyScript/visaedit.js?" type="text/javascript"></script>
<script type="text/javascript">
    $(document).keydown(function (event) {
        //19 for Mac Command+S
        if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.altKey) && !(event.which == 19))
            return true;
        //alert("Ctrl-s pressed");
        $("#submit").click();
        event.preventDefault();
        return false;
    });

    $(document).keydown(function (event) {
        //19 for Mac Command+S
        if (!(String.fromCharCode(event.which).toLowerCase() == 'c' && event.altKey) && !(event.which == 19))
            return true;
        //alert("Ctrl-s pressed");
        $("#exit").click();
        event.preventDefault();
        return false;
    });
</script>
</head>
<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <!--<i class="fa fa-times"></i>-->
                        </div> 
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="hidden" class="form-control" id="leadvouch" name="leadvouch" value="<?php Echo ($addflag != 1) ? $row["leadvouch"] : ""; ?>" readonly>
                                <input type="text" class="form-control " id="vouchno" name="vouchno" value="<?php Echo ($addflag != 1) ? $row["vouchno"] : "$qvouch"; ?>" readonly>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2" style="padding-left: 0px;">
                                <input type="date" class="form-control" name="vouchdt" value="<?php Echo ($addflag != 1) ? $row["vouchdt"] : date('Y-m-d'); ?>" >
                            </div> 
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Mobile</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control mobile" style="width:129px;" autofocus="" name="mobile" value="<?php Echo ($addflag != 1) ? $row["mobile"] : ""; ?>" <?php if ($addflag != 1) { ?> readonly <?php } ?>>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Travel Date</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="date" class="form-control" style="width:150px;" name="travdate" value="<?php Echo ($addflag != 1) ? $row["deptdate"] : ""; ?>" <?php if ($addflag != 1) { ?> readonly <?php } ?>>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Name</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control name" name="name" value="<?php Echo ($addflag != 1) ? $row["name"] : ""; ?>" <?php if ($addflag != 1) { ?> readonly <?php } ?>>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Last Name</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control lastname" name="lastname" value="<?php Echo ($addflag != 1) ? $row["lastname"] : ""; ?>" <?php if ($addflag != 1) { ?> readonly <?php } ?>>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Destination</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <select name="destination" class="form-control destination select2">
                                    <option value="<? Echo ($addflag != 1 ) ? $row[destination] : "" ?>"><? Echo ($addflag != 1 ) ? $row[destination] : "" ?></option>
                                    <?
                                    $rowdest = mysqli_query($conn,"SELECT * FROM `destination` order by `name`")or die(mysqli_error($conn));
                                    while ($mdest = mysqli_fetch_array($rowdest)) {
                                        Echo "<option value='$mdest[name]'>$mdest[name]</option>";
                                    }
                                    ?>
                                </select>

                                            <!--<input type="text" class="form-control destination" name="destination" value="<?php Echo ($addflag != 1) ? $row["destination"] : ""; ?>" readonly>-->
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Type</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <select name='package' id="package"  class="package form-control select2" style='text-align: center;height:33px;width:150px;'>
                                    <option value=""></option>
                                    <option value='P'<?php
                                    if ($addflag != 1) {
                                        if ($row["package"] == "P") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?> >Package</option>
                                    <option value='N'<?php
                                    if ($addflag != 1) {
                                        if ($row["package"] == "N") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Non Package</option>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Client Status</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <select  name='status' id="status"  class="status form-control select2" style='height:33px;'>
                                    <option value='0'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "0") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?> >Still to Speak</option>
                                    <option value='1'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "1") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Requirement to be Given</option>
                                    <option value='2'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "2") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Requirement Given - Follow up</option>
                                    <option value='3'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "3") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Copy Collected</option>
                                    <option value='4'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "4") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Original Collected</option>
                                    <option value='5'<?php
                                    if ($addflag != 1) {
                                        if ($row["status"] == "5") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Cancelled</option>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Image Taken</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <select name='imagetkn' id="imagetkn"  class="imagetkn form-control  select2" style='text-align: center;height:33px;width:100px;'>
                                    <option value='NO'<?php
                                    if ($addflag != 1) {
                                        if ($row["imagetkn"] == "NO") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?> >No</option>
                                    <option value='YES'<?php
                                    if ($addflag != 1) {
                                        if ($row["imagetkn"] == "YES") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Yes</option>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Remarks</label>
                            </div>
                            <div class="col-lg-3 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control " name="remarks" value="<?php Echo ($addflag != 1) ? $row["remarks"] : ""; ?>" >

                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Adult</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control adult" style="text-align: right;" name="adult" value="<?php Echo ($addflag != 1) ? $row["adult"] : "0"; ?>" >
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Child</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" style="text-align: right;" class="form-control child" name="child" value="<?php Echo ($addflag != 1) ? $row["child"] : "0"; ?>" >
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Infant</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" style="text-align: right;" class="form-control infant" name="infant" value="<?php Echo ($addflag != 1) ? $row["infant"] : "0"; ?>" >
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Semi Inf</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" style="text-align: right;" class="form-control semiinf" name="semiinf" value="<?php Echo ($addflag != 1) ? $row["semiinf"] : "0"; ?>" >
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label style="color: red;" class="label-control marg">Total</label>
                            </div>
                            <div style="color: red;" class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text"  style="color: red;background-color: #E7E7E7;text-align: right;" class="form-control totpax" name="totpax" value="<?php Echo ($addflag != 1) ? $row["totpax"] : "0"; ?>" readonly>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Party Status Copy</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                <select  name='passcopy' id="passcopy"  class="passcopy form-control select2" style='height:33px;'>
                                    <option value='0'<?php
                                    if ($addflag != 1) {
                                        if ($row["passcopy"] == "0") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?> >Copy Received(Login Pending)</option>
                                    <option value='1'<?php
                                    if ($addflag != 1) {
                                        if ($row["passcopy"] == "1") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Login Done</option>
                                    <option value='2'<?php
                                    if ($addflag != 1) {
                                        if ($row["passcopy"] == "2") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Approved</option>
                                    <option value='3'<?php
                                    if ($addflag != 1) {
                                        if ($row["passcopy"] == "3") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Sent</option>
                                    <option value='4'<?php
                                    if ($addflag != 1) {
                                        if ($row["passcopy"] == "4") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Billed</option>
                                </select>
                            </div>
                            <div class="row">
                                <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                    <label class="label-control marg">No. of Passports</label>
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                    <input type="number" class="form-control passports" style="text-align: right;" name="nopass" value="<?php Echo ($addflag != 1) ? $row["nopass"] : "0"; ?>" >
                                </div>
                                <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                    <label class="label-control marg">Email Id</label>
                                </div>
                                <div class="col-lg-3 col-md-1 col-sm-1 col-xs-1 pad">
                                    <input type="text" class="form-control email" style="text-align: right;" name="email" value="<?php Echo ($addflag != 1) ? $row["email"] : ""; ?>" >
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table id="data" align="center" border="1px" width="100%" class="table-bordered">
                                    <thead>
                                        <tr>
                                            <th width="10%" style="font-family: arial-regular;color:black;" align="center"><label class="control-label">Sr.</label></th>
                                            <!--<th width="40%" style="font-family: arial-regular;color:black;" align="center"><label class="control-label">Pax Name</label></th>-->
                                            <th width="20%" style="font-family: arial-regular;color:black;" align="center"><label class="control-label">Given Name</label></th>
                                            <th width="20%" style="font-family: arial-regular;color:black;" align="center"><label class="control-label">Last Name</label></th>
                                            <th width="10%" style="font-family: arial-regular;color:black;" align="center"><label class="control-label">Passport No.</label></th>
                                            <th width="20%" align="center" style="text-align:center;color:black;font-family: arial-regular;"><label class="control-label">Image</label></th>
                                            <th width="20%" align="center" style="text-align:center;color:black;font-family: arial-regular;"><label class="control-label">Party Status Original</label></th>
                                            <!--<th width="10%" align="right" style="text-align:right;color:black;font-family: arial-regular;"><label class="control-label">Image</label></th>-->
                                        </tr>
                                    </thead>

                                    <?php
                                    if ($addflag != 1) {
                                        $qry = mysqli_query($conn,"SELECT * FROM  `$trandb` WHERE vouchno='$qvouch' ORDER BY srno") or die(mysqli_error($conn));
                                        $rowqry = mysqli_num_rows($qry);
                                        $ctr = 0;

                                        if ($rowqry > 0) {
                                            while ($row = mysqli_fetch_array($qry)) {
                                                $rowimg = mysqli_query($conn,"SELECT * FROM `chalimage` WHERE `vouchno`='$row[vouchno]' and `passport`='$row[passport]'")or die(mysqli_error($conn));
                                                $img = mysqli_fetch_array($rowimg);
                                                $imgpath = $img[imgpath];
                                                $imgpath1 = $img[imgpath1];


                                                echo "<tr>";
                                                echo "<td style='height:30px;' align='left' valign='center'><input type='text' size='6' maxlength='6' name='srno_" . $ctr . "' class='srno form-control' style='height:29px;' value='$row[srno]'/></td>";
//                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='paxname_$ctr' class='paxname form-control' style='height:29px;text-align:left;' value='$row[paxname]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='givename_$ctr' class='givename form-control' style='height:29px;text-align:left;' value='$row[givename]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='lastname_$ctr' class='lastname form-control' style='height:29px;text-align:left;' value='$row[lastname]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size='' id='passport'  name='passport_$ctr' class='passport form-control' id='passport' style='height:29px;text-align:left;' value='$row[passport]'/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'>";
                                                ?>
                                                <button type="button" class="btn btn-primary btn-square challanupload1 passUploader" name="challanupload1_<?= $ctr ?>">
                                                    <i class="fa fa-cloud-upload"></i>&nbsp;&nbsp;&nbsp;Image Upload  - View 
                                                </button>
                                                <?php
                                                echo "</td>";
                                                echo "<td>";
                                                ?>
                                                <select  name='passorig_<?= $ctr ?>' id="passorig"  class="passorig form-control select2" style='height:33px;'>
                                                    <option value='0'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "0") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?> >Document Pending</option>
                                                    <option value='1'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "1") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Sent to Supplier</option>
                                                    <option value='2'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "2") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Visa Done(PP Recd.)</option>
                                                    <option value='3'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "3") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Visa Rejected(PP Recd.)</option>
                                                    <option value='4'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "4") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Passport Hand Over</option>
                                                </select>
                                                <?php
                                                echo "</td>";
                                                echo "</tr>";
                                                $ctr++;
                                            }
                                        } else {
                                            $pctr = 0;
                                            $yctr = 0;
                                            for ($i = $pctr; $i < 6; $i++) {
                                                $yctr++;
                                                echo "<tr>";
                                                echo "<td style='height:30px;' align='left' valign='center'><input type='text' size='6' maxlength='6' name='srno_$pctr' class='sno form-control' style='height:29px;' value='$yctr'/></td>";
//                                                echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='paxname_$pctr' class='paxname form-control' style='height:29px;text-align:left;' value='' /></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='givename_$pctr' class='givename form-control' style='height:29px;text-align:left;' value=''/></td>";
                                                echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='lastname_$pctr' class='lastname form-control' style='height:29px;text-align:left;' value=''/></td>";
                                                echo "<td align='center' style='height:30px;' valign='center'><input type='text' size='' id='passport'  name='passport_$pctr' class='passport form-control' style='height:29px;text-align:left;' value='' /></td>";
                                                echo "<td align='center' style='height:30px;' valign='center'>";
                                                ?>
                                                <button type="button" class="btn btn-primary btn-square challanupload1 passUploader" name="challanupload1_<?= $pctr ?>">
                                                    <i class="fa fa-cloud-upload"></i>&nbsp;&nbsp;&nbsp;Image Upload  - View
                                                </button>
                                                <?php
                                                echo"</td>";
                                                echo "<td>";
                                                ?>
                                                <select  name='passorig_<?= $pctr ?>' id="passorig"  class="passorig form-control select2" style='height:33px;'>
                                                    <option value='0'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "0") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?> >Document Pending</option>
                                                    <option value='1'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "1") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Sent to Supplier</option>
                                                    <option value='2'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "2") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Visa Done(PP Recd.)</option>
                                                    <option value='3'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "3") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Visa Rejected(PP Recd.)</option>
                                                    <option value='4'<?php
                                                    if ($addflag != 1) {
                                                        if ($row["passorig"] == "4") {
                                                            echo "selected='selected'";
                                                        }
                                                    }
                                                    ?>>Passport Hand Over</option>
                                                </select>
                                                <?php
                                                echo "</td>";
                                                echo "</tr>";
                                                $pctr++;
                                            }
                                        }
                                    } else {
                                        $pctr = 0;
                                        $yctr = 0;
                                        for ($i = $pctr; $i < 6; $i++) {
                                            $yctr++;
                                            echo "<tr>";
                                            echo "<td style='height:30px;' align='left' valign='center'><input type='text' size='6' maxlength='6' name='srno_$pctr' class='sno form-control' style='height:29px;' value='$yctr'/></td>";
//                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size=''  name='paxname_$pctr' class='paxname form-control' style='height:29px;text-align:left;' value='' /></td>";
                                            echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='givename_$pctr' class='givename form-control' style='height:29px;text-align:left;' value=''/></td>";
                                            echo "<td style='height:30px;' align='center' valign='center'><input type='text' size=''  name='lastname_$pctr' class='lastname form-control' style='height:29px;text-align:left;' value=''/></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'><input type='text' size='' id='passport'  name='passport_$pctr' class='passport form-control' style='height:29px;text-align:left;' value='' /></td>";
                                            echo "<td align='center' style='height:30px;' valign='center'>";
                                            ?>
                                            <button type="button" class="btn btn-primary btn-square challanupload1 passUploader" name="challanupload1_<?= $pctr ?>">
                                                <i class="fa fa-cloud-upload"></i>&nbsp;&nbsp;&nbsp;Image Upload  - View
                                            </button>
                                            <?php
                                            echo"</td>";
                                            echo "<td>";
                                            ?>
                                            <select  name='passorig_<?= $pctr ?>' id="passorig"  class="passorig form-control select2" style='height:33px;'>
                                                <option value='0'>Document Pending</option>
                                                <option value='1'>Sent to Supplier</option>
                                                <option value='2'>Visa Done(PP Recd.)</option>
                                                <option value='3'>Visa Rejected(PP Recd.)</option>
                                                <option value='4'>Passport Hand Over</option>
                                            </select>
                                            <?php
                                            echo "</td>";

                                            echo "</tr>";
                                            $pctr++;
                                        }
                                    }
                                    ?>
                                </table>
                                <!--                        <label class="control-label col-lg-3"></label>
                                                        <div class="col-lg-8">
                                                            <button class="btn btn-lg btn-success form" data-toggle="modal" data-target=".slacker-modal" style="width: 100%;">Detail</button>
                                                        </div>-->
                            </div>
                            <div class="form-group" style="padding-left: 13px;">
                                <input type="button" style="height: 30px; width: 30px; padding: 0px" id="addnew" class="btn btn-success btn-lg" accode="addnew2" value="+" />
                                <?php
                                if ($rowqry > 0) {
                                    ?>
                                    <input type="hidden" id="items" name="items" value="<?php echo $ctr ?>" />  
                                    <?php
                                } else {
                                    ?>
                                    <input type="hidden" id="items" name="items" value="<?php echo $yctr; ?>" />  
                                    <?php
                                }
                                ?>
<!--<input type="hidden" id="items" name="items" value="<?php // echo ($addflag != 1) ? $ctr : 1;                                                                     ?>" />-->  

                            </div>
                        </div>
                        <div style="padding-left: 40%;" class="panel-footer">
                            <input type="submit"  name="submit" id="submit" value="Update" class="btn btn-success" >
                            <input type="submit" name="exit" value="Exit" id="exit" class="btn btn-danger" onclick="">
                            <?php // include("includes/buttons.php");       ?>
                        </div>
                        <!--                        <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                                <h4 class="modal-title" id="myModalLabel">Challan Upload & Download</h4>
                                                            </div>
                                                            <div class="modal-body">
                                                                <div class="row">
                                                                    <div class="col-lg-12 upload">
                                                                        <p>To Download Right Click And Click On Save As..</p>
                                                                        <form id="upload_form" enctype="multipart/form-data" method="post">
                                                                            <div class="col-lg-12">
                                                                                <span class="btn btn-default btn-file btn-square btn-warning">
                                                                                    Choose File <input type="file" name="file1" id="file1">
                                                                                </span>
                                                                                <input type="hidden" name="evouchno" id="evouchno" value='<?php Echo ($addflag != 1) ? $row['vouchno'] : "$qvouch"; ?>'>
                                                                                <input type="hidden" name="epassno" id="epassno"  value="<?php Echo $row[passport]; ?>">
                                                                                <input type="button" value="Upload File" class="btn btn-square" style="background-color: #C0CA33; color: white" id="uploadbtn">
                                                                                <input type="button" value="Delete File" class="btn btn-square btn-danger" id="deletebtn">
                                                                                <a href="" class="btn btn-primary btn-square print_image" target="_blank">Print Challan</a>
                                                                            </div>
                                                                            <div class="col-lg-12">
                                                                                <div class="progress">
                                                                                    <progress id="progressBar" class="progress-bar"  role="progressbar" value="0" max="100" style="width:100%;color: red;"></progress>
                                                                                </div>
                                                                                <h3 id="status"></h3>
                                                                                <p id="loaded_n_total"></p>
                                                                            </div>
                                                                        </form>
                                                                    </div>
                                                                    <div class="col-lg-6 upload">
                                                                        <img id="preview" src="#" alt="your image" />
                                                                    </div>
                                                                    <div class="col-lg-12 mview">
                                                                        <img  src="<?php Echo ($addflag != 1) ? $img[imgpath] : ''; ?>" alt="Passport Image" id="mpreview" />
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>-->
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal"><span>&times;</span></button>
                        <h4 class="modal-title" id="myLargeModalLabel"></h4>
                    </div>
                    <!--<input type='button' style="float: right;" name='exit' value='Exit' class="btn btn-danger" onClick="window.location.href = '<? Echo $file; ?>'">-->
                    <!--<button style="float: right;" type='submit' name='update' value='Update' class="btn btn-success">-->
                    <div class="container">
                        <button id='submit'  type='submit' name='submit' value='Update' class="btn btn-success">Save</button> 
                    </div>
                    <div class="modal-body">
                        <div class="table-responsive">
                            <table>
                                <tr id="tr1">
                                    <td><label class="label-control marg">Reason</label></td>
                                    <!--<td><input type="text" name="cancresn" id='cancresn' placeholder="" value="<?php // echo ($addflag != 1) ? $row['cancresn'] : "";                 ?>" style="width:300px;" class="form-control reason"></td>-->
                                    <td>
                                        <select class="form-control select2 cancresn"  autofocus="" name="cancresn" style="width:300px;">
                                            <option value="<? Echo ($addflag != 1 ) ? $row[cancresn] : "" ?>"><? Echo ($addflag != 1 ) ? $row[cancresn] : "" ?></option>
                                            <?
                                            $rowsource = mysqli_query($conn,"SELECT * FROM `reason` order by `code` desc")or die(mysqli_error($conn));
                                            while ($msource = mysqli_fetch_array($rowsource)) {
                                                Echo "<option value='$msource[name]'>$msource[name]</option>";
                                            }
                                            ?>
                                        </select>

                                    </td>
                                </tr>
                                <tr id="tr2">
                                    <td><label class="label-control marg">Ok To Board</label></td>
                                    <!--<td><input type="text" name="cancresn" id='cancresn' placeholder="" value="<?php // echo ($addflag != 1) ? $row['cancresn'] : "";                 ?>" style="width:300px;" class="form-control reason"></td>-->
                                    <td>
                                        <select class="form-control select2 okboard"  autofocus="" name="okboard" style="width:150px;">
                                            <option></option>
                                            <option value='0'<?php
                                            if ($addflag != 1) {
                                                if ($row["okboard"] == "0") {
                                                    echo "selected='selected'";
                                                }
                                            }
                                            ?> >Not Required</option>
                                            <option value='1'<?php
                                            if ($addflag != 1) {
                                                if ($row["okboard"] == "1") {
                                                    echo "selected='selected'";
                                                }
                                            }
                                            ?>>Done</option>
                                            <option value='2'<?php
                                            if ($addflag != 1) {
                                                if ($row["okboard"] == "2") {
                                                    echo "selected='selected'";
                                                }
                                            }
                                            ?>>Pending</option>
                                        </select>

                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer"></div>
                </div>
            </div>
        </div>
    </form>
    <form id="upload_form" enctype="multipart/form-data" method="post">
        <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Passport Upload & Download</h4>
                    </div>
                    <div class="modal-body" style="height: 900px">
                        <div class="row">
                            <div class="col-lg-2 col-sm-2 pad text-right">
                                <label class="label-control marg">Select Image Type</label>
                            </div>
                            <div class="col-lg-2 col-sm-2 pad">
                                <select class="form-control select2 snapType" id="snapType" name="snapType" style="width:100%">
                                    <option value="0"></option>
                                    <option value="F">Front</option>
                                    <option value="B">Back</option>
                                    <option value="M">Miscellaneous</option>
                                </select>
                                <input type="hidden" id="snapVouch" >
                                <input type="hidden" id="snapGive" >
                                <input type="hidden" id="snapLast" >
                                <input type="hidden" id="snapPass" >
                            </div>
                            <div class="col-lg-2 col-sm-2 pad">
                                <input type="button" class="btn btn-primary snapShot" value="Take Snapshot" style="width: 100%">
                            </div>
                            <div class="col-lg-2 col-sm-2 pad">
                                <input type="button" class="btn btn-primary snapUpload" value="Upload"  style="width: 100%">
                            </div>
                            <div class="col-lg-4 col-sm-2 pad">
                                <h3 id="mstatus">

                                </h3>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6 col-sm-6 pad">
                                <div id="my_camera"></div>
                            </div>
                            <div class="col-lg-6 col-sm-6 pad">
                                <div id="results" style="height: 500px;width: 500px;border: 1px solid black"></div>
                            </div>
                        </div>
                        <div class="row snapImages">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
