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

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


    $sqlView = "SELECT *
          FROM departments;";

  
    $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\">Departments</h1>";

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

            echo "<div class=\"btn-group mr-2\">";
                echo "<a href=\"addDepartment.php\" class=\"btn btn-sm btn-outline-secondary\" role=\"button\">Add Department</a>";
                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>Deparment Name</td>";
  echo "<td>View</td>";
  echo "<td>Edit</td>";
  echo "<td>Delete</td>";
  echo "</thead>";
  echo "<tbody>";

  while ($rowdepartment = mysqli_fetch_array($result)) { // FETCHING  DATA START
    echo "<tr>";
    echo "<td>" . $rowdepartment['departmentname'] . "</td>";
    echo "<td><a href = \"viewdepartment.php?departmentid=" . $rowdepartment['departmentid'] . "\">View Department</a></td>";
    echo "<td><a href = \"editDepartment.php?departmentid=" . $rowdepartment['departmentid'] . "\">Edit Department</a></td>";
    echo "<td><a href = \"deleteDepartment.php?departmentid=" . $rowdepartment['departmentid'] . "\">Delete Department</a></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');

?>