<?php
session_start();
include 'include/config.php';

if(!isset($_SESSION['id'])){
 echo "<script> window.location.href = 'index.php' </script>";
  }
?>

<?php  include 'include/head.php'; ?>
                    
                      <!-- Start Content-->
                      <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Vehicle</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Vehicle</h4>
                                </div>
                            </div>
                        </div>
                         <!--end page title -->
                         
        <!--                 <div class="row">-->
        <!--<div class="card">-->
        <!--    <div class="card-body">-->
                <!-- Form start -->
        <!--        <form method="post" action="">-->
                    <!-- Dropdown and Input field -->
                    <div class="row">
                        <!--<div class="col-lg-4">-->
                        <!--    <div class="form-group">-->
                        <!--        <label for="exampleFormControlSelect1">Select Spa</label>-->
                        <!--        <select name="spa" class="form-control" id="exampleFormControlSelect1">-->
                        <!--            <option>Select..</option>-->
                        <!--            <?php while($data = mysqli_fetch_assoc($select_spa)){?>-->
                        <!--            <option value="<?php echo $data['unique_id'];?>"><?php echo $data['unique_id'] . ' = ' .$data['name'];?></option>-->
                        <!--            <?php }?>-->
                                    
                        <!--        </select>-->
                        <!--    </div>-->
                        <!--</div>-->
                <!--        <div class="col-lg-4">-->
                <!--           <div class="form-group">-->
                <!--               <label for="schedule">User ID/Ac No /Phone No</label>-->
                <!--               <input type="text" name="userid" class="form-control" id="schedule" placeholder="Enter User ID">-->
                <!--           </div>-->
                <!--       </div>-->
                       
                <!--       <div class="col-lg-3">-->
                <!--           <div class="form-group">-->
                <!--               <label for="schedule">To</label>-->
                <!--               <input type="date"  name="to_date" class="form-control" id="schedule">-->
                <!--           </div>-->
                <!--       </div>-->
                       
                <!--       <div class="col-lg-3">-->
                <!--           <div class="form-group">-->
                <!--               <label for="schedule">From</label>-->
                <!--               <input type="date"  name="from_date" class="form-control" id="schedule">-->
                <!--           </div>-->
                <!--       </div>-->
                       
                       <!--<div class="col-lg-4">-->
                       <!--    <div class="form-group">-->
                       <!--        <label for="schedule">From Date</label>-->
                       <!--        <input type="date" name="from_date" class="form-control" id="schedule">-->
                       <!--    </div>-->
                       <!--</div>-->
                <!--        <div class="col-lg-4" style="margin-top:20px;">-->
                <!--         <button type="submit" name="submittt" class="btn btn-primary">Submit</button>-->
                <!--         </div>-->
                <!--    </div>-->
                    <!-- End of Dropdown and Input field -->
                    <!-- Submit button -->
                   
                <!--</form>-->
                
                <!-
                 <!-- if(isset($_POST['submittt'])){-->
                 <!--    $userid = $_POST['userid'];-->
             <!--    $to_date = $_POST['to_date'];-->
                <!--    $from_date = $_POST['from_date'];-->
             <!--    $sqll = mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM `user` where `id`='$userid' OR `a_c_number`='$userid' OR phone`='$userid'"));-->
                 <!--     $iddd = $sqll['id'];-->
                     
                 <!--      $to_date_formatted = str_replace('-', '/', $to_date);-->
                 <!--      $from_date_formatted = str_replace('-', '/', $from_date);-->
                 <!--   $sql = "SELECT * FROM `cd` where `userid`='$iddd' AND `cd_date` BETWEEN '$to_date_formatted' AND '$from_date_formatted'";-->
                <!--//  }else{-->
                <!--//      $sql = "SELECT * FROM `cd`";-->
                <!--//  }-->
                <!--// ?>-->
                <!-- Form end -->
            </div>
        </div>
</div>

                          <div>
                              <!--<a href="add_cd.php"  class="btn btn-success"> Add CD Amount</a>-->
                          </div>
                          
<!--                          <div style=" width:300px; margin-top:20px;">-->
    <!--<a href="export_pdf.php?iddd=<?php echo $iddd ?>&to_date=<?php echo $to_date_formatted ?>&from_date=<?php echo $from_date_formatted ?>" class="btn btn-info" target="_blank">Export</a>-->
<!--</div>-->
                          
                          

                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">
                                        
                                        <?php
                                        if(isset($_GET['user'])){
                                            $id = $_GET['user'];
                                        
                                            $sql = "DELETE FROM `add_vehicle` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){
                                             echo "<script>alert('Your Data deleted successfully');</script>";
                                            echo "<script>window.location.href='cd_amount.php';</script>";
                                            }
                                           
                                        }
                                        ?>
                                        <div class="table-responsive">
                                            <div class="tab-pane show active" id="basic-datatable-preview">
                                                <table id="datatable" class="table table-striped dt-responsive nowrap w-100">
                                                    <thead>
    <tr>
        <th>ID</th>
        <th>User ID</th>
        <th>User Latitude</th>
        <th>User Longitude</th>
        <th>User Address</th>
        <th>Vendor ID</th>
        <th>Vendor Name</th>
        <th>Service Name</th>
        <th>Vendor Address</th>
        <th>Service Charge</th>
        <th>Vendor Image</th>
        <th>Vendor Latitude</th>
        <th>Vendor Longitude</th>
        <th>Booking Date</th>
        <th>Booking Time</th>
        <th>Status</th>
        <th>Booking OTP</th>
        <th>Current Date</th>
        <th>Action</th>
    </tr>
</thead>

                                                    <tbody>
<?php
$sql = "SELECT * FROM `booking`";
$res = mysqli_query($conn, $sql);
$i = 1;
while ($row = mysqli_fetch_assoc($res)) {
    $iddd = $row['id'];
    $query = mysqli_query($conn, "SELECT * FROM `booking` WHERE `id`='$iddd'");
    $select_user_detail = mysqli_fetch_assoc($query);

    // Skip if no vehicle data exists for this user
    if (!$select_user_detail) continue;
?>
    <tr>
        <td><?= $i; ?></td>
       <!--<?php print_r( $select_user_detail); ?>-->
<!--<td>-->
<!--    <img src="../upload/<?= $select_user_detail['image'] ?>" alt="Vehicle Image" width="100" style="height:auto;">-->
<!--</td>-->


    <td><?php echo $row['user_id']; ?></td>
    <td><?php echo $row['user_latitude']; ?></td>
    <td><?php echo $row['user_longitude']; ?></td>
    <td><?php echo $row['address']; ?></td>
    <td><?php echo $row['vendor_id']; ?></td>
    <td><?php echo $row['vendor_name']; ?></td>
    <td><?php echo $row['service_name']; ?></td>
    <td><?php echo $row['vendor_address']; ?></td>
    <td><?php echo $row['service_charge']; ?></td>
    <td>
        <?php
        if (!empty($row['vendor_image'])) {
            echo '<img src="' . $row['vendor_image'] . '" alt="Vendor Image" width="100">';
        } else {
            echo '<span>No Image</span>';
        }
        ?>
    </td>
    <td><?php echo $row['vendor_lat']; ?></td>
    <td><?php echo $row['vendor_long']; ?></td>
    <td><?php echo $row['booking_date']; ?></td>
    <td><?php echo $row['booking_time']; ?></td>
    <td><?php echo $row['status']; ?></td>
    <td><?php echo $row['booking_otp']; ?></td>
    <td><?php echo $row['cureent_date']; ?></td>
   
        <td>
            <a href="booking.php?user=<?= $row['id'] ?>" onclick="return confirm('Are You Sure Want To Delete This?');" class="action-icon">
                <i class="mdi mdi-delete"></i>
            </a>
        </td>
    </tr>
<?php $i++; } ?>

                                                    </tbody>
                                                </table>                                           
                                            </div> <!-- end preview-->
                                        
                                            
                                        </div> <!-- end tab-content-->

                                    </div> <!-- end card body-->
                                </div> <!-- end card -->
                            </div><!-- end col-->
                        </div> <!-- end row-->

                    
                    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>