<?php
session_start();
if(!isset($_SESSION['sys_id'])) header("Location: ?d=index");
require_once("../../config.php");
require_once("m_user.php");

$User = getUser($whereclause, '');
$output_filename = "User_Password_".date("d-m-Y").".xls";
// Redirect the output to the stream
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename={$output_filename}");

echo "<h4>User and Password</h4> ";
?>		
	<table border='1'> 
		<tr bgcolor='#8EE5EE'>
			<th width="50px">ລ/ດ</th>	  	
            <th width="200px">ຊື່ເຂົ້າໃຊ້</th>
            <th width="300px">ລະຫັດຜ່ານ</th>
            <th width="200px">ຊື່</th>	  		  		
            <th width="200px">ນາມສະກຸນ</th>
            <th width="450px">ອີເມລ</th>
            <th width="450px">ພະແນກ ຫຼື ສາຂາ</th>	   		  		
            <th width="250px">ສິດການເຂົ້າໃຊ້</th>	
            <th width="150px">ປະເພດຜູ້ໃຊ້ລະບົບ</th>	
		</tr>
		<?php $i=1;
			while ($row = mysql_fetch_array($User)) { 
				$bg = $i%2 == 1 ? "" : "#e1f9fa";//for color on row in table
			?>
			<tr bgcolor="<?=$bg?>">
				<td class="centered">
					<span><?= ($i+$start) ?></span>
					<input type="hidden" name="type[]" class="type" value="unchanged" />
					<input type="hidden" id = "id[]" name="id[]" value="<?=$row["sysuserid"];?>" class="id"/>				</td>
				<td><?=$row['username'];?></td>
				<td>(ບໍ່ສາມາດເຂົ້າເບິ່ງໄດ້ ສອບຖາມ Admin)</td>
				<td><?=$row['first_name']; ?></td>
				<td><?=$row['last_name']; ?></td>
				<td><?=$row['email_address']; ?></td>
				<td>
				<?php
						
						echo $row['orgunitname'];
						 
						?>
                                    </td>
				<td>
				<?php
						 
						echo $row['role_name'];
						
					?>
                    </td>
			  <td>
				<?php
								
						$type_ = user_type();
					if($row['sys_type'] == 'none') {
						echo 'ຜູ້ໃຊ້ພະແນກ';
						}elseif ($row['sys_type'] == 'counter'){
						echo 'ຜູ້ໃຊ້ເຄົາເຕີ';
						}elseif ($row['sys_type'] == 'secretary') {
						echo 'ຜູ້ໃຊ້້ຫ້ອງເລຂາ';
						}
						?>			  
                        </td>
			</tr>
		<?php $i++; } ?>
	</table>
<?php mysql_close($conn); ?>