<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{
$aksi="po-component/po-user/proses.php";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icon-user"></span><?php echo $languser1; ?></span>
    </div>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="admin.php?mod=home"><?php echo $langmenu1; ?></a></li>
                <li class="current"><a><?php echo $languser2; ?></a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
	default:
?>
	<div class="widget">
		<div class="whead"><h6><?php echo $languser1; ?></h6><div class="clear"></div></div>
			<div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
<?php
				if ($_SESSION[leveluser]=='admin'){
					$tableuser = new PoTable('users');
					$users = $tableuser->findAll('', '');
					echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable' id='dynamic'>
						<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 class='tableActs' align='center'>
									<a href='?mod=user&act=edit&id=$user->id_session' class='tablectrl_small bDefault tipS' title='$langaction1'><span class='iconb' data-icon='&#xe1db;'></span></a>
								</td>
							</tr>";
							$no++;
						}
					echo "</tbody></table>";
				}else{
					$tableuser = new PoTable('users');
					$currentUser = $tableuser->findBy(username, $_SESSION[namauser]);
					$currentUser = $currentUser->current();
					echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable' id='dynamic'>
						<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 class='tableActs' align='center'>
									<a href='?mod=user&act=edit&id=$currentUser->id_session' class='tablectrl_small bDefault tipS' title='$langaction1'><span class='iconb' data-icon='&#xe1db;'></span></a>
								</td>
							</tr>";
					echo "</tbody></table>";
				}
?>
			</div>
		<div class="clear"></div>
	</div>
