<?php
/*-------- 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");

$org_id = $_SESSION['orgunitid_r'];
$user_role = $_SESSION['role_id'];

/*=========================================================================*/
htmltage("ເອກະສານຂາເຂົ້າ-ຂາອອກ");
$doc = doc();
//echo $doc;
/*---------------------------------- retrieve data  from database -----------------------------------*/
 @$row = mysql_fetch_array($doc);
?>
 
<form method="post" enctype="multipart/form-data" id="frm_assign" onsubmit="" >
<div class="contentpage">
<?php if(isset($_GET["doc_id"]) && $_GET["doc_id"] != ""){?>
		<h3 class = "headtitle centered">ສົ່ງເອກະສານໃຫ້ຄະນະກໍາມະການ</h3>
	<?php } else { ?>
		<!-- <h3 class = "headtitle centered">ເພີ່ມຂໍ້ມູນ ເອກະສານຂາເຂົ້າ</h3> -->
	<?php }	?>

<center><label id = "msgwar" class = "msgChk"></label></center>
<!-- The New Edition to Create Event or Activity -->

<!-- <fieldset id = "f_receive">
	<legend>ຂໍ້ມູນເອກະສານ</label></legend> -->
	<table border = '0' width="100%">
		<tr>
			<td>
			<fieldset id = "f_receive">
			<legend>ຂໍ້ມູນເອກະສານ</label></legend>
			<table class = "" border = "0" id="">
			<tr>
				<td height="40" class = "align_right"><label for="doc_code"> ເລກທີເອກະສານ:</label></td>
				<td width = "">
					<input type="hidden" name="h_doc_id" id="h_doc_id" value ="<?=$row["doc_id"]?>">
					<input type="hidden" name = "h_m_id" id = "h_m_id" value ="<?=$row["m_id"]?>">
					<input type="hidden" name = "h_org_id" id = "h_org_id" value ="<?=$org_id?>">
					<input type="text" disabled name="doc_code" id = "doc_code" size= "" placeholder = "" maxlength="25" value = "<?=$row["doc_code"]?>" >
				</td>
				<td height="40" class = "align_right"><label for="doc_date">ລົງວັນທີ:</label></td>
				<td><input type="text" disabled id = "doc_date" name="doc_date" class="date" value = "<?=$row["doc_date"]?>" />

				</td>				
			</tr>
			
			<tr>
				<td height="40" class = "align_right"><label for="doctype">ປະເພດເອກະສານ:</label></td>
				<td>
					<select name="doctype" disabled id = "doctype" class = "doctype">
						<option value="" >--- ເລືອກ ---</option>
						<?php $doctype = doctype();
							
						while($rdt = mysql_fetch_array($doctype, MYSQL_ASSOC)){ 
							$selected = $rdt['doctype_id'] == $row['doctype_id'] ? "selected" : ""; ?>
							<option value="<?= $rdt['doctype_id'] ?>" <?= $selected ?>><?= $rdt['doctype_name'] ?></option>
						<?php }?>
					</select>
				</td>
				<td height="40" class = "align_right"><label for="io_type">ປະເພດຂາເຂົ້າ:</label></td>
				<td>
					<select name="io_type" disabled id = "io_type" class = "io_type">
						<option value="" >--- ເລືອກ ---</option>
						<?php $doc_io_type = doc_io_type();
							
						while($rt = mysql_fetch_array($doc_io_type, MYSQL_ASSOC)){ 
							$selected = $rt['doc_io_id'] == $row['doc_io_id'] ? "selected" : ""; ?>
							<option value="<?= $rt['doc_io_id'] ?>" <?= $selected ?>><?= $rt['io_name'] ?></option>
						<?php }?>
					</select>
				</td>				
			</tr>
			<tr>
				<td height="40" class = "align_right">ເລກທີ ອທອ:</label></td>
				<td><input type="text" disabled id = "etl_code" name="etl_code" value = "<?=$row["etl_code"]?>" />
				</td>	
				<td height="40" class = "align_right"><label for="doc_from">ມາຈາກ:</label></td>
				<td ><input type="text" disabled name="doc_from" id="doc_from"  value = "<?=$row["doc_from"]?>"></td>
			</tr>
			<tr>
				<td height="40" class = "align_right"><label for="doc_title">ເລື່ອງ:</label></td>
				<td colspan = "3"><textarea name="doc_title" disabled id="doc_title" rows = '2' cols='5'><?=$row["doc_title"]?></textarea></td>
			</tr>
			<tr>
				<td height="40" class = "align_right"><label for="doc_comment">ຄໍາເຫັນຂອງພະແນກ:</label></td>
				<td colspan = "3"><textarea name="doc_comment" disabled id="doc_comment" rows = '2' cols='5'><?=$row["doc_comment"]?></textarea></td>
			</tr>
			<tr>
				<td height="40" class = "align_right">ໝາຍເຫດ:</td>
				<td colspan = "3"><textarea name="remark" id="remark" disabled rows = '2' cols='5'><?=$row["remark"]?></textarea></td>
			</tr>
			<tr><!--- 
				<td height="40" class = "align_right">ແນບເອກະສານ:</td>
				<td ><input type="file" name="doc_file" value="<?//=$row["doc_file"]?>"></td>
				-->
			</tr>
		</table>
		</fieldset>
	</td>
	</tr>
	</table>

