<?php

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

$array = '';
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn,$zdb);

if (isset($_REQUEST['mobile'])) {
    $mmobile = $_REQUEST['mobile'];
//   print "SELECT a.*, b.discount FROM `item` a, `itemgrp` b WHERE a.barcode = '$barcoden' and a.group = b.code " ;
    $iresult = mysqli_query($conn,"SELECT `mobile`, `name`, `lastname`,`vouchno`,  DATE_FORMAT(`deptdate`, '%d-%m-%Y') as deptdate,
                         `destination` FROM `leadenq` WHERE mobile ='$mmobile' and status='Confirmed' order  by vouchno desc") or die(mysqli_error($conn));

    $ctr = 1;
    if (mysqli_num_rows($iresult) > 0) {
        echo "<b>Confirmed</b>";
        echo "<table class='table-bordered'>";
        echo "<tr>";
        echo "<th>Sr.</th>";
        echo "<th>Book No.</th>";
        echo "<th>Name</th>";
        echo "<th>Last Name</th>";
        echo "<th>Mobile</th>";
        echo "<th>Destination</th>";
        echo "<th>Travel Date</th>";
        echo "</tr>";


        while ($rec = mysqli_fetch_array($iresult)) {
            $name = strtoupper($rec[name]);
            $lastname = strtoupper($rec[lastname]);
            
            Echo "<tr>";
            Echo "<td><input type='text 'value='$ctr' name='srno_$ctr' style='width:40px;' readonly class=''></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec[vouchno]&mode=edit\"><input type='text'  value='$rec[vouchno]' name='vouchno_$ctr'  readonly style='width:65px;' class='vouchno'></a></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec[vouchno]&mode=edit\"><input type='text' value='$name' name='name_$ctr' style='width:100px;' readonly class='name'></a></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec[vouchno]&mode=edit\"><input type='text' value='$lastname' name='lastname_$ctr' readonly style='width:100px;' class='lastname'></a></td>";
            Echo "<td><input type='text'value='$rec[mobile]' name='mobile_$ctr' readonly style='width:80px;' class='mobile'></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec[vouchno]&mode=edit\"><input type='text' style='width:100px;' value='$rec[destination]' name='destination_$ctr' readonly class='destination'></a></td>";
            Echo "<td><input type='text' value='$rec[deptdate]' name='deptdate_$ctr' style='width:100px;'  readonly class='deptdate'></td>";
            Echo "</tr>";
            
            
            $ctr++;
        }
        echo "</table>";
    }


    $iresult1 = mysqli_query($conn,"SELECT `mobile`, `name`, `lastname`,`vouchno`, `status`,  DATE_FORMAT(`deptdate`, '%d-%m-%Y') as deptdate,
                         `destination` FROM `leadenq` WHERE mobile ='$mmobile' and status!='Confirmed' order  by vouchno desc") or die(mysqli_error($conn));

    $ctr1 = 1;
    if (mysqli_num_rows($iresult1) > 0) {
        echo "<br>";
        echo "<br>";
        echo "<b>Lead Query</b>";
        echo "<table class='table-bordered' width=''>";
        echo "<tr>";
        echo "<th>Sr.</th>";
        echo "<th>Book No.</th>";
        echo "<th>Name</th>";
        echo "<th>Last Name</th>";
        echo "<th>Mobile</th>";
        echo "<th>Destination</th>";
        echo "<th>Travel Date</th>";
        echo "<th>Status</th>";
        echo "</tr>";


        while ($rec1 = mysqli_fetch_array($iresult1)) {
            $name1 = strtoupper($rec1[name]);
            $lastname1 = strtoupper($rec1[lastname]);
            
            Echo "<tr>";
            Echo "<td><input type='text 'value='$ctr1' name='srno_$ctr1' style='width:40px;' readonly class=''></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec1[vouchno]&mode=edit\"><input type='text'  value='$rec1[vouchno]' name='vouchno_$ctr1'  readonly style='width:65px;' class='vouchno'></a></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec1[vouchno]&mode=edit\"><input type='text' value='$name1' name='name_$ctr1' style='width:100px;' readonly class='name'></a></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec1[vouchno]&mode=edit\"><input type='text' value='$lastname1' name='lastname_$ctr1' readonly style='width:100px;' class='lastname'></a></td>";
            Echo "<td><input type='text'value='$rec1[mobile]' name='mobile_$ctr1' readonly style='width:80px;' class='mobile'></td>";
            Echo "<td><a href=\"leadenq.php?vouchno=$rec1[vouchno]&mode=edit\"><input type='text' style='width:100px;' value='$rec1[destination]' name='destination_$ctr1' readonly class='destination'></a></td>";
            Echo "<td><input type='text' value='$rec1[deptdate]' name='deptdate_$ctr1' style='width:90px;'  readonly class='deptdate'></td>";
            Echo "<td><input type='text' value='$rec1[status]' name='status_$ctr1' style='width:150px;'  readonly class='status'></td>";
            Echo "</tr>";
            $ctr1++;
        }
        echo "</table>";
    }
    //$iresult = mysqli_query($conn,"SELECT * FROM `item` WHERE name = '$itemn' ") or die(mysqli_error($conn));
//   if(mysqli_num_rows($iresult) > 0){
//      $array    = mysqli_fetch_array($iresult);
//      
//      $mobile2      = $array["mobile2"];
//      $name         = $array["name"];
//      $lastname     = $array["lastname"];
//      $tel          = $array["tel"];
//      $tel2         = $array["tel2"];
//      $email        = $array["email"];
//      $city         = $array["city"];
//    } 
//    
//    header("Content-type: application\json");
//    $data=array("mobile2"=>$mobile2,"name"=>$name,"lastname"=>$lastname,"tel"=>$tel,"tel2"=>$tel2,"email"=>$email,"city"=>$city);
//    echo json_encode($data);
}
?>