<?php
session_start();
if(!isset($_SESSION['sys_id'])) header("Location: ?d=index");
require_once("../../config.php");
require_once("m_addfile_doc.php");

$docin = docin($whereclause, '');
$output_filename = "ETL_Secretary_document".date("d-m-Y").".xls";
// Redirect the output to the stream
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename={$output_filename}");

echo "<h4>ລາຍງານເອກະສານຂາເຂົ້າ-ຂາອອກ ລໍຖ້າໃຫ້ຄໍາເຫັນ (ຫ້ອງເລາຂາ) </h4> ";

if ($startdate != null && $enddate != null) echo "<p>ແຕ່ວັນທີ ".date("d-m-Y", strtotime($startdate))." ຫາ ".date("d-m-Y", strtotime($enddate))."</p> \n"; ?>		
	<table border='1'> 
		<tr bgcolor='#8EE5EE'>
	<th>&nbsp;No.&nbsp;</th>
    <th width="180">ເລກທີເອກສານຂາເຂົ້າ-ຂາອອກ</th>
    <th>ປະເພດເອກະສານ</th>
    <th>ເລື່ອງ</th>
    <th>ຄໍາເຫັນ</th>
	<?php if($_SESSION['sys_type']=='secretary'){ ?>
	<th width='120'>ຢືນຢັນ/ສົ່ງຕໍ່</th>
	<? } ?>
	</tr>
  <?php 
		$i = 1;
		while($row = mysql_fetch_array($docin, MYSQL_ASSOC)) {
			$bgcolor = "";
			if($row['receive_status'] == 1)  $bgcolor = "#ffe8c5";
			$doc_status = $row['doc_status'] == 1 ? " (ຂາເຂົ້າ)" : " (ຂາອອກ)";
			$d = $row['doc_status']==1 ? "?d=document/docin/docin_add&doc_id=$row[doc_id]&action=edit&st=scan" : "?d=document/docout/docout_add&doc_id=$row[doc_id]&action=edit&st=scan";
		?>
			<tr bgcolor="<?=$bgcolor?>"  > <!-- class='tb_hover ' --->
			<td class="centered"><?=$i + $start ?>
				<input type="hidden" name="type[]" class="type" value="unchanged" />
				<input type='hidden' value="<?=$row['doc_id']?>" name="id[]">
			</td>
			<td class=""><?=$row['doc_code']?> , <?=date("d-m-Y", strtotime($row['doc_date']))?></td>
			<td class=""><?=$row['doctype_name'].$doc_status ?></td>
			<td>
			<?php if($row['doc_file']!=""){
				if($row['doc_status']==1){ 
			?>
				<a target="_blank" href="document/show_filein.php?type=<?=$row['doctype_id']?>&filein=<?=$row['doc_file']?>"><?=$row['doc_title'] ?></a>
				<?php }else{ ?>
				<a target="_blank" href="document/show_fileout.php?type=<?=$row['doctype_id']?>&filein=<?=$row['doc_file']?>"><?=$row['doc_title'] ?></a>
				<?php } }else{ ?>
				<?=$row['doc_title'] ?>
				<? } ?>
			</td>
			<td class=""><?=$row['doc_comment'] ?></td>
			<?php if($_SESSION['sys_type']=='secretary'){ 
			
					if($row['receive_status'] == 1){ ?>
					<td class="" >ລໍຖ້າຢືນຢັນ</td>
					<?php }else{ ?>
					<td class="centered">ສົ່ງໃຫ້ອໍານວຍການ</td>
			<?php	} ?>
			 <? } ?>
			</tr>
		
		<?php $i++;
		}
		?>
	</table>
<?php mysql_close($conn); ?>
