<?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']!='secretary'){
	if($_SESSION['sys_type']!='counter') 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'>ທ່ານສາມາດແກ້ໄຂ ຫຼື ລຶບ ລາຍການເອກະສານໄດ້ທີ່ນີ້ (ລາຍການຍັງເປັນສີສົ້ມ) ຫຼື ລາຍການຫ້ອງເລຂາຍັງບໍ່ທັນໄດ້ຢືນຢັນຮັບ
</h2> -->
<? } ?>
<h1 class="headtitle">ລາຍການເອກະສານຜ່ານ ຫ້ອງເລຂາ(ເຂົ້າເລກທີ່ແລ້ວຈາກ ເຄົາເຕີ່)</h1>

<input type="hidden" name="d" value="document/list_docin/addfile_doc" />
<input type="hidden" name="orgunitid" value="<?=(int)$_GET['orgunitid']?>" />
<div class="searchbox">
	<fieldset>	
		<legend>ຄົ້ນຫາ</legend>
		<table width="" border='0'>
						<tr>
							<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>
							<td  colspan='3'>
								<select name="type_io">
									<option value="">-- ປະເພດຂາເຂົ້າ-ຂາອອກ --</option>
									<?php 
										$selected3 = $_GET['type_io'] == 1 ? "selected" : ""; 
										$selected4 = $_GET['type_io'] == 2 ? "selected" : ""; 
									?>
									<option value="1" <?=$selected3 ?>> ປະເພດຂາເຂົ້າ </option>
									<option value="2" <?=$selected4 ?>> ປະເພດຂາອອກ </option>
								</select>
							</td>
						</tr>
						<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/addfile_doc&orgunitid=<?=$_GET['orgunitid']?>&status=&start=<?=$_GET['start']?>'" />
							</td>
							<td>
								<p class="right"><input type="submit" value="Export To Excel" class="toexcel" onclick='window.open ("document/list_docin/ex_secretary.php?<?=$params?>")'/></p>
							</td>
						</tr>
		</table>
	</fieldset>
</div>
</form>
<form method="post">
<?php 	
	$rs = docin($whereclause, $limitclause);
	if(mysql_num_rows($rs)!= 0){
?>
<div id = "control_view">
<div id = "">
<h4><?= $pagedescription ?></h4>
<table class="beautified editable">
	<tr>
    <th>&nbsp;&nbsp;No.&nbsp;&nbsp;</th>
    <th width="">ວັນເວລາເຄົາເຕີ່ເອົາເຂົ້າ ຫຼື update ລ່າສຸດ</th>
    <th width="180">ເລກທີເອກສານຂາເຂົ້າ-ຂາອອກ</th>
    <th width="">ປະເພດເອກະສານ</th>
    <th>ເລື່ອງ</th>
    <th>ຄໍາເຫັນ</th>
	<?php if($_SESSION['sys_type']=='secretary'){ ?>
	<th width='50'>ສົ່ງຄືນ<br/>ໃຫ້ເຄົາເຕີ່</th>
	<th width='120'>ຢືນຢັນ/ສົ່ງຕໍ່</th>
	<th width='60'>scan ໄຟລ໌<br/>ເອກະສານ</th>
	<? }elseif($_SESSION['sys_type']=='counter'){	?>
	<th width='60'>ແກ້ໄຂ</th>	
	<th width='60'>ລຶບ</th>		
	<?php }  ?>
	</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=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=""><?=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>
			<?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']?>&fileout=<?=$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'){ ?>
				<?php if($row['m_step']=='secretary' && $row['doc_comment'] == ""){
				?>
					<td class="centered"></td>
				<?php }else{ ?>
					<td class="centered"><input type="checkbox" class="send" name="send_[]" value=''></td>
				<?php }
			
				?>
			<?php if($_SESSION['sys_type']=='secretary'){ 
			
					if($row['receive_status'] == 1){ ?>
					<td class="" ><a href="?d=document/list_docin/addfile_doc&action=edit&doc_id=<?=$row['doc_id']?>&m_id=<?=$row['m_id']?>&orgunitid=<?=(int)$_GET['orgunitid']?>&status=<?=$_GET['status']?>&start=<?=(int)$_GET['start']?>" onclick="return confirm('ທ່ານຕ້ອງການຢືນຢັນແທ້ບໍ່...?')" ><input type="button" name="btnbill" class = "toprint" value="ລໍຖ້າຢືນຢັນ" /></a> </td>
					<?php }else{ ?>
						<td class="centered"><input type="button" onclick="window.location.href='?d=document/assign_staff/docin_assign&start=<?=$_GET['start']?>&m_id=<?=$row['m_id']?>&doc_id=<?=$row['doc_id']?>&orgunitid=<?=(int)$_GET['orgunitid']?>'" class = "toreturn" value="ສົ່ງໃຫ້ອໍານວຍການ" /></td>
			<?php		 } ?>
				<td class="centered">
				<a href ="<?=$d?>"><img src = "img/add_01.png" border = '0' width = '30' height = '30'/></a> 
				</td>
			 <?php }
		
			}elseif($_SESSION['sys_type']=='counter'){ 
				if($row['receive_status'] == 1){ ?>
					<td class='centered'><a href ="?d=document/docin/docin_add&doc_id=<?=$row["doc_id"]?>&action=edit" >
					<img src = "img/edit.png" border = '0' width = '30' height = '30'  /></a> 
					</td><td class='centered'>
					<a href ="?d=document/list_docin/addfile_doc&orgunitid=35&doc_id=<?=$row["doc_id"]?>&action=del&start=<?=$_GET['start']?>&status=<?=$_GET['status']?>" onclick="return confirm('ທ່ານຕ້ອງການລຶບຂໍ້ມູນນີ້ແທ້ບໍ...?')" ><img src = "img/del.ico" border = '0' width = '20' height = '20'  /></a> 
					</td>
				<? }else{ ?>
					<td></td><td></td>
				<? } ?>
			<? } ?>
			</tr>
		<?php
		$i++;
		}
		?>
	</table>
</div>
<?php if($_SESSION['sys_type'] =='secretary' || $_SESSION['orgunitid_r']==''){ ?>
	<div class="menubox">		
		<!--<input type="button" name ="test" id="addEq" class = "btn2" value="  &#3776;&#3742;&#3765;&#3784;&#3745;  " />-->
		<input type="button" id="reset" class = "btn2" value="  &#3725;&#3771;&#3713;&#3776;&#3749;&#3765;&#3713;  " />
		<input type="submit" name="btnsave" class = "btn2 right btnsave" value="  &#3738;&#3761;&#3737;&#3735;&#3766;&#3713;  "  id="right" onclick="return confirm('ທ່ານຕ້ອງການບັນທຶກແທ້ບໍ...?')" />
	</div>
	
	<?php } ?>
</form>

<div class="paging">
<?php
	if ($pagecount > 1){
		if ($pagenum > 1) echo "<a href='?d=document/list_docin/addfile_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/addfile_doc&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
			}
			$j++;
		}
		if ($pagenum < $pagecount) echo "<a href='?d=document/list_docin/addfile_doc&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
<?}else{ ?>
<div class="messagebox">
	<p class="centered errormessage">ບໍ່ມີລາຍການ ເອກະສານຂາເຂົ້າ-ຂາອອກໃຫ້ຢືນຢັນ </p>
</div>
<?php } ?>
</div>
<?=$err;?>