<!DOCTYPE html>
<html lang="en"> 

<head>
<?php ob_start(); ?>
<?php   require_once 'head_link.php'; ?>

</head>

<body>
 
<?php   require_once 'header1.php'; ?> 

<?php 
	if(isset($_GET['delete_id']))
	{
		// select image from db to delete
		$stmt_select = $DB_con->prepare('SELECT userPic FROM customer WHERE customer_id =:uid');
		$stmt_select->execute(array(':uid'=>$_GET['delete_id']));
		$imgRow=$stmt_select->fetch(PDO::FETCH_ASSOC);
		//unlink("user_images/".$imgRow['userPic']);
		
		// it will delete an actual record from db
		$stmt_delete = $DB_con->prepare('DELETE FROM customer WHERE customer_id =:uid');
		$stmt_delete->bindParam(':uid',$_GET['delete_id']);
		$stmt_delete->execute();
		
		//header("Location:customer.php");
	}

?>

<?php  require_once 'sidebar.php'; ?>


  <main id="main" class="main">

    <div class="pagetitle bg-light rounded p-2">
     <h1>Student List | <a target="_blank" href="student-list-active">   <i class="bi bi-printer"></i> </a>  |  <span> <a href="student-add">   <i class="bi bi-plus-square-fill"></i> </a> </span> </h1>
      
    </div> 

    <section class="section">
      <div class="row">
	  
        <div class="col-lg-12">

          <div class="card">
            <div class="card-body">
             
              <table class="table table-hover datatable">
                  
				  <thead class="alert-primary">
                            
                            <tr>
								 
                                <th>SL</th> 
                                <th>Students Name</th> 	
                                <th>Batch No</th>								
								<th>Course</th>
								<th>Phone</th> 
                                <th>Date</th>								
                                <th>Photo</th>								
								<th>Print</th>
								<th>Edit</th>
								<th>Delete</th>
                            </tr>
                        </thead>
						
						
                   <tbody id="tbody">
							<?php
							$sl=0;
								$eq=mysqli_query($con,"SELECT *
														FROM customer
														LEFT JOIN cust_position ON cust_position.id = customer.position
														left join batch on batch.id = customer.batch_no
														left join product on product.product_id = customer.course_id
														WHERE customer.status = 1 AND customer.member_id = '".$_SESSION['id']."'
														ORDER BY customer.customer_id DESC ");
														
														while($eqrow=mysqli_fetch_array($eq)){ 
									?>
										<tr>
											 
											<td><?php echo ++$sl; ?></td> 
											<td><?php echo $eqrow['customer_name']; ?></td>
											<td><?php echo $eqrow['batch_name']; ?></td>  
											<td> <?php echo $eqrow['product_name']; ?> </td>
											<td><?php echo $eqrow['contact_info']; ?></td> 
											<td><?php echo date("d-M-Y", strtotime($eqrow['join_date'])); ?></td>
										 <td> <img src="user_images/<?php echo $eqrow['userPic']; ?>" class="img-rounded" height="30px;" width="30px;" /></td> 
			
				<td>
					<a  target="_blank" class="btn-sm btn-primary" href="view-student?view=<?php echo $eqrow['customer_id']; ?>" title="click for view" ><span class="bi bi-printer"></span> Print</a> 

		 		</td> 

					<td>
					
					<a  class="btn-sm btn-info" href="student-edit?update=<?php echo $eqrow['customer_id']; ?>" title="click for edit"><span class="bi bi-pencil-square"></span>  Edit</a> 
		  			
		 		</td> 
				
				<td>
				<a class="btn-sm btn-danger delete-btn" href="#"   data-id="<?php echo $eqrow['customer_id']; ?>" 
                   data-bs-toggle="modal" data-bs-target="#confirmDeleteModal" 
				   title="Click for delete"> <span class="bi bi-trash"></span> Delete
                 </a>
				 
               <?php  require_once 'modal/delete_modal_for_all_list.php'; ?>
				</td> 
			
				
			</tr>
		<?php
		}  
		?>

</tbody>
              </table>
            
            </div>
          </div>

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

  </main>
  
  <?php  require_once 'footer1.php'; ?>