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

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

<?php
$iddddd = $_GET['idddd'];
$dateee = date("d-m-Y");

?>

<?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">Booking List</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Booking List</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 
                          <!--<div>-->
                          <!--    <a href="add_dharmi.php"  class="btn btn-success"> Add Dharmi</a>-->
                          <!--</div>-->
                          
                                                                       <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">Booking Schedule</label>
                                                                         <select name="booking_schudle" class="form-control" id="exampleFormControlSelect1">
                                                                             <option>Select Booking</option>
                                                                             <option value="old_booking">Old Booking</option>
                                                                             <option value="today_booking">Today Booking</option>
                                                                             <option value="upcoming_booking">Upcoming Booking</option>
                                                                         </select>
                                                                     </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 -->
                                                         </form>
                                                         <!-- Form end -->

                                                <?php
                                               if(isset($_POST['submittt'])){
                                        $booking_schudle = $_POST['booking_schudle'];
                                        if($booking_schudle == 'old_booking'){
                                            // Fetch data for old bookings (before current date)
                                            $selll = mysqli_query($conn, "SELECT * FROM `booking` WHERE `vender_id` = '$iddddd' AND STR_TO_DATE(`booking_date`, '%d-%m-%Y') < STR_TO_DATE('$dateee', '%d-%m-%Y')");
                                        } elseif($booking_schudle == 'today_booking'){
                                            // Fetch data for today's bookings
                                            $selll = mysqli_query($conn,"SELECT * FROM `booking` WHERE `vender_id`='$iddddd' AND STR_TO_DATE(`booking_date`, '%d-%m-%Y') = STR_TO_DATE('$dateee', '%d-%m-%Y')");
                                        } elseif($booking_schudle == 'upcoming_booking'){
                                            // Fetch data for upcoming bookings (after current date)
                                            $selll = mysqli_query($conn, "SELECT * FROM `booking` WHERE `vender_id`='$iddddd' AND STR_TO_DATE(`booking_date`, '%d-%m-%Y') > STR_TO_DATE('$dateee', '%d-%m-%Y')");
                                        }
                                    }
                                                                                             ?>
                                            </div>
                                        </div>
                                    </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 `dharmi` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){

                                            echo "<script>document.location('dharmi.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>Sr No</th>
                    <th>User Name</th>
                    <th>Phone Number</th>
                    <th>Email ID</th>
                    <th>Booking Date</th>
                    <th>Booking Time</th>
                    <th>Booking Status</th>
                    <th>Spa ID</th>
                    <th>Booking ID</th>
                    <th>Employee Name</th>
                    <th>Employee Charges</th>
                    <th>Employee ID</th>
                    <th>Employee Profile</th>
                    
                </tr>
            </thead>
            <tbody>
                <?php 
                $i = 1;
                while($data = mysqli_fetch_assoc($selll)) {
                ?>
                <tr>
                    <td><?= $i; ?></td>
                    <td><?= $data['user_name']; ?></td>
                    <td><?= $data['user_phone']; ?></td>
                    <td><?= $data['user_email']; ?></td>
                    <td><?= $data['booking_date']; ?></td>
                    <td><?= $data['booking_time']; ?></td>
                    <td><?= $data['booking_status']; ?></td>
                    <td><?= $data['vender_id']; ?></td>
                    <td><?= $data['unique_id']; ?></td>
                    <td><?= $data['employee_name']; ?></td>
                    <td><?= $data['employee_chargs']; ?></td>
                    <td><?= $data['employee_id']; ?></td>
                    <!--<td><?= $data['employee_profile']; ?></td>-->
                    <?php  
                    $fullImagePath = $data['employee_profile'];

                    $prefixToRemove = 'upload/image/';

                    $imageFilename = str_replace($prefixToRemove, '', $fullImagePath);
                    ?>
                    <td><img src="<?= '../upload/image/' . $imageFilename; ?>" style="width:100px; height:60px;"></td>
                    
                    <!--<td><a href="spa_detail.php?idddd=<?= $data['unique_id'];?>" class="btn btn-success">View</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'; 
?>