<?php
/**
 * File			: user_form.php
 * Description  : View untuk halaman user
 * Created By	: Hendi
 * Created Date : 11 Feb 2021
 * Last Update  : 06 Apr 2021
**/
# sts add keterangannya jadi tambah
$stsket = ($sts == 'add' ? 'Tambah' : ucwords($sts));
?>
<div class="container-fluid">
	<div class="row">
		<div class="col-md-4">
			<div class="card">
				<div class="card-header card-header-info">
					<h4 class="card-title">User</h4>
					<p id="from-tag-category" class="card-category"><?= esc($stsket) ?> user </p>
				</div>
				<div class="card-body">
					<?php	
						# jika menggunakan form_open(), maka csrf token otomatis sudah dibuat.
						# esc() berfungsi menjaga serangan xss (cross site scripting)
					?>
					<?= form_open('user/save', ['id' => 'form-user']) ?>
						<input type="hidden" id="sts" name="sts" value="<?= esc($sts)?>" />
						<div class="row">
							<div class="col-md-12">
								<label>User ID</label>
								<div class="form-group">
									<input type="text" id="user-id" name="user_id" class="form-control" value="<?= esc($user_data['user_id'] ?? '') ?>" required <?= ($sts == 'edit' ? 'readonly' : '') ?> />
								</div>
							</div>
							<div class="col-md-12">
								<label>Nama Lengkap</label>
								<div class="form-group">
									<input type="text" id="full-name" name="full_name" class="form-control" value="<?= esc($user_data['full_name'] ?? '') ?>" required />
								</div>
							</div>
							<div class="col-md-12">
								<label>Level</label>
								<div class="form-group">
									<select id="level-id" name="level_id" class="selectpicker" data-style="select-with-transition" required>
									<?php
									foreach ($level as $lv)
									{
										echo '<option value="'.$lv['level_id'].'"'.($sts == 'edit' && $lv['level_id'] == $user_data['level_id'] ? ' selected' : '').'>'.$lv['description'].'</option>';
									}
									?>
									</select>
								</div>
							</div>
							<div class="col-md-12">
								<label>Keterangan</label>
								<div class="form-group">
									<input type="text" id="description" name="description" class="form-control" value="<?= esc($user_data['description'] ?? '') ?>" />
									<small>Opsional</small>
								</div>
							</div>
						</div>
						<button type="submit" class="btn btn-info">Simpan</button>
						<a href="<?= base_url('user') ?>" rel="tooltip" title class="btn btn-default btn-back pull-right">Tutup</a>
						<div class="clearfix"></div>
					<?= form_close() ?>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
  //_mod dideklarasikan di myscrypt.js
  _mod = '<?= $mod ?>';
</script>