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

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

if(isset($_GET['id']) && $_GET['id']!=''){
	$deleteEmployee=mysqli_query($con,"update banners set status=1 WHERE id=".$_GET['id']);
	if($deleteEmployee){
		$del_stat=1;
		$message='sms activated successfully.';
	}
}
if(isset($_GET['del_id']) && $_GET['del_id']!=''){
	$deleteEmployee=mysqli_query($con,"DELETE FROM banners WHERE id=".$_GET['del_id']);
	if($deleteEmployee){
		$del_stat=1;
		$message='Banner deleted successfully.';
	}
}
$customers=mysqli_query($con,'SELECT * FROM banners WHERE user_id>0 ORDER BY id DESC');

require_once 'includes/header.php';
?>
<div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-md-12">
			<!--<a href="add_smsbygroup.php" class="btn btn-primary btn-round">Add New SMS<div class="ripple-container"></div></a>-->
              <div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title ">Merchant Banners </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>Merchant Name</th> 		   <th>Image </th> 
		  <th>Url </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 $cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users WHERE id=".$customer['user_id'])); echo $cat['username'];?></td>
		<td><img src="<?php echo $customer['image'];?>" width="100" height="100"></td>
		<td><?php echo $customer['url'];?></td>		<td>
		<!--<a href="edit_smsbygroup.php?id=<?php echo $customer['id'];?>" title="Edit Group" class="btn btn-success"><i class="fa fa-edit"></i></a>-->
		<a href="userbanners.php?del_id=<?php echo $customer['id'];?>" class="btn btn-danger delete_btn" title="Delete"><i class="fa fa-trash"></i></a>
		<?php
		if ($customer['status']==0) { ?>
		<a href="userbanners.php?id=<?php echo $customer['id'];?>" title="Activate SMS" class="btn btn-success">Activate Promotions</a>
		<?php } ?>
		</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> 