234 lines
12 KiB
PHP
234 lines
12 KiB
PHP
<?= $this->extend('_layouts/main.php') ?>
|
|
|
|
<?= $this->section('title') ?>
|
|
<title>User Management Glenlis</title>
|
|
<?= $this->endSection() ?>
|
|
|
|
<?= $this->section('content') ?>
|
|
<div class="container-fluid px-5 py-4">
|
|
|
|
<!-- Header -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4 mt-3">
|
|
<h3 class="fw-bold text-dark mb-0">👤 User Management Glenlis</h3>
|
|
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addUserModal">
|
|
✚ Add User
|
|
</button>
|
|
</div>
|
|
|
|
<?php if (session('success')): ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<?= esc(session('success')) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Table -->
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-info">
|
|
<tr>
|
|
<th width="5%">#</th>
|
|
<th>Name</th>
|
|
<th>Role</th>
|
|
<th>Level</th>
|
|
<th width="20%" class="text-center">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php $i=1; foreach ($data as $row) : ?>
|
|
<tr>
|
|
<td><?= $i++ ?></td>
|
|
<td><?= $row['USERID'] ?></td>
|
|
|
|
<!-- Untuk User Level -->
|
|
<?php if ($row['USERLEVEL'] == 1) : ?>
|
|
<td>
|
|
<button type="button" class="btn btn-light btn-sm position-relative">
|
|
👨🏻💻 Admin
|
|
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-success border border-light rounded-circle"></span>
|
|
</button>
|
|
</td>
|
|
<td><span class="badge text-bg-success"><?= $row['USERLEVEL'] ?></span></td>
|
|
<?php elseif ($row['USERLEVEL'] == 2) : ?>
|
|
<td>
|
|
<button type="button" class="btn btn-light btn-sm position-relative">
|
|
🩺 Doctor
|
|
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-primary border border-light rounded-circle"></span>
|
|
</button>
|
|
</td>
|
|
<td><span class="badge text-bg-primary"><?= $row['USERLEVEL'] ?></span></td>
|
|
<?php elseif ($row['USERLEVEL'] == 3) : ?>
|
|
<td>
|
|
<button type="button" class="btn btn-light btn-sm position-relative">
|
|
👩🏻🏭 Analyst
|
|
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-info border border-light rounded-circle"></span>
|
|
</button>
|
|
</td>
|
|
<td><span class="badge text-bg-info"><?= $row['USERLEVEL'] ?></span></td>
|
|
<?php elseif ($row['USERLEVEL'] == 4) : ?>
|
|
<td>
|
|
<button type="button" class="btn btn-light btn-sm position-relative">
|
|
👩💼 Customer Service
|
|
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-warning border border-light rounded-circle"></span>
|
|
</button>
|
|
</td>
|
|
<td><span class="badge text-bg-warning"><?= $row['USERLEVEL'] ?></span></td>
|
|
<?php endif; ?>
|
|
|
|
<td class="text-center">
|
|
<div class="row g-1 justify-content-center">
|
|
<div class="col-8">
|
|
<button class="btn btn-sm btn-outline-primary w-100"
|
|
data-bs-toggle="modal"
|
|
data-bs-target="#editUserModal<?= $row['USERID'] ?>">
|
|
✎ Edit
|
|
</button>
|
|
</div>
|
|
<div class="col-8">
|
|
<form method="POST" action="<?= base_url('admin/user/delete') ?>" onsubmit="return confirm('Yakin ingin menghapus user <?= esc($row['USERID']) ?>?')">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="userid" value="<?= esc($row['USERID']) ?>">
|
|
<button type="submit" class="btn btn-sm btn-outline-danger w-100">🗑 Delete</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal: Add User -->
|
|
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<form method="POST" action="<?= base_url('admin/user/create') ?>">
|
|
<?= csrf_field() ?>
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title" id="addUserModalLabel">✚ Add New User</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
|
|
<?php if (session('errors.server_error')): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<?= esc(session('errors.server_error')) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Userid</label>
|
|
<input type="text" name="userid" class="form-control" placeholder="enter userid" style="text-transform: uppercase;" value="<?= old('userid') ?>" required>
|
|
<?php if (session('errors.userid')): ?>
|
|
<div class="text-danger small"> <?= esc(session('errors.userid')) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Role</label>
|
|
<select class="form-select" name="userlevel" required>
|
|
<option value="1" <?= old('userlevel') == '1' ? 'selected' : '' ?>>Admin</option>
|
|
<option value="2" <?= old('userlevel') == '2' ? 'selected' : '' ?>>Doctor</option>
|
|
<option value="3" <?= old('userlevel') == '3' ? 'selected' : '' ?>>Analyst</option>
|
|
<option value="4" <?= old('userlevel') == '4' ? 'selected' : '' ?>>Customer Service</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Password</label>
|
|
<input type="password" name="password" class="form-control" placeholder="Enter Password" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Confirm Password</label>
|
|
<input type="password" name="password_2" class="form-control" placeholder="Confirm Password" required>
|
|
<?php if (session('errors.password')): ?>
|
|
<div class="text-danger small"> <?= esc(session('errors.password')) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Save User</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal: Edit User -->
|
|
<?php foreach ($data as $row) : ?>
|
|
<div class="modal fade" id="editUserModal<?=$row['USERID']?>" tabindex="-1" aria-labelledby="editUserModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<form method="POST" action="<?= base_url('admin/user/update') ?>">
|
|
<?= csrf_field() ?>
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title" id="editUserModalLabel">Edit User</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
|
|
<input type="hidden" name="userid" value="<?= esc($row['USERID']) ?>">
|
|
|
|
<div class="modal-body">
|
|
<?php if (session('errors.server_error')): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<?= esc(session('errors.server_error')) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Userid</label>
|
|
<input type="text" disabled class="form-control" style="text-transform: uppercase;" value="<?= esc($row['USERID']) ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Role</label>
|
|
<select class="form-select" name="userlevel" required>
|
|
<option value="1" <?= esc($row['USERLEVEL']) == '1' ? 'selected' : '' ?>>Admin</option>
|
|
<option value="2" <?= esc($row['USERLEVEL']) == '2' ? 'selected' : '' ?>>Doctor</option>
|
|
<option value="3" <?= esc($row['USERLEVEL']) == '3' ? 'selected' : '' ?>>Analyst</option>
|
|
<option value="4" <?= esc($row['USERLEVEL']) == '4' ? 'selected' : '' ?>>Customer Service</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Password</label>
|
|
<input type="password" name="password" class="form-control" placeholder="Enter Password">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Confirm Password</label>
|
|
<input type="password" name="password_2" class="form-control" placeholder="Confirm Password">
|
|
<?php if (session('errors.password')): ?>
|
|
<div class="text-danger small"> <?= esc(session('errors.password')) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Update</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?= $this->endSection() ?>
|
|
|
|
<?= $this->section('script') ?>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
<?php if (session('showModal')): ?>
|
|
var targetModal = new bootstrap.Modal(document.getElementById('<?= session('showModal') ?>'));
|
|
targetModal.show();
|
|
<?php endif; ?>
|
|
});
|
|
</script>
|
|
<?= $this->endSection() ?>
|