<!DOCTYPE html>


<html lang="en">
<head>
	<!-- Required meta tags -->
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<!-- Metro 4 -->
	<link rel="stylesheet" href="<?php echo base_url('assets/pandora/vendors/metro4/css/metro-all.min.css'); ?>">
	<link rel="stylesheet" href="<?php echo base_url('assets/pandora/css/index.css'); ?>">
	<script src="<?php echo base_url('assets/pandora/vendors/jquery/jquery-3.4.1.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/pandora/vendors/metro4/js/metro.min.js'); ?>"></script>
<?php
$tiga=$this->db->query("SELECT * from web_setting where id='1'");
foreach ($tiga->result() as $rt) {
	$nama_sekolah=$rt->nama;
	$namsek=$rt->nama;
	$logo=$rt->logo;
$sesiku = $this->session->userdata('sesiku');
echo $sesiku;
	if (!$sesiku==""){
		
	//redirect('smart/main');
	?>
		<script language='javascript'>
			$(document).ready(function(){
					window.location.replace("../smart/main");
			});
		</script>
		<?php
	}
}

?>
	<title>Log in</title>
</head>
<body class="m4-cloak h-vh-100 d-flex flex-justify-center flex-align-center">
<div class="login-box">
	<input type="file" accept="image/*;capture=camera">
	<img class="profile-img" src="<?php echo base_url('assets/back/'.$logo.'');?>" height="100" alt="">
	<form class="bg-white p-4" name="formx2" id="formx2" action="" method="post"
              data-role="validator"
              data-clear-invalid="2000"
              data-on-error-form="invalidForm">
		<h3 class="flex-align-center mb-0">Login</h3>
		<div class="text-muted mb-4">Silahkan anda melakukan Login</div>
		<div id="ihasil"></div>
		<div class="form-group">
			<input type="text" name="iuser" id="iuser" data-role="input" placeholder="Username" data-append="<span class='mif-user'>" data-validate="required">
			<span class="invalid_feedback">Masukkan Username</span>
		</div>
		<div class="form-group">
			<input type="password" name="ipass" id="ipass" data-role="input" placeholder="Password" data-append="<span class='mif-key'>" data-validate="required">
			<span class="invalid_feedback">Masukkan Password</span>
		</div>
		<div class="form-group d-flex flex-align-center flex-justify-between">
			<button class="button primary" name="btnKRM" id="btnKRM" type="submit">Masuk</button>
		</div>
	</form>
</div>
</body>
</html>
<?php
if(isset($_POST['btnKRM']))
	{
	//ambil nilai
	$euser = cegah( $_POST['iuser']);
	$epass = md5(cegah( $_POST['ipass']));


	//empty
	if ((empty($euser)) OR (empty($epass)))
		{
		echo '<b>
		<font color="red">Tidak boleh kosong!<br>Masukkan Username & Password Anda!</font>
		</b>';
		}
	else
		{
		//cek
		$tiga=$this->db->query("SELECT * from web_siswa where absen='$euser' AND password='$epass'");
		$tku=$tiga->num_rows();
		foreach ($tiga->result() as $rt) {
			$ku_kd=$rt->absen;
			$ku_nama=$rt->NM_PEGAWAI;
			$ku_passx=$rt->password;
			$ku_dep=$rt->departemen;
		}

		//jika null
		if ($tku==0)
			{
			echo '<b>
			<font color="red">
			Login Gagal. <br>Silahkan ulangi lagi..!
			</font>
			</b>';
			}
		else
			{
			//bikin sesi
			$this->session->set_userdata('sesiku', $ku_kd);
			$this->session->set_userdata('sesinama', $ku_nama);
			$this->session->set_userdata('passx', $ku_passx);
			$this->session->set_userdata('departemen', $ku_dep);
			?>
			<script language='javascript'>
			//membuat document jquery
			$(document).ready(function(){
					window.location.href = "../smart/main";

			});

			</script>

			<?php
			}
		}
	exit();
	}
?>