<?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($_SESSION['orgunitid_r'] != null) header("Location: ?d=document/docin/docin");

$ptn_id = $_SESSION['position_id'];
$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_add_docin" 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="text" 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" 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" 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" 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" 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" 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" 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" 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" 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"]?>"><br/><?=$row['doc_file']?></td>
			</tr>
		</table>
		</fieldset>
	</td>
	</tr>
	<!--- the refer doc --->
	<tr>
	<td>
		<fieldset id = "f_receive">
		<legend>ຂໍ້ມູນເອກະສານ ອ້າງອີງ</label></legend>
		<table class = "" border = "0" id="">
			<tr>
				<td height="40" class = "align_right">ເລກທີເອກະສານອ້າງອີງ:</td>
				<td width = "">
					<input type="text" name="refer_code" id = "refer_code" size= "" placeholder = ""  value = "<?=$row["refer_code"]?>" >
				</td>
				<td height="40" class = "align_right">ລົງວັນທີ:</td>
				<td><input type="text" id = "refer_date" name="refer_date" class="date" value = "<?php if($row["refer_date"] != "" && $row["refer_date"] !="0000-00-00") echo $row["refer_date"]; ?>" />

				</td>
				
				
			</tr>
			
			<tr>
				<td height="40" class = "align_right">ປະເພດເອກະສານ:</td>
				<td>
					<select name="refer_type" id = "refer_type" class = "refer_type">
						<option value="" >--- ເລືອກ ---</option>
						<?php $doctype = doctype();
							
						while($rdt1 = mysql_fetch_array($doctype, MYSQL_ASSOC)){ 
							$selected = $rdt1['doctype_id'] == $row['refer_type'] ? "selected" : ""; ?>
							<option value="<?= $rdt1['doctype_id'] ?>" <?= $selected ?>><?= $rdt1['doctype_name'] ?></option>
						<?php }?>
					</select>
				</td>
				<td height="40" class = "align_right">ແນບເອກະສານອ້າງອີງ:</td>
				<td ><input type="file" name="refer_file" value="<?//=$row['refer_file']?>"></td>
			</tr>
		</table>
		</fieldset>
	</td>
	</tr>
	</table>
	

<!-- </fieldset> -->

<br />
<!-- end create Event or activity area-->
<fieldset>
	<legend>ເລືອກ ພະແນກ/ສາຂາ ທີ່ຮັບເອກະສານ &nbsp;<label id = "errEq" class = "errChk"></label></legend>
	<br />
<table class="beautified editable" >
	<tr align = "center" class = "tbHeader">
		<th width = "30px" >ລ/ດ</th>
		<th width = "20px" ><input type="checkbox" class="select-all"></th>
		<th width = "" >ພະແນກ/ສາຂາ</th>
		<!-- <th width = "" >ຊື່</th>	
		<th width = "" >ເບີໂທ</th> -->
	 </tr>
	<?php
	while(@$rs_sec = mysql_fetch_array($dept_branch, MYSQL_ASSOC)){ ?>
	<tr><?$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_sec["orgunitid"]?>" class="id"/>
			<input type="hidden"  name="m_id[]" value="<?//=$rs_sec["m_id"]?>" class="m_id"/>
		</td>
		<td>
		<?php $ch = list_org();
		while(@$rs_ch = mysql_fetch_array($ch, MYSQL_ASSOC)){ 
			$checked = $rs_sec['orgunitid'] == $rs_ch['orgunitid']  ? "checked" : "";
			if($checked == "checked") break;		
		}
		?>
		<input type="checkbox" <?=$checked?> name="orgunitid[]" class="item-checkbox"  value="<?=$rs_sec["orgunitid"]?>">
		</td>
		<td><?=$rs_sec["orgunitname"]?></td>
		<!-- <td><?//=$rs_sec["first_name"]?></td>
		<td><?//=$rs_sec["tel"]?></td>-->
	</tr>
	<?php } ?>	
</table>
<br />
</fieldset>
<?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>
<? } ?>

<br />

</div>
<br />
</form>
<!-- new edittion -->
<!-- 
<table class="template hidden" border = "1" id = "tab">			
	<tr>
		<td class = "centered adjust">
			<span><?//= ($i+$start) ?></span>
			<input type="hidden" name="type[]" class="type" value="added" />
			<input type="hidden" id = " id[]" name="id[]" value="" class="id"/>
		</td>
		<td><input type="text" name="staff_name[]"  class = "staff_name" /></td>
		<td><input type="text" id="orgunit[]" name="orgunit[]" size = ""   readonly class = "orgunit" /></td>
		<td><input type="text" id="position[]" name="position[]" size = ""  readonly class = "position" /></td>
		<td><input type="text" id="tel[]" name="tel[]" size = ""  readonly class = "tel" /></td>
		<td><img src = "img/del.ico" border = '0' width = '20p' height = '20px' class = "delete1" /></td>
	</tr>
</table>
-->
<?php echo $err; ?>