<?php	
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
require_once "modules/$_REQUEST[option]/time_inc.php";
foreach($_REQUEST as $key=>$value)
{
  $$key=$value;
}
$sql_idocument_status =  "SELECT * FROM `idocument_status`";
$query_idocument_status = mysqli_query($connect, $sql_idocument_status);
$arrComment = array();
while($data_idocument_status = mysqli_fetch_assoc($query_idocument_status)){
  $arrComment[$data_idocument_status['bookstatusid']] = $data_idocument_status['bookstatusname'];
}
?>
<style type="text/css">
#content td{
  font-family: "Sarabun";
  font-size: 16pt;
}
</style>
<br>
<?php
$id = $_REQUEST['id'];
$sql = "Select * From idocument_main where id = $id";
$dbquery = mysqli_query($connect,$sql);
$dataDisplay = mysqli_fetch_assoc($dbquery);
?>
<div class="container" >
  <div class="panel panel-default">
    <div class="panel-heading">
      <strong>
        <span class='glyphicon glyphicon-list-alt' aria-hidden='true'> </span> รายละเอียดบันทึกข้อความ         
        <?php
        if($dataDisplay['officer'] == $_SESSION['login_user_id']){
        ?>
        <a href="modules/idocument/display.php?id=<?=$id?>" class="pull-right btn btn-sm" alt="พิมพ์เอกสาร" title="พิมพ์เอกสาร" target="_blank">
          <span><img src="images/b_print.png" border="0" alt="พิมพ์เอกสาร" title="พิมพ์เอกสาร"></span>
        </a>&nbsp;
        <!--a onClick="#" class="pull-right btn btn-sm" alt="แก้ไขเอกสาร" title="แก้ไขเอกสาร">
        <span  class="glyphicon glyphicon-pencil">  </span></a-->&nbsp;
        <a href="?option=idocument&task=view" class="pull-right btn btn-sm btn-warning">
        <span  class="glyphicon glyphicon-arrow-left">  ย้อนกลับ</span></a>&nbsp;
        <?php
        }
        ?>
      </strong>
    </div>
    <div class="panel-body" id = "content">

<font face="Sarabun" >
<table width="100%" border="0">
  <tr>
    <td width="60">
      <img = src="./modules/<?php echo $_REQUEST['option']; ?>/main/krut.png" border="0" width="60">
    </td>
    <td align = "center" valign="middle" colspan="3">
      <strong>บันทึกข้อความ</strong>
    </td>
  </tr>
  <tr>
    <td colspan="4">
      <p>
        <strong>ส่วนราชการ </strong> <?php echo $dataDisplay['workgroup_txt'];?>
      </p>
    </td>
  </tr>
  <tr>
    <td valign="middle" colspan="2">
      <p>    
        <strong>ที่  </strong><?php echo $dataDisplay['book_no'];?>
      </p>
    </td>
    <td valign="middle" align="center" colspan="2">
      <p>
        <strong>วันที่ </strong><?php echo thai_dateBook($dataDisplay['book_date']);?>
      </p>
    </td>
  </tr>  
  <tr>
    <td colspan="4" style="border-bottom: 1px solid">
      <p>
        <strong>เรื่อง</strong> <?php echo $dataDisplay['subject'];?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="4" style="">
      <p><br>
        <strong>เรียน </strong><?php echo $dataDisplay['book_to'];?>
      </p>
    </td>
  </tr>
