<?= $this->extend('layouts/form.php') ?>

<?= $this->section('content') ?>
<?php
$userid = 0;
$firstname = '';
$lastname = '';
$userdeptid = '';
$userposid = '';
$reportto = '';
$offid = '';
if(isset($users)) { $data = $users[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
  if(isset($data['userid'])) { 
    $userid= $data['userid']; }
  $firstname = $data['firstname'];
  $lastname = $data['lastname'];
  $userposid = $data['userposid'];
  $userdeptid = $data['userdeptid'];
  $reportto = $data['reportto'];
  $offid = $data['offid'];
}
?>
<div class="form-body">
  <h3 class="card-title">User Role Editor</h3>
  <hr>
  <?php 
  if(isset($validation)) {
  ?>
    <div class='alert alert-danger alert-dismissible'>
      <?= $validation->listErrors(); ?>
      <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <span aria-hidden="true"></span> </button>
    </div>
  <?php
  }
  ?>
  <form method='post'>

    <input type='hidden' name='userid' value='<?=$userid;?>'/>
    
    <div class="form-group row">
      <label class="col-2 col-form-label">Full Name</label>
      <div class="col-10"><input disabled class="form-control" type="text" name='firstname' value="<?=$firstname;?> <?=$lastname;?>"></div>
    </div>
    
    <div class="form-group row">
      <label class="col-2 col-form-label">Reportto</label>
      <div class="col-10">
        <select class="form-control select2" name='reportto' >
          <option value='0'>-</option>
          <?php
          foreach ($userreportto as $data) {
            $quserid= $data['userid'];
            $qfirstname = $data['firstname'];
            $qlastname = $data['lastname'];
            if ($quserid == $reportto) { echo "<option value='$quserid' selected>$qfirstname $qlastname</option>"; }
            else { echo "<option value='$quserid'>$qfirstname $qlastname</option>"; }
          }
          ?>
        </select>
      </div>
    </div>
    
    <div class="form-group row">
      <label class="col-2 col-form-label">Office</label>
      <div class="col-10">
        <select class="form-control select2" name='offid' >
          <option value='0'>-</option>
          <?php
          foreach ($offices as $data) {
            $qoffid = $data['offid'];
            $qoffname = $data['offname'];
            if ($qoffid == $offid) { echo "<option value='$qoffid' selected>$qoffname</option>"; }
            else { echo "<option value='$qoffid'>$qoffname</option>"; }
          }
          ?>
        </select>
      </div>
    </div>

    <div class="form-group row">
      <label class="col-2 col-form-label">User Department</label>
      <div class="col-10">
        <select class="form-control select2" name='userdeptid' >
          <option value='0'>-</option>
          <?php
          foreach ($userdepartment as $data) {
            $quserdeptid= $data['userdeptid'];
            $qshorttext = $data['shorttext'];
            $qtexts = $data['texts'];
            if ($quserdeptid== $userdeptid) { echo "<option value='$quserdeptid' selected>$qshorttext - $qtexts</option>"; }
            else { echo "<option value='$quserdeptid'>$qshorttext - $qtexts</option>"; }
          }
          ?>
        </select>
      </div>
    </div>
    
    <div class="form-group row">
      <label class="col-2 col-form-label">User Position</label>
      <div class="col-10">
        <select class="form-control select2" name='userposid' >
          <option value='0'>-</option>
          <?php
          foreach ($userposition as $data) {
            $quserposid= $data['userposid'];
            $qshorttext = $data['shorttext'];
            $qtexts = $data['texts'];
            if ($quserposid== $userposid) { echo "<option value='$quserposid' selected>$qshorttext - $qtexts</option>"; }
            else { echo "<option value='$quserposid'>$qshorttext - $qtexts</option>"; }
          }
          ?>
        </select>
      </div>
    </div>

    <!-- <div class="form-group row">
      <label class="col-2 col-form-label">Start Work <br>(Hari Mulai Menjabat)</label>
      <div class="col-10 fs-6"><input class="form-control" type="date" name='startwork' value="<?=$startwork?>"></div>
    </div> -->
    
    <div class="form-group row">
      <label class="col-2 col-form-label">Start
        <br> 
				<small class="text-muted fs-6">Mulai Menjabat</small>
      </label>
      <div class="col-10"><input class="form-control" required type="date" name='startdate'></div>
    </div>

    <button type="button" class="btn btn-dark float-start" onclick="window.close()">Cancel</button>
    <button type="submit" class="btn btn-success text-white float-end"> <i class="fa fa-check"></i> Submit</button>
  </form>
</div>
<?= $this->endSection() ?>