<?php
	htmltage("ລາຍການເອກະສານເຂົ້າ");
	/*-------- Check if user not have permission ---------------- kong*/
// the I fixed role access app -- if you change info in table app you should check this again ==>> kong
if (strlen(session_id()) < 1)  session_start();
if($_SESSION['sys_type']!='counter'){
	//if($_SESSION['orgunitid_r']!=null) header("Location: ?d=index");
	if($_SESSION['sys_type']!= "secretary") header("Location: ?d=index");
} 

/*=========================================================================*/
?>
<form method="get">
<div class="contentpage">
<center><label id = "msgwar" class = "msgChk"></label></center>
<?php if($_SESSION['sys_type']=='counter'){?>
<!--- <h2 class='announce'>ແຈ້ງການ update ໃໝ່: ເມື່ອທ່ານຈ່າຍໃຫ້ ພະແນກ/ສາຂາ ໄປແລ້ວ ຖ້າສົ່ງບໍ່ຖຶກ ຫຼື ຢາກແກ້ໄຂແມ່ນໃຫ້ເລືອກລາຍການ ສະຖານະແຖວທໍາອິດ ຫຼື ປ້ອນຂໍ້ມູນເອກະສານທີ່ຕ້ອງການຄົ້ນຫາ ແລ້ວ ຄຣີກເພື່ອແກ້ໄຂ</h2> -->
<?php } ?>
<h1 class="headtitle">ລາຍການເອກະສານຜ່ານ ເຄົາເຕີ່ (ພ້ອມຈ່າຍໃຫ້ ພະແນກ/ສາຂາ) / ຄຣິກທີ່ລາຍການເອກະສານເພີ່ອສົ່ງ</h1>

<input type="hidden" name="d" value="document/list_docin/send_doc" />
<input type="hidden" name="orgunitid" value="<?=(int)$_GET['orgunitid']?>" />
<div class="searchbox">
	<fieldset>	
		<legend>ຄົ້ນຫາ</legend>
		<p class="right"><input type="submit" value="Export To Excel" class="toexcel" onclick='window.open ("document/list_docin/ex_counter.php?<?=$params?>")'/></p>
		<table>
						<td colspan=''>
								<select name="status" onchange="this.form.submit();" >
									<option value="">-- ທຸກສະຖານະ --</option>
									<?php 
										$selected1 = $_GET['status'] == 1 ? "selected" : ""; 
										$selected2 = $_GET['status'] == 2 ? "selected" : ""; 
									?>
									<option value="1" <?=$selected1 ?>> ເອກະສານທີ່ຍັງບໍ່ທັນຈ່າຍໃຫ້ ພະແນກ/ສາຂາ </option>
									<option value="2" <?=$selected2 ?>> ເອກະສານທີ່ ຈ່າຍອອກແລ້ວ </option>
								</select>
							</td>
						<tr>
							<td colspan='4'>
							<p>
							<input type="text"  name="startdate" class="date" size="12" value = "<?=$_GET['startdate']?>" />&nbsp;<span class="bold"> ຫາ</span> &nbsp;
							<input type="text" name="enddate" class="date" size="12" value = "<?=$_GET['enddate']?>" />  		
							</p>
							</td>
						</tr>
						<tr>
							<td>
								<select name="doctype_id">
									<option value="">-- ທຸກປະເພດ (ເອກະສານ) --</option>
									<?php 
									$doctype = doctype();
									foreach ($doctype as $typeitem) {
										$selected = $typeitem['doctype_id'] == $_GET['doctype_id'] ? "selected" : ""; 
									?>
									<option value="<?= $typeitem['doctype_id'] ?>" <?= $selected ?>><?= $typeitem['doctype_name'] ?></option>
									<?php } ?>
								</select>
							</td>
						
							<td>
								<input name="doc_code" type="text" placeholder="ເລກທີເອກະສານ" size="10" value="<?= $_GET['doc_code'] ?>"/>
								<input name="doc_title" type="text" placeholder="ຫົວຂໍ້ເອກະສານ" size="30" value="<?= $_GET['doc_title'] ?>"/>
							</td>
							<td>
								<input type="submit" value="ຄົ້ນຫາ" class="btn2" />
								<input type="reset" value="ຍົກເລີກ" class="btn2" onclick="document.location='?d=document/list_docin/send_doc&orgunitid=<?=$_GET['orgunitid']?>&status=1&start=<?=$_GET['start']?>'" />
							</td>
							<td>
								
							</td>
						</tr>
		</table>
	</fieldset>
</div>
<?php 	
	$rs = docin($whereclause, $limitclause);
	if(mysql_num_rows($rs)!= 0){
?>
<div id = "control_view">
<!-- <div id = "fixed_confirm">--->
<h4><?= $pagedescription ?></h4>
<table class="beautified">
	<tr>
    <th>No.</th>
    <th>ວັນເວລາອອກຈາກຫ້ອງເລຂາ</th>
    <th>ເລກທີເອກສານຂາເຂົ້າ-ຂາອອກ</th>
    <th>ປະເພດເອກະສານ</th>
    <th>ເລື່ອງ</th>
    <th>ຄໍາເຫັນ</th>
	</tr>
  <?php 
		$i = 1;
		while($row = mysql_fetch_array($rs, 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=assign" : "?d=document/docout/docout_add&doc_id=$row[doc_id]&action=edit&st=assign";
		?>
			<tr bgcolor="<?=$bgcolor?>" onclick="window.location.href='<?php if($_SESSION['sys_type']=="counter"){ echo $d;}else{ echo "?d=document/list_docin/send_doc&orgunitid=31&status=".$_GET['status'];}?>'" class='tb_hover '>
			<td class="centered"><?=$i + $start ?></td>
			<td class=""><?=date("d-m-Y H:i:s", strtotime($row['m_date']))?></td>
			<td class=""><?=$row['doc_code']?> , <?=date("d-m-Y", strtotime($row['doc_date']))?></td>
			<td class=""><?=$row['doctype_name'].$doc_status;?></td>
			<td><?=$row['doc_title'] ?></td>
			<td><?=$row['doc_comment']?></td>
			</tr>
		
		<?php $i++;
		}
		?>
	</table>
</div>
<div class="paging">
<?php
	if ($pagecount > 1){
		if ($pagenum > 1) echo "<a href='?d=document/list_docin/send_doc&$params&start=".(($pagenum-2)*$pagesize)."' $isselected>&lt; ກັບຄືນ</a>";
		$j=1;
		$g_start = 0;
		if($_GET['start'] >= $pagesize*4) $g_start = ($_GET['start'] / $pagesize) - 4;
		
		for ($i = $g_start; $i < $pagecount; $i++){
			if ($i == $pagenum-1) $isselected = "class='selected'";
			else $isselected = "";
		
			if($j<10){
				echo "<a href='?d=document/list_docin/send_doc&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
			}
			$j++;
		}
		if ($pagenum < $pagecount) echo "<a href='?d=document/list_docin/send_doc&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
</form>
<?}else{ ?>
<div class="messagebox">
	<p class="centered errormessage">ບໍ່ມີລາຍການ ເອກະສານຂາເຂົ້າ-ອອກທີ່ຄົ້ນຫາ </p>
</div>
<?php } ?>
</div>
<?=$err;?>