<div class="breadcrumb">
    <h1>Admin Log List</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Admin Log List</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<form action="" method="post">
<div class="row">
    <div class="col-lg-12 col-md-12">
        <div class="card mb-5">
            <div class="card-body">
                <div class="row row-xs">
                    
                    <div class="col-md-2 mt-3 mt-md-0"  id="div_login_fullname">
                        <label for="login_user_id">Login User</label>
                        <!-- <input type="text" class="form-control" name="login_fullname" id="login_fullname"  /> -->
                        <select class="form-control" name="login_user_id" id="login_user_id">
                            <option value="">Select LoginUser</option>
                            <?php
                                $adminObj = new admin();
                                $fields = array('admin_id','admin_fname','admin_lname');
                                $data = array('fields'=>$fields);
                                $adminDetails = $adminObj->getAllRecords($data);
                                foreach($adminDetails as $adminval)
                                { ?>
                                    <option value="<?php echo $adminval->admin_id;?>"><?php echo $adminval->admin_fname." ".$adminval->admin_lname; ?> </option>
                               <?php }
                            ?>
                            
                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_module_name">
                        <label for="module_name">Module Name</label>
                        <!-- <input type="text" class="form-control" name="module_name" id="module_name"  /> -->

                        <select class="form-control" name="module_name" id="module_name">
                            <option value="">Select Module</option>
                            <?php
                                $moduleObj = new modules();
                                $fields = array('id','name');
                                if($_REQUEST['module_id'] != '')
                                {
                                    $where = "id=".$_REQUEST['module_id']."";
                                }else{
                                    $where = "1=1";
                                }
                                $data = array('fields'=>$fields,"where"=>$where);
                                $moduleDetails = $moduleObj->getAllRecords($data);
                                foreach($moduleDetails as $moduleval)
                                { ?>
                                    <option value="<?php echo $moduleval->id;?>" <?php echo ($moduleval->id==$_REQUEST['module_id']) ? "selected='selected'" : "" ?>> <?php echo $moduleval->name; ?> </option>
                               <?php }
                            ?>
                            
                        </select>
                    </div>

                    <!-- <div class="col-md-2 mt-3 mt-md-0"  id="div_page_name">
                        <label for="page_name">Page Name</label>
                        <input type="text" class="form-control" name="page_name" id="page_name"  />
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="">&nbsp;</label>
                        <button type="submit" name="submit" class="btn btn-primary btn-block">Search</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="">&nbsp;</label>
                        <button type="reset" name="reset" class="btn btn-primary btn-block" onClick="window.location.reload()">Reset</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

<div class="row mb-4">
    <div class="col-md-12 mb-4">
        <div class="card text-left">

            <div class="card-body">
                <div class="table-responsive">
                  <form id="listFrm" name="listFrm" action="" method="post">       
                    <input type="hidden" id="action" name="action" value="">
                    <table id="list" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <!-- <th>Id</th> -->
                                <th>Login Detail</th>
                                <th>Module Detail</th>
                                <th>Create Date</th>
                                <th>Detail</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript">
<?php if($_REQUEST['module_id'] != ''){ ?>

   $(document).ready(function() {
     $('#list').DataTable( { 
          "ajax": "adminloglist.php?act=load&module_id="+<?php echo $_REQUEST['module_id']; ?>,
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      });

     $( "form" ).on( "submit", function(e) {
        e.preventDefault();
        
        var login_user_id = $("#login_user_id").val();
        var module_name = $("#module_name").val();
        //var page_name = $("#page_name").val();
        //+"&page_name="+page_name

        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "adminloglist.php?act=load&login_user_id="+login_user_id+"&module_name="+module_name+"&module_id="+<?php echo $_REQUEST['module_id']; ?>,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [0] }
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });
    });
<?php }else{ ?>
        $(document).ready(function() {
         $('#list').DataTable( { 
              "ajax": "adminloglist.php?act=load",
              "processing": true,
              "serverSide": true,
              "pageLength": 25,
                    "aaSorting": [],
                    "aoColumnDefs": [
                        { 'bSortable': false, 'aTargets': [0] }
                    ],
              language: {
                  "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                  "sEmptyTable" :  "No records found."
              }
              
          });

         $( "form" ).on( "submit", function(e) {
            e.preventDefault();
            var login_user_id = $("#login_user_id").val();
            var module_name = $("#module_name").val();
            //var page_name = $("#page_name").val();
            //+"&page_name="+page_name
            $('#list').DataTable().destroy();
              $('#list').DataTable({ 
                "ajax": "adminloglist.php?act=load&login_user_id="+login_user_id+"&module_name="+module_name,
                "processing": true,
                "serverSide": true,
                "pageLength": 25,
                      "aaSorting": [],
                      "aoColumnDefs": [
                          { 'bSortable': false, 'aTargets': [0] }
                      ],
                language: {
                    "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
                }
                
            });
        });
    });

<?php } ?>
</script>