<?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 = 'CRM';
$maindb = 'crm';
$file = 'crm.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"];
    $name = $_POST["name"];
    $mobile = $_POST["mobile"];
    $emailid = $_POST["emailid"];
    $passport = $_POST["passport"];
    $category = $_POST["category"];
    $edu = $_POST["edu"];
    $remark = $_POST["remark"];
    $mvouch = $qvouch;

    if ($a == 1) {

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

        if ($addflag == 1) {

            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchdt`,`myvouch`, `name`, `mobile`,`emailid`,`remark`,`edu`,`category`,`passport`)
                                               VALUES ('$vouchdt','$qvouch','$name','$mobile','$emailid','$remark','$edu','$category','$passport')")
                    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',`name`='$name',`mobile`='$mobile',`emailid`='$emailid',`remark`='$remark',
                                                        `edu`='$edu',`category`='$category',`passport`='$passport' 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 {
//    $getfit = 'Un Fit';
//}





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

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

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

        }





        function get() {
            var paxname = $(".paxname").val();
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "get_detail.php",
                data: {paxname: paxname},
                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/crm_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-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">Name</label>
                            </div>
                            <div class="col-lg-5 col-md-4 col-sm-4 col-xs-4 pad">
                                <!--<input type="text" class="form-control form alpha" name="state" value="<?php // Echo ($addflag != 1) ? $get["state"] : "";                             ?>" >-->
                                <input list='name' name='name' value="<?php Echo ($addflag != 1) ? $get["name"] : ""; ?>"" class='size form-control form ' autocomplete="off">
                                <datalist id='name' char="#">
                                    <option value=''></option>
                                    <?php
                                    $msize = mysqli_query($conn, "SELECT `name` FROM `crm` group by name ") or die(mysqli_error($conn));

                                    while ($tsize = mysqli_fetch_array($msize)) {
                                        $sizename = $tsize['name'];
                                        echo "<option value='$sizename'>";
                                    }
                                    ?>
                                </datalist>
                            </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">Email ID</label>
                            </div>
                            <div class="col-lg-5 col-md-3 col-sm-3 col-xs-3 pad"  style="">
                                <input type="text" class="form-control form emailid" id="emailid" name="emailid" value="<?php Echo ($addflag != 1) ? $get["emailid"] : ""; ?>">
                            </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=""> Mobile No.</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad ">
                                <input type="number" class="form-control form mobile" id="mobile" name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : "AH-"; ?>" 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">Passport</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-2 text-right pad">
                                <label class="label-control marg">Job Category</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad" style="">
                                <input list='category' name='category' value="<?php Echo ($addflag != 1) ? $get["category"] : ""; ?>"" class='size form-control form ' autocomplete="off">

                                <datalist id='category' char="#">
                                    <option value=''></option>
                                    <?php
                                    $msize = mysqli_query($conn, "SELECT `category` FROM `crm` group by category ") or die(mysqli_error($conn));

                                    while ($tsize = mysqli_fetch_array($msize)) {
                                        $sizename = $tsize['category'];
                                        echo "<option value='$sizename'>";
                                    }
                                    ?>
                                </datalist>
                            </div><!-- comment -->
                        </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">Education</label>
                            </div>
                            <div class="col-lg-6 col-md-3 col-sm-3 col-xs-3 pad" style="">
                                <input type="text" class="form-control form edu" name="edu" id="taken" value="<?php Echo ($addflag != 1) ? $get["edu"] : ""; ?>">
                            </div>
                        </div>
                        <br>
                        <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">Remark</label>
                            </div>
                            <div class="col-lg-6 col-md-3 col-sm-3 col-xs-3 pad" style="">
                                <input type="text" class="form-control form remark" name="remark" id="remark" value="<?php Echo ($addflag != 1) ? $get["remark"] : ""; ?>">
                            </div><!-- comment -->
                        </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>
