<?php
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
foreach($_REQUEST as $key=>$value)
{
  $$key=$value;
}

?>

<div class="panel panel-info">
    <div class="panel-heading">
      <h4 class="panel-title"><span class='glyphicon glyphicon-list-alt' aria-hidden='true'> </span> บันทึกความเห็น (รอง ผอ)</h4>
    </div>
    <div class="panel-body">
<?php
$sqlCHK = "Select * From idocument_comment where document_id= '$id' ANd comments_status='3' AND person_comments_name <>''";
if(mysqli_num_rows(mysqli_query($connect, $sqlCHK))==0){
?>      
<form data-toggle="validator" role="form" enctype="multipart/form-data" class="form-horizontal was-validated" method="POST" action="?option=<?php echo $_REQUEST['option'];?>&task=book_pass&action=comment&id=<?php echo $_REQUEST['id'];?>">

<input type="hidden" name="commentLevel" value="2">
<input type="hidden" name="rec_id" value="<?php echo md5($_REQUEST['id']). $_SESSION['login_user_id'];?>">
<input type="hidden" name="rec_from" value="<?php echo md5($_REQUEST['id']). $_SESSION['login_user_id'];?>">
<input type="hidden" name="document_from" value="<?php echo $_SESSION['login_user_id'];?>">

  <div>
    <input type="radio" class="custom-control-input" id="customControlValidation2" name="radio-stacked" value = "transfer" required>
    <label class="custom-control-label" for="customControlValidation2">เสนอต่อผู้อำนายการ</label>
  </div>
  <div id = "frmtransfer"></div>
  <div>
    <input type="radio" class="custom-control-input" id="customControlValidation3" name="radio-stacked"  value = "cmd" required>
    <label class="custom-control-label" for="customControlValidation3">สั่งการ (ปฏิบัติราชการแทน)</label>
  </div>
  <div id = "frmcmd"></div>
  <div>
    <input type="radio" class="custom-control-input" id="customControlValidation4" name="radio-stacked"  value = "cmdActing" required>
    <label class="custom-control-label" for="customControlValidation4">สั่งการ (รักษาราชการแทน)</label>
  </div>
  <div id = "frmcmdActing"></div>

<br />
      <button type="submit" class="btn btn-default pull-right" ><span class="glyphicon glyphicon-ok"></span>&nbsp;บันทึก </button>
  </div>  
</div>
</form>
<?php

$sqlComment = "Select * From idocument_comment where document_id = $id AND person_comments_id = '" . $_SESSION['login_user_id'] . "'";
//echo $sqlComment;
    $dbqueryComment = mysqli_query($connect, $sqlComment);
    if (mysqli_num_rows($dbqueryComment) > 0) {
        $commentData = mysqli_fetch_array($dbqueryComment);
        $data_comment = explode(", ", $commentData['comments_select']);
    }else{unset($data_comment);}

$sql_idocument_status = "SELECT * FROM `idocument_status` ";
$query_idocument_status = mysqli_query($connect, $sql_idocument_status);
$textform_transfer="";
$textform_cmd="";
while ($data_idocument_status = mysqli_fetch_assoc($query_idocument_status)) {
  $chkBox = "";
  if (isset($commentData)) {
      foreach ($data_comment as $value) {
          if ($data_idocument_status['bookstatusid'] == $value) {
              $chkBox = " checked ";
          }
      }
  }
if($data_idocument_status['position_use']== 0){
  $textform_transfer .="&nbsp;&nbsp;&nbsp;<input type=radio name=comment1[] id = chk[".$data_idocument_status['bookstatusid']."] value=".$data_idocument_status['bookstatusid']." ".$chkBox."> <label class = text-".$data_idocument_status['textColor']." for=chk[". $data_idocument_status['bookstatusid']."]>".$data_idocument_status['bookstatusname']."</label><br />";
}else{
  $textform_cmd .="&nbsp;&nbsp;&nbsp;<input type=checkbox name=comment1[] id = chk[".$data_idocument_status['bookstatusid']."] value=".$data_idocument_status['bookstatusid']." ".$chkBox."> <label class = text-".$data_idocument_status['textColor']." for=chk[". $data_idocument_status['bookstatusid']."]>".$data_idocument_status['bookstatusname']."</label><br />";
}
}
// เรียกหมายเลข ผอ
$sqlSelectSend = "Select * From person_main Where position_code IN ('1') and status=0 Order by position_code Desc,   person_order";
$dbquery = mysqli_query($connect, $sqlSelectSend);
$dataSelectSend = mysqli_fetch_assoc($dbquery);

  $textform_transfer .="<label class=control-label for=commentETCtxt> ความเห็นเพิ่มเติม </label><br><textarea rows=3  name=\"comment1[]\" id=commentETCtxt placeholder=บันทึกความเห็นเพิ่มเติม class=form-control>".((isset($data_comment)) ? $data_comment[count($data_comment) - 1]:"") ."</textarea><input type=hidden name=bookto_id value=".$dataSelectSend['person_id'].">";

  $textform_cmd .="<label class=control-label for=commentETCtxt> ความเห็นเพิ่มเติม </label><br><textarea rows=3 name=\"comment1[]\" id=commentETCtxt placeholder=บันทึกความเห็นเพิ่มเติม class=form-control>".((isset($data_comment)) ? $data_comment[count($data_comment) - 1]:"") ."</textarea>";

  ?>
<script>
  $('input[type=radio][name=radio-stacked]').change(function() {
      if (this.value == 'cmd') {
        document.getElementById('frmcmd').innerHTML = '<?=$textform_cmd;?>';
        document.getElementById('frmtransfer').innerHTML = '';
        document.getElementById('frmcmdActing').innerHTML = '';
      }
      else if (this.value == 'transfer') {
        document.getElementById('frmtransfer').innerHTML = '<?=$textform_transfer;?>';
        document.getElementById('frmcmd').innerHTML = '';
        document.getElementById('frmcmdActing').innerHTML = '';
      }else if (this.value == 'cmdActing') {
        document.getElementById('frmcmdActing').innerHTML = '<?=$textform_cmd;?>';
        document.getElementById('frmtransfer').innerHTML = '';
        document.getElementById('frmcmd').innerHTML = '';
      }
  });
</script>
<?php
}else{
?>
<span class="badge" style="background-color:orange;">ผอ.สพท. ลงความเห็น/สั่งการแล้ว</span>
<?php
}
  ?>
</div>
</div>
