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

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

<?php
if(isset($_GET['pend'])){
    $idddd = $_GET['pend'];
    $status = "done";
    
    $update = mysqli_query($conn,"UPDATE `vender` SET `status`='$status' WHERE `id`='$idddd'");
    if($update){
        echo "<script>document.location.href='vender.php'</script>";
    }
}

if(isset($_GET['done'])){
    $idd = $_GET['done'];
    $status = "pending";
    
    $updatee = mysqli_query($conn,"UPDATE `vender` SET `status`='$status' WHERE `id`='$idd'");
    if($updatee){
        echo "<script>document.location.href='vender.php'</script>";
    }
}
?>

                                        <?php
                                        if(isset($_GET['user'])){
                                            $id = $_GET['user'];
                                        
                                            $sql = "DELETE FROM `verder` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){
                                             echo "<script>alert('Your Data deleted successfully');</script>";
                                            // echo "<script>document.location('user.php');</script>";
                                            echo "<script>window.location.href='user.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">Vender List</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Vender List</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 
                          <!--<div>-->
                              <a href="add_vender.php"  class="btn btn-success"> Add Vender</a>
                          <!--</div>-->

                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">
                                        
                                        <?php
                                        if(isset($_GET['id'])){
                                            $id = $_GET['id'];
                                        
                                            $sql = "DELETE FROM `vender` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){

                                            echo "<script>document.location('vender.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>Name</th>
                                                            <th>Phone</th>
                                                            <th>Address</th>
                                                            <th>City</th>
                                                            <th>Pincode</th>
                                                            <th>Password</th>
                                                            <th>Email</th>
                                                            <th>State</th>


                                                        </tr>
                                                    </thead>
                                              <?php 
                                                          $i = 1;
                                                         $selll = mysqli_query($conn,"SELECT * FROM `vender`");
                                                                   while($data = mysqli_fetch_assoc($selll)) {?>
                                                     
                                                          <tr>
                                                              <td><?php echo $i;?></td>
                                                              <td><?= $data['name'];?></td>
                                                              <td><?= $data['phone'];?></td>
                                                              <td><?= $data['address'];?></td>
                                                              <td><?= $data['city'];?></td>
                                                           
                                                              <td><?= $data['pincode'];?></td>
                                                              <td><?= $data['password'];?></td>
                                                                <td><?= $data['email'];?></td>
                                                                <td><?= $data['state'];?></td>


                                                           <td>
                                                                <a href="venderedit.php?id=<?php echo $data['id']?>" class="action-icon"> <i class="mdi mdi-square-edit-outline"></i></a>
                                                                <a href="vender.php?user=<?= $data['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>
                                                     
                                                      </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'; 
?>