<?php  include "header.php";
$today_date = date('Y-m-d');

$currentMonth = date('m');
$currentYear = date('Y');

// Get the start and end dates of the current month
$startDate = date('Y-m-01', strtotime("$currentYear-$currentMonth-01"));
$endDate = date('Y-m-t', strtotime("$currentYear-$currentMonth-01"));
?>

  
<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">
    <?php if($session_id=="1" || $allPermissions["sales"]["read"]==1){ ?>
    <div class="row">
        <div class="col-xs-12">
            
            
            
            
            
            
<!-- Section 1 Starts Here -->           
            <div class="box box-primary" style="box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;">
                
                
                <div class="box-header">
                        <span class="btn btn-default btn-sm pull-right filter" style="margin-right: 5px;"> Show/Hide Filter</span>
                        <h3 class="box-title">Notifications List</h3>
                </div>
                
                
<div class="box-body" style="padding: 0px 10px 0px 10px;">
                    
                    
    <div class="row" id="filter">
    
    
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="required" for="category">Category</label>                                   
            <select name="category" class="form-control select2" style="width:100%" id="category" required="required">
                <option value="">All Category</option>
                <option value="Sales">Sales</option>
                <option value="Barcode">Barcode</option>
                <option value="Purchase">Purchase</option>
                <option value="Customers">Customers</option>
                <option value="Payments">Payments</option>
            </select>
        </div>
    </div>
                            

    
    <div class="col-md-2">
        <div class="form-group">
            <label class="required" for="created_user">Created Users</label>                                   
            <select name="created_user" class="form-control select2" style="width:100%" id="created_user" required="required">
                <option value="">All Users</option>
                <?php $statementss = $pdo->prepare("SELECT * FROM `tbl_users` where status=1 and id!=1");
                    $statementss->execute();
                    $resultss = $statementss->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($resultss as $result) { ?>
                        <option value="<?=$result['id']?>"><?=$result['name']?></option>
                <?php  }  ?>
            </select>
        </div>
    </div>
    
    <div class="col-md-2">
        <div class="form-group">
            <label class="required" for="start_date">Start date</label>
            <input type="date" name="start_date" class="form-control" style="width:100%;" value="<?=$startDate?>" id="start_date">
        </div>
    </div>
    
    <div class="col-md-2">
        <div class="form-group">
            <label class="required" for="end_date">End date</label>
            <input type="date" name="end_date" class="form-control" style="width:100%;" value="<?=$endDate?>" id="end_date">
        </div>
    </div>
    
    </div>


                    <div class="clearfix"></div>
                    <div class="clearfix"></div>
                </div>
            </div>
<!-- Section 1 Endsss Here -->                
            
            
            
            
            
            
            
<!-- Section 2 Starts Here -->               
            <div class="box box-primary" style="box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;">
                
                <div class="box-body">
                    


<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="13" class="p0"><input type="text" class="form-control b0" name="search_table" id="search_table"  placeholder="Search Here" style="width:100%;background-color: darkblue;color: white;"></td>
                                </tr>
                                <tr class="active">
                                    <th>S.No</th>
                                    <th data-sortable="false" id="checkAll"><i class="fa fa-check"></i>
                                        <span id="check_box_sections"></span>
                                    </th>
                                    <th style="min-width: 200px;">Message</th>
                                    <th>Date</th>
                                    <th>Category</th>
                                    <th>Created&nbsp;By</th>
                                    <th>Created&nbsp;At</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="13" class="dataTables_empty"><center> Loading Pls Wait Data</center></td>
                                </tr>
                            </tbody>
                            
                        </table>
                    </div>
                    
                    <br></br>
                    <div class="row">
                        <div class="col-md-4">
                            <select name="status" class="form-control" id="status" style="">
                                <option value="" style="font-size: 17px;">Select Status</option>
                                <option value="2" style="font-size: 17px;">Read</option>
                                <option value="0" style="font-size: 17px;">Delete</option>
                            </select> 
                        </div>
                        <div class="col-md-4">
                            <button class="btn btn-primary btn-sm" id="btn_update"><i class="fa fa-check"></i> Update Status</button> 
                        </div>
                    </div>
                    
                    
                    
                    <div class="clearfix"></div>
                </div>
            </div>
<!-- Section 2 Endsss Here --> 
            
            
            
        </div>
    </div>
    <?php }else{ ?>
<center>Invalid Access</center>

<?php } ?>
</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 category = $('#category').val();
              var created_user = $('#created_user').val();
              var start_date = $('#start_date').val();
              var end_date = $('#end_date').val();
              
            var table = $('#StData').DataTable({

                    'ajax' : { 
                        url: 'data-tables/notifications-data-table.php', 
                        data:{search:search_table, category:category, created_user:created_user, start_date:start_date, end_date:end_date}, 
                        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_data();
        function emp_data(){
            <?=$data_table?>
        }
        
        $('#search_table').keyup(function() {  
            emp_data();
            document.getElementById("search_table").focus();
        });
        
        $('#category,  #created_user, #start_date, #end_date').change(function() {
            emp_data();
        });

    });
    function delete_Details(id){
            var result = confirm("Confirm Want to Delete This User?");
            if (result) {
                    $.ajax({
                    type: 'POST',
                    url: 'api/delete.php',
                    data: {type:'user_delete',delete_id:id},                  
                    success: function(response) {
                        console.log(response); 
                        emp_datas();
                    }
                });
            }
         }
    function emp_datas(){
        
        $('#check_box_sections').text('');
            <?=$data_table?>
    }
    
    
    
    
    $(document).ready(function() {  
    
  $('#checkAll').click(function () { 
        var check_box_sections=$('#check_box_sections').text();
        if(check_box_sections==''){
            $('#check_box_sections').text('Checked');
            $('.check_box').prop('checked',true);
        }else{
            $('#check_box_sections').text('');
            $('.check_box').prop('checked',false);
        }
 });
 

    
$('#btn_update').on('click',function(){
    var checkValues = $('input[name=assign_ids]:checked').map(function(){
                return $(this).val();
            }).get();
            
    var status=$('#status').val();
    
    
    if(checkValues != '' && status!=''){
        var r = confirm("Confirm if You Want to Update Those Status?");
	    console.log(checkValues);
        if (r == true) {
            var ids=[];
            var status = $('#status').val();
            ids = checkValues;
            $.ajax({
                url: 'api/bulk-notifications-status-update-api.php',
                type: 'post',
                data: {type:'dynamic_bulk_notifications',ids:ids,status:status},
                success: function(response){
                console.log(response);
                emp_datas();
          }
        });
    }
     
    }else{
        alert("Please Select Minimum One Notification...");
    }
});   
    
    
    
    
    
    
    
    
});  
</script>