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

$formname = 'Feed Status';
$maindb = 'confmain';
$printfile = "";
$file = 'feedstus.php';
$fileadd = 'leadenq.php';
$trandbexist = 0;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
$mgrpcode = '009';
$zroot = $_SESSION["zdir"];


$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];


$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];
//browse($user);

mysqli_select_db($conn,$zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["mailbutn"])) {


//    if (isset($_POST["submit"])) {
    $mailvouch = trim($_POST["mailvouch"]);
    $ename = trim($_POST["ename"]);
    $elastname = trim($_POST["elastname"]);
    $edest = trim($_POST["edest"]);
    $etravdate = $_POST["etravdate"];
    $eremarks = trim($_POST["eremarks"]);
    $mobile = trim($_POST["mobile"]);

    $count = $_POST["count"];

    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $vouchno = $_POST["vouchno_$i"];
        $feedsend = $_POST["feedsend_$i"];
        $remarks = trim($_POST["remarks_$i"]);
        $remarks1 = trim($_POST["remarks_$i"]);


        if (!empty($msrno)) {
            mysqli_query($conn,"UPDATE `confmain` SET  `feedsend`='$feedsend'  WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));
        }
    }
    updmess();
}

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 () {
        $("body").on('change', '.feedsend', getEmailModal);
        $("body").on('click', '.CMail', sendMail);
        
        function getEmailModal() {
            var $row = $(this).closest("tr");
            var option_value1 = $row.find('.feedsend').val();
            var vouchno1 = $row.find('.vouchno').val();
            var data = {vouchno: vouchno1};
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: "show_custconf_dtl.php",
                data: data,
                success: function (response) {
                    //            var option_value = document.getElementById("status").value;
                    if (option_value1 == "Y") {
                        $('#mailvouch').val(vouchno1);
//                                    $($row.find('.rate')).val(response.rate);
                        $('.modal-body .ename').val(response.name);
                        $('.modal-body .elastname').val(response.lastname);
                        $('.modal-body .edest').val(response.destination);
                        $('.modal-body .etravdate').val(response.deptdate);
                        $("#emailModal").modal("show");
                    }
                },
                error: function (request, textStatus, errorThrown) {
                    alert(errorThrown);
                }
                //dataType:'json'
            });
        }

        function sendMail() {
            var ename = $(".ename").val(), elastname = $(".elastname").val(), edest = $(".edest").val(),
                    etravdate = $(".etravdate").val(), eremarks = $(".eremarks").val(), mailvouch = $(".mailvouch").val();
            $.post('customer_SendMail2.php', {ename: ename, elastname: elastname, edest: edest, etravdate: etravdate, eremarks: eremarks, mailvouch: mailvouch}, function (data) {
                if (data = "succcess") {
                    alert("Feedback Form Send To The Customer");
                    $("#emailModal").modal("hide");
                } 
            });
        }
        

//        $('table tbody tr  td').on('change', function () {
//            $("#myModal").modal("show");
//            $("#status").val($(this).closest('tr'));
    });
