<?php
//session_start();
$filenyax = base_url()."/android/i_login";
$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;

}
$hasilaksi=$_GET['aksi'];
//echo "ini aksinya = ".$hasilaksi;
//form
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'form'))
	{
	?>
	

	<script language='javascript'>
	//membuat document jquery
	$(document).ready(function(){

		$("#btnKRM").on('click', function(){
			$("#formx2").submit(function(){
				$.ajax({
					url: "<?php echo $filenyax;?>?aksi=simpan",
					type:$(this).attr("method"),
					data:$(this).serialize(),
					success:function(data){
						$("#ihasil").html(data);
						}
					});
				return false;
			});
		});
	});

	</script>
	<style>
 
 .profile-img
 {
     height: 96px;
     margin: 0 auto 10px;
     display: block;
 }
 

 </style>
	<div class="login-box">
	<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="javascript:"
              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>
	

	<?php
	/*
	echo '<table width="100%" border="0" cellpadding="5" cellspacing="5">
					<tr align="center">
					<td width="10">&nbsp;</td>
					<td valign="top">
						<div id="ihasil"></div>
						<form name="formx2" id="formx2">
							<p>
								Username :
								<br>
								<input name="iuser" id="iuser" value="" type="text" class="btn btn-block btn-success">
							</p>
							<p>
								Password :
								<br>
								<input name="ipass" id="ipass" value="" type="password" class="btn btn-block btn-success">
							</p>
							<p>
								<input type="submit" name="btnKRM" id="btnKRM" value="KIRIM >" class="btn btn-block btn-danger">
							</p>
						</form>
					</td>
					<td width="10">&nbsp;</td>
					</tr>
					</table>
	<br>
	<br>
	<br>';
*/

	exit();
	}

//jika simpan
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'simpan'))
	{
	//ambil nilai
	$euser = cegah($_GET['iuser']);
	$epass = md5(cegah($_GET['ipass']));


	//empty
	if ((empty($euser)) OR (empty($epass)))
		{
		echo '<br><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 '<br><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 = "main.html";

			});

			</script>

			<?php
			}
		}
	exit();
	}

//jika logout
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'logout'))
	{
	//habisi
	//$this->session->sess_unset();
	$this->session->sess_destroy();
	?>
	<script language='javascript'>
	//membuat document jquery
	$(document).ready(function(){
			window.location.href = "login.html";
	});
	</script>
	<?php
	exit();
	}
exit();
?>
