<?php  include "header.php";

if(isset($_GET['cus'])){
    $cus = $_GET['cus'];
}else{
    $cus = "";
}

?>

  
<div class="content-wrapper">
    
        <!--<section class="content-header">
            <h1>Users List</h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active"> Users List</li>            
            </ol>
        </section>-->

        <div class="clearfix"></div>
        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            
            <?php if(isset($_SESSION['message']) && $_SESSION['message']!=""){ ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?=$_SESSION['message'];?>
            </div>
            <?php  unset($_SESSION['message']); } ?>
            
            
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php } if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            <?php } if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $site_name; ?>
            </div>
            <?php } ?>
        </div>
        



<section class="content">
    
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary" style="box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px, rgba(9, 30, 66, 0.08) 0px 0px 0px 1px;">
                
                
                <div class="box-header">
                        <?php if($session_id==1 || $session_user_type==1 || $allPermissions['customers']['create']==1){ ?>
                            <a  href="customers-add.php" class="btn btn-success btn-sm pull-right"><i class="fa fa-plus-circle"></i> Add New Customers</a>
                        <?php } ?>
                        <?php if($session_id==1 || $session_user_type==1 || $allPermissions['customers']['read']==1){ ?>
                            <span class="btn btn-default btn-sm pull-right filter" style="margin-right: 5px;"> Show/Hide Filter</span>
                        <?php } ?>
                    <h3 class="box-title">Customers List</h3>
                </div>
                
                
                <?php if($session_id==1 || $session_user_type==1 || $allPermissions['customers']['read']==1){ ?>
                
                <div class="box-body">
                    
                    
    <div class="row" id="filter">
    
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="" for="gender">Gender</label>
            <select name="gender" id="gender" class="form-control select2">
                <option value="">All Gender</option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
            </select>
        </div>
    </div>
    

    
    <div class="col-md-3">
        <div class="form-group">
            <label for="religion">Religion </label>
            <select name="religion" id="religion" class="form-control select2">
                <option value="">All Religion</option>
                <option value="Hindu">Hindu</option>
                <option value="Muslim">Muslim</option>
                <option value="Christian">Christian</option>
            </select>
        </div>
    </div>
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="control-label" for="status">Status</label>
            <select name="status" class="form-control select2" style="width:100%" id="status">
                <option value="1">Active</option>
                <option value="0">In-Active</option>
                <option value="">All Status</option>
            </select>
        </div>
    </div>
    
    
    
    </div>


<div class="clearfix"></div>


                    <div class="table-responsive">
                        <table id="StData" class="table table-striped table-bordered table-condensed table-hover" style="margin-bottom:5px;">
                            <thead>
                                <tr>
                                    <td colspan="10" class="p0"><input type="text" class="form-control b0" name="search_table" id="search_table" value="<?=$cus?>" placeholder="Search Here" style="width:100%;background-color: darkblue;color: white;"></td>
                                </tr>
                                <tr class="active">
                                    <th style="width:100px;">Actions</th>
                                    <th>S.No</th>
                                    <th>Name</th>
                                    <th>Mobile Number</th>
                                    <th>Customer ID</th>
                                    <th>Sales Details</th>
                                    <th>Gender</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="10" class="dataTables_empty"><center> Loading Pls Wait Data</center></td>
                                </tr>
                            </tbody>
                            
                        </table>
                    </div>
                    <div class="clearfix"></div>
                </div>
                
                
                <?php }else{ ?>
    
                <?=$page_not_access?>
                
                <?php } ?>
                
                
            </div>
        </div>
    </div>
    


</section>

<?php include "footer.php";?>
<script>
    $(document).ready(function(){
       /* $('#filter').hide();*/
        $('.filter').click(function(){
            $("#filter").slideToggle();
            return false;
        });
    });
</script>

<script type="text/javascript">
<?php
$data_table = "var search_table = $('#search_table').val();
              var status = $('#status').val();
              var gender = $('#gender').val();
              var religion = $('#religion').val();
            var table = $('#StData').DataTable({

                    'ajax' : { 
                        url: 'data-tables/customers-data-table.php', 
                        data:{search:search_table, status:status, gender:gender, religion:religion}, 
                        type: 'POST'},
                        bFilter: true,
                        bDestroy: true,
                        searching: true,
                    'buttons': [
                    { extend: 'copyHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'excelHtml5', 'footer': false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'csvHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'pdfHtml5', orientation: 'landscape', pageSize: 'A4', 'footer': false,
                    exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'colvis', text: 'Columns'},
                    ]

                });";

?>
    $(document).ready(function() {        
        emp_datas();
        
        $('#search_table').keyup(function() {  
            emp_datas();
            document.getElementById("search_table").focus();
        });
        
        $('#status, #gender, #religion').change(function() {
            emp_datas();
        });

    });
    
    
    function delete_Details(id){
            var result = confirm("Confirm Want to In-Active This Customer?");
            if (result) {
                    $.ajax({
                    type: 'POST',
                    url: 'api/delete.php',
                    data: {type:'soft_delete',delete_id:id, table:'tbl_customers'},                  
                    success: function(response) {
                        console.log(response); 
                        emp_datas();
                    }
                });
            }
    }
    
    function DynamicActive(id){
            var result = confirm("Confirm Want to Active This Customer?");
            if (result) {
                $.ajax({
                    type: 'POST',
                    url: 'api/delete.php',
                    data: {type:'dynamic_active',delete_id:id, table:'tbl_customers'},                  
                    success: function(response) {
                        console.log(response); 
                        emp_datas();
                    }
                });
            }
    }
    function emp_datas(){
            <?=$data_table?>
    }
</script>