<?
session_start();
include"../plg/ses.php";
include"../plg/kon.php";
$id = $_GET['id'];
$sqle = "select * from karyawan where id='$id'";
$rese = $conn->query($sqle);
while($k = $rese->fetch_assoc()){
  $nip = $k['nip'];
  $nama = $k['nama'];
  $unit = $k['unit'];
  $jab = $k['jab'];
  $kodejab = $k['kodejab'];
  $lok = $k['lokasi'];
  $bos = $k['bos'];
  $saverec = $k['saverec'];
}
if($saverec == '0'){
  $fung = "ceknip()";
  $btndis = "none";
}
if($saverec == '1'){
  $nipdis = "readonly";
}
?>
<link rel="stylesheet" href="../plg/w3.css">
<form action="savedatakar.php" method="post" id="formdatkar">
  <input type="hidden"name="id" value="<?=$id?>">
<table class="w3-table" id="" style="">
  <tr>
    <th style="width:150px" class="w3-small w3-border w3-blue-gray w3-center">NIP</th>
    <th style="width:300px" class="w3-small w3-border w3-blue-gray w3-center">NAMA</th>
    <th style="width:200px" class="w3-small w3-border w3-blue-gray w3-center">ATASAN</th>
  </tr>
  <tr>
    <td class="w3-small w3-border">
      <input type="text" name="nip" id="nip" class="w3-border w3-input" value="<?=$nip?>" <?=$nipdis?>>
    </td>
    <td class="w3-small w3-border">
      <input type="text" name="nama" class="w3-border w3-input" value="<?=$nama?>" onclick="<?=$fung?>"/>
    </td>
    <td class="w3-small w3-border">
      <input type="text" name="bos" class="w3-border w3-input" value="<?=$bos?>" onclick="<?=$fung?>"/>
    </td>
  </tr>
</table>
<br/>
<table class="w3-table" id="" style="">
  <tr>
    <th style="width:200px" class="w3-small w3-border w3-blue-gray w3-center">UNIT</th>
    <th style="width:400px" class="w3-small w3-border w3-blue-gray w3-center">JABATAN</th>
    <th style="width:200px" class="w3-small w3-border w3-blue-gray w3-center">LOKASI</th>
    <th style="width:250px" class="w3-small w3-border w3-blue-gray w3-center">KODE JAB</th>
  </tr>
  <tr>
    <td class="w3-small w3-border">
      <div class="w3-dropdown-click" style="">
        <input class="w3-input w3-padding" type="text" placeholder="Search.." id="Iunit" name="unit" value="<?=$unit?>"
        onkeyup="filterFunction('Dunit','Iunit');dropFunction('Dunit');" onclick="dropFunction('Dunit');<?=$fung?>;" style="width:300px;">
        <div class="w3-dropdown-content w3-bar-block w3-card w3-light-grey" id="Dunit" style="width:300px;height:200px;overflow:scroll;"
        onmouseout="dropFunction('Dunit')">
          <?
          $sql2 = "select distinct(unit)as unt from karyawan order by unit asc";
          $res2 = $conn->query($sql2);
          while($a = $res2->fetch_assoc()){
          ?>
          <a class="w3-border w3-small w3-padding w3-bar-item" style="width:300px;cursor:pointer;"
          onclick="loncatisi('<?=$a['unt']?>','Iunit','Dunit')"><?=$a['unt']?></a>
          <?}?>
        </div>
      </div>
    </td>
    <td class="w3-small w3-border">
      <div class="w3-dropdown-click" style="">
        <input class="w3-input w3-padding" type="text" placeholder="Search.." id="Ijab" name="jab" value="<?=$jab?>"
        onkeyup="filterFunction('Djab','Ijab');dropFunction('Djob');" onclick="dropFunction('Djab');<?=$fung?>;" style="width:400px;">
        <div class="w3-dropdown-content w3-bar-block w3-card w3-light-grey" id="Djab" style="width:400px;height:200px;overflow:scroll;"
        onmouseout="dropFunction('Djab')">
          <?
          $sql1 = "select distinct(jab)as jab from karyawan order by jab asc";
          $res1 = $conn->query($sql1);
          while($a = $res1->fetch_assoc()){
          ?>
          <a class="w3-border w3-small w3-padding w3-bar-item" style="width:400px;cursor:pointer;"
          onclick="loncatisi('<?=$a['jab']?>','Ijab','Djab')"><?=$a['jab']?></a>
          <?}?>
        </div>
      </div>
    </td>
    <td class="w3-small w3-border">
      <div class="w3-dropdown-click" style="">
        <input class="w3-input w3-padding" type="text" placeholder="Search.." id="Ilok" name="lok" value="<?=$lok?>"
        onkeyup="filterFunction('Dlok','Ilok');dropFunction('Dlok');" onclick="dropFunction('Dlok');<?=$fung?>;" style="width:200px;">
        <div class="w3-dropdown-content w3-bar-block w3-card w3-light-grey" id="Dlok" style="width:300px;height:200px;overflow:scroll;"
        onmouseout="dropFunction('Dlok')">
          <?
          $sql3 = "select distinct(lokasi)as lok from karyawan order by lok asc";
          $res3 = $conn->query($sql3);
          while($a = $res3->fetch_assoc()){
          ?>
          <a class="w3-border w3-small w3-padding w3-bar-item" style="width:300px;cursor:pointer;"
          onclick="loncatisi('<?=$a['lok']?>','Ilok','Dlok')"><?=$a['lok']?></a>
          <?}?>
        </div>
      </div>
    </td>
    <td class="w3-small w3-border">
      <input class="w3-input w3-padding" type="text" name="kodejab" value="<?=$kodejab?>"/>
    </td>
  </tr>
</table>
</form>
<hr/>
<center>
<div class="w3-btn w3-blue w3-small w3-round-large" onclick="editkar()" id="btnsave" style="display:<?=$btndis?>">SAVE</div>
&nbsp;
<div class="w3-btn w3-red w3-small w3-round-large" onclick="batalkar()">CANCEL</div>
</center>
<iframe style="display:none" id="rangka2"></iframe>
<script>
function loncatisi(a,y,d){
  document.getElementById(y).value=a;
  dropFunction(d);
}
function editkar(){
  var r = confirm('UPDATE DATA KARYAWAN ?...');
  if(r == true){
    document.getElementById('formdatkar').submit();
  }
}
function batalkar(){
  parent.keluar();
}
function ceknip(){
  nip = document.getElementById('nip').value;
  document.getElementById('rangka2').src="ceknip.php?nip="+nip;
}
function ulang(){
  document.getElementById('nip').focus();
  document.getElementById('btnsave').style="display:none";
}
// Dropdown
function dropFunction(x) {
  var x = document.getElementById(x);
  if (x.className.indexOf("w3-show") == -1) {
    x.className += " w3-show";
  } else {
    x.className = x.className.replace(" w3-show", "");
  }
}

// Filter
function filterFunction(x,y) {
  var input, filter, ul, li, a, i;
  input = document.getElementById(y);
  filter = input.value.toUpperCase();
  div = document.getElementById(x);
  a = div.getElementsByTagName("a");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
}
</script>
