<?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=document/docout/docout");
/*=========================================================================*/ 
htmltage("ເພີ່ມເອກະສານຂາອອກ");
/*---------------------------------- retrieve data  from database -----------------------------------*/
//echo $sql_doc;
$docout=docout();
 @$row = mysql_fetch_array($docout);
?>
 
<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">ເລກທີເອກະສານ:</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 = ""  value = "<?=$row["doc_code"]?>" >
				</td>
				<td width="37%"></td>
				<td></td>
			</tr>
			<tr>
				<td height="40" class = "align_right">ລົງວັນທີ:</td>
				<td><input type="text" id = "doc_date" name="doc_date" class="date" value = "<?=$row["doc_date"]?>" />

				</td>
				<td></td><td></td>
			</tr>
			
			<tr>
				<td height="40" class = "align_right">ປະເພດເອກະສານ:</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></td><td></td>
				<!-- <td height="40" class = "align_right">ເລກທີ ອທອ:</td>
				<td><input type="text" id = "etl_code" name="etl_code" value = "<?//=$row["etl_code"]?>" />
				</td>
				-->				
			</tr>
			<tr>
				<td height="40" class = "align_right">ເລື່ອງ:</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">ຊື່ຜູ້ເຊັນອອກ:</td>
				<td colspan = "3"><textarea name="signer" id="doc_title" rows = '2' cols='5'><?=$row['tm_signer']?></textarea> 
				
					<!--
					<select name="signer" id = "signer" class = "signer">
						<option value="" >--- ເລືອກ ---</option>
						<?php //$signer = signer();
							
						//while($rs_sign = mysql_fetch_array($signer, MYSQL_ASSOC)){ 
							//$selected = $rs_sign['emp_id'] == $row['signer_id'] ? "selected" : ""; ?>
							<option value="<?//= $rs_sign['emp_id'] ?>" <?//= $selected ?>><?//=$rs_sign['name'] ?>  (<?//= $rs_sign['position'] ?>)</option>
						<?php// }?>
					</select>
					-->
				</td>
				<td></td><td></td>
			</tr>
			
			<tr>
				<td height="40" class = "align_right">ບ່ອນສົ່ງ (ຮຽນ):</td>
				<td colspan = "3"><textarea name="place_sent" id="place_sent" rows = '2' cols='5'><?=$row['place_sent']?></textarea></td>
			</tr>
			<tr>
				<td height="40" class = "align_right">ຄໍາເຫັນຂອງພະແນກ:</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 colspan = "3"><input type="file" name="doc_file" value=""><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=""></td>
			</tr>
		</table>
		</fieldset>
	</td>
	</tr>
	</table>
<!-- </fieldset> -->
<!-- end create Event or activity area-->
<?php // if($_SESSION['sys_type']=='counter' && $row["doc_file"] !=""){ ?>
<fieldset id = "f_receive">
	<legend>ເລືອກປະເພດເອກະສານຂາອອກ: &nbsp;
	<select  name='type_out' id = "type_out" OnChange = 'showDocOut(this.value);'>
		<option value = ''>----- ເລືອກ -----</option>
		<?php $selected_in =  $row['doc_io_id']==1 ? "selected" : "";
			$selected_out =   $row['doc_io_id']==2 ? "selected" : "";
		?>
		<option value = '1' <?=$selected_in?>>ຂາອອກພາຍໃນບໍລິສັດ</option>
		<option value = '2'<?=$selected_out?>>ຂາອອກພາຍນອກ</option>
	</select>	
	</legend>
	<table class = "" border = "0" id="out_selected">
			<tr>
				<td height="40" class = "align_right">ຜູ້ຮັບເອກະສານ:</td>
				<td width = "">
					 <textarea name="doc_to" id="doc_to" rows = '2' cols='100' ><?=$row['doc_to']?></textarea>
				</td>
				<td width=""></td>
				<td></td>
		</tr>
	</table>	
<table class="beautified editable" id='in_selected' >
	<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)) { 
		$orgbg = $_SESSION['orgunitid_r'] == $rs_sec['orgunitid'] ? "orgtr" : "" ;
	?>
	<tr class="<?= $orgbg ?>">
		<?$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 width='20px' class="centered" <?php if($rs_sec["orgunitid"]==31) echo "bgcolor='#gray'"?>>
		<?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 //} ?>
<br />
<?php if($_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;  " />
	<?php if($row['sum_status'] <2){  ?>
	<input type="submit" name="btnsave" class = "btn2 right btnsave" value="  &#3738;&#3761;&#3737;&#3735;&#3766;&#3713;  "  id="right" onclick="return confirm('ທ່ານຕ້ອງການບັນທຶກແທ້ບໍ...?')" />
	<? }elseif($_GET['doc_id']==""){ ?>
	<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>

<?php echo $err; ?>