<?php 
session_start();
if($_SESSION['orgunitid_r'] != "")  header("Location: ?d=index");
htmltage("ຜູ້ໃຊ້ລະບົບ");
?>
<div class="contentpage">
	<h3 class="headtitle">ລາຍການຜູ້ເຂົ້າໃຊ້</h3>
	<div class="searchbox">
	<form method="get">
		<input type="hidden" name="d" value="webmaster/manage/user" />
		<table class="">
			<tr>
				<td>ຄົ້ນຫາ: </td>
				<td><input type="text" name="username_form" placeholder="ຊື່ເຂົ້າໃຊ້ລະບົບ" size="20" value="<?= $_GET['username_form'] ?>" /></td>
				<td><input type="text" name="first_name_form" placeholder="ຊື່" size="20" value="<?= $_GET['first_name_form'] ?>" /></td>
				<td>
					<select name="w_id_from">
						<option value="0">-- ທັງໝົດ --</option>
						<?php 
							$rs_org = selOrgunit();
							while ($row_c = mysql_fetch_array($rs_org,MYSQL_ASSOC)) {
							$selected = $row_c['orgunitid'] == $_GET['w_id_from'] ? "selected" : ""; 
						?>
							<option value="<?= $row_c['orgunitid'] ?>" <?= $selected ?>><?= $row_c['orgunitname'] ?></option>
						<?php } ?>
					</select>
				</td>
				<td width="620px"><input type="submit" value="Search" class="btn2" /><input type="reset" value="Reset" class="btn2" onclick="document.location='?d=webmaster/manage/user'"  />
                <p class="right"><input type="submit" value="Export To Excel" class="toexcel" onclick='window.open ("webmaster/manage/ex_user.php?<?=$params?>")'/></p>
                </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="frmuser" action="?d=webmaster/manage/user">
	<table class = "beautified editable">
	  <tr>
	  	<th width="10">ລ/ດ</th>	  	
	  	<!-- <th width="50">ລະຫັດ ພ/ງ</th> -->
	  	<th width="100">ຊື່ເຂົ້າໃຊ້</th>
	  	<th width="80">ຊື່</th>	  		  		
		<th width="80">ນາມສະກຸນ</th>
		<th width="150">ອີເມວ</th>
		<th width="150">ພະແນກ ຫຼື ສາຂາ</th>	  		  		
		<!-- <th width="">ຕໍາແໜ່ງ</th> -->	  		  		
		<th width="">ສິດການເຂົ້າໃຊ້</th>	
		<th width="">&nbsp;&nbsp;ປະເພດຜູ້ໃຊ້ລະບົບ&nbsp;&nbsp;</th>	
		<?php if(isset($_SESSION['role_id']) && $_SESSION['role_id'] ==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['sysuserid'] ?>" />
			</td>
		
			<!-- <td class="adjust"><input type="text" name="emp_code_form[]" maxlength="4" value="<?//= $row['emp_code'] ?>" /></td> -->
			<td class="adjust"><input type="text" name="username_form[]" size="" value="<?= $row['username'] ?>" /></td>
			<td class="eqcodecols itemcode"><input type="text" name="first_name_form[]" size = "" value="<?= $row['first_name'] ?>" /></td>
			<td class="eqcodecols itemcode"><input type="text" name="last_name_form[]" size = "" value="<?= $row['last_name'] ?>" /></td>
			<td class=""><input type="text" name="email_address[]" size = "" value="<?= $row['email_address'] ?>" /></td>
			<td class="eqcodecols itemcode">
				<select name="orgunitid[]">
					<option value="">--ເລືອກ--</option>
					<?php
						$org = selOrgList();
						$loop = 0;
						while ($row_org = mysql_fetch_array($org, MYSQL_ASSOC)) {
						if($row['orgunitid_r'] == 0){   // && $row['orgunitid'] == 1
							$selected_a  = "selected";
						}else{
							$selected_ = $row['orgunitid_r'] == $row_org['orgunitid'] ? "selected" : ""; 
						}
						if($loop == 0){
						?>
						<option value="0" <?=$selected_a?>>== ບໍ່ຂື້ນກັບໃຜ ==</option>
						<?php
						
						}
						?>	
						<option value="<?= $row_org['orgunitid'] ?>" <?= $selected_ ?>><?= $row_org['orgunitname'] ?></option>
					<?php $loop++; } ?>
				</select>
			</td>
			<!--
			<td class="eqcodecols itemcode">
				<select name="position_id[]">
					<option value="">--ເລືອກ--</option>
					<?php
						//$rs_p = selPosition();
						//while ($row_p = mysql_fetch_array($rs_p, MYSQL_ASSOC)) {
						//$selected_1 = $row_p['position_id'] == $row['position_id'] ? "selected" : ""; 
					?>
						<option value="<?//= $row_p['position_id'] ?>" <?//= $selected_1 ?>><?//= $row_p['position_name'] ?></option>
					<?php //} ?>
				</select>
			</td>
			-->
			<td class="eqcodecols itemcode">
				<select name="role_id_form[]">
					<option value="">--ເລືອກ--</option>
					<?php
						$rs_user = selUser_role();
						while ($row_cc = mysql_fetch_array($rs_user, MYSQL_ASSOC)) {
						$selected = $row_cc['role_id'] == $row['role_id'] ? "selected" : ""; 
					?>
						<option value="<?= $row_cc['role_id'] ?>" <?= $selected ?>><?= $row_cc['role_name'] ?></option>
					<?php } ?>
				</select>
			</td>	
			<td class="">
				<select name="sys_type_form[]">
					<?php
					$type_ = user_type();
					foreach ($type_ as $k=>$n){
						$selected_2 = $k == $row['sys_type'] ? "selected" : ""; ?>
						<option  value="<?=$k?>" <?= $selected_2 ?>><?=$n['name_la']?></option>
					<?php } ?>
				</select>
			</td>			
			<?php if(isset($_SESSION['role_id']) && $_SESSION['role_id'] ==1){ ?>
			<td class="centered adjust" ><a href ="?d=webmaster/manage/user&del_id=<?php echo $row["sysuserid"]; ?>" onclick="return confirm('ທ່ານຕ້ອງການລຶບແທ້ບໍ...?')"><img src = "img/del.ico" border = '0' width = '20px' height = '20px'  /></a> </td>						
			<?php } ?>
		</tr>
		<?php $i++;} ?>	
	</table>
	<?php if(isset($_SESSION['role_id']) && $_SESSION['role_id'] ==1){ ?>
	<div class="menubox">		
		<input type="button" id="adduser" 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" id="save" class = "btn2 right" value="  &#3738;&#3761;&#3737;&#3735;&#3766;&#3713;  "   onclick="return confirm('ທ່ານຕ້ອງການບັນທຶກແທ້ບໍ...?')"/>
	</div>
	<?php }  ?>

