<?php
/**
 * File			: change_password.php
 * Description  : View untuk halaman ubah password
 * Created By	: Hendi
 * Created Date : 11 Feb 2021
 * Last Update  : 11 Feb 2021
**/
# cek validasi 
$inputs = session()->getFlashdata('inputs');
$errors = session()->getFlashdata('errors');
$success = session()->getFlashdata('success');
?>
<div class="container-fluid">
	<div class="row">
		<div class="col-md-4">
			<div class="card">
				<div class="card-header card-header-primary">
					<h4 class="card-title">Ubah Password</h4>
					<p id="from-tag-category" class="card-category">Untuk keamanan, ubah secara periodik </p>
				</div>
				<div class="card-body">
					<?php 
						if (!empty($errors))
						{ 
							echo '<div class="alert alert-danger" role="alert">
									<button type="button" class="close" data-dismiss="alert" aria-label="Close">
										<i class="material-icons">close</i>
									</button>
									<ul>';
							 
							foreach ($errors as $error) 
							{ 
								echo '<li>'.esc($error).'</li>';
							} 
							
							echo '	</ul>
								  </div>';
						}
						
						if (!empty($success))
						{ 
							echo '<div class="alert alert-success" role="alert">
									<button type="button" class="close" data-dismiss="alert" aria-label="Close">
										<i class="material-icons">close</i>
									</button>
									<span>'.$success.'<span>
								  </div>';
						}
						
						# jika menggunakan form_open(), maka csrf token otomatis sudah dibuat.
						# esc() berfungsi menjaga serangan xss (cross site scripting)
					?>
					<?= form_open('admin/do-change-password', ['id' => 'form-change-password']) ?>
						<div class="row">
							<div class="col-md-12">
								<label>Password Lama</label>
								<div class="form-group">
									<input type="password" id="password" name="password" class="form-control" value="<?= esc($inputs['password'] ?? '') ?>" required />
								</div>
							</div>
							<div class="col-md-12">
								<label>Password Baru</label>
								<div class="form-group">
									<input type="password" id="new-password" name="new_password" class="form-control" value="<?= esc($inputs['new_password'] ?? '') ?>" required />
								</div>
							</div>
							<div class="col-md-12">
								<label>Konfirmasi Password</label>
								<div class="form-group">
									<input type="password" id="confirm-password" name="confirm_password" class="form-control" value="<?= esc($inputs['confirm_password'] ?? '') ?>" required />
									<small>Konfirmasi Password Baru</small>
								</div>
							</div>
						</div>
						<button type="submit" class="btn btn-hejo pull-right">Ubah Password</button>
						<div class="clearfix"></div>
					<?= form_close() ?>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
  //_mod dideklarasikan di myscrypt.js
  _mod = '<?= $mod ?>';
</script>