<?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">

<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="3">
<input type="hidden" name="document_from" value="<?php echo $_SESSION['login_user_id']; ?>">

<?php

    $sqlComment = "Select * From idocument_comment where document_id = $id AND person_comments_id = '" . $_SESSION['login_user_id'] . "'";

    $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="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>
 
<br>
      <button type="submit" class="btn btn-default pull-right" ><span class="glyphicon glyphicon-ok"></span>&nbsp;บันทึก </button>
  </div>
</div>
</form>

</div>
</div>