<?php  include "header.php"; ?>
<?php if($session_id ==1 || $allPermissions['userManagement']['read']=="1"){ ?>

<section class="content" >
    
    <div class="row">
		<div class="col-md-12">
			<div class="box box-primary">
			    <div class="box-header">
			        
			        <?php if($session_id==1 || $allPermissions['userManagement']['create']=="1"){ ?>
                        <a href="auth-users.php" class="btn btn-success btn-sm pull-right" contenteditable="false" style="cursor: pointer;"><i class="fa fa-plus-circle"></i> Add New User</a>
                    <?php } ?>
                    
                        <span class="btn btn-default btn-sm pull-right filter" style="margin-right: 5px;"> Show/Hide Filter</span>
                    <h3 class="box-title"><i class="fa fa-users"></i> Auth - Users List</h3>
                </div>
                
                
                
			    <!-- Filter Starts Here -->
			    <div class="row" id="filter" style="padding: 2px;">
    
                            
    
    <div class="col-md-2">
        <div class="form-group">
            <label class="required" for="status">Status</label>                                   
            <select name="status" class="form-control select2" style="width:100%;" id="status" >
                <option value="">All Status</option>
                <option value="1">Active</option>
                <option value="0">In-Active</option>
                
            </select>
        </div>
    </div>
    
    
    </div>
			    <!-- Filter Endsss Here -->
			    
			</div>
		</div>
	</div>
	
	
    
    
	
	
	<div class="row">
		<div class="col-md-12">
			<div class="box box-info">
				<div class="box-body table-responsive">
					<table id="tbl_users"  class="table table-bordered table-striped">
						<thead>
							<tr>
							    <th>Actions</th>
								<th width="10">S.No</th>
								<th>Name</th>
								<th>Email</th>
								<th>Password</th>
								<th>User Type</th>
								<th>Role</th>
								<th>Status</th>
								<th>Created By</th>
								<th>Updated At</th>
							</tr>
						</thead>
						
					</table>
				</div>
			</div>
		</div>
	</div>

</section>





<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Delete Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure want to Delete Details?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>



<?php }else{ ?>
    <?=$page_not_access?>
<?php } ?>



<script>
    $(document).ready(function(){
        get_data();	  
        $('#filter').hide();
        $('.filter').click(function(){
            $("#filter").slideToggle();
            return false;
        });
    });
</script>

<script type="text/javascript">
	$(document).ready(function() {
		
		$("#status").change(function() {
    	    console.log('Status:'+$('#status').val() );
           get_data();
        });
	});
			
			
function get_data(){
    var status = $('#status').val();
    var dataTable = $('#tbl_users').DataTable( {
					"processing": true,
					"serverSide": true,
					"bDestroy": true,
					"ajax":{
						url :"data-tables/users-data-table.php", 
						data: {status:status},
						type: "post",  
						error: function(){
							$(".datatable-error").html("");
							$("#tbl_users").append('<tbody class="datatable-error"><tr><th colspan="3">No Data Found in the Server</th></tr></tbody>');
							$("#tbl_users_processing").css("display","none");
							
						}
					}
				});
}

    function delete_Details(id){
            var result = confirm("Confirm Want to In-Active This User?");
            if (result) {
                    $.ajax({
                    type: 'POST',
                    url: 'apis/delete.php',
                    data: {type:'soft_delete_table',delete_id:id, table: 'tbl_users'},                  
                    success: function(response) {
                        console.log(response); 
                        get_data();
                    }
                });
            }
    }
    function HardDelete(id){
            var result = confirm("Confirm Want to Hard Delete This User?");
            if (result) {
                $.ajax({
                    type: 'POST',
                    url: 'apis/delete.php',
                    data: {type:'hard_delete',delete_id:id, table:'tbl_users'},                  
                    success: function(response) {
                        console.log(response); 
                        get_data();
                    }
                });
            }
    }
	
</script>

<?php require_once('footer.php'); ?>