<?php 

session_start();
if(!isset($_SESSION["login"]) ) {
	header("Location: login.php");
	exit;
}	




 if(isset($_SESSION["login"]) && ($_SESSION["logkanwil"] <>"KP") ) {
     	header("Location: index.php");
  	exit;
  }


require 'functions.php';

if( isset($_POST["register"]) ) {

	if( registrasi($_POST) > 0 ) {
		echo "<script>
				alert('User baru berhasil ditambahkan!');
			  </script>";
	} else {
		echo mysqli_error($conn);
	}

}

?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
<link rel="shortcut icon" href="idea.png">    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

	<title>Registrasi</title>
	<style>
		label {
			display: block;
		}
	</style>
</head>
<body>

<a href="logout.php"> |Logout|</a>
<a href="index.php"> Home|</a>


<h1>Registrasi</h1>

	<table>
	<form action="" method="post">
		
				
    	<tr>
			<td><label for="username">Username :</label></td>
			<td><input type="text" name="username" id="username" onkeyup="this.value = this.value.toUpperCase()" autofocus></td>
		</tr>
		<tr>
			<td><label for="password">Password : </label></td>
			<td><input type="password" name="password" id="password" onkeyup="this.value = this.value.toUpperCase()"></td>
		</tr>
		<tr>
			<td><label for="password2">Konfirmasi Password : </label></td>
			<td><input type="password" name="password2" id="password2" onkeyup="this.value = this.value.toUpperCase()"></td>
		</tr>
		<tr>
			<td><label for="gol">Level [1]Admin [2]User: </label></td>
			<td><input type="text" name="gol" id="gol"size="1" onkeyup="this.value = this.value.toUpperCase()"></td>
		</tr>
		<tr>
			<td><label for="kanwil">Kanwil [01-12 dsb.]: </label></td>
			<td><input type="text" name="kanwil" id="kanwil"size="1" onkeyup="this.value = this.value.toUpperCase()"></td>
		</tr>
		
		
			<td colspan="2">

                <button type="submit" class="btn btn-danger" name="register">Register!</button>

				
</td>

</form>
</body>
</html>