<?php
ob_start();
//require("includes/dbconnect.php");
//ob_start();
$conn = mysqli_connect("localhost", "cepheisy_cepheis", "rajF@1998") or die(mysqli_error($conn));
mysqli_select_db($conn, "cepheisy_cartweb_root") or die(mysqli_error($conn)) ;

$formname = 'OTP';
$maindb = 'otptable';
$trandb = '';
$printfile = "";
$file = 'autotran.php';
//$fileadd = 'visaedit.php';
$trandbexist = 1;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
//$mgrpcode = '009';
$bseries = $_SESSION["user_series"];
$zroot = $_SESSION["zdir"];

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

$compcd = $_SESSION["comp_" . $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");
$count = $_POST["items"];
if (isset($_POST["submit"])) {
    $date = date("Y-m-d");

    for ($i = 0; $i < $count; $i++) {


        $vouchno = $_POST["vouchno_$i"];
        $usernam = $_POST["usernam_$i"];
        $entdate = $_POST["entdate_$i"];
        $enttime = $_POST["enttime_$i"];
        $complete = $_POST["complete_$i"];

        if ($complete == 1) {
            mysqli_query($conn, "UPDATE `$maindb` SET `otpgive` = '$complete' 
                                 WHERE `vouchno`='$vouchno' and `username`='$usernam'
                                 and `entdate`='$entdate' and `enttime`='$enttime' ")or die(mysqli_error($conn));
        }
    }
}

include("includes/linkshead_otp.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-body table-responsive" style="width:100%">
                        <div class="row">
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9"></div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">

                                <input style="padding-right: 15px;float:right;"  type='submit' id="update" name='submit' value='SAVE' class="btn btn-success">
                            </div>
                        </div>
                        <table id="example1" class="table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="width: 5%;">Sr.</th>
                                    <th style="width: 9%;">Bill No.</th>
                                    <th style="width: 5%;">Bill Type</th>
                                    <th style="width: 5%;">User Name</th>
                                    <th style="width: 25%;">Message</th>
                                    <th style="width: 5%;">Close</th>
                                </tr>
                            </thead>
                            <tbody class="mytable table-bordered">
                                <?php
                                $srchresult = mysqli_query($conn, "SELECT *, DATE_FORMAT(`entdate`, '%d-%m-%Y')as vouchdt
                                                                   FROM `$maindb` where `otpgive`= '' order by entdate,enttime DESC") or die(mysqli_error($conn));

                                $ctr = 0;
                                $mctr = 0;
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    $mctr++;

                                    echo "<tr>";
                                    Echo "<td style='align:center;' class=''>$mctr</td>";
                                    Echo "<td style='align:center;' class=''><input type='text' style='border:none;background-color:white;font-size:15px' name= 'vouchno_$ctr' value='$row[vouchno]' class='vouchno form-control' readonly></a></td>";
                                    Echo "<td  class='' style='font-size:15px'>$row[billtype]</td>";
                                    Echo "<td  class='' style='font-size:15px'>$row[username]</td>";
                                    Echo "<td class='' style='font-size:15px'>$row[mesg]
                                                      <input type='hidden' name= 'usernam_$ctr' value='$row[username]' class='form-control' readonly>
                                                      <input type='hidden' name= 'enttime_$ctr' value='$row[enttime]' class='form-control' readonly>
                                                      <input type='hidden' name= 'entdate_$ctr' value='$row[entdate]' class='form-control' readonly></td>";
                                    Echo "<td style='align:center;padding-left:15px;padding-bottom: 33px;' class=''><input type='checkbox' style='border:none;height:25px;width:25px;' align='center' name= 'complete_$ctr' value='1' class='commplete form-control'></a></td>";
                                    echo "</tr>";
                                    $ctr++;
                                }
                                ?>
                            <input type = "text" style="display: none;" name = "items" value = "<? Echo $ctr; ?>">
                            </tbody> 
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </form>

    <?php include("includes/linksfoot_otp.php"); ?>

</body>
</html>