</script>
<script type="text/javascript">
    $(document).keydown(function (event) {
        if (!(String.fromCharCode(event.which).toLowerCase() == 'l' && event.ctrlKey) && !(event.which == 19))
            return true;
        $("#addnew").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>


<style>
    .button {
        padding: 15px 25px;
        font-size: 15px;
        text-align: center;
        cursor: pointer;
        outline: none;
        color: #fff;
        background-color: #4CAF50;
        border: none;
        border-radius: 15px;
        box-shadow: 0 9px #999;
    }

    .button:hover {background-color: #3e8e41}

    .button:active {
        background-color: #3e8e41;
        box-shadow: 0 5px #666;
        transform: translateY(4px);
    }
</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-12">
                <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> 
                        <!--<input type='button' style="float: right;" name='exit' value='Exit' class="btn btn-danger" onClick="window.location.href = '<? Echo $file; ?>'">-->

                    </div> 

                    <br>
                    <div class="panel-body table-responsive " style="width:100%">
                        <table id="example1" class="table-bordered" width="100%">
                            <thead>
                                <tr style="background-color: #64CCFC">
                                    <th style="text-align:center" >Sr.</th>
                                    <th style="text-align:center">Book No.</th>
                                    <th style="text-align:center">Travel Date</th>
                                    <th style="text-align:center">Name</th>
                                    <th style="text-align:center">Last Name</th>
                                    <th style="text-align:center">Mobile</th>
                                    <th style="text-align:center">Destination</th>
                                    <th style="text-align:center">Retn. Date</th>
                                    <th style="text-align:center">Feed Send</th>
                                    <th style="text-align:center">Feed Recd.</th>
                                </tr>
                            </thead>
                            <tbody>

                                <?php
                                $datetoday = date("Y-m-d");
                                $dateafter = date('Y-m-d', strtotime("+3 days"));
                                if ($usertype == 1) {
                                    $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `retndate` >= '$datetoday' and `retndate` <= '$dateafter'") or die(mysqli_error($conn));
                                } else {
                                    $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `username` ='$user' and `retndate` >= '$datetoday'  and `retndate` <= '$dateafter'") or die(mysqli_error($conn));
                                }
//                                print table($srchresult);

                                $ctr = 1;

                                while ($row = mysqli_fetch_array($srchresult)) {
                                    if ($row[feedrecd] == "Y"){
                                        $feedrecd = "YES";
                                    } else{
                                        $feedrecd = "NO";
                                    }
//                                    browse($row[deptdate]);
                                    echo "<tr>";
                                    Echo "<td class='text-right'><input type='text' value='$ctr' name='srno_$ctr' style='border : none;width : 30px;text-align:center;' readonly></td>";
                                    Echo "<td class='text-right'  style='display: $adddisabled '><input type='text' value='$row[vouchno]' name='vouchno_$ctr' style='border : none;width : 70px; padding : 0px;text-align:center;' readonly class='vouchno'></td>";
                                    Echo "<td class=''><input type='date' value='$row[deptdate]' name='vouchdt_$ctr' style='border : none;width : 130px; padding : 0px;text-align:center;' readonly class='vouchdt'></td>";
                                    Echo "<td class=''><input type='text' value='$row[name]' name='name_$ctr' style='border : none; padding : 0px;text-align:center;width:120px;' readonly class='name'></td>";
                                    Echo "<td class=''><input type='text'value='$row[lastname]' name='lastname_$ctr' style='border : none; padding : 0px;text-align:center;width:110px;' readonly class='lastname'></td>";
                                    Echo "<td class=''><input type='text'value='$row[mobile]' name='mobile_$ctr' style='border : none; padding : 0px;text-align:center;width:110px;' readonly class='mobile'></td>";
                                    Echo "<td class=''><input type='text'value='$row[destination]' name='destination_$ctr' style='border : none; padding : 0px;text-align:center;width:100px;' readonly class='destination'></td>";
                                    Echo "<td class=''><input type='date' value='$row[retndate]' name='retndate_$ctr' style='border : none; padding : 0px;text-align:center;width:130px;' readonly class='deptdate'></td>";

                                    echo "<td>"
                                    ?>
                                <select name='feedsend_<?= $ctr ?>' id="feedsend"  class="feedsend form-control" style='padding: 0px;width:100%;border: none;'>
                                    <option value='N'<?php
                                    if ($addflag != 1) {
                                        if ($row["feedsend"] == "N") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?> >No</option>
                                    <option value='Y'<?php
                                    if ($addflag != 1) {
                                        if ($row["feedsend"] == "Y") {
                                            echo "selected='selected'";
                                        }
                                    }
                                    ?>>Yes</option>
                                </select>


                                <?php
                                echo "</td>";
                                Echo "<td class=''><input type='text' value='$feedrecd' name='feedrecd_$ctr' style='border : none; padding : 0px;text-align:center;width:100px;' readonly class='feedrecd'></td>";
                                $ctr++;
                            }
                            ?>
                            <input type = "hidden" name = "count" value = "<? Echo $ctr; ?>">
                            </tbody> 
                        </table>

                    </div>
                    <!--                    <div class="panel-footer">
                    <?php // include("includes/buttons.php");      ?>
                                        </div>-->
                </div>
            </div>
        </div>
        <?php
        mysqli_select_db($conn,$zdb);

//        $ressubvouch = mysqli_query($conn,"SELECT *,DATE_FORMAT(`flwup2dt`, '%d-%m-%Y')as flwup2dt, DATE_FORMAT(`flwup3dt`, '%d-%m-%Y')as flwup3dt FROM `$maindb` WHERE $keyfld='$subvouch' ") or die(mysqli_error($conn));
//        $getsub = mysqli_fetch_array($ressubvouch);
        ?>
        <div class="modal fade bs-example-modal-lg" id="emailModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg" style="width: 70%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal"><span>&times;</span></button>
                        <h4 class="modal-title" id="myLargeModalLabel"></h4>
                    </div>
                    <!--<input type='button' style="float: right;" name='exit' value='Exit' class="btn btn-danger" onClick="window.location.href = '<? Echo $file; ?>'">-->
                    <!--<button style="float: right;" type='submit' name='update' value='Update' class="btn btn-success">-->
                    <!--<button id='submit'  type='submit' name='submit' value='Update' class="btn btn-success">Save</button>--> 


                    <div class="modal-body">
                        <div class="table-responsive">
                            <table>
                                <tr id="">
                                    <td><label class="label-control marg">Booking No.</label></td>
                                    <td><input type="text" name="mailvouch" id="mailvouch" value="<?php echo ($addflag != 1) ? $row['mailvouch'] : ""; ?>"  style="width:175px;" class="mailvouch form-control" readonly="readonly"></td>
                                </tr>
                                <tr id="">
                                    <td><label class="label-control marg">Name</label></td>
                                    <td><input type="text" name="ename" id='ename' placeholder="" value="<?php echo ($addflag != 1) ? $row['name'] : ""; ?>" style="width:300px;" class="form-control ename" readonly="readonly"></td>
                                    <td><label class="label-control marg">Last Name</label></td>
                                    <td><input type="text" name="elastname" id='elastname' placeholder="" value="<?php echo ($addflag != 1) ? $row['lastname'] : ""; ?>" style="width:300px;" class="form-control elastname" readonly="readonly"></td>
                                </tr>
                                <tr id="">
                                    <td><label class="label-control marg">Destination</label></td>
                                    <td><input type="text" name="edest" id='edest' placeholder="" value="<?php echo ($addflag != 1) ? $row['destination'] : ""; ?>" style="width:175px;" class="form-control edest" readonly="readonly"></td>
                                </tr>
                                <tr id="">
                                    <td><label class="label-control marg">Travel Date</label></td>
                                    <td><input type="date" name="etravdate" id='etravdate' placeholder="" value="<?php echo ($addflag != 1) ? $row['deptdate'] : ""; ?>" style="width:175px;" class="form-control etravdate" readonly="readonly"></td>
                                </tr>
                                <tr id="">
                                    <td><label class="label-control marg">Remarks</label></td>
                                    <td><input type="text" name="eremarks" id='eremarks' placeholder="" value="<?php echo ($addflag != 1) ? $row['remarks'] : ""; ?>" style="width:400px;" class="form-control eremarks"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad text-right">
                        <button type="submit" name="mailbutn" id="mailbutn" class="btn btn-primary CMail" style="margin-right: 20px"><i class="fa fa-envelope"></i>Send</button>
                    </div>
                    <div class="modal-footer"></div>
                </div>
            </div>
        </div>
    </form>

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