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

?>

<?php 


// start role specific 

$user_role = $_SESSION['role'];
$companyID = $_SESSION['companyselect'];

switch ($user_role) {

  case 1: // Admin Role

  break;


  default:

}

$sqlemployees = "
        SELECT
        employees.employeeid AS employeeid,
        employees.employeefileno AS employeefileno,
        employees.employeename AS employeename,
        employees.employeesurname AS employeesurname,
        departments.departmentname AS departmentname,
        positions.positionname AS positionname
        FROM employees
        LEFT JOIN employee_job
        ON employee_job.employeeid = employees.employeeid
        LEFT JOIN departments
        ON employee_job.departmentid = departments.departmentid
        LEFT JOIN positions
        ON employee_job.positionid = positions.positionid
        WHERE companyid = $companyID
        ORDER BY 'employeename' ASC
        ";

$resultemployees = mysqli_query($db,$sqlemployees);

$countemployees = mysqli_num_rows($resultemployees);


?>


        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
          <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
            <h1 class="h2">Employees (<?php echo $countemployees; ?>)</h1>
            <div class="btn-toolbar mb-2 mb-md-0">
              <div class="btn-group mr-2">
                <a href="addEmployee.php" class="btn btn-sm btn-outline-secondary" role="button">Add Employee</a>
                <button class="btn btn-sm btn-outline-secondary">Export to Excel</button>
              </div>
            </div>
          </div>

<?php if($countemployees != 0): ?>
        
  <div class="table-responsive">
    <table class="table">
      <thead>
        <tr>
          <th>File No.</th>
          <th>Surname</th>
          <th>Name</th>
          <th>Position</th>
          <th>Department</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>

        <?php while ($rowemployee = mysqli_fetch_array($resultemployees)) { 

          echo "<tr>";
          echo "<td>";
          echo $rowemployee['employeefileno'];
          echo "</td>";
          echo "<td>";
          echo $rowemployee['employeesurname'];
          echo "</td>";
          echo "<td>";
          echo $rowemployee['employeename'];
          echo "</td>";
          echo "<td>";
          echo $rowemployee['positionname'];
          echo "</td>";
          echo "<td>";
          echo $rowemployee['departmentname'];
          echo "</td>";
          echo "<td>";
          echo "<a href = \"viewEmployee.php?employeeID=" . $rowemployee['employeeid'] . "\">View Master File</a> - 
                <a href = \"editEmployee.php?employeeID=" . $rowemployee['employeeid'] . "\">Edit Basic Details</a>";

          echo "</td>";
          echo "</tr>";

         } ?>

      </tbody>
    </table>
  </div>


<?php elseif ($countemployees == 0): ?>
    <p>No employees registered on system..</p>
<?php endif; ?>



        </main>
      </div>
    </div>

<?php
   include('footer1.php');
?>



