<?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=\"addCarBenefit1.php\">";

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

    	  $sqlGetCarBenefits = "SELECT * FROM carbenefits";

		  $resultCarBenefits = mysqli_query($db,$sqlGetCarBenefits);

		  $countCarBenefits = mysqli_num_rows($resultCarBenefits);

		    if ($countCarBenefits !== 0) { 

		    	echo "<p>Tier</p>";

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

  				while ($rowCarBenefit = mysqli_fetch_array($resultCarBenefits)) { 
            $selected = "";
            if ($rowCarBenefit['carbenefitid'] == $rowemployee['employee_carbenefit']){
              $selected = "selected";
            } else {
              $selected = "";
            }
  					echo "<option value ='" . $rowCarBenefit['carbenefitid'] . "' " . $selected . ">" . $rowCarBenefit['tiername'] . "</option>";

  				}


  				echo "</select>";

  				echo "</p>";

  			}

	  			}



    }

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

   }


include('footer1.php');
?>