<?php
//nilai
$filenya = base_url()."/android1212/i_akun_pass";
$filenyax = base_url()."/android1212/i_akun_pass";
$judul = "Ganti Password";
$juduli = $judul;
//nilai session
$ku_hkode=$_GET['hkode'];
$tiga=$this->db->query("SELECT * from web_login where hkode='$ku_hkode'");
foreach ($tiga->result() as $rt) {
	$sesiku=$rt->sesiku;
	$sesinama=$rt->sesinama;
	$passx=$rt->passx;
	$departemen=$rt->departemen;
	$kd6_session=$rt->sesiku;
	$kodeabsen = $rt->sesiku;
	
}

//PROSES ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//jika simpan
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'simpan'))
	{
	//ambil nilai
	$passlama = md5(cegah($_GET["passlama"]));
	$passbaru = md5(cegah($_GET["passbaru"]));
	$passbaru2 = md5(cegah($_GET["passbaru2"]));

	//cek
	//nek null
	if ((empty($passlama)) OR (empty($passbaru)) OR (empty($passbaru2)))
		{
		//pesan
		echo "<font color=red><b>Input Tidak Lengkap. Harap Diulangi...!!</b></font>";
		exit();
		}

	//nek pass baru gak sama
	else if ($passbaru != $passbaru2)
		{
		//pesan
		echo "<font color=red><b>Password Baru Tidak Sama. Harap Diulangi...!!</b></font>";
		exit();
		}
	else
		{
		//query
		$ceksiswa=$this->db->query("SELECT * FROM web_siswa WHERE absen='$sesiku' AND password='$passlama'");
		$hasilcek=$ceksiswa->num_rows();

		//cek
		if ($hasilcek != 0)
			{
			//perintah SQL
			$this->db->query("UPDATE web_siswa SET password = '$passbaru' ".
							"WHERE absen = '$sesiku'");

			//pesan
			echo "<font color=red><b>PASSWORD BERHASIL DIGANTI.</b></font>";
			exit();
			}
		else
			{
			//pesan
			echo "<font color=red><b>PASSWORD LAMA TIDAK COCOK. HARAP DIULANGI...!!!</b></font>";
			exit();
			}
		}



	exit();
	}








//jika form
if ((isset($_GET['aksi']) && $_GET['aksi'] == 'form'))
	{
		$latx = cegah($_GET['latx']);
		$laty = cegah($_GET['laty']);
		//echo $latx."<br>";
		//echo $laty."<br>";
	?>


	<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>
	<div class="row m-3">
	    <div class="cell-md-4 text-center text-left-md">
	        <h3 class="dashboard-section-title">GANTI PASSWORD</h3>

	    </div>
	</div>
	<div class="login-box">
	<form class="bg-white p-4" name="formx2" id="formx2" action="javascript:"
              data-role="validator"
              data-clear-invalid="2000"
              data-on-error-form="invalidForm">
		<div id="ihasil"></div>
		<div class="form-group">
			<input type="password" name="passlama" id="passlama" data-role="input" placeholder="Password Lama" data-append="<span class='mif-key'>" data-validate="required">
			<span class="invalid_feedback">Please enter a password</span>
		</div>
		<div class="form-group">
			<input type="password" name="passbaru" id="passbaru" data-role="input" placeholder="Password Baru" data-append="<span class='mif-key'>" data-validate="required">
			<span class="invalid_feedback">Please enter a password</span>
		</div>
		<div class="form-group">
			<input type="password" name="passbaru2" id="passbaru2" data-role="input" placeholder="Password Baru Lagi" data-append="<span class='mif-key'>" data-validate="required">
			<span class="invalid_feedback">Please enter a 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">Ganti Password</button>
			<a class="button alert" href="utama.html">Batal</a>
		</div>
	</form>
</div>

	<?php

	exit();
	}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
