<?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 = 'Medical';
$maindb = 'medent';
$file = 'medical.php';
$printfile = 'medical_print.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"];
    $manualno = $_POST["manualno"];
    $partyname = $_POST["partyname"];
    $broker = $_POST["broker"];
    $mobile = $_POST["mobile"];
    $voucher = $_POST["vouchno"];
    $fitdate = $_POST["fitdate"];
    $fitness = $_POST["fitness"];
    $paxname = $_POST["paxname"];
    $passport = $_POST["passport"];
    $dob = $_POST["dob"];
    $taken = $_POST["taken"];
//    $paxname = $_POST["paxname"];
    $doctor = $_POST["doctor"];
    $issplace = $_POST["issplace"];
    $issdate = $_POST["issdate"];
    $doe = $_POST["doe"];
    $religion = $_POST["religion"];
    $address = $_POST["address"];
    $branch = $_POST["branch"];
    $mvouch = $qvouch;

    if ($a == 1) {

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

        if ($addflag == 1) {

            mysqli_query($conn, "INSERT INTO `$maindb`(`yearno`,`myvouch`, `vouchno`, `vouchdt`, `mobile`,
                                               `manualno`,`branch`,`broker`,`doctor`,`taken`,`fitness`,`fitdate`,`paxname`,`passport`,`dob`,`issplace`,`doe`,`issdate`,`religion`,`address` )
                                               VALUES ('$myyear','$qvouch','$voucher','$vouchdt','$mobile','$manualno','$branch','$broker','$doctor','$taken','$fitness',
                                                       '$fitdate','$paxname','$passport','$dob','$issplace','$doe','$issdate','$religion','$address')") or die(mysqli_error($conn));

            insmess();
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {

            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt',`mobile`='$mobile',`broker`=N'$broker',`manualno`='$manualno',`branch`='$branch', "
                            . "`doctor`='$doctor',`fitness`='$fitness',`fitdate`='$fitdate',`paxname`='$paxname',`passport`='$passport',`dob`='$dob',`taken`='$taken',`issplace`='$issplace',`doe`='$doe',`religion`='$religion',`address`='$address',`issdate`='$issdate' where `myvouch` = '$mvouch' ") or die(mysqli_error($conn));

//            updmess(); 
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
    }
    mysqli_query($conn, "UNLOCK TABLES");
}


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);
}
//$getfit = $get['fitness'];
if ($get['fitness'] == 1) {
    $getfit = 'Fit';
} else if ($get['fitness'] == 2) {
    $getfit = 'Un Fit';
} else if ($get['fitness'] == 3) {
    $getfit = 'Pending';
} else if ($get['fitness'] == 4) {
    $getfit = 'Repeat';
} else {
    $getfit = '';
}


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

include("includes/linkshead.php");
?>
<script>
    $(document).ready(function () {
//        $("body").on("keyup blur ", '.manualno', getSubcateg);
        $("body").on("blur", '.manualno', get);
//        function getSubcateg() {
//            $(".paxname").val();
//
//            var manualno = $(".manualno").val();
//            $.post('getSub2.php', {manualno: manualno}, function (data) {
//                $(".paxname").html(data);
//            });
//
//        }





        function get() {
            var manualno = $(".manualno").val();

            $.ajax({
                type: "POST",
                dataType: "json",
                url: "get_detail.php",
                data: {manualno: manualno},
                success: function (response) {
//                    $("#party").val(response[0].party).trigger("change");
//                    $(".passport").val(response[0].passport);
                    $(".broker").val(response[0].broker);

                },
                error: function (request, textStatus, errorThrown) {
                },
            });

        }
    });
</script>
<script src="MyScript/shortkeys.js" type="text/javascript"></script>
<!--<script src="MyScript/medical_search.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-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg" style="color: #5D96E4"> File No.</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad " >
                                <input type="text" class="form-control form manualno" id="manualno" name="manualno" value="<?php Echo ($addflag != 1) ? $get["manualno"] : ""; ?>" required
                                       style="color: #5D96E4;background-color: white;border: 1px solid #5D96E4" autofocus>
                            </div>
                            <div class="col-lg-4 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg" >Branch</label>
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 pad " >
                                <!--<input type="text" class="form-control form branch" id="branch" name="branch" value="<?php Echo ($addflag != 1) ? $get["branch"] : ""; ?>" required>-->
                                <select name = "branch" class="form-control form branch">
                                    <option value="<?php Echo ($addflag != 1) ? $get['branch'] : ""; ?>"><?php Echo ($addflag != 1) ? $get["branch"] : ""; ?></option>
                                    <option value="Mumbai">Mumbai</option>
                                    <option value="New Delhi">New Delhi</option>
                                    <option value="Lucknow">Lucknow</option>
                                </select>
                                
                            </div>
                        </div>


                        <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 class="row">

                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Pax Name</label>
                            </div>

                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad"  style="">
                                <input type="text" class="form-control form paxname" id="paxname" name="paxname" value="<?php Echo ($addflag != 1) ? $get["paxname"] : ""; ?>">
                            </div>
                                <!--<input type="text" class="form-control form alpha" name="state" value="<?php // Echo ($addflag != 1) ? $get["state"] : "";                                    ?>" >-->
