<?php htmltage("ເອກະສານຂາອອກ"); 
if (strlen(session_id()) < 1)  session_start();
if(!isset($_SESSION['sys_id']))	header("Location: ?d=index");

/*=========================================================================*/
?>
<div class="contentpage">
	<h1 class="headtitle">ລາຍການເອກະສານຂາອອກ ຂອງ <?=$_SESSION['orgunitname']?></h1>
	<center><label id = "msgwar" class = "msgChk"></label></center>
	<form method="get">
		<input type="hidden" name="d" value="document/docout/docout_dept" />
		<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>
								
								<!-- 	<select name="doc_io_id">
									<option value="">-- ທຸກປະເພດຂາອອກ --</option>
									<?php /*
									$doctype_in = doctype_in();
									foreach ($doctype_in as $item_) {
										$selected = $item_['doc_io_id'] == $_GET['doc_io_id'] ? "selected" : ""; 
									*/
									?>
									<option value="<?//= $item_['doc_io_id'] ?>" <?//= $selected ?>><?//= $item_['io_name'] ?></option>
									<?php //} ?>
								</select>
							-->
							</td>
						</tr>
						<tr>
							<td>
								ເລກທີເອກະສານ:&nbsp;<input name="doc_code" type="text" placeholder="ເລກທີເອກະສານ" size="10" value="<?= $_GET['doc_code'] ?>"/>
								ເລກທີ ETL:&nbsp;<input name="etl_code" type="text" placeholder="ເລກທີ ETL" size="10" value="<?= $_GET['etl_code'] ?>"/>
								<!-- ມາຈາກ:&nbsp;<input name="doc_from" type="text" placeholder="ມາຈາກ" size="15" value="<?//= $_GET['doc_from'] ?>"/> -->
							</td>
						</tr>
						<tr><td>
								&nbsp;ຫົວຂໍ້ເອກະສານ:&nbsp;<input name="doc_title" type="text" placeholder="ຫົວຂໍ້ເອກະສານ" size="69" 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_dept'" />
								<?php if($_SESSION['role_id'] == 1 && $_SESSION['orgunitid_r'] != null){ ?>
								<input type="button" value="ເພີ່ມເອກະສານ" class="btn2" onclick="document.location='?d=document/docout/docout_add_admin&st=dept'" />
								<?php } ?>
								<p class="right"><input type="submit" value="Export To Excel" class="toexcel" onclick='window.open ("document/docout/ex_docout_dept.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>ປະເພດຂາອອກ</th>
			<th>ເລກທີ&nbsp;ETL</th>
			<th style='min-width: 20em;'>ເລື່ອງ</th>
			<!--- <th>ມາຈາກ</th> -->
			<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ຜູ້ຮັບເອກະສານ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
			<th>ຄໍາເຫັນ</th>
			<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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, H:i:s", strtotime($item['up_date']))?></td>
				<td><?=$item['doctype_name'] ?></td>
				<td><?=$item['io_name'] ?></td>
				<td width=""><?=$item['etl_code'] ?></td>
				<td>
				<?php if($item['doc_file']!=""){
					if($item['doc_status']==1){ 
				?>
					<a target="_blank" href="document/show_filein.php?type=<?=$item['doctype_id']?>&filein=<?=$item['doc_file']?>"><?=$item['doc_title'] ?></a>
					<?php }else{ ?>
					<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'] ?>
					<? } ?>
				</td>
				<!-- <td><?//=$item['doc_from'] ?></td> -->
				<td>
				<table id="inuser">
				<?php
					$j = 1;
					$rs_org = orgunit($item['orgunitid'], $item['doc_id']);
					$permission_ = "";
					while ($rs = mysql_fetch_array($rs_org, MYSQL_ASSOC)) {
						$r_status = $rs['receive_status'] == 2 ? "ຮັບແລ້ວ" : "ບໍ່ໄດ້ຢືນຢັນຮັບ";
						$bgcolor = $rs['receive_status'] == 2 ? "" : "#fcfb82";
						if($permission_ =="") $permission_ = $rs['type_doc_status'] == 'doc_out' ? "editable" : "";
						if($rs['type_doc_status'] == 'doc_in'){ ?>
						<tr bgcolor="<?=$bgcolor?>"><td class=""><?php echo $j.".".$rs['orgunitname'];?><?php echo "(".$r_status.")"?><? if ($rs['receive_status'] == 2) echo " (".date("d-m-Y, H:i:s", strtotime($rs['m_date'])).")"?></td>
						</tr>
						<?php
						$j++;
						}
						
					}
					?>
				</table>
				</td>
				<td><?=$item['doc_comment'] ?></td>
				<td><?=$item['remark'] ?></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'] !="" && $item['back_date'] !="0000-00-00"){ echo date("d-m-Y", strtotime($item['back_date']));}?></td> -->
				<?php// if($permission_ == "editable" && $item['sum_status']<2){ ?>
				
					<td>
					<?php if($user_role == 1){ ?>
					<?php if($item['sum_status']<2){ ?>
						<a href ="?d=document/docout/docout_add_admin&doc_id=<?=$item["doc_id"]?>&action=edit&st=dept" >
						<img src = "img/edit.png" border = '0' width = '30' height = '30'  /></a>
					</td>
					<? } ?>
					<td class="centered" >
					<?php if($item['sum_status']<2){ ?>
					<a href ="?d=document/docout/docout_dept&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> 
					</td>
					<? } ?>
				<?php } ?>
			</tr>
		<?php $i++; } ?>
	</table>
	
	</div>
	<?php if(isset($_SESSION['sys_id']) && $_SESSION['role_id'] ==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_dept&$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_dept&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
			}
			$j++;
		}
		if ($pagenum < $pagecount) echo "<a href='?d=document/docout/docout_dept&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
<?php } ?>
</div>
<?php echo $err; ?>