<!-- </fieldset> -->

<br />
<!-- end create Event or activity area-->
<fieldset>
	<legend>ສົ່ງຕໍ່ໃຫ້ຄະນະກໍາມະການ<label id = "errEq" class = "errChk"></label></legend>
	<br />
<table class="beautified editable" >
	<tr align = "center" class = "tbHeader">
		<th width = "30px" >ລ/ດ</th>
		<th width = "20px" ></th>
		<th width = "" >ລາຍການຄະນະກໍາມະການ</th>
	 </tr>
	<?php //}
	$i = 0;
	// 
	$list = list_org();
	while(@$rs_org = mysql_fetch_array($list, MYSQL_ASSOC)){ ?>
	<tr class="tb_hover"><?$i++;?>
		<td class="centered adjust">
			<span><?= ($i+$start) ?></span>
			<input type="hidden" name="type[]" class="type" value="unchanged" />
			<input type="hidden" id = "id[]" name="id[]" value="<?=$rs_org["orgunitid"]?>" class="id"/>
			<input type="hidden"  name="m_id[]" value="<?=$rs_org["m_id"]?>" class="m_id"/>
		</td>
		<td class="">
		<?php $ch = doc();
		while(@$rs_ch = mysql_fetch_array($ch, MYSQL_ASSOC)){ 
			$checked = $rs_org['orgunitid'] == $rs_ch['orgunitid']  ? "checked" : "";
			if($checked == "checked") break;		
		}
		?>
		<input type="radio" <?=$checked?> name="orgunitid[]" id="<?= $i ?>" class="send" value=""/>
		</td>
		<td class=""><label for="<?= $i ?>" class="radiochecked"><?= $rs_org['orgunitname'] ?></label></td>
	</tr>
	<?php } ?>	
</table>
<br />
</fieldset>
<?php if ($_SESSION['sys_type'] == 'secretary') { ?> 
<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('ທ່ານຕ້ອງການບັນທຶກແທ້ບໍ...?')" />
	<!-- back to the previous without history.back -->
	<button class = "btn2" onclick="window.location.href='?d=document/list_docin/addfile_doc&orgunitid=<?=$_GET['orgunitid']?>&status=<?=$_GET['status']?>&start=<?=$_GET['start']?>'" type="button">&nbsp;<<ກັບຄືນ&nbsp;&nbsp;</button>
</div>
<?php } ?>

<br />

</div>
<br />
</form>
<?php echo $err; ?>