<?php
//Check Ref doc
$sql = "Select * From idocument_files Where document_id = '$id' and docType = 'ref'";
$result = mysqli_query($connect,$sql);
if($result->num_rows > 0){
$i = 1;
echo'  <tr>
    <td valign="top" width ="120"><strong>อ้างถึง</strong>
    </td>
    <td colspan="3" style="">
      <p>';
      while ($row = $result->fetch_assoc()) {
        if(!empty($row['file_name'])){
          if(empty($row['file_des'])){
            echo $i.". <a target='_blank' href='".$row['file_name'] ."'>เอกสารหนังสืออ้างถึง</a><br>";
          }else{
            echo $i.". <a target='_blank' href='".$row['file_name'] ."'>".$row['file_des']."</a><br>";
          }
        }else{
          echo $i.". ". $row['file_des']."<br>";
        }
        $i++;
      }
echo'        </p>
    </td>
  </tr>';
}
?>  
<?php
//Check Ref doc
$sql = "Select * From idocument_files Where document_id = '$id' and docType = 'attach'";
$result = mysqli_query($connect,$sql);
if($result->num_rows > 0){
$i = 1;
echo'  <tr>
    <td valign="top" width ="120"><strong>สิ่งที่ส่งมาด้วย</strong>
    </td>
    <td colspan="3" style="">
      <p>';
      while ($row = $result->fetch_assoc()) {
        if(!empty($row['file_name'])){
          if(empty($row['file_des'])){
            echo $i.". <a target='_blank' href='".$row['file_name'] ."'>เอกสารสิ่งที่ส่งมาด้วย</a><br>";
          }else{
            echo $i.". <a target='_blank' href='".$row['file_name'] ."'>".$row['file_des']."</a><br>";
          }
        }else{
          echo $i.". ". $row['file_des']."<br>";
        }
        $i++;
      }
echo'        </p>
    </td>
  </tr>';
}
?>  
  <tr>
    <td colspan="4" style="">
      <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content1']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="4" style="">
      <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content2']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="4" style="">
      <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content3']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="3" style="text-align:center;"><br>
ตรวจสอบเสนอ
<br>
<?php
// Add signature
$sigFile = "./modules/person/signature/". $dataDisplay['officer'] .".png";
//$sigFile = "./signature/3700300113267.png";
if(file_exists($sigFile)){
	echo "<img src='". $sigFile ."' border='0' width='150'>";
}
?>
<br>
(<?php echo $dataDisplay['officer_name'];?>)
<br>
<?php echo $dataDisplay['officer_position'];?>
<br>
<?php echo thai_dateBook($dataDisplay['book_date']);?>
</td>
    <td style=""></td>
  </tr>
</table>
</font>
<br /><br />
<?php
$sqlComment = "Select * From idocument_comment where document_id = $id Order by id";
//echo $sqlComment;
$dbqueryComment = mysqli_query($connect,$sqlComment); 
if(mysqli_num_rows($dbqueryComment)==0){

}else{
  echo "<br><br>";
  while($commentData = mysqli_fetch_array($dbqueryComment)){
$fullname  = '( '. $commentData['person_comments_name'].' )<br>
'. $commentData['person_comments_position'].'<br>
'. thai_dateBook($commentData['comments_date']);
//'. thai_dateBook(date("Y-m-d",$commentData['comments_date']));
$data_comment = explode(", ", $commentData['comments_select']);
$comment ="";
foreach($data_comment as $value){
  @$comment .=($value=="")?"":("-". (($arrComment[$value])?$arrComment[$value]:$value)."<br />");
}
echo "<div class='col-sm-4' style='font-size:14pt;font-family: \"Sarabun\";'>";
echo $comment;
echo "<p align=center>";

// Add signature
$sigFileComment = "./modules/person/signature/". $commentData['person_comments_id'] .".png";
//$sigFile = "./signature/3700300113267.png";
if(file_exists($sigFileComment)){
	echo "<img src='". $sigFileComment ."' border='0' width='150'>";
}

echo "<br>".$fullname;
echo "</p>";
echo "</div>";
  }
}

?>
    </div>
<?php
$sql3 = "SELECT * FROM `idocument_sendto` where document_id='$id' and (status='0' or status is null) and person_id<>'' ";
$dbquery3 = mysqli_query($connect,$sql3);
$result3 = mysqli_fetch_array($dbquery3);
$num_row=mysqli_num_rows($dbquery3);   

if($num_row>=1){
$sql4 = "SELECT * FROM `person_main` where person_id='$result3[person_id]' ";
$dbquery4 = mysqli_query($connect,$sql4);
$result4 = mysqli_fetch_array($dbquery4);

echo "(ขณะนี้อยู่ระหว่างการพิจารณาของ : ";
echo $result4['prename']; 
echo $result4['name'];
echo "  ";
echo $result4['surname'];
echo ")";
}
?>
  </div>
</div> 

