<?php
   include('session.php');
   include('header1.php');
   include('ietpartial.php');
   include('calculations.php');

// start role specific 
$user_role = $_SESSION['role'];


    $sqlView = "SELECT *
          FROM eventlog
          ORDER BY timestamp DESC
          LIMIT 25;";

  
    $result = mysqli_query($db,$sqlView);

    $count = mysqli_num_rows($result);



    echo "<main role=\"main\" class=\"col-md-9 ml-sm-auto col-lg-10 px-4\">";

    echo "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\">";

    echo "<h1 class=\"h2\">Log Viewer</h1>";

      echo "<div class=\"btn-toolbar mb-2 mb-md-0\">"; // TOOLBAR STARTS HERE

            echo "<div class=\"btn-group mr-2\">";
                echo "<a href=\"technicalsettings.php\" class=\"btn btn-sm btn-outline-secondary\" role=\"button\">Back</a>";
            echo "</div>";

          echo "</div>";

    echo "</div>";


    if ($count !== 0) {


 
    // TABLE STARTS HERE

  echo "<table class = \"table\">";

  echo "<thead>";
  echo "<td>User</td>";
  echo "<td>Type</td>";
  echo "<td>Event</td>";
  echo "<td>Timestamp</td>";
  echo "</thead>";
  echo "<tbody>";

  while ($rowevent = mysqli_fetch_array($result)) { // FETCHING  DATA START
    echo "<tr>";
    echo "<td>" . $rowevent['eventuser'] . "</td>";
    echo "<td>" . $rowevent['eventtype'] . "</td>";
    echo "<td>" . $rowevent['eventname'] . "</td>";
    echo "<td>" . $rowevent['timestamp'] . "</td>";

   
    echo "</tr>";


  } // FETCHING  DATA END

  echo "</tbody>";
  echo "</table>";

    // TABLE ENDS HERE


    } // COUNT EMPLOYEES END HERE
    else 
    {

      echo "Audit Log empty..";
    }



include('footer1.php');

?>