<?php 
if($_SESSION['orgunitid_r'] != "")  header("Location: ?d=index");
htmltage("ຂໍ້ມູນໂຄງຮ່າງການຈັດຕັ້ງ");
?>
<div class="contentpage">
	<h1 class="headtitle">ລາຍການໂຄງຮ່າງການຈັດຕັ້ງ</h1>
	<div class="searchbox">
	<form method="get">
		<input type="hidden" name="d" value="webmaster/manage/orgunit" />
		<table class="">
			<tr>
				<td>ຄົ້ນຫາ: </td>
				<td><input type="text" name="orgunitname" placeholder="ຊື່ໂຄງຮ່າງການຈັດຕັ້ງ (ລາວ)" size="30" value="<?= $_GET['orgunitname'] ?>" /></td>
				<td><input type="submit" value="Search" class="btn2" /><input type="reset" value="Reset" class="btn2" 
                onclick="document.location='?d=webmaster/manage/orgunit'"  /></td>
			</tr>
		</table>
	</form>
	</div>
	
<!-- The table Select From -->

<?php if ($eqcount == 0) { ?>
	<div class="centered messagebox">
		<p class="errormessage">ບໍ່ພົບລາຍການທີ່ຄົ້ນຫາ, ກະລຸນາປ້ອນຂໍ້ມູນໃຫມ່</p>
	</div>	 	
<?php } else { ?>	  <?}?>  
<h4><?= $pagedescription ?></h4>
<form method="post" id="frmorgunit" action="?d=webmaster/manage/orgunit">
	<table class = "beautified editable">
	  <tr>
	  	<th>ລຳດັບ</th>	  
	  	<th>ຊື່ໂຄງຮ່າງການຈັດຕັ້ງ (ລາວ)</th>	  		  		  	
	  	<th>ຊື່ໂຄງຮ່າງການຈັດຕັ້ງ (ອັງກິດ)</th>  		
	  	<th width="50">ຊື່ຫຍໍ້(ອັງກິດ)</th>  		
	  	<th>ຂຶ້ນກັບ</th>  		
	  	<th>ປະເພດການຈັດຕັ້ງ</th>  		
		<?php if($user_role == 1){ ?> 
		<th>ລຶບ</th>
		<? } ?>
	  </tr>
	  <?php  
		$i = 1;
		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
		<tr>
			<td class ="centered itemcols">
				<span><?= ($i+$start) ?></span>
				<input type="hidden" name="type[]" class="type" value="unchanged" />
				<input type="hidden" name="id[]" value="<?= $row['orgunitid'] ?>" />
			</td>
			<td class=""><input type="text" name="orgname_la[]" size = "" value="<?= $row['orgunitname'] ?>" /></td>					
			<td class=""><input type="text" name="orgname_eng[]" size = "" value="<?= $row['orgunitnameeng'] ?>" /></td>
			<td class=""><input type="text" name="short_name[]" size = "" value="<?= $row['short_name'] ?>" /></td>
			<td class="">
				<select name="parentid[]">
					<option value="">-- ເລືອກ --</option>
					<?php 
					$parent = fparent();
					$loop = 0;
					while ($rs = mysql_fetch_array($parent,MYSQL_ASSOC)) {
						
						//if($row['parentunit'] == 1 && $rs['orgunitid'] == 0){
						if($row['parentunit'] == 0){   // && $row['orgunitid'] == 1
							$selected_a  = "selected";
						}else{
							$selected = $row['parentunit'] == $rs['orgunitid'] ? "selected" : ""; 
						}
						if($loop == 0){
						?>
						<option value="0" <?=$selected_a?>>== ບໍ່ຂື້ນກັບໃຜ(ສູງສຸດ) ==</option>
						<?php
						
						}
						?>	
						<option value="<?= $rs['orgunitid'] ?>" <?=$selected ?>><?=$rs['orgunitname']?></option>
					<?php  
					$loop++;
					} ?>
				</select>
			</td>
			<td class="">
				<select name="unittype[]">
					<option value="">-- ເລືອກ --</option>
					<?php 
					$unittype = unittype();
					while ($rsu = mysql_fetch_array($unittype,MYSQL_ASSOC)) {
						$selected = $rsu['unittypeid'] == $row['unittypeid'] ? "selected" : ""; 
					?>
						<option value="<?= $rsu['unittypeid'] ?>" <?= $selected ?>><?= $rsu['unittypename'] ?></option>
					<?php } ?>
				</select>
			</td>
			<?php if($user_role == 1){ ?> 
			<td class="centered adjust" ><a href ="?d=webmaster/manage/orgunit&del_id=<?php echo $row["orgunitid"]; ?>" 
            onclick="return confirm('ທ່ານຕ້ອງການລຶບແທ້ບໍ...?')"><img src = "img/del.ico" border = '0' width = '20p' height = '20px'  /></a> </td>						
			<?}?>
		</tr>
		<?php $i++;} ?>	
	</table>
	<?php if($user_role == 1){ ?> 
	<div class="menubox">		
		<input type="button" 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" class = "btn2 right" 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=webmaster/manage/orgunit&$params&start=".(($pagenum-2)*$pagesize)."' $isselected>&lt; ກັບຄືນ</a>";
		for ($i = 0; $i < $pagecount; $i++){
			if ($i == $pagenum-1) $isselected = "class='selected'";
			else $isselected = "";
			echo "<a href='?d=webmaster/manage/orgunit&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
		}
		if ($pagenum < $pagecount) echo "<a href='?d=webmaster/manage/orgunit&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
</div>
<table class="template hidden" id = "tab">			
	<tr>
		<td class = "centered">
			<span></span>
			<input type="hidden" name="type[]" class="type" value="added" />
			<input type="hidden" name="id[]" />
		</td>		
		<td class="eqcodecols"><input type="text" name="orgname_la[]" value="" /></td>
		<td class=""><input type="text" name="orgname_eng[]" size = "" value="" /></td>
		<td class=""><input type="text" name="short_name[]" size = "" value="" /></td>
		<td class="">
				<select name="parentid[]">
					<option value="" >-- ເລືອກ --</option>
					<option value="0" >== ບໍ່ຂື້ນກັບໃຜ(ສູງສຸດ) ==</option>
					<?php 
					$parent = fparent();
					while ($rs = mysql_fetch_array($parent,MYSQL_ASSOC)) {
						//$selected = $rs['parentunit'] == $row['parentunit'] ? "selected" : ""; 
						
						?>	
					
						<option value="<?= $rs['orgunitid'] ?>" ><?= $rs['orgunitname'] ?></option>
					<?php }  ?>
				</select>
			</td>
			<td class="">
				<select name="unittype[]">
					<option value="">-- ເລືອກ --</option>
					<?php 
					$unittype = unittype();
					while ($rsu = mysql_fetch_array($unittype,MYSQL_ASSOC)) {
						//$selected = $rsu['unittypeid'] == $row['unittypeid'] ? "selected" : ""; 
					?>
						<option value="<?= $rsu['unittypeid'] ?>" ><?= $rsu['unittypename'] ?></option>
					<?php } ?>
				</select>
			</td>	
		<td class="centered"><img src = "img/del.ico" border = '0' width = '20p' height = '20px' class = "delete1" /></td>
	</tr>
</table>