<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');
header("Content-Type: text/html;charset=UTF-8");

$formname = 'Submission';
$maindb = 'visamain';
$trandb = 'visatran';
$file = 'submission.php';
//$printfile = 'crmlist.php';
$keyfld = "myvouch";
$myyear = $_SESSION["tit_" . $dbname];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$username = $_SESSION["username_" . $dbname];
$zroot = $_SESSION["zdir"];
//$modet = $_GET["mode"];
mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");
if (isset($_POST["submit"])) {
    $a = 1;

    $vouchdt = $_POST["vouchdt"];
    $count = $_POST["items"];
//    $myvouch = $_POST["myvouch"];
//    browse($myvouch);

    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$trandb` WRITE");

        for ($i = 0; $i <= $count; $i++) {
            $cnt++;
            $srno = $_POST["srno"][$i];
            $paxname = $_POST["paxname"][$i];
            $passport = $_POST["passport"][$i];
            $submission_date = $_POST["submission_date"][$i];
            $manualno = $_POST["manualno"][$i];
            $myvouch = $_POST["myvouch"][$i];
//            browse($myvouch);

            mysqli_query($conn, "UPDATE `$trandb` SET  `submission_date`='$vouchdt' where `myvouch` = '$myvouch' and passport = '$passport'") or die(mysqli_error($conn));

//            if (!empty($paxname)) {
//                mysqli_query($conn, "INSERT INTO `$trandb`(`myvouch`, `yearno`, `visatype`, `vouchno`, `vouchdt`, `srno`, `paxname`, `passport`)
//                                        VALUES ('$mvouch','$myyear','$visatype','$vouchno','$vouchdt','$cnt','$paxname','$passport')") or die(mysqli_error($conn));
//            }
        }
    }
    mysqli_query($conn, "UNLOCK TABLES");
    browse("Submission Date Updated");
}



if ($addflag != 1) {

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

    mysqli_query($conn, "SET NAMES 'utf8'");
    mysqli_query($conn, 'SET CHARACTER SET utf8');
    $result = mysqli_query($conn, "SELECT *, date_format(`vouchdt`,'%d-%m-%Y') as mydt FROM `$maindb` WHERE $keyfld='$getvouch'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}

if (isset($_GET["delete"])) {

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

include("includes/linkshead.php");
?>
<script>
    $(document).ready(function () {
    $("body").on("blur", ".passport", getPass);

    function getPass() {
        var tr = $(this).closest("tr"),
                passport = tr.find(".passport").val(),
                data = {passport: passport};
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: "get_ppdetail.php",
            data: data,
            success: function (response) {
                if (response != '') {
                    $.each(response, function () {
                        var success = this.success;
                        if (success == false) {
                            alert("Passport No. Invalid ");
                            tr.find(".passport").val("");
                            tr.find(".passport").focus();
                        } else {
                            tr.find(".paxname").val(this.paxname);
                            tr.find(".submission_date").val(this.submission_date);
                            tr.find(".manualno").val(this.manualno);
                            tr.find(".myvouch").val(this.myvouch);
                            
                        }
                        if (response.submission_date != '0000-00-00' && response.submission_date != 'null') {
                        $(".submission_date").css("color", "red");
                    } else {
                        $(".submission_date").css("color", "black");
                    }
                    });
                } 
            }
        });
    }
    
        
        $("#hprint").hide();
        $("#search").hide();
        $("#edit").hide();
        $("#hprevious").hide();
        $("#hnext").hide();
        $("#hdelete").hide();
    });
</script>
<script src="MyScript/submission.js"  type="text/javascript"></script>   


</head>
<body>
    <form action='' method='POST'  enctype="multipart/form-data" accept-charset="utf-8">
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-6" >
                <div class="panel panel-default" >
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <?php Echo $formname; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<!--                            <span style="color: #5D96E4;font-size: 11px">
                                (Alt+T &nbsp;&nbsp;-&nbsp;&nbsp; New Visa Type)</span>-->
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">

                            <div class="col-lg-2 col-md-3 col-sm-1 col-xs-1 text-right pad "style="">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-2 pad" style="" >
                                <input type="date" class="form-control form vouchdt" name="vouchdt"  value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" required>
                            </div>
                        </div>
                    </div>
                    <div class="pax_d" >
                            <div class="table-responsive">
                                <table class="  table-striped table-condensed table-bordered table-fixed-top" width="100%">
                                    <thead  class="mySearchTr">
                                        <tr>
                                            <th style="width: 1%;"></th>
                                            <th style="width: 2%;">Sr.</th>
                                            <th style="text-align:center ; width: 4%">Passport</th> 
                                            <th style="width: 15% ;  text-align:center">Pax Name</th>
                                            <th style="width: 15% ;  text-align:center">Submission Date</th>
                                            <th style="width: 15% ;  text-align:center">File</th>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody">
                                            <tr class='colrrow'>                                    
                                                <td><i class='fa fa-close remove form-control form'></i></td>
                                                <td><input type='text' name='srno[]' class='srno form-control form' value='1'></td>
                                                <td>
                                                    <input type='text' name='passport[]'  class='passport form-control  form' value='' >
                                                </td>
                                                <td>
                                                    <input type='text' name='paxname[]'  class='paxname form-control  form' readonly value='' >
                                                </td>
                                                <td>
                                                    <input type='text' name='submission_date[]'  class='submission_date form-control  form' readonly value='' >
                                                </td>
                                                <td>
                                                    <input type='text' name='manualno[]'  class='manualno form-control  form' readonly value='' >
                                                    <input type='hidden' name='myvouch[]'  class='myvouch form-control  form' readonly value='' >
                                                </td>
                                            <?php
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                            <div>
                                <button type='button'  class='btn btn-success btn-square form'  id='addnew'>
                                    <i class='fa fa-plus' style='color:#ffffff' data-toggle='tooltip' title='Add Row'></i>    
                                </button>
                                <input type='hidden' name='items' id="items" class='items form-control form' value="<?php Echo ($addflag != 1) ? $ctr : 1; ?>" >
                            </div>
                        </div>

                    <div class="panel-footer">
                        <? include("includes/buttons.php"); ?>
                    </div>
                </div>
            </div>
        </div>
    </form>

  <div class="modal fade bs-example-modal-lg searchModal" 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">Search <? Echo $formname; ?></h4>
                            </div>
                            <div class="modal-body">
                                <div class="row">
                                    <div class="col-lg-2">
                                        <select class="form-control sfield">
                                            <!--<option value="1">Code</option>-->
                                            <option value="1">Date</option>
                                            <option value="2">Name</option>
                                            <option value="3">Email Id</option>
                                            <option value="4">Mobile No.</option>
                                            <option value="5">Passport No.</option>
                                            <option value="6">Job Category</option>
                                            <option value="7">Education</option>
                                            <option value="8">Remarks</option>
                                        </select>
                                    </div>
                                    <div class="col-lg-2">
                                        <select class="form-control soperator">
                                            <option value="">Type of Search</option>
                                            <option value="%">Like</option>
                                            <option value="=">Exactly</option>
                                        </select>
                                    </div>
                                    <div class="col-lg-2">
                                        <select class="form-control sortBy">
                                            <option value="">Sort By</option>
                                            <option value="1">Date</option>
                                            <option value="2">Name</option>
                                            <option value="3">Email Id</option>
                                            <option value="4">Mobile No.</option>
                                            <option value="5">Passport No.</option>
                                            <option value="6">Job Category</option>
                                            <option value="7">Education</option>
                                            <option value="8">Remarks</option>
                                        </select> 
                                    </div>
                                    <div class="col-lg-2">
                                        <select class="form-control orderAs">
                                            <option value="asc">Asc</option>
                                            <option value="desc">Desc</option>
                                        </select>
                                    </div>
                                    <div class="col-lg-2">
                                        <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                                    </div>
                                    <div class="col-lg-2">
                                        <input type="button" class="btn btn-primary sload" value="Search" >
                                    </div>
                                </div>
                                <div class="col-lg-12 sloader text-center">
                                    <!--<img src="images/search.gif" alt="loading">-->       
                                </div>
                                <div class="col-lg-12 snoRecord text-center">
                                    <h3>NO RECORDS FOUND</h3>
                                </div>
                                <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                                    <table  class="table table-striped table-condensed table-bordered" width="100%">
                                        <thead>
                                            <tr class="mySearchTr">
                                                <th width="6%">Date</th>
                                                <th width="15%">Name</th>
                                                <th width="6%">Email Id</th>
                                                <th width="7%">Mobile No.</th>
                                                <th width="9%">Passport No.</th>
                                                <th width="10%">Job Category</th>
                                                <th width="10%">Education</th>
                                                <th width="10%">Remarks</th>
                                                <th width="1%">Action</th>
                                            </tr>
                                        </thead>
                                        <tbody class="sTbody">
                                        </tbody>
                                    </table>
                                </div>
                                <div class="row">
                                    <div class="col-xs-12 text-right search-action-bar">
                                        <input type="button"  class="btn btn-primary sprev" value="Previous">
                                        <input type="button"  class="btn btn-primary snext" value="Next">
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer"></div>
                        </div>
                    </div>
                </div>
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>
