<?php

 

$table_name = 'membership';
$redirection_page = "index.php?action=$page_name";
$action_name = "action=$page_name";
$type = $_REQUEST['type'];
$edit_id = $_REQUEST['edit_id'];
$delete_id = $_REQUEST['delete_id'];
$myy_id = $_REQUEST['myy_id'];
$plan_action = $_POST['plan_action'];


if(isset($_POST['submit1'])){
     
   $insert_bookings = "UPDATE `$table_name` SET
  status   = '".addslashes($plan_action)."' 
  where id='".$myy_id."'";   
  
  
$sql_insert = $dbconn->prepare($insert_bookings);
$sql_insert->execute();
}
 

// For Submitting The Form

if(isset($_POST['submit'])){
  
  $field1    =  $_POST['field1'];
  $field2    =  $_POST['field2'];
  $field3    =  $_POST['field3'];
  $field4    =  $_POST['field4'];
  $field5    =  $_POST['field5'];
  $field6    =  $_POST['field6'];
  $field7    =  $_POST['field7'];
  $field8    =  $_POST['field8'];
  $field9    =  $_POST['field9'];
  $field10    =  $_POST['field10'];
   
  
 if ($type == 'Edit') {
   $insert_bookings = "UPDATE `$table_name` SET
  sidebar_menu_name   = '".addslashes($field1)."',   
  sidebar_menu_type   = '".addslashes($field2)."',
  sidebar_menu_master   = '".addslashes($field3)."'
  where id='".$edit_id."'";   
  
  
$sql_insert = $dbconn->prepare($insert_bookings);
$sql_insert->execute();

  
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page&id=$edit_id");
 } else{ 
  $insert_bookings = "INSERT `$table_name` SET
  sidebar_menu_name   = '".addslashes($field1)."',   
  sidebar_menu_type   = '".addslashes($field2)."',
  sidebar_menu_master   = '".addslashes($field3)."',
  status   = 'Active'";   
  
  
$sql_insert = $dbconn->prepare($insert_bookings);
$sql_insert->execute();
$myid = $dbconn->lastInsertId();
  
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page&id=$myid");
 }
    
}

// For Displaying the table

if (isset($_GET['pageno'])) {
            $pageno = $_GET['pageno'];
        } else {
            $pageno = 1;
        }
        $no_of_records_per_page = 20;
        $offset = ($pageno-1) * $no_of_records_per_page;


$select_enquiry="SELECT * FROM $table_name  order by id desc";
 $sql=$dbconn->prepare($select_enquiry);
 $sql->execute();
  
        
        $total_rows = $sql->fetchColumn();
        $total_pages = ceil($total_rows / $no_of_records_per_page);

        $select_enquiry = "SELECT * FROM $table_name   order by id desc LIMIT $offset, $no_of_records_per_page";
$sql=$dbconn->prepare($select_enquiry);
 $sql->execute();
 $wlvd=$sql->fetchAll(PDO::FETCH_OBJ);


 $select_bookings= "SELECT * FROM `$table_name` WHERE id = '$edit_id'";
 $sql1=$dbconn->prepare($select_bookings);
 $sql1->execute();
 $wlvd1=$sql1->fetchAll(PDO::FETCH_OBJ);
 foreach($wlvd1 as $rows1);


