<script type="text/javascript">
function valuser(form){
	if (form.username.value == ""){
		$(".page-error").show();
		form.username.focus();
		return (false);
	}
	return (true);
}
</script>

<script type="text/javascript">
$(document).ready(function () {
	$("#username").keyup(function() {
		$(".page-error").fadeOut('slow');
	});
});
</script>

<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{

$aksi="po-component/po-user/proses.php";
switch($_GET[act]){
	default:
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-user'></span>
		</div>
		<h1>$languser1<small><span class='text-info'>$languser2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				if ($_SESSION[leveluser]=='admin'){
					$tableuser = new PoTable('users');
					$users = $tableuser->findAll('', '');
					echo "<div class='data-fluid'>
					<table class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$languser3</th>
							<th>$languser4</th>
							<th>$languser5</th>
							<th>$languser6</th>
							<th>$languser7</th>
						</tr></thead><tbody>"; 
						$no=1;
						foreach($users as $user){
							echo "<tr>
								<td>$no</td>
								<td>$user->username</td>
								<td>$user->nama_lengkap</td>
								<td>$user->level</td>
								<td>$user->blokir</td>
								<td><a href='?mod=user&act=edit&id=$user->id_session'><span class='label label-info'><i class='icon-user icon-white'></i> $langaction1</span></a></td>
							</tr>";
							$no++;
						}
					echo "</tbody></table>";
				}else{
					$tableuser = new PoTable('users');
					$currentUser = $tableuser->findBy(username, $_SESSION[namauser]);
					$currentUser = $currentUser->current();
					echo "<div class='data-fluid'>
					<table class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$languser3</th>
							<th>$languser4</th>
							<th>$languser5</th>
							<th>$languser6</th>
							<th>$languser7</th>
						</tr></thead><tbody>"; 
						$no=1;
							echo "<tr>
								<td>$no</td>
								<td>$currentUser->username</td>
								<td>$currentUser->nama_lengkap</td>
								<td>$currentUser->level</td>
								<td>$currentUser->blokir</td>
								<td><a href='?mod=user&act=edit&id=$currentUser->id_session'><span class='label label-info'><i class='icon-user icon-white'></i> $langaction1</span></a></td>
							</tr>";
					echo "</tbody></table>";
				}
				echo "</div>
			</div>
			<div style='width:100%; height:500px;'>&nbsp;</div>
		</div>
	</div>";
    break;
  
	case "addnew":
    if ($_SESSION[leveluser]=='admin'){
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-user'></i> Add User</legend>
				<form method='post' action='$aksi' onSubmit='return valuser(this)' autocomplete='off'>
					<input type='hidden' name='mod' value='user'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Username</label><input class='input-xxlarge' type='text' id='username' name='username' required>
						<label>Password</label><input class='input-xxlarge' type='text' name='password' required>
						<label>Fullname</label><input class='input-xxlarge' type='text' name='nama_lengkap'>
						<label>Email</label><input class='input-xxlarge' type='text' name='email'>
						<label>Phone Number</label><input class='input-xxlarge' type='text' name='no_telp'>
						<br /><br />
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
					</fieldset>
				</form><br />
				<div class='page-error'>
					<div class='alert alert-error'>
						<strong>Warning!</strong> Best check yourself, you're not looking too good.
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
    }else{
		echo "<div class='page-header'></div>
		<div class='row-fluid'>
			<div class='span12'>
				<div class='errorContainerpage'>
					<h1>404</h1>
					<h2>$languser1</h2>
					<button class='btn btn-large btn-primary' onClick='document.location.href=\"admin.php?mod=home\";'>$langpagenotfound2</button> <button class='btn btn-large' onClick='history.back();'>$langpagenotfound3</button>
				</div>
			</div>
		</div>";
    }
    break;
    
	case "edit":
	$valid = $val->validasi($_GET['id'],'xss');
	$table = new PoTable('users');
	$currentUser = $table->findBy(id_session, $valid);
	$currentUser = $currentUser->current();

    if ($_SESSION[leveluser]=='admin'){
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-user'></i> Edit User</legend>
				<form method='post' action='$aksi' onSubmit='return valuser(this)' autocomplete='off'>
					<fieldset>
						<input type='hidden' name='id' value='$currentUser->id_session'>
						<input type='hidden' name='blokir' value='$currentUser->blokir'>
						<input type='hidden' name='mod' value='user'>
						<input type='hidden' name='act' value='update'>
						<label>Username **)</label><input class='input-xxlarge' type='text' id='username' name='username' value='$currentUser->username' disabled>
						<label>Password *)</label><input class='input-xxlarge' type='text' name='password'>
						<label>Fullname</label><input class='input-xxlarge' type='text' name='nama_lengkap' value='$currentUser->nama_lengkap'>
						<label>Email</label><input class='input-xxlarge' type='text' name='email' value='$currentUser->email'>
						<label>Phone Number</label><input class='input-xxlarge' type='text' name='no_telp' value='$currentUser->no_telp'>";
						if ($currentUser->blokir=='N'){
							echo "<label>Block</label>
							<label class='radio inline'><input type='radio' name='blokir' value='Y'>Y</label>
							<label class='radio inline'><input type='radio' name='blokir' value='N' checked>N</label><br /><br />";
						}else{
							echo "<label>Block</label>
							<label class='radio inline'><input type='radio' name='blokir' value='Y' checked>Y</label>
							<label class='radio inline'><input type='radio' name='blokir' value='N'>N</label><br /><br />";
						}
						echo "<span class='label label-important'>*) If the password is not changed, just vacated.</span>
						<span class='label label-important'>**) Username can not be changed.</span><br />
						<br />
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
					<fieldset>
				</form><br />
				<div class='page-error'>
					<div class='alert alert-error'>
						<strong>Warning!</strong> Best check yourself, you're not looking too good.
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
    }else{
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-user'></i> Edit User</legend>
				<form method='post' action='$aksi' onSubmit='return valuser(this)' autocomplete='off'>
					<fieldset>
						<input type='hidden' name='id' value='$currentUser->id_session'>
						<input type='hidden' name='blokir' value='$currentUser->blokir'>
						<input type='hidden' name='mod' value='user'>
						<input type='hidden' name='act' value='update'>
						<label>Username **)</label><input class='input-xxlarge' type='text' id='username' name='username' value='$currentUser->username' disabled>
						<label>Password *)</label><input class='input-xxlarge' type='text' name='password'>
						<label>Fullname</label><input class='input-xxlarge' type='text' name='nama_lengkap' value='$currentUser->nama_lengkap'>
						<label>Email</label><input class='input-xxlarge' type='text' name='email' value='$currentUser->email'>
						<label>Phone Number</label><input class='input-xxlarge' type='text' name='no_telp' value='$currentUser->no_telp'>
						<br /><br />
						<span class='label label-important'>*) If the password is not changed, just vacated.</span>
						<span class='label label-important'>**) Username can not be changed.</span><br />
						<br />
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
						<fieldset>
				</form><br />
				<div class='page-error'>
					<div class='alert alert-error'>
						<strong>Warning!</strong> Best check yourself, you're not looking too good.
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";    
    }
    break;  
}
}
?>