<style>
  .mytable{
    font-size:16px;
	width:700px;
	margin-top:10px;
	color:#FFFFFF;
  }
  
  .mytableth{
    background-color:#000000;
	color:#FFCC00;
	padding:5px 5px 5px 5px;
  }
  
    .mytabletd{
        background-color: #EEEEEE;
        text-align: center;
        color: #000000;
    }
    
  .mybtn{
    width:100px;
	font-size:14px;
	font-weight: bold;
	font-family: Arial;
    color: #0000FF;
  }
    
    .mybtnsubmit{
        padding: 3px 10px 3px 10px;
	    font-size:14px;
	    font-weight: bold;
	    font-family: Arial;
        color: #0000FF;
    }
    
  .mytext{
    text-align: center;
    padding: 3px;
  }
</style>

<script>
	function btnCancel(){
		window.location = 'main.php?pg=stf';
	}
</script>

<?php
  $pid = $_GET["id"];
?>
<?php
  $qtea = "SELECT * FROM punchsys_staff WHERE id='$pid'";
  $rtea = mysqli_query($conn,$qtea);
  
  while($myrow = mysqli_fetch_array($rtea)){
	  $tid = $myrow["id"];
	  $tename = $myrow["eName"];
	  $tcname = $myrow["cName"];
	  $tjwt = $myrow["position"];
	  $tsec = $myrow["section"];
	  $tadmin = $myrow["administrator"];
	  $tstatus = $myrow["userID"];
	  
//	  if($tadmin>7){
//		$chk_adm = "CHECKED";
//	  }else{
//		$chk_adm = "";
//	  }

//	  $tvisb = $myrow["type"];
//	  if($tvisb>0){
//		$chk_vis = "CHECKED";
//	  }else{
//		$chk_vis = "";
//	  }  

	  if($tstatus>0){
		$pstatus = "0";
		$chk_status = "CHECKED";
	  }else{
		$pstatus = "1";
		$chk_status = "";
	  }

	  $tpass = $myrow["password"];
	  
	  $arrStf[$tid]["ename"] = $tid;
	  $arrStf[$tid]["cname"] = $tcname;
	  $arrStf[$tid]["position"] = $tjwt;
	  $arrStf[$tid]["section"] = $tsec;
	  $arrStf[$tid]["administrator"] = $tadmin;
	  $arrStf[$tid]["status"] = $tstatus;
	  $arrStf[$tid]["visb"] = $tvisb;
	  $arrStf[$tid]["pass"] = $tpass;
	  
  }
?>
<?php
  $qsec = "SELECT * FROM punchsys_section";
  $rsec = mysqli_query($conn,$qsec);
  while($myrow = mysqli_fetch_array($rsec)){
  
    $tid = $myrow["id"];
    $tname = $myrow["name"];
	$arrSec[$tid] = $tname;
  
  }
?>

<center>
<form action="staff_up.php" method="post">
<table border="0" cellpadding="0" cellspacing="1" class="mytable">
<input type="hidden" name="hid" value="<?= $pid ?>" />
    <tr>
      <th width="80px" class="mytableth">ID</th>
      <th class="mytableth">NAME</th>
      <th width="160px" class="mytableth">POSITION</th>
      <th width="40px" class="mytableth">SEC</th>
    </tr>
    

<tr>
  <td class="mytabletd">
      <input type="text" name="pid" value="<?= $pid ?>" class="mytext"  maxlength="10" style="width:70px">
  </td>
  <td class="mytabletd">
      <input type="text" name="pename" value="<?= $tename ?>" class="mytext" maxlength="30" style="width:190px">
      <input type="text" name="pcname" value="<?= $tcname ?>" class="mytext" style="width:90px">
  </td>
  <td class="mytabletd">
      <input type="hidden" name="pvisb" value="1" <?= $chk_vis ?>  />
      <input type="hidden" name="padmin" value="8" <?= $chk_adm ?>  />
      <input type="text" name="pjwt" value="<?= $tjwt ?>" class="mytext" maxlength="15" style="width:130px" placeholder="position...">
      <input type="hidden" name="pstatus" value="<?= $arrStf[$pid]["status"] ?>" />
  </td>
  <td class="mytabletd">
        <select name="psec">
          <?php
            foreach($arrSec as $tid=>$tsec){
              if($tid==$arrStf[$pid]["section"]){
                  $selected = "SELECTED";
              }else{
                  $selected = "";
              }
              echo "<option value='$tid' $selected>[$tid] $tsec</option>";
            }
          ?>
        </select>
  </td>
</tr>
<input type="hidden" name="pvisb" value="1" <?= $chk_vis ?>  />
<tr>
  <th colspan="4" class="mytableth">
  	  <input type="submit" value="UPDATE" class="mybtn">
	  <?php
	    if( $arrStf[$pid]["status"] == "1"){
		?>
			<input type="button" value="ACTIVE" class="mybtn" style="color: #0000FF" onClick="btnStatus()">
	    <?php
		}else{
		?>
			<input type="button" value="PASIVE" class="mybtn" style="color: #FF0000" onClick="btnStatus()">
	    <?php
		}
	  ?>
	  
	  <input type="button" value="CANCEL" class="mybtn" style="color: #FF0000" onClick="btnCancel()">
  </th>
</tr>
</form>
</table>
</center>

<script>
	function btnStatus(){
		document.getElementById("frmStatus").submit();
	}
</script>
<form id="frmStatus" action="staff_upstatus.php" method="post">
	<input type="hidden" name="pid" value="<?= $pid ?>">
	<input type="hidden" name="pstatus" value="<?= $pstatus ?>">
</form>

<!-- show error msg if found error -->
<?php
  if($_SESSION["err"]!=""){
    $perr = $_SESSION["err"];
    switch($perr){
      case "0":
	    $msg = "record saved";
        break;
      case "1":
	    $msg = "sorry, id can not be empty.";
	    break;
      case "2":
	    $msg = "sorry, name can not be empty.";
	    break;
      case "3":
	    $msg = "sorry, id already in used.";
	    break;
    }
	echo "<script>alert('$msg')</script>";
  }
  unset($_SESSION["err"]);
?>