?>
 
 
    <div class="container-fluid">
      
      <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Breadcrumb-->
     <div class="row pt-2 pb-2">
        <div class="col-sm-9">
        <h4 class="page-title"><?php  echo $page_name; ?></h4>
         <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.php?action=Welcome">Dashboard</a></li>
             
            <li class="breadcrumb-item active" aria-current="page"><a href="index.php?action=<?php  echo $page_name; ?>"><?php  echo $page_name; ?></a></li>
         </ol>
     </div>
     
     <div class="col-sm-3">
       <?php include ('plugins/alert.php') ;?>
       <!-- Button trigger modal -->
 

 



     </div>
     
     </div>
    <!-- End Breadcrumb-->
    <?php if ($type == 'Delete'){

     $delete_statement = "UPDATE `$table_name` SET
      status   = 'Inactive'
      where id='".$delete_id."'";   
  
  
$sql_insert = $dbconn->prepare($delete_statement);
$sql_insert->execute();

  
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page&id=$delete_id");
 
      
      }else {
        ?>
        <div class="row">
         

        <div class="col-lg-12">
            
          <div class="card">
               
            <div class="card-header"> 
            <br>
            <form method="POST" action="index.php?action=Quotation-Search">
            <div class="row">
                
                <div class="col-md-9">
                    <input type="text" class="form-control" name="companyName" placeholder="Company Name">
                </div>
                <div class="col-md-3">
                    <button type="submit"  name="submit11111" value="Submit" class="btn btn-primary">Submit</button>
                </div>
               
            </div>
             </form>
            
            </div>
            <div class="card-body">
              <div class="table-responsive">
               
                <table class="table table-hover" id="sample-table-1">
                    <thead class="thead-dark">
                      <tr>
                        <th class="center"> ID</th>
                        <th class="center"> Name</th>
                        <th class="center"> Start Date</th>
                        <th class="center"> End Date</th>
                        <th class="center">  Proof</th>
                        <th class="center">  Status</th>
                     
                        
                        <th class="center">  Action</th>  
                      </tr>
                    </thead>
                    <tbody>
     <?php

//while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
//{ 
if($sql->rowCount() > 0){
  
    foreach($wlvd as $rows){
$mem_mobile = $rows->mem_mobile ;
$mem_start_date = $rows->mem_start_date;
$mem_end_date = $rows->mem_end_date;
$field1 = $rows->id;
$agentt = $rows->quo_cus_agent;
$status = $rows->status;
$photo = $rows->membership_payment_proof;
 





  
?>                  
                      <tr>
                      <td class="center"><?php echo $field1;?></td> 
                      <td class="center"><?php 
                       
                      
$select_customer= "SELECT * FROM `users` WHERE user_phone = '$mem_mobile'";
 $sql2=$dbconn->prepare($select_customer);
 $sql2->execute();
 $wlvd2=$sql2->fetchAll(PDO::FETCH_OBJ);
 foreach($wlvd2 as $rows2);
echo $rows2->user_name;?></td>

                      <td class="center"><?php echo $mem_start_date;?></td>
                      <td class="center"><?php echo $mem_end_date;?></td>
                      <td class="center">
                        <?php      
                          if($photo == ''){
                             
                              
                        
                          }else{
                              ?>
                              <a target="_blank" href="../mobile/Flutter/assets/uploads/payment_proof/<?php echo $rows->membership_payment_proof;?>" ><img height='100' src="../mobile/Flutter/assets/uploads/payment_proof/<?php echo $rows->membership_payment_proof;?>"><br>Zoom</a>
                              <?php
                          }
                        ?>
                      </td>
                      <td class="center"><?php echo $status?></td>
                      <td class="center">
                          
                          
     <div class="dropdown">
  <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Activate / Deactivate
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenuButton" style="text-align:left; padding-left:10px">
    <a class="dropdown-item" style="padding-left:2px; padding-right:2px; font-size:13px" href="" data-toggle="modal" data-target="#Modal<?php echo $field1;?> " ><i class="fa fa-envelope"></i> Activate / Deactivate</a> 
     
 
  </div>
</div>                        
                          
                          
                       
<!------- Modal Starts ---->

<div class="modal fade" id="Modal<?php echo $field1;?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Activate or Deactivate</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      
      
       
     
<form id="formID" class="m-t-30" method="POST" action="">      
<div class="modal-body">
    
     
        <div class="row">
          <div class="col-lg-12">
            <label>Action</label>
            <input name='myy_id' type="hidden" value='<?php echo $field1?>'>
            <select name='plan_action' class='form-control'>
                <option><?php echo $rows->status ;?></option>
                <option>--Select--</option>
                <option>Active</option>
                <option>Inactive</option>
            </select>

           </div>
           
           
           
          
           
          
          
           
           
          
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit"  name="submit1" value="Submit" class="btn btn-primary">Submit</button>
      </div>
    </form>
    </div>
</div>
</div>



<!------- Modal Ends ------>
                       
                       
                     
                       
                     
                       
                     </td>
                     </tr> 

                      <?php }} ?>
                     </tbody> 
                  </table>
                  
   

                  <?php include ('plugins/pagination.php') ;?>
                
        </div>

            </div>
            </div>
          </div>
        </div>

        <?php
      };
      ?>

        
      </div><!-- End Row-->

      
    </div><!--End content-wrapper-->
    <!--Start Back To Top Button-->
     <script>
      $('#myModal').on('shown.bs.modal', function () {
  $('#myInput').trigger('focus')
})
    </script>
    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
    <!--End Back To Top Button-->