<?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(!isset($_SESSION['sys_id'])) header("Location: ?d=index");
if ($_SESSION['orgunitid_r'] != "" && $_SESSION['sys_type']!="counter" && $_SESSION['sys_type']!="secretary") header("Location: ?d=document/docin/docin_dept"); 
$user_role = $_SESSION['role_id'];
/*=========================================================================*/
 ?>
<div class="contentpage">
	<h1 class="headtitle">ລາຍການເອກະສານຂາອອກ</h1>
	<center><label id = "msgwar" class = "msgChk"></label></center>
	<form method="get">
		<input type="hidden" name="d" value="document/docout/docout" />
		<div class="searchbox">
			<fieldset>	
				<legend>ຄົ້ນຫາ</legend>
					<p class="bold">ແຕ່ວັນທີ(ເອກະສານຂາອອກ):</p>
					<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>
					<table border='0' width="100%">
						<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>
						</tr>
						<tr>
							<td>
								ເລກທີເອກະສານ:&nbsp;<input name="doc_code" type="text" placeholder="ເລກທີເອກະສານ" size="10" value="<?= $_GET['doc_code'] ?>"/>
								ຫົວຂໍ້ເອກະສານ:&nbsp;<input name="doc_title" type="text" placeholder="ຫົວຂໍ້ເອກະສານ" size="40" value="<?= $_GET['doc_title'] ?>"/>
							</td>
						</tr>
						<tr>
							<td>
								<input type="submit" value="ຄົ້ນຫາ" class="btn2" />
								<input type="reset" value="ຍົກເລີກ" class="btn2" onclick="document.location='?d=document/docout/docout'" />
								<?php if($_SESSION['role_id'] == 1 && ($_SESSION['sys_type'] == 'secretary')){ ?>
								<input type="button" value="ເພີ່ມເອກະສານ" class="btn2" onclick="document.location='?d=document/docout/docout_add'" />
								<?php }elseif($_SESSION['role_id'] == 1 && $_SESSION['sys_type'] != 'counter' && $_SESSION['sys_type'] != 'secretary'){ ?>
								<input type="button" value="ເພີ່ມເອກະສານ" class="btn2" onclick="document.location='?d=document/docout/docout_add_admin'" />
								<?php } ?>
								<p class="right"><input type="submit" value="Export To Excel" class="toexcel" onclick='window.open ("document/docout/ex_docout.php?<?=$params?>")'/></p>
							</td>
						</tr>
					</table>
			</fieldset>
		</div>
	</form>
	<form method="post">
	<!---<h3>ລາຍການເອກະສານຂາເຂົ້າ</h3>-->
	<?php if ($ecount == 0) { ?>
		<div class="centered messagebox">
	<p class="errormessage">ບໍ່ພົບລາຍການເອກະສານທີ່ຄົ້ນຫາ</p>
</div>
	<?php } else { ?> 
	<div id ="control_view">
	<h4><?= $pagedescription ?></h4>
	<table class="beautified_doc editable">
		<tr>
			<th width="50">No.</th>
			<th style='min-width: 10em;'>ເລກທີເອກະສານ</th>
			<th >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ວັນທີບັນທຶກ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
			<th>ປະເພດເອກະສານ</th>
			<th style='min-width: 20em;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ເລື່ອງ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
			<th>ຜູ້ເຊັນເອກະສານ</th>
			<th>ບ່ອນສົ່ງ(ຮຽນ)</th>
			<th>ຂາເຂົ້າເລກທີ</th>
			<th>ຜູ້ຮັບເອກະສານ</th>	
			<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ຄໍາເຫັນ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>	
			<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ໝາຍເຫດ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>	
			<!-- <th>ຕອບກັບ</th>	-->
			<!-- <th>ວັນທີຕອບກັບ</th>-->
			<?php if($user_role == 1){ ?>
			<th>ແກ້ໄຂ</th>	
			<th>ລຶບ</th>	
			<? } ?>			
		</tr>
		<?php $i=1;
			while ($item = mysql_fetch_array($Docout)) {
				$bg = $i%2 == 1 ? "" : "#e1f9fa";
			?>
			<tr bgcolor="<?=$bg?>">
				<td class="centered">
					<span><?= ($i+$start) ?></span>
					<input type="hidden" name="type[]" class="type" value="unchanged" />
					<input type="hidden" id = "id[]" name="id[]" value="<?=$item["doc_id"]?>" class="id"/>
				</td>
				<td><?=$item['doc_code'].", ".date("d-m-Y", strtotime($item['doc_date']));?></td>
				<td class="centered"><?=date("d-m-Y", strtotime($item['m_date']))?></td>
				<td><?=$item['doctype_name'] ?></td>
				<td>
				<?php if($item['doc_file']!=""){ ?>
				<a target="_blank" href="document/show_fileout.php?type=<?=$item['doctype_id']?>&fileout=<?=$item['doc_file']?>"><?=$item['doc_title'] ?></a>
				<?php }else{ ?>
				<?=$item['doc_title'] ?>
				<?php } ?>				
				</td>
				<td><?=$item['tm_signer'] ?></td>
				<td><?=$item['place_sent'] ?></td>
				<td><?=$item['refer_code'] ?></td>
				<td>
				<?php// if($item['doc_io_id']==1 || $item['doc_io_id']==3){ ?>
				<table id="inuser">
					<?php if($item['doc_to']!="") { ?><tr><td><?=$item['doc_to']?></td></tr><? } ?>
				<?php
					$j = 1;
					$rs_org = orgunit($item['orgunitid'], $item['doc_id']);
					$doc_status ="";
					while ($rs = mysql_fetch_array($rs_org, MYSQL_ASSOC)) { 
						$r_status = "";
						if($rs['receive_status'] == 1){
							$r_status =  "ບໍ່ໄດ້ຢືນຢັນຮັບ";
						}elseif($rs['receive_status'] == 2){
							if($rs['type_doc_status']=='doc_out'){
								$r_status =  "ຂາອອກຂອງພະແນກ";
							}else{
								$r_status =  "ຮັບແລ້ວ";
							}
						}
						
						$bgcolor = $rs['receive_status'] == 2 ? "" : "#fcfb82";
						?>
						
						<tr bgcolor="<?=$bgcolor?>"><td><?echo $j.".".$rs['orgunitname'];?><?php echo "(".$r_status.")"?></td>
						</tr>
						<?php
						$j++;
					}
					?>
				</table>
				<?php// }else{ ?>
				<?//=$item['doc_to'] ?>
				<?php// } ?>
				</td>
				<td><?=$item['doc_comment'] ?></td>
				<td><input type="text" name ="remark[]" value="<?=$item['remark'] ?>"></td>
				<!-- <td class="centered"><input type="checkbox" name ="back[]" <?//=$item['back']?> value="checked"></td> -->
				<!--- <td><?php// if($item['back_date'] !=""){ echo date("d-m-Y", strtotime($item['back_date']));}?></td>-->
				<?php if($user_role == 1){ ?>
				<td class="centered" >
				<?php if(($_SESSION['sys_type'] == 'secretary')){ ?>
					<a href ="?d=document/docout/docout_add&doc_id=<?=$item["doc_id"]?>&action=edit" >
					<img src = "img/edit.png" border = '0' width = '30' height = '30'  /></a> 
				<?php }elseif($_SESSION['sys_type'] != 'counter' && $_SESSION['sys_type'] != 'secretary'){ ?>
					<a href ="?d=document/docout/docout_add_admin&doc_id=<?=$item["doc_id"]?>&action=edit" >
					<img src = "img/edit.png" border = '0' width = '30' height = '30'  /></a>
				<?php } ?>
				</td>
				<td class="centered" >
				<?php if(($_SESSION['orgunitid_r'] == null || $_SESSION['sys_type'] == "secretary") && $item["m_step"] !="public"){ ?>
				<a href ="?d=document/docout/docout&doc_id=<?=$item["doc_id"]?>&action=del&start=<?=$_GET['start']?>" onclick="return confirm('ທ່ານຕ້ອງການລຶບຂໍ້ມູນນີ້ແທ້ບໍ...?')" ><img src = "img/del.ico" border = '0' width = '20' height = '20'  /></a> 
				<?php } ?>
				</td>
				<? } ?>
			</tr>
		<?php $i++; } ?>
	</table>
	
	</div>
	<?php if($user_role == 1){ ?>
	<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>
	</form>
	<? } ?>
	<div class="paging">
<?php
	if ($pagecount > 1){
		if ($pagenum > 1) echo "<a href='?d=document/docout/docout&$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/docout/docout&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
			}
			$j++;
		}
		if ($pagenum < $pagecount) echo "<a href='?d=document/docout/docout&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
<?php } ?>
</div>
<?php echo $err; ?>