<?php
session_start();
require_once 'includes/config.php';

if (!isset($_SESSION['user_logged_in']) && $_SESSION['user_logged_in'] != TRUE) {
    header('Location:login.php');
}

$customers=mysqli_query($con,'SELECT * FROM coupons WHERE status=1  ORDER BY id DESC');

if(isset($_GET['del_id']) && $_GET['del_id']!=''){
	$deleteEmployee=mysqli_query($con,"DELETE FROM coupons WHERE id=".$_GET['del_id']);
	if($deleteEmployee){
		$del_stat=1;
		$message='coupons deleted successfully.';
	}
}
require_once 'includes/header.php';
?>
<div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12">
			<a href="add_coupon.php" class="btn btn-primary btn-round">Add Coupon<div class="ripple-container"></div></a>
              <div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title "> All Coupons</h4>
                  <p class="card-category"> </p>
                </div>
                <div class="card-body">
                  <div class="table-responsive">
                    <table class="table">
                      <thead class=" text-primary">
                        <th>No</th>  
		  <th>Coupon Code </th> 
		  <th>Discount Type </th> 
		  <th>Discount </th> 
		  <th>Start Date </th> 
		  <th>End Date </th> 
		 
		  
		  <th>Action </th>
                      </thead>
                      <tbody>
                        <?php
		if(mysqli_num_rows($customers)>0){	
		$i=1;
		while($customer=mysqli_fetch_array($customers)){?>
		<tr>
		<td><?php echo $i;?></td>
		<td><?php echo $customer['coupon_code'];?></td>
		<td><?php echo $customer['discount_type'];?></td>
		<td><?php echo $customer['discount'];?></td>
		<td><?php echo $customer['start_date'];?></td>
		<td><?php echo $customer['end_date'];?></td>
		
		<td>
		<a href="edit_coupon.php?id=<?php echo $customer['id'];?>" title="Edit Coupon" class="btn btn-success"><i class="fa fa-edit"></i></a>
		<a href="coupons.php?del_id=<?php echo $customer['id'];?>" class="btn btn-danger delete_btn" title="Delete Coupon"><i class="fa fa-trash"></i></a>
		</td>
		</tr>	
		<?php $i++;}
		}
		?>   
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>

<?php include_once 'includes/footer.php'; ?>

<script type="text/javascript">
    $(document).ready(function () {
        $('.delete_btn').click(function () {
            var r = confirm("Are you sure?")
            if (r == true) {
                return true;
            } else {
                return false;
            }
        });
    });
</script> 