<?php

 include("../../../dbconnection/dbconnection.php");$name='';if(isset($_SESSION["id"])){  $user=strtolower($_SESSION['type']); if($user==="admin"){$id=$_SESSION['id'];include("../../../steam_functions/steam_functions.php");$team=(staff_team($connect));$loggedin=staff_loggedin($id,$connect);$students=few_students($connect);}else if($user=="staff"){header("location:../../../pages/staff_login.php");}else{ header("location:../../../pages/staff_login.php"); }}else{header("location:.../../../pages/staff_login.php");}

include("../../header.php");

?>      
	
	<link rel="stylesheet" href="../../bootstrap/css/datepicker.css">
	<script src="../../bootstrap/js/bootstrap-datepicker1.js"></script>
	
<!-- jQuery 2.2.3 -->
<script src="../../plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>


	
   <div class="content-wrapper"  style='min-height:auto'>
      <section class="content-header">
      <h1>
        <small></small>
      </h1>
       <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active">Subscribers</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        
		
		<div class="col-md-9" style='padding:3px'>
          <div class="box">
            <div class="box-header bg-red">
              <h3 class="box-title">Subscribers</h3>
			<button type="button" name="add" id="add_button" class="btn btn-primary btn-xs pull-right ">Add</button>    	
										
            </div>
            <!-- /.box-header -->
            
            <div class=" panel-body  table-responsive">
						<table id="subscribers" class="table  table-bordered table-striped ">

						
										<thead>
											<tr>
												<th>No</th>
												<th>Email</th>
												<th>Date Subscribed</th>
												<th>Status</th>
												<th></th>
											</tr>
										</thead>
										<tbody>
										 <!---->
                						
											<?php
											
										$sub=subscribers($connect);
										foreach($sub as $row){
											$id=$row["id"];
											$email=$row["email"];
											$date=date("d-m-Y",$row["date"]);
											$status=$row["status"];
											if($status==="1")
											{
												$status = '<span class="label label-success">Active</span>'; 
												$btn='<button type="button" name="disable" id="'.$row["id"].'" class="btn btn-danger btn-xs delete" data-status="'.$row["status"].'">Unsubscribe</button>';
											}
											else
											{
												$status = '<span class="label label-danger">Disabled</span>';
												$btn='<button type="button" name="disable" id="'.$row["id"].'" class="btn btn-success btn-xs delete" data-status="'.$row["status"].'">Subscribe</button>';
											}
											
										?>
										<tr>
										  <td><?php echo $id;?></td>
										  <td><?php echo $email;?></td>
										  <td><?php echo $date;?></td>
										  <td><?php echo $status;?></td>
										  <td><?php echo $btn;?></td>
										</tr>
										<?php 
										}
										?>
               <!-- // -->
										</tbody>
										
						</table>
            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.col -->
		</div>
        <!-- /.col -->
	
		  
		  

		
        </div>
        <!-- /.col -->
		
				
<div id="subscribe-Modal" class="modal  fade">

    	<div class="modal-dialog " style='top:30%'>
    		<form method='POST' id='form-subscribe'  >
    			<div class="modal-content " style='padding:0px'>
    				<div class="modal-header ">
    					<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title"><i class="fa fa-plus"></i> New Subscription</h4>
    				</div>
    				<div class="modal-body"  style='padding:0px'>

								<!-- /.box-header -->
								<div class="box-body" style='padding:0px'>

										  <!-- First Name -->
								  <div class="form-group col-md-12">
										<label>User Email</label>
									<div class="input-group">
									  <div class="input-group-addon">
										<i class="fa fa-envelope-o"></i>
									  </div>
									  <input  class="form-control" type="email" name='user-email' placeholder='User Email' style="height:50px" required>
									</div>
									<!-- /.input group -->
								  </div>
								  <!-- /.form group -->
								
								
							</div>
    				<div class="modal-footer"> 
					<button type="reset" class="btn btn-default pull-left " data-dismiss="modal"><i class="fa fa-times"></i> Discard</button>
							<div class="pull-right">
									<input type="hidden" name="btn_action" value='Add-Subscriber' id="btn_action" />
									<button type="submit" class="btn btn-danger"><i class="fa fa-paper-plane"></i> Subscribe</button>
								 </div>
							
    				</div>
    			</div>
    		</form>
    	</div>

    </div>
    </div>
		
    </section>
    <!-- /.content -->

	
	


	</div>
 

	
	
	
<!-- jQuery 2.2.3 -->
<script src="../../plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>
	<!-- DataTables -->
<script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../plugins/fastclick/fastclick.js"></script>

<!-- Bootstrap WYSIHTML5 -->
<script src="../../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>

<script src="../../plugins/select2/select2.full.min.js"></script>


<script>
  $(function () {
  
	    $("#subscribers").DataTable();
    $('#id').DataTable({
		"processing":true,
      "paging": true,
      "lengthChange": false,
	  "ordering": true,
      "searching": false,
      "info": true,
      "autoWidth": false
	  
		
    });

	
  });
  $(document).ready(function(){
	  
	  		$('#add_button').click(function(){
			
			$('#subscribe-Modal').modal('show');
			$('#form-subscribe')[0].reset();
			$('#btn_action').val('Add-Subscriber');
			// $('#span_product_details').html('');
			// add_product_row();
		});
		
		
		$(document).on('submit', '#form-subscribe', function(event){
			event.preventDefault();
			// $('#action').attr('disabled', 'disabled');
			// alert();
			var form_data = $(this).serialize();
			$.ajax({
				url:"pages/users/user_action.php",
				method:"POST",
				data:form_data,
				success:function(data){
					alert(data);
				}
			});
		});
		
  })
  
</script>
<?php include("../../footer.php");?>