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

$formname = 'Postponed Records';
$maindb = 'leadenq';
$printfile = "";
$file = 'postponed.php';
$trandbexist = 0;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
$mgrpcode = '009';
$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];

$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["update"])) {

//    if (isset($_POST["submit"])) {
    $count = $_POST["count"];
//    BROWSE($count);

    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $vouchno = $_POST["vouchno_$i"];
        $postflag = $_POST["postflag_$i"];
        browse($postflag);
        if (!empty($msrno)) {
            mysqli_query($conn,"UPDATE `leadenq` SET `postflag`='$postflag' WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));
        }
    }
    updmess();
//    header("refresh: 1; $file");
}

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

include("includes/linkshead.php");
?>
</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> 
                    </div>
                    <div class="container" style="float:right;">
                        <input style="padding-right: 15px;float:right;"  type='submit' id="update" name='update' value='Save' class="btn btn-success">
                    </div>
                    <div class="panel-body" style="">
                        <table id="example1" class="table-bordered" width="100%">

                            <thead>
                                <tr style="background-color: #64CCFC;padding-right: 5px;">
                                    <th style="width:5%;">Sr.</th>
                                    <?php
                                    if($usertype == 1){
                                        echo "<th>Staff</th>";
                                    }
                                    ?>
                                    <th style="width:10%;">Book No.</th>
                                    <th style="width:10%;">Name</th>
                                    <th style="width:10%;">Last Name</th>
                                    <th style="width:10%;">Mobile</th>
                                    <th style="width:10%;">Destination</th>
                                    <th style="width:10%;">Postponed Date</th>
                                    <th style="width:10%;">Reminder Date</th>
                                    <th style="width:10%;">Close</th>
                                </tr>
                            </thead>  
                            <tbody>
                                <?php
                                $date = date("Y-m-d");
//                                $date2 = date("Y-m-d") + 2;
                                $date2 = date('Y-m-d', strtotime("+2 days"));
//                                browse($date2);
                                if ($usertype == 1) {
                                    $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `status` = 'Postponed' and `remddate` >= '$date' and `remddate` <= '$date2'
                                                               and `postflag`!= '1' ") or die(mysqli_error($conn));
                                } else {
                                    $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `username`='$user' and `status` = 'Postponed' and `remddate` >= '$date' and 
                                                               `remddate` <= '$date2' and `postflag`!= '1'") or die(mysqli_error($conn));
                                }

                                $ctr = 1;

                                while ($row = mysqli_fetch_array($srchresult)) {
//                                    browse($row[deptdate]);
                                    echo "<tr>";
                                    Echo "<td class=''><input type='text' value='$ctr' name='srno_$ctr' style='border : none;width : 30px;text-align:center;' readonly></td>";
                                    if($usertype == 1){
                                        Echo "<td class=''><input type='text' value='$row[username]' name='username_$ctr' style='border : none;width : 80px;text-align:center;' readonly></td>";
                                    }
                                    Echo "<td class=''><input type='text 'value='$row[vouchno]' name='vouchno_$ctr' style='border : none;width : 100px; padding : 0px;text-align:center;' readonly class='vouchno'></td>";
                                    Echo "<td class=''><input type='text 'value='$row[name]' name='name_$ctr' style='border : none; padding : 0px;text-align:left;' readonly class='name'></td>";
                                    Echo "<td class=''><input type='text 'value='$row[lastname]' name='lastname_$ctr' style='border : none; padding : 0px;text-align:left;' readonly class='lastname'></td>";
                                    Echo "<td class=''><input type='text 'value='$row[mobile]' name='mobile_$ctr' style='border : none; padding : 0px;text-align:left;' readonly class='mobile'></td>";
                                    Echo "<td class=''><input type='text 'value='$row[destination]' name='destination_$ctr' style='border : none; padding : 0px;text-align:left;' readonly class='destination'></td>";
                                    Echo "<td class=''><input type='date' value='$row[postdate]' name='deptdate_$ctr' style='width : 140px;border : none; padding : 0px;text-align:left;' readonly class='deptdate'></td>";
                                    Echo "<td class=''><input type='date' value='$row[remddate]' name='deptdate_$ctr' style='width : 140px;border : none; padding : 0px;text-align:left;' readonly class='deptdate'></td>";
                                    Echo "<td class='' align='center'>";
                                    ?>
                                <input type="checkbox" name="postflag_<?= $ctr ?>" style="width: 30px;height:  30px;" id="postflag" value="1"  class="form-control">
                                <?php
                                echo "</td>";
                                echo "</tr>";
                                $ctr++;
                            }
                            ?>
                            
                                    <input type = "text" style="width: 1px;display: none;" name = "count" value = "<? Echo $ctr; ?>" >
                            

                            </tbody> 
                        </table>

                    </div>
                    <!--                    <div class="panel-footer">
                    <?php // include("includes/buttons.php");     ?>
                                        </div>-->
                </div>
            </div>
        </div>
    </form>

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