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

$formname = 'Lead Enquiry';
$maindb = 'leadenq';
$printfile = "";
$file = 'leadrecd.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"];
    $email2 = $_POST["email2"];
    $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"];
    $semiinf = $_POST["semiinf"];
    $totpax = $_POST["totpax"];
    $remarks = $_POST["remarks"];
    $source = $_POST["source"];
//    $username = $_POST["username"];
    $username = $_SESSION["username_" . $dbname];
    $editcontent = $_POST['hiddenRajEditorContents'];

//    browse($name);
    if ($name == "") {
        $a = 0;
        browse("Name Cannot Be Empty");
        if ($addflag == 1) {
            header("location:javascript://history.go(-1)");
        } else {
            header("refresh: ; $file?mode=last");
        }
    }




    if ($a == 1) {
        if ($addflag == 1) {
            mysqli_query($conn,"INSERT INTO `$maindb`(vouchno, `vouchdt`, `name`, `lastname`, `city`, `destination`, mobile , mobile2 ,tel, tel2,
`email`,`email2`,`destcity1`, `destcity2`, `destcity3`,`destcity4`,`destcity5`, `deptdate`, `username`, 
`adult`, `child`, `infant`, `semiinf`, `totpax`,`remarks`, `source`, `editcontent`, `status`)
VALUES($qvouch, '$vouchdt', '$name', '$lastname', '$city', '$destination', '$mob' , '$mob2' , '$tel', '$tel2',
'$email','$email2', '$destcity1', '$destcity2', '$destcity3', '$destcity4', '$destcity5', '$travdate', '$username', 
'$adult', '$child', '$infant', '$semiinf', '$totpax','$remarks', '$source', '$editcontent', 'Not Qouted')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $_GET["vouchno"];
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");

//            header("refresh: 1; $file?mode=true");
        } else {
            $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',`email2`='$email2', `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', 
`semiinf`='$semiinf', `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>
<style type="text/css">
    table th{
        color: black;
    }
</style>
</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-5">
                <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-2 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-4 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="date" class="form-control vouchdt" name="vouchdt" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date('Y-m-d'); ?>" >
                            </div>
                        </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">Source</label>
                            </div>
                            <div class="col-lg-9 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-2 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-3 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 mobile2" name="mobile2" value="<?php Echo ($addflag != 1) ? $get["mobile2"] : ""; ?>" >
                            </div>
                        </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">Name</label>
                            </div>
                            <div class="col-lg-9 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-2 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-9 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-2 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-3 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-2 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-6 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-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Email Id.2</label>
                            </div>
                            <div class="col-lg-6 col-md-5 col-sm-5 col-xs-5 pad">
                                <input type="text" class="form-control email" name="email2" value="<?php Echo ($addflag != 1) ? $get["email2"] : ""; ?>" >
                            </div>
                        </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">City</label>
                            </div>
                            <div class="col-lg-6 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-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Destination</label>
                            </div>
                            <div class="col-lg-9 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-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-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="date" class="form-control travdate" name="travdate" value="<?php Echo ($addflag != 1) ? $get["deptdate"] : ""; ?>" >
                            </div>
                        </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">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" 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" 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" 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 class="label-control marg">Semi Infant</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control semiinf" name="semiinf" value="<?php Echo ($addflag != 1) ? $get["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;" class="form-control totpax" name="totpax" value="<?php Echo ($addflag != 1) ? $get["totpax"] : "0"; ?>" >
                            </div>
                        </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">Remarks</label>
                            </div>
                            <textarea name="remarks" rows="4" cols="50"><?php Echo ($addflag != 1) ? $get["remarks"] : ""; ?></textarea>
                        </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">
                            <button><a href="demoexcel.php?vouchno=<?=$qvouch?>">Button Text</a></button>
                            <!--<button class="excelbutn">Button Text</button>-->
                            <input type="hidden" id="hiddenRajEditorContents" name="hiddenRajEditorContents"  value='<?php Echo ($addflag != 1) ? $get["editcontent"] : ""; ?>'>
                        </div>
                    </div>
                    <div style="padding-left: 40%;" class="panel-footer">
                        <?php
                        if ($addflag == 1) {
                            $valbut = "Save";
                        } else {
                            $valbut = "Update";
                        }
                        ?>
                        <input type="submit" name="submit" id="submit" value="<?php echo $valbut ?>" 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>-->
<!--                    <input type=button name="exceltest" class="open-editor"  value="Open File">
                    <input type="hidden" id="hiddenRajEditorContents" name="hiddenRajEditorContents"  value='<?php Echo ($addflag != 1) ? $get["editcontent"] : ""; ?>'>-->
                </div>
            </div>
            <div class="col-lg-7 table-responsive" >

                <label class="label-control marg">Travel History</label>

                <div class="mytable" id="mytable">
<!--                    <table class=''>
                        <th style='width:5%'>Sr.</th>
                        <th style='width:5%'>Book No.</th>
                        <th style='width:15%'>Name</th>
                        <th style='width:15%'>Last Name</th>
                        <th style='width:10%'>Mobile</th>
                        <th style='width:10%'>Destination</th>
                        <th style='width:10%'>Travel Date</th>
                    </table>-->
                </div>
            </div>
        </div>

    </form>
    <div class="modal fade bs-example-modal-lg" 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">
                        <table id="example1" class="table table-striped">
                            <thead>
                                <tr style="background-color: #64CCFC">
                                    <th>Name</th>
                                    <th>Last Name</th>
                                    <th>Destination</th>
                                    <th>Mobile</th>
                                    <th>Email</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb`  ") or die(mysqli_error($conn));
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                    echo "<td align='left'>$row[name]</td>";
                                    echo "<td align='left'>$row[lastname]</td>";
                                    echo "<td align='left'>$row[destination]</td>";
                                    echo "<td align='left'>$row[mobile]</td>";
                                    echo "<td align='left'>$row[email]</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>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {

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