<?php
    break;

	case "addnew":
    if ($_SESSION[leveluser]=='admin'){
?>
		<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" autocomplete="off">
            <fieldset>
                <div class="widget fluid">
				<div class="whead"><h6>Add User</h6><div class="clear"></div></div>
					<input type="hidden" name="mod" value="user">
					<input type="hidden" name="act" value="input">
					<div class="formRow">
						<div class="grid3"><label>Username</label></div>
						<div class="grid9"><input class="required" type="text" id="username" name="username" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Password</label></div>
						<div class="grid9"><input class="required" type="password" id="password" name="password" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Repeat Password</label></div>
						<div class="grid9"><input type="password" class="required" name="repeatPass" id="repeatPass"/></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Fullname</label></div>
						<div class="grid9"><input type="text" id="nama_lengkap" name="nama_lengkap"></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Email</label></div>
						<div class="grid9"><input class="required" type="text" id="email" name="email" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<div class="grid3"><label>Phone Number</label></div>
						<div class="grid9"><input type="text" id="no_telp" name="no_telp"></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<input class="buttonM bBlue" type="submit" value="Submit">
						<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
					</div>
				</div>
            </fieldset>
		</form>
<?php
    }else{
?>
    <div class="wrapper" id="errorWrapperadmin">
		<span class="errorNum">404</span>
		<div class="errorContent">
			<span class="errorDesc"><span class="icon-warning"></span>Ooops! Error Somethings Wrong</span>
			<div class="fluid">
				<?php
					$url = rtrim("http://".$_SERVER['HTTP_HOST'], "/").$_SERVER['PHP_SELF'];
					$url2 = preg_replace("/\/po-admin\/(admin\.php$)/","",$url);
					$siteurl = $url2;
				?>
				<a title="Back to Previous page" class="buttonM bLightBlue grid6" onClick="history.back();">Back to previous page</a>
				<a href="<?php echo $siteurl; ?>" title="Back to the website" class="buttonM bRed grid6">Back to the website</a>
			</div>
		</div>
	</div>
<?php
    }
    break;
    
	case "edit":
	$valid = $val->validasi($_GET['id'],'xss');
	$table = new PoTable('users');
	$currentUser = $table->findBy(id_session, $valid);
	$currentUser = $currentUser->current();
	$dutf=html_entity_decode($currentUser->bio);

	if ($currentUser == '0'){
?>
		<div class="wrapper" id="errorWrapperadmin">
			<span class="errorNum">404</span>
			<div class="errorContent">
				<span class="errorDesc"><span class="icon-warning"></span>Sorry! Your Request Data Not Found. Please Try Again Submit Your Data</span>
			</div>
		</div>
<?php
	}else{
		if ($_SESSION[leveluser]=='admin'){
?>
			<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" enctype="multipart/form-data" autocomplete="off">
				<fieldset>
					<div class="widget fluid">
					<div class="whead"><h6>Edit User</h6><div class="clear"></div></div>
						<input type="hidden" name="id" value="<?php echo $currentUser->id_session; ?>">
						<input type="hidden" name="iduser" value="<?php echo $currentUser->id_user; ?>">
						<input type="hidden" name="blokir" value="<?php echo $currentUser->blokir; ?>">
						<input type="hidden" name="mod" value="user">
						<input type="hidden" name="act" value="update">
						<div class="formRow">
							<div class="grid3"><label>Username</label></div>
							<div class="grid9">
								<input class="required" type="text" id="username" name="username" value="<?php echo $currentUser->username; ?>" disabled>
								<p><i>Username can not be changed, except from direct database (phpmyadmin)</i></p>
							</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Password</label></div>
							<div class="grid9">
								<input type="password" id="newpassword" name="newpassword">
								<p><i>If the password is not changed, just empty</i></p>
							</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Fullname</label></div>
							<div class="grid9"><input type="text" id="nama_lengkap" name="nama_lengkap" value="<?php echo $currentUser->nama_lengkap; ?>"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Email</label></div>
							<div class="grid9"><input class="required" type="text" id="email" name="email" value="<?php echo $currentUser->email; ?>" required></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Phone Number</label></div>
							<div class="grid9"><input type="text" id="no_telp" name="no_telp" value="<?php echo $currentUser->no_telp; ?>"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>User Picture</label></div>
							<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Bio</label></div>
							<div class="grid9">
								<textarea rows="8" cols="" name="bio" id="bio" class="auto lim"><?php echo $dutf; ?></textarea>
								<span class="note" id="limitingtext">Field limited to 600 characters.</span>
							</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
						<?php if ($currentUser->blokir=="N"){ ?>
							<div class="grid3"><label>Block</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="blokir1" name="blokir" value="Y"></div><label for="blokir1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="blokir2" name="blokir" value="N" checked="checked"></div><label for="blokir2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php }else{ ?>
							<div class="grid3"><label>Block</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="blokir1" name="blokir" value="Y" checked="checked"></div><label for="blokir1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="blokir2" name="blokir" value="N"></div><label for="blokir2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php } ?>
						</div>
						<div class="formRow">
							<input class="buttonM bBlue" type="submit" value="Submit">
							<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
						</div>
					</div>
				</fieldset>
			</form>
<?php
		}else{
?>
			<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" enctype="multipart/form-data" autocomplete="off">
				<fieldset>
					<div class="widget fluid">
					<div class="whead"><h6>Edit User</h6><div class="clear"></div></div>
						<input type="hidden" name="id" value="<?php echo $currentUser->id_session; ?>">
						<input type="hidden" name="iduser" value="<?php echo $currentUser->id_user; ?>">
						<input type="hidden" name="blokir" value="<?php echo $currentUser->blokir; ?>">
						<input type="hidden" name="mod" value="user">
						<input type="hidden" name="act" value="update">
						<div class="formRow">
							<div class="grid3"><label>Username</label></div>
							<div class="grid9">
								<input class="required" type="text" id="username" name="username" value="<?php echo $currentUser->username; ?>" disabled>
								<p><i>Username can not be changed, except from direct database (phpmyadmin)</i></p>
							</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Password</label></div>
							<div class="grid9">
								<input type="password" id="newpassword" name="newpassword">
								<p><i>If the password is not changed, just empty</i></p>
						</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Fullname</label></div>
							<div class="grid9"><input type="text" id="nama_lengkap" name="nama_lengkap" value="<?php echo $currentUser->nama_lengkap; ?>"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Email</label></div>
							<div class="grid9"><input class="required" type="text" id="email" name="email" value="<?php echo $currentUser->email; ?>" required></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Phone Number</label></div>
							<div class="grid9"><input type="text" id="no_telp" name="no_telp" value="<?php echo $currentUser->no_telp; ?>"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>User Picture</label></div>
							<div class="grid9"><input style="opacity: 0;" size="24" class="fileInput" id="fileInput" name="fupload" type="file"></div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<div class="grid3"><label>Bio</label></div>
							<div class="grid9">
								<textarea rows="8" cols="" name="bio" id="bio" class="auto lim"><?php echo $dutf; ?></textarea>
								<span class="note" id="limitingtext">Field limited to 600 characters.</span>
							</div>
							<div class="clear"></div>
						</div>
						<div class="formRow">
							<input class="buttonM bBlue" type="submit" value="Submit">
							<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
						</div>
					</div>
				</fieldset>
			</form>
<?php 
		}
	}
    break;  
}
?>
	</div>
<?php
}
?>