<?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['orgunitid_r']!="") header("Location: ?d=index");
} 

/*=========================================================================*/
?>
<form method="get">
<div class="contentpage">
<center><label id = "msgwar" class = "msgChk"></label></center>
<h1 class="headtitle">ລາຍການເອກະສານຂາເຂົ້າ-ຂາອອກ ຂອງ <?php $sec = orgunit((int)$_GET['orgunitid']); echo $sec;?></h1>

<input type="hidden" name="d" value="document/list_docin/head_doc" />
<input type="hidden" name="orgunitid" value="<?=(int)$_GET['orgunitid']?>" />
<div class="searchbox">
	<fieldset>	
		<legend>ຄົ້ນຫາ</legend>
		<table>
						<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/head_doc&orgunitid=<?=$_GET['orgunitid']?>&status=<?=$_GET['status']?>&type_io=<?=$_GET['type_io']?>&start=<?=$_GET['start']?>'" />
							</td>
							<td>
								
							</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 = "fixed_confirm">--->
<h4><?= $pagedescription ?></h4>
<table class="beautified editable">
	<tr>
    <th>No.</th>
    <th>ເລກທີເອກສານຂາເຂົ້າ-ຂາອອກ</th>
    <th width='150'>ປະເພດເອກະສານ</th>
    <th width='200'>ເລື່ອງ</th>
    <th width='200'>ຜູ້ຮັບເອກະສານ</th>
    <th width='200'>ຄໍາເຫັນ</th>
    <th width='200'>ຫມາຍເຫດ</th>
	<?php if($_SESSION['sys_type'] =='secretary' || $_SESSION['orgunitid_r']==''){ ?>
    <th width="">ໃຫ້ຄໍາເຫັນ</th>
	<? } ?>
	<?php// if($user_role == 1 || $parentunit == 1){ ?>
	<?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 ? " (ຂາເຂົ້າ)" : " (ຂາອອກ)"
		?>
			<tr bgcolor="<?=$bgcolor?>">
			<td class="centered"><?=$i + $start ?>
				<input type='hidden' class='id' value="<?=$row['doc_id']?>">
				<input type="hidden" name="type[]" class="type" value="unchanged" />
				<input type="hidden" id = "id[]" name="id[]" value="<?=$row["doc_id"]?>" class="id"/>
				<input type="hidden" id = "orgunitid" name='orgunitid[]' value="<?=$row["orgunitid"]?>"/>
				<input type="hidden" id = "short_name" value="<?=$row["short_name"]?>"/>
			</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><?=$row['orgunitname']?></td>
			<td id='addcomment'>
				<input type="hidden" id="comment_" value="<?=$row['doc_comment']?>">
				<?=$row['doc_comment']?>
			</td>
			<td class=""><input type="text" name="remark[]" value="<?=$row['remark']?>"> </td>
			<?php if($_SESSION['sys_type'] =='secretary' || $_SESSION['orgunitid_r']==''){ ?>
			<td class="centered" ><input type="button" class="addcomment button_1" value="ເພີ້ມຄໍາເຫັນ"></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>
	</form>
	<? } ?>
<div class="paging">
<?php
	if ($pagecount > 1){
		if ($pagenum > 1) echo "<a href='?d=document/list_docin/head_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/head_doc&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
			}
			$j++;
		}
		if ($pagenum < $pagecount) echo "<a href='?d=document/list_docin/head_doc&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
</form>
<?}else{ ?>
<div class="messagebox">
	<p class="centered errormessage">ບໍ່ມີລາຍການ ເອກະສານຂາເຂົ້າ-ຂາອອກ </p>
</div>
<?php } ?>
</div>
<?=$err;?>