   <?php

   session_start();

    include_once('../../config/conn/db-connection.php');
    include_once('../../config/class/sap_model.php');


   if(!isset($_SESSION['logged_in']))
    {
       header("location:../../index.php");
    }else{

    $user_session = trim($_SESSION['user_no']);
    $SAP = new SAP_infosytem();
    $fetchaudittrail = $SAP->fetch_audittrail();  

    /////////////////////////////////////////////////

?>


   <?php include '../header/main-header2.php';?>
   <div class="content-wrapper">
       <section class="content-header">
           <div class="container-fluid">
               <div class="row mb-2">
                   <div class="col-sm-6">
                       <h1>Audit Trail </h1>
                   </div>
                   <div class="col-sm-6">
                       <ol class="breadcrumb float-sm-right">
                           <li class="breadcrumb-item"><a href="../home-page.php">Home</a></li>
                           <li class="breadcrumb-item active">Audit Trail</li>
                       </ol>
                   </div>
               </div>
           </div>
       </section>

       <section class="content">
           <div class="container-fluid">
               <div class="row">
                   <div class="col-12">
                       <div class="card">
                           <div class="card-body">
                            <div class="table-responsive">
                               <table id="household-table" class="table table-bordered table-striped">
                                   <thead>
                                       <tr>
            
                                           <th>Username</th>
                                           <th>User IP</th>
                                           <th>User Host</th>
                                           <th>Log Date/Time</th>
                                           <th>Action</th>
                                       </tr>
                                   </thead>
                                   <tbody>
                                       <?php
                                      foreach($fetchaudittrail as $audit){ ?>
                                       <tr>

                                           <td><?= ucfirst(htmlentities($audit['user_name'])); ?></td>
                                           <td><?= htmlentities($audit['user_ip']); ?></td>
                                           <td><?= htmlentities($audit['user_host']); ?></td>
                                           <td><?= date('M/d/Y h:i A', strtotime(htmlentities($audit['logdate']))); ?></td>
                                           <td><?= ucfirst(htmlentities($audit['action'])); ?></td>

                                       </tr>
                                       <?php $found_rows = true; }  if (!isset($found_rows)) echo "<tr><td colspan ='5'><div class='alert alert-danger' style='font-weight:bold;'>No records found.</div></td></tr>"; 
                                       ?>

                                   </tbody>

                               </table>
                             </div>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
       </section>
   </div>
   <?php } ?>

   <footer class="main-footer">
       <div class="float-right d-none d-sm-block">
           <b>Version</b> 1.0.0
       </div>
       <strong>Copyright &copy; 2021 <b>SAP Information System </b>.</strong>
   </footer>

   <aside class="control-sidebar control-sidebar-dark">
   </aside>
   </div>


   <script>
       $("#checkAl").click(function() {
           $('input:checkbox').not(this).prop('checked', this.checked);
       });
   </script>

   <script src="../../plugins/jquery/jquery.min.js"></script>
   <script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
   <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
   <script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
   <script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
   <script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
   <script src="../../dist/js/adminlte.min.js"></script>
   <script src="../../dist/js/demo.js"></script>
   <script>
       $(function() {
           $("#household-table").DataTable({
               // "responsive": true,
               // "autoWidth": false,
           });
       });
   </script>
   </body>

   </html>