<?php 
if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}

$peranan = 'Pemohon';
?>
<div class="modal-header">
	<h5 class="modal-title"><b>Kemaskini Kata Laluan <?= $peranan;?></b></h5>
	<span class="text-muted font-weight-bold font-size-sm">Sila kemaskini kata laluan anda</span><br>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeBtn" name="closeBtn" ></button>
</div>
<div class="modal-body">
	<form action="javascript:;" class="form-horizontal" name="tind_form" id="tind_form">
		<div class="form-body">
			<div class="row">
				<div class="col-md-12">					
					<!--begin::Card-->
					<div class="card card-custom" style="margin-top : 5px">
						<!--begin::Form-->
						<form class="form" id="pwd_form2" name="pwd_form2">
							<div class="card-body">
								<div class="form-group row">
								<?php
									$panduanKataLaluan = '- Tidak kurang dari 8 karakter<br>- Gabungan alphabet, nombor dan simbol<br>- Simbol yang dibenarkan adalah !@#$*_ sahaja';
									createTextBox('Kata laluan Baru', 'pengguna_pwd', 'Kata laluan Baru', '', 3, 0, 7, 12, '', 'password', $panduanKataLaluan);
									createTextBox('Kata laluan Baru(Ulang)', 'pengguna_pwd2', 'Kata laluan Baru(Ulang)', '', 3, 0, 7, 12, '', 'password');
								?>
								</div>
							</div>
						</form>
						<!--end::Form-->
					</div>
					<!--end::Card-->
				</div>
			</div>
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		echo '<button type="button" class="btn btn-primary" id="resetBtn">Kemaskini Katalaluan</button>';
	?>
</div>


<script>

$(document).ready(function(){  

	$('.select2').select2({ width: '100%' }); 		
	
	$('#resetBtn').click(function() {
		var pengguna_list = [[]];
		pengguna_list.push(['pengguna_pwd', 'Kata laluan Baru', 'pwd']);
		pengguna_list.push(['pengguna_pwd2', 'Kata laluan Baru (Ulang)', 'tb']);
		
		if (checkInput(pengguna_list))
		{
			if($('#pengguna_pwd').val() == $('#pengguna_pwd2').val())
			{
				$(this).prop("disabled",true);
				var param = $('#pwd_form').serialize();
				$.ajax({
					type: "POST", 
					url: "profile_pemohon-pwd_insert.php", 
					data: param+ '&id=' + <?=$my_details->usr_id?> + '&newpwd=' + $('#pengguna_pwd').val(),

					success: function(res){
						if(res > 0)
						{
							swal.fire({
								text: "Berjaya kemaskini kata laluan, sila login menggunakan kata laluan baru anda",
								icon: "success",
								buttonsStyling: false,
								confirmButtonText: "OK!",
								customClass: {
									confirmButton: "btn font-weight-bold btn-light-primary"
								}
							}).then(function() {					
								window.location.href = 'logout_pemohon.php';
							});
						}
						else
						{
							swal.fire({
								text: "Error. " + res,
								icon: "error",
								buttonsStyling: false,
								confirmButtonText: "OK!",
								customClass: {
									confirmButton: "btn font-weight-bold btn-light-primary"
								}
							}).then(function() {
								$(this).prop("disabled",false);								
							});
						}
						
					} 
				});  //end ajax
			}
			else
			{
				swal.fire({
					text: "Kata laluan tidak sepadan",
					icon: "error",
					buttonsStyling: false,
					confirmButtonText: "OK!",
					customClass: {
						confirmButton: "btn font-weight-bold btn-light-primary"
					}
				}).then(function() {
					$('#pengguna_pwd2').focus();
				});
				return false;
			}
		}
	});				
});		
</script>