<?php 
require('includes/header.php');
?>	

<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Subheader-->
	<div class="subheader py-2 py-lg-6 subheader-solid" id="kt_subheader">
		<div class="container-fluid d-flex align-items-center justify-content-between flex-wrap flex-sm-nowrap">
			<!--begin::Info-->
			<div class="d-flex align-items-center flex-wrap mr-1">
				<!--begin::Mobile Toggle-->
				<button class="burger-icon burger-icon-left mr-4 d-inline-block d-lg-none" id="kt_subheader_mobile_toggle">
					<span></span>
				</button>
				<!--end::Mobile Toggle-->
				<!--begin::Page Heading-->
				<div class="d-flex align-items-baseline flex-wrap mr-5">
					<!--begin::Page Title-->
					<h5 class="text-dark font-weight-bold my-1 mr-5">Profil Pengguna</h5>
					<!--end::Page Title-->
				</div>
				<!--end::Page Heading-->
			</div>
			<!--end::Info-->
		</div>
	</div>
	<!--end::Subheader-->
	<!--begin::Entry-->
	<div class="d-flex flex-column-fluid">
		<!--begin::Container-->
		<div class="container">
			<!--begin::Profile Account Information-->
			<div class="d-flex flex-row">
				<!--begin::Aside-->
				<div class="flex-row-auto offcanvas-mobile w-250px w-xxl-350px" id="kt_profile_aside">
					<!--begin::Profile Card-->
					<div class="card card-custom card-stretch">
						<!--begin::Body-->
						<div class="card-body pt-4">
							<!--begin::User-->
							<div class="d-flex align-items-center">
								<div class="symbol symbol-60 symbol-xxl-100 mr-5 align-self-start align-self-xxl-center">
									<div>
										<span class="svg-icon svg-icon-primary svg-icon-6x">
											<?=$Usershield_svg?>
										</span>
									</div>
								</div>
								<div>
									<a href="#" class="font-weight-bolder font-size-h5 text-dark-75 text-hover-primary"><?=$pengguna_List['nama']?></a>
									<div class="text-muted"><?=$pengguna_List['desk_peranan']?></div>
								</div>
							</div>
							<!--end::User-->
							<!--begin::Contact-->
							<div class="py-9">
								<div class="d-flex align-items-center justify-content-between mb-2">
									<span class="font-weight-bold mr-2">Emel:</span>
									<a href="#" class="text-muted text-hover-primary"><?=$pengguna_List['emel']?></a>
								</div>
								<div class="d-flex align-items-center justify-content-between mb-2">
									<span class="font-weight-bold mr-2">No. Telefon:</span>
									<span class="text-muted"><?=$pengguna_List['no_tel']?></span>
								</div>
								<div class="d-flex align-items-center justify-content-between mb-2">
									<span class="font-weight-bold mr-2">Jabatan:</span>
									<span class="text-muted"><?=$pengguna_List['desk_jabatan']?></span>
								</div>	
								<?php
								if($pengguna_List['id_daerah'] > 0)
								{
								?>
									<div class="d-flex align-items-center justify-content-between mb-2">
										<span class="font-weight-bold mr-2">Daerah:</span>
										<span class="text-muted"><?=$pengguna_List['desk_daerah']?></span>
									</div>								
								<?php
								}
								
								if($pengguna_List['id_dun'] > 0)
								{
								?>
									<div class="d-flex align-items-center justify-content-between mb-2">
										<span class="font-weight-bold mr-2">KADUN:</span>
										<span class="text-muted"><?=$pengguna_List['desk_dun']?></span>
									</div>									
								<?php
								}
								
								if($pengguna_List['id_parlimen'] > 0)
								{
								?>
									<div class="d-flex align-items-center justify-content-between mb-2">
										<span class="font-weight-bold mr-2">Parlimen:</span>
										<span class="text-muted"><?=$pengguna_List['desk_parlimen']?></span>
									</div>									
								<?php
								}
								?>
							</div>
							<!--end::Contact-->
						</div>
						<!--end::Body-->
					</div>
					<!--end::Profile Card-->
				</div>
				<!--end::Aside-->
				<!--begin::Content-->
				<div class="flex-row-fluid ml-lg-8">
					<!--begin::Card-->
					<div class="card card-custom">
						<!--begin::Header-->
						<div class="card-header py-3">
							<div class="card-title align-items-start flex-column">
								<h3 class="card-label font-weight-bolder text-dark">Maklumat Peribadi</h3>
								<span class="text-muted font-weight-bold font-size-sm mt-1">Kemaskini maklumat peribadi anda</span>
							</div>
						</div>
						<!--end::Header-->
						<!--begin::Form-->
						<form class="form" id="pengguna_form" name="pengguna_form">
							<div class="card-body">
								<!--begin::Form Group-->
								<div class="form-group row">
									<?php
										createTextBox('Nama', 'nama', 'Nama', $pengguna_List['nama'], 3, 0, 7, 12, '', 'text', 'Sila masukkan nama pengguna');
										createTextBox('No. Kad Pengenalan Baru', 'kpbaru', 'No. Kad Pengenalan Baru', $pengguna_List['kpbaru'], 3, 1, 7, 12, '', 'text');
										createTextBox('Id Pengguna', 'login', 'Id Pengguna', $pengguna_List['login'], 3, 1, 7, 12, '', 'text');
										createTextBox('Emel', 'emel', 'Emel', $pengguna_List['emel'], 3, 0, 7, 12, '', 'email','contoh : myacc@example.com');
										createTextBox('No. Telefon', 'no_tel', 'No. Telefon', $pengguna_List['no_tel'], 3, 0, 7, 12, '', 'email','contoh : 042665555');
										createDropDown($PDO, 'Soalan Rahsia', 'i_soalanrahsia', 'id_soalanrahsia', $pengguna_List['id_soalanrahsia'], 'Pilih Soalan Rahsia', 7, 3, 12, $readonly);
										createTextBox('Jawapan Rahsia', 'jawapan_rahsia', 'Jawapan Rahsia', $pengguna_List['jawapan_rahsia'], 3, 0, 7, 12, '', 'text','');
									?>
								</div>
							</div>
						</form>
						<div class="card-footer d-flex justify-content-between">
							<div class="card-toolbar">
								<button type="reset" class="btn btn-success mr-2" id="saveBtn">Kemaskini Maklumat</button>
							</div>
						</div>
						<!--end::Form-->
					</div>
					<!--begin::Card-->
					<div class="card card-custom" style="margin-top : 5px">
						<!--begin::Header-->
						<div class="card-header py-3">
							<div class="card-title align-items-start flex-column">
								<h3 class="card-label font-weight-bolder text-dark">Kemaskini Kata laluan</h3>
								<span class="text-muted font-weight-bold font-size-sm mt-1">Kemaskini kata laluan anda</span>
							</div>
						</div>
						<!--end::Header-->
						<!--begin::Form-->
						<form class="form" id="pwd_form" name="pwd_form">
							<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, $readonly, 7, 12, '', 'password', $panduanKataLaluan);
									createTextBox('Kata laluan Baru(Ulang)', 'pengguna_pwd2', 'Kata laluan Baru(Ulang)', '', 3, $readonly, 7, 12, '', 'password');
								?>
								</div>
							</div>
						</form>
						<div class="card-footer d-flex justify-content-between">
							<div class="card-toolbar">
								<button type="reset" class="btn btn-success mr-2" id="resetBtn">Kemaskini Katalaluan</button>
							</div>
						</div>
						<!--end::Form-->
					</div>
					<!--end::Card-->
				</div>
				<!--end::Content-->
			</div>
			<!--end::Profile Account Information-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->		
			
<?php 
require('includes/footer.php');
?>	

<script>
$(document).ready(function(){  
	
	$('#saveBtn').click(function() {
		var pengguna_list = [[]];
		pengguna_list.push(['nama', 'Name', 'nm']);
		pengguna_list.push(['emel', 'Emel', 'em']);
		
		if (checkInput(pengguna_list))
		{	
			$(this).prop("disabled",true);
			var param = $('#pengguna_form').serialize();
			$.ajax({
				type: "POST", 
				url: "profile-info_insert.php", 
				data: param+ '&id=' + <?=$my_details->usr_id?>,

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya Kemaskini Maklumat Peribadi",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							location.reload();
						});
					}
					else if (res == -888)
					{
						swal.fire({
							text: "Alamat emel telah wujud di dalam sistem",
							icon: "error",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							$('#emel').focus();
							$(this).prop("disabled",false);	
						});						
					}
					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
		}
	});
	
	$('#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-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.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>