</form>
<div class="paging">
<?php
	if ($pagecount > 1){
		if ($pagenum > 1) echo "<a href='?d=webmaster/manage/user&$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/user&$params&start=".($i*$pagesize)."' $isselected>".($i+1)."</a>";
		}
		if ($pagenum < $pagecount) echo "<a href='?d=webmaster/manage/user&$params&start=".($pagenum*$pagesize)."' $isselected>ຕໍ່ໄປ  &gt;</a>";
	}
?>
</div>
</div>
<table class="template hidden" id = "tab">			
	<tr>
			<td class ="centered itemcols">
				<span></span>
				<input type="hidden" name="type[]" class="type" value="added" />
				<input type="hidden" name="id[]" value="" />
			</td>
		
			<!-- <td class="adjust"><input type="text" name="emp_code_form[]" maxlength="4" /></td> -->
			<td class="adjust"><input type="text" name="username_form[]"  /></td>
			<td class="eqcodecols itemcode"><input type="text" name="first_name_form[]" /></td>
			<td class="eqcodecols itemcode"><input type="text" name="last_name_form[]"  /></td>
			<td class="eqcodecols itemcode"><input type="text" name="email_address[]"  /></td>
			<td class="eqcodecols itemcode">
				<select name="orgunitid[]">
					<option value="">--ເລືອກ--</option>
					<option value="0" >== ບໍ່ຂື້ນກັບໃຜ ==</option>
					<?php
						$org = selOrgList();
						while ($row_org = mysql_fetch_array($org, MYSQL_ASSOC)) {
						$selected_ = $row_org['orgunitid'] == $row['role_id'] ? "selected" : ""; 
					?>
						<option value="<?= $row_org['orgunitid'] ?>" <?= $selected_ ?>><?= $row_org['orgunitname'] ?></option>
					<?php } ?>
				</select>
			</td>
			<!--- 
			<td class="eqcodecols itemcode">
				<select name="position_id[]">
					<option value="">--ເລືອກ--</option>
					<?php
						//$rs_p = selPosition();
						//while ($row_p = mysql_fetch_array($rs_p, MYSQL_ASSOC)) {
						//$selected_1 = $row_p['position_id'] == $row['role_id'] ? "selected" : ""; 
					?>
						<option value="<?//= $row_p['position_id'] ?>" <?//= $selected_1 ?>><?//= $row_p['position_name'] ?></option>
					<?php //} ?>
				</select>
			</td>
			-->
			<td class="">
				<select name="role_id_form[]">
					<option value="">--ເລືອກ--</option>
					<?php
						$rs_user = selUser_role();
						while ($row_cc = mysql_fetch_array($rs_user, MYSQL_ASSOC)) {
						$selected = $row_cc['role_id'] == $row['role_id'] ? "selected" : ""; 
					?>
						<option value="<?= $row_cc['role_id'] ?>" <?= $selected ?>><?= $row_cc['role_name'] ?></option>
					<?php } ?>
				</select>
			</td>
			<td class="">
				<select name="sys_type_form[]">
					<?php foreach ($type_ as $k=>$n){
						$selected_2 = $k == $row['sys_type'] ? "selected" : ""; ?>
						<option  value="<?=$k?>" <?= $selected_2 ?>><?=$n['name_la']?></option>
					<?php } ?>
				</select>
			</td>			
			<td class="centered adjust" ><a href ="#" class="delete1" ><img src = "img/del.ico" border = '0' width = '20p' height = '20px'  /></a> </td>						
			
		</tr>
</table>
