286 lines
14 KiB
PHP
286 lines
14 KiB
PHP
<?php
|
|
$search_name = $_GET['name'] ?? '';
|
|
$search_group = $_GET['group_id'] ?? '';
|
|
|
|
$query = "
|
|
SELECT t.*, g.name_$lang as group_name
|
|
FROM laboratory_tests t
|
|
LEFT JOIN test_groups g ON t.group_id = g.id
|
|
WHERE 1=1";
|
|
$params = [];
|
|
|
|
if ($search_name) {
|
|
$query .= " AND (t.name_en LIKE ? OR t.name_ar LIKE ?)";
|
|
$params[] = "%$search_name%";
|
|
$params[] = "%$search_name%";
|
|
}
|
|
if ($search_group) {
|
|
$query .= " AND t.group_id = ?";
|
|
$params[] = $search_group;
|
|
}
|
|
|
|
$query .= " ORDER BY t.id DESC";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute($params);
|
|
$tests = $stmt->fetchAll();
|
|
|
|
// Fetch all groups for filter dropdown
|
|
$gStmt = $db->query("SELECT * FROM test_groups ORDER BY name_$lang");
|
|
$all_test_groups = $gStmt->fetchAll();
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h3 class="fw-bold text-secondary"><?php echo __('tests'); ?></h3>
|
|
<div>
|
|
<button class="btn btn-outline-primary shadow-sm me-2" data-bs-toggle="modal" data-bs-target="#importTestsModal">
|
|
<i class="bi bi-upload me-1"></i> <?php echo __('import'); ?>
|
|
</button>
|
|
<button class="btn btn-primary shadow-sm" data-bs-toggle="modal" data-bs-target="#addTestModal" onclick="resetTestModal()">
|
|
<i class="bi bi-plus-circle me-1"></i> <?php echo __('add_test'); ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Search Bar -->
|
|
<div class="card shadow-sm border-0 mb-4">
|
|
<div class="card-body">
|
|
<form method="GET" action="" class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-search"></i></span>
|
|
<input type="text" name="name" class="form-control bg-light border-start-0" placeholder="<?php echo __('test_name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<select name="group_id" class="form-select bg-light">
|
|
<option value=""><?php echo __('test_group'); ?> (<?php echo __('all'); ?>)</option>
|
|
<?php foreach ($all_test_groups as $group): ?>
|
|
<option value="<?php echo $group['id']; ?>" <?php echo $search_group == $group['id'] ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($group['name_' . $lang]); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" class="btn btn-secondary w-100"><?php echo __('search'); ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-light text-secondary">
|
|
<tr>
|
|
<th class="px-4 py-3">#</th>
|
|
<th class="py-3"><?php echo __('test_name'); ?></th>
|
|
<th class="py-3"><?php echo __('test_group'); ?></th>
|
|
<th class="py-3"><?php echo __('normal_range'); ?></th>
|
|
<th class="py-3"><?php echo __('price'); ?></th>
|
|
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($tests)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center py-5 text-muted">
|
|
<i class="bi bi-prescription2 display-4 d-block mb-3"></i>
|
|
<?php echo __('no_tests_found'); ?>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($tests as $test): ?>
|
|
<tr>
|
|
<td class="px-4 fw-medium text-secondary"><?php echo $test['id']; ?></td>
|
|
<td>
|
|
<div class="d-flex align-items-center">
|
|
<div class="bg-primary bg-opacity-10 text-primary p-2 rounded-circle me-3">
|
|
<i class="bi bi-list-check fs-5"></i>
|
|
</div>
|
|
<div>
|
|
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($test['name_'.$lang]); ?></div>
|
|
<small class="text-muted"><?php echo htmlspecialchars($test['name_'.($lang == 'en' ? 'ar' : 'en')]); ?></small>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-info bg-opacity-10 text-info border border-info border-opacity-25 px-2 py-1">
|
|
<?php echo htmlspecialchars($test['group_name'] ?? '-'); ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="text-muted small italic">
|
|
<?php echo htmlspecialchars($test['normal_range'] ?? '-'); ?>
|
|
</span>
|
|
</td>
|
|
<td class="text-secondary fw-bold"><?php echo number_format($test['price'], 2); ?></td>
|
|
<td class="text-end px-4">
|
|
<div class="btn-group shadow-sm border rounded bg-white">
|
|
<button class="btn btn-link text-primary py-1 px-2 border-end"
|
|
onclick="showEditTestModal(<?php echo htmlspecialchars(json_encode($test, JSON_UNESCAPED_UNICODE)); ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('edit'); ?>">
|
|
<i class="bi bi-pencil-square"></i>
|
|
</button>
|
|
<button class="btn btn-link text-danger py-1 px-2"
|
|
onclick="showDeleteTestModal(<?php echo $test['id']; ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('delete'); ?>">
|
|
<i class="bi bi-trash3"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Import Tests Modal -->
|
|
<div class="modal fade" id="importTestsModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title"><?php echo __('import_tests'); ?></h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<form method="POST" action="" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="import_tests">
|
|
<div class="modal-body p-4">
|
|
<div class="mb-3">
|
|
<label class="form-label"><?php echo __('upload_file'); ?> (CSV, Excel) <span class="text-danger">*</span></label>
|
|
<input type="file" class="form-control" name="csv_file" accept=".csv, .xlsx, .xls" required>
|
|
</div>
|
|
<div class="alert alert-info small mb-0">
|
|
<i class="bi bi-info-circle me-1"></i> <?php echo __('format'); ?>: Name (En), Name (Ar), Group, Price, Normal Range
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer bg-light">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('close'); ?></button>
|
|
<button type="submit" class="btn btn-primary"><?php echo __('import'); ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add/Edit Test Modal -->
|
|
<div class="modal fade" id="addTestModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header bg-primary text-white">
|
|
<h5 class="modal-title" id="testModalTitle"><?php echo __('add_test'); ?></h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<form method="POST" action="">
|
|
<input type="hidden" name="action" id="testAction" value="add_test">
|
|
<input type="hidden" name="id" id="testId">
|
|
<div class="modal-body p-4">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label"><?php echo __('name_en'); ?> <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="name_en" id="testNameEn" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label"><?php echo __('name_ar'); ?> <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="name_ar" id="testNameAr" required>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label"><?php echo __('test_group'); ?></label>
|
|
<select class="form-select" name="group_id" id="testGroupId">
|
|
<option value=""><?php echo __('select_group'); ?></option>
|
|
<?php foreach ($all_test_groups as $group): ?>
|
|
<option value="<?php echo $group['id']; ?>">
|
|
<?php echo htmlspecialchars($group['name_' . $lang]); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label"><?php echo __('price'); ?></label>
|
|
<div class="input-group">
|
|
<span class="input-group-text">$</span>
|
|
<input type="number" step="0.01" class="form-control" name="price" id="testPrice">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<label class="form-label"><?php echo __('normal_range'); ?></label>
|
|
<textarea class="form-control" name="normal_range" id="testRange" rows="2"></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer bg-light">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('close'); ?></button>
|
|
<button type="submit" class="btn btn-primary"><?php echo __('save'); ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Delete Test Modal -->
|
|
<div class="modal fade" id="deleteTestModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header bg-danger text-white">
|
|
<h5 class="modal-title"><?php echo __('delete_test'); ?></h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<form method="POST" action="">
|
|
<input type="hidden" name="action" value="delete_test">
|
|
<input type="hidden" name="id" id="deleteTestId">
|
|
<div class="modal-body p-4 text-center">
|
|
<div class="mb-3 text-danger">
|
|
<i class="bi bi-exclamation-triangle display-1"></i>
|
|
</div>
|
|
<p class="mb-0 fs-5"><?php echo __('are_you_sure_delete'); ?></p>
|
|
<p class="text-muted small"><?php echo __('action_cannot_be_undone'); ?></p>
|
|
</div>
|
|
<div class="modal-footer bg-light justify-content-center">
|
|
<button type="button" class="btn btn-secondary px-4" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
|
|
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function resetTestModal() {
|
|
document.getElementById('testModalTitle').textContent = '<?php echo __('add_test'); ?>';
|
|
document.getElementById('testAction').value = 'add_test';
|
|
document.getElementById('testId').value = '';
|
|
|
|
document.getElementById('testNameEn').value = '';
|
|
document.getElementById('testNameAr').value = '';
|
|
document.getElementById('testGroupId').value = '';
|
|
document.getElementById('testPrice').value = '';
|
|
document.getElementById('testRange').value = '';
|
|
}
|
|
|
|
function showEditTestModal(test) {
|
|
document.getElementById('testModalTitle').textContent = '<?php echo __('edit_test'); ?>';
|
|
document.getElementById('testAction').value = 'edit_test';
|
|
document.getElementById('testId').value = test.id;
|
|
|
|
document.getElementById('testNameEn').value = test.name_en;
|
|
document.getElementById('testNameAr').value = test.name_ar;
|
|
document.getElementById('testGroupId').value = test.group_id || '';
|
|
document.getElementById('testPrice').value = test.price;
|
|
document.getElementById('testRange').value = test.normal_range;
|
|
|
|
var modal = new bootstrap.Modal(document.getElementById('addTestModal'));
|
|
modal.show();
|
|
}
|
|
|
|
function showDeleteTestModal(id) {
|
|
document.getElementById('deleteTestId').value = id;
|
|
var modal = new bootstrap.Modal(document.getElementById('deleteTestModal'));
|
|
modal.show();
|
|
}
|
|
</script>
|