<!--                                <select name="paxname" class="form-control form paxname select2" required>
                                    <option value="<?php echo ($addflag != 1) ? $get['paxname'] : ""; ?>"><?php echo ($addflag != 1) ? $get['paxname'] : " "; ?></option>
                            <?php
                            $mown4 = mysqli_query($conn, "SELECT  `paxname` FROM `visatran` ") or die(mysqli_error($conn));
                            while ($trow4 = mysqli_fetch_array($mown4)) {
                                echo "<option value='$trow4[paxname]'>$trow4[paxname]</option>";
                            }
                            ?>
                                </select>-->
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg" style="color:blue"> Mobile No.</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad ">
                            <input type="number" style="color:blue" class="form-control form mobile" id="mobile" name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : " "; ?>" required>
                        </div>
                    </div>
                    <div class="row">

                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 text-right pad ">
                            <label class="label-control marg">Passport No</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad"  style="">
                            <input type="text" class="form-control form passport" id="passport" name="passport" value="<?php Echo ($addflag != 1) ? $get["passport"] : ""; ?>">
                        </div>
                    </div>
                    <div class="row">

                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 text-right pad ">
                            <label class="label-control marg">DOB</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad"  style="">
                            <input type="date" class="form-control form dob" id="dob" name="dob" value="<?php Echo ($addflag != 1) ? $get["dob"] : ""; ?>">
                        </div>
                    </div>
                    <div class="panel-body" style="background-color: #5D96E4 ">
                        <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" style="color:white">DOI</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 issdate" name="issdate" style="background:white" value="<?php Echo ($addflag != 1) ? $get["issdate"] : date("Y-m-d"); ?>" required>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-1 col-xs-1 text-right pad "style="">
                                <label class="label-control marg" style="color:white">DOE</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 doe" name="doe" style="background:white"  value="<?php Echo ($addflag != 1) ? $get["doe"] : date("Y-m-d"); ?>" required>
                            </div>
                        </div>
                        <div class="row">

                            <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                                <label class="label-control marg" style="color:white">POI</label>
                            </div>
                            <div class="col-lg-3 col-md-1 col-sm-1 col-xs-1 pad">
                                <input list='issplace' name='issplace' value="<?php Echo ($addflag != 1) ? $get["issplace"] : ""; ?>" class='issplace form-control form ' autocomplete="off">
                                <datalist id='issplace' char="#">
                                    <option value=''></option>
                                    <?php
                                    $me = mysqli_query($conn, "SELECT `myvouch`,issplace FROM `medent` where myvouch != '' group by issplace") or die(mysqli_error($conn));

                                    while ($te = mysqli_fetch_array($me)) {
                                        $ename = $te['issplace'];
                                        echo "<option value='$ename'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                            
<!--                            <div class="col-lg-3 col-md-3 col-sm-1 col-xs-2 pad">

                                <select name = "issplace" class="form-control form issplace">

                                    <option value="<?php Echo ($addflag != 1) ? $get['issplace'] : ""; ?>"><?php Echo ($addflag != 1) ? $get["issplace"] : ""; ?></option>
                                    <option value="Mumbai">Mumbai</option>
                                    <option value="New Delhi">New Delhi</option>
                                    <option value="Lucknow">Lucknow</option>
                                </select>
                            </div>-->
                            <!--                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad"  style="">
                                                            <input type="text" class="form-control form issplace" id="issplace" name="issplace" value="<?php Echo ($addflag != 1) ? $get["issplace"] : ""; ?>">
                                                        </div>-->

                            <!--<div class="row">-->
                            <div class="col-lg-3 col-md-3 col-sm-2  col-xs-2 text-right pad">
                                <label class="label-control marg" style="color:white">Religion</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-1 col-xs-2 pad"  >
                                <select name="religion" class=" form-control form  religion" required>
                                    <option value="<?php Echo ($addflag != 1) ? $get["religion"] : ""; ?>"><?php Echo ($addflag != 1) ? $get["religion"] : ""; ?></option>
                                    <option value="Muslim">Muslim</option>
                                    <option value="Non-Muslim">Non-Muslim</option>
                                    <!--<option value="3">Pending</option>-->
                                    <!--<option value="4">Repeat</option>-->

                                </select>
                            </div>
                            <!--</div>-->

                        </div>
                    </div>

                    <!--                    <div class='row'>
                                            <div class='col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad'>
                                                <label class='label-control marg'>Branch</label>
                                            </div>
                                            <div class="col-lg-3 col-md-3 col-sm-1 col-xs-2 pad">
                                                <select name = "branch" class="form-control form branch">
                                                    
                                                    <option value="<?php Echo ($addflag != 1) ? $get['branch'] : ""; ?>"><?php Echo ($addflag != 1) ? $get["branch"] : ""; ?></option>
                                                    <option value="Mumbai">Mumbai</option>
                                                    <option value="New Delhi">New Delhi</option>
                                                    <option value="Lucknow">Lucknow</option>
                                                </select>
                                                
                                            </div>
                                            
                                            
                                        </div>-->
                    <div class="row">

                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg">Address</label>
                        </div>
                        <div class="col-lg-6 col-md-4 col-sm-4 col-xs-4 pad"  style="">
                            <input type="text" class="form-control form address" id="address" name="address" value="<?php Echo ($addflag != 1) ? $get["address"] : ""; ?>">
                        </div>
                    </div>


                    <div class="row">

                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg">Agent</label>
                        </div>
                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad"  style="">
                            <input type="text" class="form-control form broker" id="broker" name="broker" value="<?php Echo ($addflag != 1) ? $get["broker"] : ""; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg">Doctor Name</label>
                        </div>
                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad" style="">
                            <input type="text" class="form-control form doctor" name="doctor" id="doctor" value="<?php Echo ($addflag != 1) ? $get["doctor"] : ""; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg">Token</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad" style="">
                            <input type="text" class="form-control form taken" name="taken" id="taken" value="<?php Echo ($addflag != 1) ? $get["taken"] : ""; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2 text-right pad">
                            <label class="label-control marg">Fitness</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-1 col-xs-2 pad"  >
                            <select name="fitness" class=" form-control form  fitness" required>
                                <option value="<?php Echo ($addflag != 1) ? $get['fitness'] : "3"; ?>"><?php Echo ($addflag != 1) ? $getfit : "Pending"; ?></option>
                                <option value="1">Fit</option>
                                <option value="2">Un Fit</option>
                                <option value="4">Repeat</option>
                            </select>
                        </div>
                    </div>

                    <div class="row">

                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-1 text-right pad "style="">
                            <label class="label-control marg">Fit 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 fitdate" name="fitdate"  value="<?php Echo ($addflag != 1) ? $get["fitdate"] : date("Y-m-d"); ?>" >
                        </div>
                    </div>

                </div>

                <?php
                mysqli_query($conn, "Create temporary table `med` SELECT Date_Format(`vouchdt`, '%d/%m/%Y') as mydt, myvouch,
                        manualno, paxname, mobile,passport, broker,doctor FROM `$maindb` WHERE myvouch != ''  ORDER BY vouchdt DESC")or die(mysqli_error($conn));

                $srchresult = "SELECT *  FROM `med` WHERE myvouch != '' "or die(mysqli_error($conn));

                $result = mysqli_query($conn, $srchresult)or die(mysqli_error($conn));
                ?>
                <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="table-responsive" style="max-height: 400px;overflow: auto;">
                                    <table id="example1" class="table table-striped table-condensed table-bordered" width="100%" >
                                        <thead>
                                            <tr class="mySearchTr">
                                                <th style="width:7%;">Date</th>
                                                <th style="width:5%;">File No.</th>
                                                <th style="width:20%;">Pax Name</th>
                                                <th style="width:10%;">Mobile</th>
                                                <th style="width:10%;">Passport No.</th>
                                                <th style="width:10%;">Agent</th>
                                                <th style="width:7%;">Doctor</th>
                                                <th align="center"  style="width:1%;">Action</th>
                                            </tr>
                                        </thead>
                                        <tbody class="sTbody">
                                            <?php
                                            while ($row = mysqli_fetch_array($result)) {
                                                echo "<tr class='' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                                echo "<td align='left'>$row[mydt]</td>";
                                                echo "<td align='left'>$row[manualno]</td>";
                                                echo "<td align='left'>$row[paxname]</td>";
                                                echo "<td align='left'>$row[mobile]</td>";
                                                echo "<td align='left'>$row[passport]</td>";
                                                echo "<td align='left'>$row[broker]</td>";
                                                echo "<td align='left'>$row[doctor]</td>";
                                                echo "<td align='left'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
                                                echo "</tr>";
                                            }
                                            ?>
                                        </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>
                <div class="panel-footer">
                    <? include("includes/buttons.php"); ?>
                </div>
            </div>
        </div>
    </div>
</form>


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

</html>
