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

$formname = 'Lead Queued Records';
$maindb = 'leadenq';
$printfile = "";
$file = 'leadtrnf.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"])) {

    $count = $_POST["count"];
//    browse($count);

    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $vouchno = $_POST["vouchno_$i"];
        $leadacpt = $_POST["leadacpt_$i"];
        
        if (!empty($msrno)) {
            if($leadacpt == 'Y'){
                mysqli_query($conn,"UPDATE `leadenq` SET `leadacpt` = 'Y', `username`='$user' WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));
//            } else{
//                mysqli_query($conn,"UPDATE `leadenq` SET `leadacpt`='', `questaff`='N' WHERE `vouchno`='$vouchno'")or die(mysqli_error($conn));
            }
        }
    }
  //  updmess();
    header("refresh: 1; $file?mode=last");
}

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>
                                    <th style="width:15%;">Queued By</th>
                                    <th style="width:10%;">Book No.</th>
                                    <th style="width:15%;">Name</th>
                                    <th style="width:15%;">Last Name</th>
                                    <th style="width:15%;">Mobile</th>
                                    <th style="width:15%;">Destination</th>
                                    <th style="width:10%;">Status</th>
                                </tr>
                            </thead>  
                            <tbody>
                                <?php
                                $srchresult = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `newuser` = '$user' and `questaff` != 'N' and `username`!='$user'") 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>";
                                    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 : 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>";
                                    echo "<td align='left'>"
                                    ?>
                                    <select name='leadacpt_<?= $ctr ?>' id="leadacpt"  class="leadacpt form-control" style='text-align: center;height:33px;width:150px;border: 0px;'>
                                        <option value=""></option>
                                        <option value="N">NO</option>
                                        <option value="Y">YES</option>
<!--                                        <option value='N'<?php
                                        if ($addflag != 1) {
                                            if ($row["leadacpt"] == "N") {
                                                echo "selected='selected'";
                                            }
                                        }
                                        ?> >No</option>
                                        <option value='Y'<?php
                                        if ($addflag != 1) {
                                            if ($row["leadacpt"] == "Y") {
                                                echo "selected='selected'";
                                            }
                                        }
                                        ?>>Yes</option>-->
                                    </select>
                                    <?php
                                    echo "</td>";
                                    echo "</tr>";
                                    $ctr++;
                            }
                            ?>

                            <input type = "text" style="width: 15px;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>
