<?php
defined('_VALID_') or die('Direct Access to this location is not allowed.');

?>

<div class="panel panel-default">
    <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" method="POST" action="?option=<?php echo $_REQUEST['option']; ?>&task=book_pass&action=comment&id=<?php echo $_REQUEST['id']; ?>">
<input type="hidden" name="commentLevel" value="1">
<input type="hidden" name="document_from" value="<?php echo $_SESSION['login_user_id']; ?>">

<!--label class="radio-inline">
  <input type="radio" name="comment1" id="comment1" value="0"><span class='glyphicon glyphicon-repeat' aria-hidden='true'></span> คืนเรื่องเพื่อแก้ไข
</label-->
<?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);}
    if($_SESSION['position_code'] > 2){
      $sql_idocument_status = "SELECT * FROM `idocument_status` WHERE position_use = 0";
    }else{
      $sql_idocument_status = "SELECT * FROM `idocument_status` WHERE position_use = 1";
    }
    $query_idocument_status = mysqli_query($connect, $sql_idocument_status);
    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 ";
                }
            }
        }
        ?>
<input type="checkbox" name="comment1[]" id = "chk[<?php echo $data_idocument_status['bookstatusid']; ?>]" value="<?php echo $data_idocument_status['bookstatusid']; ?>" <?=$chkBox;?>> <label class = "text-danger" for="chk[<?php echo $data_idocument_status['bookstatusid']; ?>]"><?php echo $data_idocument_status['bookstatusname']; ?></label><br />
<?php
}
    ?>
<!--
<label class="radio-inline">
  <input type="radio" name="comment1" id="comment1" value="0"><span class='glyphicon glyphicon-repeat' aria-hidden='true'></span> เพื่อโปรดทราบ
</label>

<label class="radio-inline">
  <input type="hidden" name="rec_id" value="">
  <input type="radio" name="comment1" id="comment1" value="1"><span class='glyphicon glyphicon-check' aria-hidden='true'></span> เพื่อโปรดพิจารณา </label> <br><br><input type="text"   name="commenttxt" id="commenttxt" placeholder="บันทึกความเห็นเพิ่มเติม" class="form-control">
-->
<label class="control-label" for="commentETCtxt"> ความเห็นเพิ่มเติม </label><br><br>
  <textarea rows="3" cols="" name="comment1[]" id="commentETCtxt" placeholder="บันทึกความเห็นเพิ่มเติม" class="form-control"><?=(isset($data_comment)) ? $data_comment[count($data_comment) - 1] : "";?></textarea>
  <!--input type="text" name="commentETCtxt" id="commentETCtxt" placeholder="บันทึกความเห็นเพิ่มเติม" class="form-control"-->

<?php
if ($_SESSION['position_code'] != 1) {
?>
<label for="fwTO" class="control-label"> เรียนเสนอ </label><br><br>
  <select class="form-control" id="fwTO" name="bookto_id">
<?php

    $sql_chk_sento = "SELECT * FROM idocument_sendto WHERE document_id = '$id' AND document_from ='" . $_SESSION['login_user_id'] . "'";
    $dbquery_chk = mysqli_query($connect, $sql_chk_sento);
    $data_Sendto = mysqli_fetch_assoc($dbquery_chk);

    if ($_SESSION['position_code'] != 1) {
        if ($_SESSION['position_code'] == 2) {
            $sqlSelectSend = "Select * From person_main Where position_code IN ('1') and status=0 Order by position_code Desc,   person_order"; // เรียกรายชื่อ ผอ.กลุ่ม, รอง ผอ., ผอ.
        } elseif ($_SESSION['position_code'] == 3) {
          $sqlSelectSend = "Select * From person_main Where position_code IN ('1','2') and status=0 Order by position_code Desc,   person_order"; // เรียกรายชื่อ ผอ.กลุ่ม, รอง ผอ., ผอ.
      }else{
            $sqlSelectSend = "Select * From person_main Where position_code IN ('2','3') and status=0 Order by position_code Desc,   person_order"; // เรียกรายชื่อ ผอ.กลุ่ม, รอง ผอ.
        }
        $dbquery = mysqli_query($connect, $sqlSelectSend);
        while ($dataSelectSend = mysqli_fetch_assoc($dbquery)) {
            $selected = (!$data_Sendto) ? "" : $data_Sendto['person_id'] == $dataSelectSend['person_id'] ? " selected" : "";
            echo "<option value='" . $dataSelectSend['person_id'] . "'" . $selected . ">" . $dataSelectSend['prename'] . $dataSelectSend['name'] . " " . $dataSelectSend['surname'] . "</option>\n";
        }
    }
?>
  </select>  
<?php
}else{
  echo '<input type="hidden" name="commentLevel" value="3">';
}
?>
<br>
      <button type="submit" class="btn btn-default pull-right" ><span class="glyphicon glyphicon-ok"></span>&nbsp;บันทึก </button>
  </div>
</div>
</form>
<?php
} else {
    ?>
<span class="badge" style="background-color:orange;">ผอ.สพท. ลงความเห็น/สั่งการแล้ว</span>
<?php
}
?>
</div>
</div>