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

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

?>

<?php if($_SERVER["REQUEST_METHOD"] == "GET") : ?>

  <?php 

    $employeeid = $_GET['employeeID'];

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

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

    $countEmployee = mysqli_num_rows($resultEmployee);

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

      $updated = $_GET['updated'];

    }

  ?>

      <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">Edit Employee</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
      </div>
  </div>

  <?php while($rowemployee = mysqli_fetch_array($resultEmployee)) : ?>

    <form method = "POST" action="editEmployee1.php">
        <input type = "hidden" value = "<?php echo $rowemployee['employeeid'] ?>" name = "employee_id">

        <p>File Number*
          <input type="text" value = "<?php echo $rowemployee['employeefileno'] ?>" name="employee_fileno" required class="form-control"> 
        </p>

        <p>Surname*
          <input type="text" value = "<?php echo $rowemployee['employeesurname'] ?>" name="employee_surname" required class="form-control"> 
        </p>

        <p>Maiden Name
          <input type="text" value = "<?php echo $rowemployee['employeemaidenname'] ?>" name="employee_maiden_name" class="form-control"> 
        </p>

        <p>Name*
          <input type="text" value = "<?php echo $rowemployee['employeename'] ?>" name="employee_name" required class="form-control"> 
        </p>

        <p>National Identity Card*
          <input type="text" value = "<?php echo $rowemployee['employeenic'] ?>" name="employee_nic" required class="form-control"> 
        </p>

        <p>Citizen of Mauritius?*
          <select name="employee_citizenship" id="employee_citizenship" class="form-control" required>
            <option value="Y" <?php if($rowemployee['employee_citizen_boolean'] == "Y") {echo " selected";} ?> >Y</option> 
            <option value="N" <?php if($rowemployee['employee_citizen_boolean'] == "N") {echo " selected";} ?> >N</option>
          </select>
        </p>

        <p>TAN Number
          <input type="text" value = "<?php echo $rowemployee['employee_tan_number'] ?>" name="employee_tan" class="form-control"> 
        </p>

        <p>Date of Birth*
          <input type="date" value = "<?php echo $rowemployee['employeedob'] ?>" name="employee_dob" required class="form-control"> 
        </p>

        <p>Gender*
          <select name="employee_gender" id="employee_gender" class="form-control" required>
            <option value="Male" <?php if($rowemployee['employeegender'] == "Male") {echo " selected";} ?> >Male</option> 
            <option value="Female" <?php if($rowemployee['employeegender'] == "Female") {echo " selected";} ?> >Female</option>
          </select>
        </p>

        <p>Joining Date*
          <input type="date" value = "<?php echo $rowemployee['employee_join_date'] ?>" name="employee_joining_date" required class="form-control">
        </p>

        <?php 

          //echo "<p>" . $rowemployee['employee_termination_date'] . "<p>";

          if ($rowemployee['employee_termination_date'] != '0000-00-00' || $rowemployee['employee_termination_date'] != null) {
            echo "<p>Termination Date";
            echo "<input type=\"date\" name=\"employee_termination_date\" value = \"" . $rowemployee['employee_termination_date'] . "\" class=\"form-control\">";
            echo "</p>";
          }
        
        ?>
  <!--
        <p>Termination Date
          <input type="date" name="employee_termination_date" class="form-control">
        </p>
        -->

        <p>PAYE Rate*
          <select name="employee_paye_rate" id="employee_paye_rate" class="form-control" required>
            <option value="10" <?php if($rowemployee['employee_paye_rate'] == '10') {echo " selected";} ?> >10%</option>
            <option value="12.5" <?php if($rowemployee['employee_paye_rate'] == '12.5') {echo " selected";} ?> >12.5%</option>
            <option value="15" <?php if($rowemployee['employee_paye_rate'] == '15') {echo " selected";} ?> >15%</option>
          </select>
        </p>

        <p>EDF Amount*
          <input type="numeric" value = "<?php echo $rowemployee['employee_edf_amount'] ?>" name="employee_edf_amount" required class="form-control"> 
        </p>

        <p>EDF Months Value*
          <input type="numeric" value = "<?php echo $rowemployee['edf_months_value'] ?>" name="employee_edf_months" required class="form-control"> 
        </p>

        <p>Full Time*
          <select name="employee_fulltime" id="employee_fulltime" class="form-control" required>
            <option value="Y" <?php if($rowemployee['employee_fulltime_boolean'] == "Y") {echo " selected";} ?> >Y</option> 
            <option value="N" <?php if($rowemployee['employee_fulltime_boolean'] == "N") {echo " selected";} ?> >N</option>
          </select>
        </p>

        <p>Employee Pension*
          <select name="employee_pension" id="employee_pension" class="form-control" required>
            <option value="Y" <?php if($rowemployee['employee_pension_boolean'] == "Y") {echo " selected";} ?> >Y</option> 
            <option value="N" <?php if($rowemployee['employee_pension_boolean'] == "N") {echo " selected";} ?> >N</option>
          </select>
        </p>

        <p>Employee Contribution Code*
          <select name="employee_contributioncode" id="employee_contributioncode" class="form-control" required>
            <option value="V" <?php if($rowemployee['employee_contribution_code'] == "V") {echo " selected";} ?> >V</option> 
            <option value="X" <?php if($rowemployee['employee_contribution_code'] == "X") {echo " selected";} ?> >X</option>
            <option value="G" <?php if($rowemployee['employee_contribution_code'] == "G") {echo " selected";} ?> >G</option>
            <option value="S" <?php if($rowemployee['employee_contribution_code'] == "S") {echo " selected";} ?> >S</option>
            <option value="N" <?php if($rowemployee['employee_contribution_code'] == "N") {echo " selected";} ?> >N</option>
            <option value="D" <?php if($rowemployee['employee_contribution_code'] == "D") {echo " selected";} ?> >D</option>
          </select>
        </p>

        <input type="submit">
      </form>

  <?php endwhile; ?>
<?php endif; ?>


  <br>
  <br>

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

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