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

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

if ($_SERVER["REQUEST_METHOD"] == "GET") {

  $employeeid = $_GET['employeeID'];

  if(isset($_GET['updated'])) {

    $updated = $_GET['updated'];

  }

  $sqlGetEmployee = "SELECT * FROM employees WHERE employeeid = $employeeid";

  $resultEmployee = mysqli_query($db,$sqlGetEmployee);

  $countEmployee = mysqli_num_rows($resultEmployee);

  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\">";

  if ($countEmployee !== 0) { 

  	while ($rowemployee = mysqli_fetch_array($resultEmployee)) {

    	echo "<h1 class=\"h2\">" . $rowemployee['employeesurname'] . ", " . $rowemployee['employeename'] . "</h1>";
      echo "<a href=\"viewEmployee.php?employeeID=" . $rowemployee['employeeid'] . "\" class=\"btn btn-sm btn-outline-secondary\" role=\"button\">Back to Employee File</a>";
    
    	echo "</div>";

    	echo "<form method = \"POST\" action=\"addPersonalDetail1.php\">";

    	echo "<input type = \"hidden\" value = \"" . $rowemployee['employeeid'] . "\" name = \"employee_id\">";

    	  $sqlGetDepartments = "SELECT * FROM departments";

		  $resultDepartments = mysqli_query($db,$sqlGetDepartments);

		  $countDepartments = mysqli_num_rows($resultDepartments);

		    if ($countDepartments !== 0) { 

		    	echo "<p>Department</p>";

		    	echo "<select name=\"employee_department\" id=\"employee_department\" class=\"form-control\" onchange=\"fetch_select(this.value);\" required>";

  				while ($rowDepartment = mysqli_fetch_array($resultDepartments)) { 

  					echo "<option value ='" . $rowDepartment['departmentid'] . "'>" . $rowDepartment['departmentname'] . "</option>";

  				}


  				echo "</select>";

  				echo "</p>";

  			}

  			$sqlGetPositions = "SELECT * FROM positions";

			  $resultPositions = mysqli_query($db,$sqlGetPositions);

			  $countPositions = mysqli_num_rows($resultPositions);

			    if ($countPositions !== 0) { 

			    	echo "<p>Positions</p>";

			    	echo "<select name=\"employee_position\" id=\"employee_position\" class=\"form-control\" required>";

	  				while ($rowPosition = mysqli_fetch_array($resultPositions)) { 

	  					echo "<option value ='" . $rowPosition['positionid'] . "'>" . $rowPosition['positionname'] . "</option>";

	  				}


	  				echo "</select>";

	  				echo "</p>";

	  			}



    }

    echo "<input type=\"submit\"> </form>";

   }

} 


include('footer1.php');
?>