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

$formname = 'Lead Enquiry';
$maindb = 'leadenq';
$printfile = "";
$file = 'leadenq.php';
$trandbexist = 0;
$grid = 'leadrecd.php';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
$mgrpcode = '009';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
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 = mysqli_real_escape_string($conn,$_POST["name"]);
    $lastname = mysqli_real_escape_string($conn,$_POST["lastname"]);
    $city = $_POST["city"];
    $destination = $_POST["destination"];
    $station = $_POST["station"];
    $mob = $_POST["mobile"];
    $mob2 = $_POST["mobile2"];
    $tel = $_POST["tel"];
    $tel2 = $_POST["tel2"];
    $email = $_POST["email"];
    $destcity1 = $_POST["destcity1"];
    $destcity2 = $_POST["destcity2"];
    $destcity3 = $_POST["destcity3"];
    $destcity4 = $_POST["destcity4"];
    $destcity5 = $_POST["destcity5"];
    $travdate = $_POST["travdate"];
    $adult = $_POST["adult"];
    $child = $_POST["child"];
    $infant = $_POST["infant"];
    $totpax = $_POST["totpax"];
    $remarks = $_POST["remarks"];
    $source = $_POST["source"];
//    $username = $_POST["username"];
    $username = $_SESSION["username_" . $dbname];
    $editcontent = $_POST['hiddenRajEditorContents'];
    if ($name == " ") {
        $a = 0;
        browse("Name Cannot Be Empty");
        if ($addflag == 1) {
            header("location:javascript://history.go(-1)");
        } else {
            header("refresh: ; $file?mode=last");
        }
    }



