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

$formname = 'Visa Aknowledge Records';
$maindb = 'visamain';
$trandb = 'visatran';
$printfile = "";
$file = 'visaaknw.php';
$fileadd = 'visaedit.php';
$trandbexist = 0;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
$usertype = $_SESSION["usertype"];
$zroot = $_SESSION["zdir"];

$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"];
        $aknwrecd = $_POST["aknwrecd_$i"];
        if (!empty($msrno)) {
            mysqli_query($conn,"UPDATE `visamain` SET `aknwrecd`='$aknwrecd' WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));
        }
    }
    updmess();
//    parent.window.location.reload();
//    window . location . reload();
//    header("Location:$file"); 
//    header("refresh: 1; menu.php");
}

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 submit">
                    </div>
                    <div class="panel-body" style="">
                        <table id="example1" class="table-bordered" width="100%">

                            <thead>
                                <tr style="background-color: #64CCFC;padding-right: 5px;">
                                    <th>Sr.</th>
                                    <th>Queued By</th>
                                    <th>Voucher</th>
                                    <th>Lead Vouch</th>
                                    <th>Date</th>
                                    <th>Name</th>
                                    <th>Last Name</th>
                                    <th>Mobile</th>
                                    <th>Destination</th>
                                    <th>Travel Date</th>
                                    <th style="width:10%;">Close</th>
                                </tr>
                            </thead>  
                            <tbody>
                                <?php
                                $srchresult = mysqli_query($conn,"SELECT *, DATE_FORMAT(`deptdate`, '%d-%m-%Y')as deptdate FROM `$maindb`
                                                           where `aknwgive`='1' and `aknwrecd`='' and `username`='$user' 
                                                           ORDER BY VOUCHNO DESC") or die(mysqli_error($conn));

                                $ctr = 1;

                                while ($row = mysqli_fetch_array($srchresult)) {
//                                    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=''><input type='text' value='$row[username]' name='username_$ctr' style='border : none;width : 100px; padding : 0px;text-align:center;' readonly class='username'></td>";
                                    Echo "<td class=''><input type='text' value='$row[vouchno]' name='vouchno_$ctr' style='border : none;width : 30px; padding : 0px;text-align:center;' readonly class='vouchno'></td>";
                                    Echo "<td class=''><input type='text' value='$row[leadvouch]' name='leadvouch_$ctr' style='border : none;width : 30px; padding : 0px;text-align:center;' readonly class='leadvouch'></td>";
                                    Echo "<td class=''><input type='date' value='$row[vouchdt]' name='vouchdt_$ctr' style='border : none;width : 120px; 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:left;width:110px;' readonly class='name'></td>";
                                    Echo "<td class=''><input type='text'value='$row[lastname]' name='lastname_$ctr' style='border : none; padding : 0px;text-align:left;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:left;width:80px;' readonly class='mobile'></td>";
                                    Echo "<td class=''><input type='text'value='$row[destination]' name='destination_$ctr' style='border : none; padding : 0px;text-align:left;width:90px;' readonly class='destination'></td>";
                                    Echo "<td class=''><input type='text' value='$row[deptdate]' name='deptdate_$ctr' style='border : none; padding : 0px;text-align:left;width:100px;' readonly class='deptdate'></td>";
                                    Echo "<td class='' align='center'>";
                                    ?>
                                <input type="checkbox" name="aknwrecd_<?= $ctr ?>" style="width: 30px;height:  30px;" id="aknwrecd" value="1"  class="form-control aknwrecd">
                                <?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>
