<?php
session_start();
header("Content-type:text/html; charset=UTF-8");                
header("Cache-Control: no-store, no-cache, must-revalidate");               
header("Cache-Control: post-check=0, pre-check=0", false);    
require('../../amssplus_connect.php');
require('../../modules/idocument/time_inc.php');
foreach($_REQUEST as $key=>$value)
{
  $$key=$value;
}
?>
<style type="text/css">
	@font-face {
	font-family: 'Sarabun';
	src:url('fonts/Sarabun.ttf.woff') format('woff'),
	url('fonts/Sarabun.ttf.svg#Sarabun') format('svg'),
	url('fonts/Sarabun.ttf.eot'),
	url('fonts/Sarabun.ttf.eot?#iefix') format('embedded-opentype'); 
	font-weight: normal;
	font-style: normal;
	}
#content, body 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);
?>
<font face="Sarabun" >
<table width="100%" border="0">
  <tr>
    <td width="60">
      <img = src="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>
        <?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content1']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="4" style="">
      <p>
        <?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content2']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td colspan="4" style="">
      <p>
        <?php echo nl2br(str_replace(" ", "&nbsp;", $dataDisplay['content3']));?>
      </p>
    </td>
  </tr>
  <tr>
    <td style=""></td>
    <td colspan="3" style="text-align:center;"><br>
ตรวจสอบเสนอ
<br>
<?php
// Add signature
$sigFile = "../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>
  </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{
print "<table>
  <tr>";
  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']));
if($commentData['comments_select'] == ""){
  $commenttext = "";
}
if($commentData['comments_select'] == 0){
  $commenttext = "เพื่อโปรดทราบ";
}
if($commentData['comments_select'] == 1){
  $commenttext = "เพื่อโปรดพิจารณา";
}
if($commentData['comments_select'] == 2){
  $commenttext = "ทราบ";
}
if($commentData['comments_select'] == 3){
  $commenttext = "ลงนามแล้ว";
}
if($commentData['comments_select'] == 4){
  $commenttext = "อนุญาต";
}
if($commentData['comments_select'] == 41){
  $commenttext = "อนุญาต/อนุมัติ";
}
if($commentData['comments_select'] == 5){
  $commenttext = "ไม่อนุญาต";
}
if($commentData['comments_select'] == 51){
  $commenttext = "ไม่อนุญาต/ไม่อนุมัติ";
}
if($commentData['comments_select'] == 6){
  $commenttext = "อนุมัติ";
}
if($commentData['comments_select'] == 7){
  $commenttext = "ไม่อนุมัติ";
}
if($commentData['comments_select'] == 8){
  $commenttext = "ชอบ/ให้ดำเนินการตามเสนอ";
}

$comment = '- '.$commenttext;
if(!empty($commentData['comments_etctxt'])){
$comment = $comment.'<br>
- '. $commentData['comments_etctxt'];
}

echo "<td>";
echo $comment;
echo "<p align=center>";

// Add signature
$sigFileComment = "../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 "</td>";
  }
print"  </tr>
</table>";  
}
?>

<?php
//print_r($_SESSION);
?>