//browse($totpax);
    if ($a == 1) {
        $mvouch = $qvouch;
        mysqli_query($conn,"UPDATE `$maindb`  SET `vouchdt`='$vouchdt', `name`='$name',  `lastname`='$lastname', `city`='$city', `destination`='$destination', mobile= '$mob', mobile2= '$mob2',tel='$tel', tel2='$tel2',
                         `email`='$email', `destcity1`='$destcity1',  `destcity2`='$destcity2', `destcity3`='$destcity3', `destcity4`='$destcity4', `destcity5`='$destcity5',
                        `deptdate`='$travdate', `adult`='$adult', `child`='$child', infant='$infant', `source`='$source', `totpax`='$totpax', `remarks`='$remarks', `editcontent`='$editcontent', "
                        . "`username`='$username' where vouchno = '$mvouch' ") or die(mysqli_error($conn));

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

if ($addflag != 1) {

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

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

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


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

include("includes/linkshead.php");
?>
<!--<script src="MyScript/leadenq.js" type="text/javascript"></script>-->
<script type="text/javascript">
    $(document).ready(function () {
//    $(".tbody").on("blur", '.rate', autoAddRows);
        $("body").on('keyup, change, blur', '.adult, .child, .infant, .totpax', Calculat);
        $("body").on('change', '.mobile', checkNum);

        function checkNum() {
            var mmobile = $(".mobile").val();
            if (mmobile.length < 10) {
                alert("Please Enter Valid Mobile No.");
                $(".mobile").focus();
            }
        }

        function Calculat() {
            var madult = parseFloat($(".adult").val());
            var mchild = parseFloat($(".child").val());
            var minfant = parseFloat($(".infant").val());

            var mtotpax = parseFloat($(".totpax").val());

            mtotpax = madult + mchild + minfant;

//        $(".totpax").val(mtotpax);

            if (isNaN(mtotpax)) {
                $(".totpax").val("0");
                ;
            } else {
                $(".totpax").val(mtotpax);
                /*$row.find('.final').val(fintot.toFixed(2));-*/
            }

        }
    });
</script>
<script type="text/javascript">
    $(document).keydown(function (event) {
        if (!(String.fromCharCode(event.which).toLowerCase() == 'c' && event.altKey) && !(event.which == 19))
            return true;
        $("#cancel").click();
        event.preventDefault();
        return false;
    });

    $(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;
    });
</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-6">
                <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-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" class="form-control " name="vouchno" disabled="" value="<?php Echo ($addflag != 1) ? $get["vouchno"] : "$qvouch"; ?>" >
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Enquiry Date</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="date" class="form-control " name="vouchdt" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date('Y-m-d'); ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Source</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control select2 source"  autofocus="" name="source">
                                    <option value="<? Echo ($addflag != 1 ) ? $get[source] : "" ?>"><? Echo ($addflag != 1 ) ? $get[source] : "" ?></option>
                                    <?
                                    $getsource = mysqli_query($conn,"SELECT * FROM `source`")or die(mysqli_error($conn));
                                    while ($msource = mysqli_fetch_array($getsource)) {
                                        Echo "<option value='$msource[name]'>$msource[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Mobile 1</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control  mobile" name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : ""; ?>" >
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Mobile 2</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control " name="mobile2" value="<?php Echo ($addflag != 1) ? $get["mobile2"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Name</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control name" name="name" value="<?php Echo ($addflag != 1) ? $get["name"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 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-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control lastname" name="lastname" value="<?php Echo ($addflag != 1) ? $get["lastname"] : ""; ?>" >
                            </div>
                        </div>
                        <!--                        <div class="row">
                                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                                        <label class="label-control marg">Mobile 1</label>
                                                    </div>
                                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                        <input type="text" class="form-control form  " name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : ""; ?>" >
                                                    </div>
                                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                                        <label class="label-control marg">Mobile 2</label>
                                                    </div>
                                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                        <input type="text" class="form-control form " name="mobile2" value="<?php Echo ($addflag != 1) ? $get["mobile2"] : ""; ?>" >
                                                    </div>
                                                </div>-->
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Tel. 1</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control tel" name="tel" value="<?php Echo ($addflag != 1) ? $get["tel"] : ""; ?>" >
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Tel. 2</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control  tel2" name="tel2" value="<?php Echo ($addflag != 1) ? $get["tel2"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 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-5 col-md-5 col-sm-5 col-xs-5 pad">
                                <input type="text" class="form-control email" name="email" value="<?php Echo ($addflag != 1) ? $get["email"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">City</label>
                            </div>
                            <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                <input type="text" class="form-control city" name="city" value="<?php Echo ($addflag != 1) ? $get["city"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Destination</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control select2 destination" name="destination">
                                    <option value="<? Echo ($addflag != 1 ) ? $get[destination] : "" ?>"><? Echo ($addflag != 1 ) ? $get[destination] : "" ?></option>
                                    <?
                                    $getdest = mysqli_query($conn,"SELECT * FROM `destination`")or die(mysqli_error($conn));
                                    while ($mdest = mysqli_fetch_array($getdest)) {
                                        Echo "<option value='$mdest[name]'>$mdest[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 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-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="date" class="form-control " name="travdate" value="<?php Echo ($addflag != 1) ? $get["deptdate"] : ""; ?>" >
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 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) ? $get["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) ? $get["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) ? $get["infant"] : "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) ? $get["totpax"] : "0"; ?>" readonly>
                            </div>
                        </div>

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

                            </div>
                            
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            </div>
                            <input type=button name="exceltest" class="open-editor" style="width:150px;height:50px;" value="Open File">
                            <input type="hidden" id="hiddenRajEditorContents" name="hiddenRajEditorContents"  value='<?php Echo ($addflag != 1) ? $get["editcontent"] : ""; ?>'>
                        </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="button" name="exit" value="Exit" id="cancel" class="btn btn-danger" onClick="window.location.href = '<?= $grid . "?mode=last" ?>'">
<?php // include("includes/buttons.php");  ?>
                    </div>
                    <!--<a href="MyExcel/myexcel.xls" target="_blank">open myexcel.xls</a>-->

                </div>
            </div>
        </div>
        <script>
            function closeWin() {
                window.close();
            }
        </script>
    </form>
<?php include("includes/linksfoot.php"); ?>
</body>
</html>
