updating lists for dynamic search
This commit is contained in:
parent
4d100ba658
commit
48924b82af
13
doctors.php
13
doctors.php
@ -8,6 +8,15 @@ $lang = $_SESSION['lang'];
|
||||
|
||||
require_once __DIR__ . '/includes/actions.php';
|
||||
require_once __DIR__ . '/includes/common_data.php';
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
|
||||
$is_ajax = isset($_GET['ajax_search']) || isset($_POST['ajax_search']);
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/pages/doctors.php';
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
}
|
||||
11
drugs.php
11
drugs.php
@ -7,6 +7,13 @@ $lang = $_SESSION['lang'] ?? 'en';
|
||||
|
||||
require_once __DIR__ . '/includes/actions.php';
|
||||
require_once __DIR__ . '/includes/common_data.php';
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
|
||||
if (!isset($_GET['ajax_search'])) {
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/pages/drugs.php';
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
|
||||
if (!isset($_GET['ajax_search'])) {
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
}
|
||||
@ -841,7 +841,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name_en = $row[0] ?? '';
|
||||
$name_ar = $row[1] ?? '';
|
||||
$group_name = $row[2] ?? '';
|
||||
$price = $row[3] ?? 0;
|
||||
$price = $row[3] ?? 0; if (!is_numeric($price)) { $price = 0; }
|
||||
// $expiry = $row[4] ?? null;
|
||||
// Force expiry to null as requested to bypass parsing issues
|
||||
$expiry = null;
|
||||
@ -937,7 +937,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name_en = $row[0] ?? '';
|
||||
$name_ar = $row[1] ?? '';
|
||||
$group_name = $row[2] ?? '';
|
||||
$price = $row[3] ?? 0;
|
||||
$price = $row[3] ?? 0; if (!is_numeric($price)) { $price = 0; }
|
||||
$range = $row[4] ?? '';
|
||||
|
||||
if ($name_en) {
|
||||
|
||||
@ -48,14 +48,14 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp
|
||||
|
||||
<style>
|
||||
body { font-family: 'Inter', 'Tajawal', sans-serif; background-color: #f4f7f6; }
|
||||
.sidebar { min-height: 100vh; width: 250px; background-color: #002D62; color: white; transition: all 0.3s; }
|
||||
.sidebar { min-height: 100vh; width: 250px; background-color: #002D62; color: white; transition: all 0.3s; flex-shrink: 0; }
|
||||
.sidebar-link { color: #cfd8dc; text-decoration: none; padding: 12px 20px; display: block; border-left: 4px solid transparent; }
|
||||
.sidebar-link:hover, .sidebar-link.active { background-color: #003a80; color: white; border-left-color: #4fc3f7; }
|
||||
.sidebar-submenu { background-color: #001f44; padding-left: 20px; }
|
||||
<?php if (is_rtl()): ?>
|
||||
.sidebar-submenu { padding-left: 0; padding-right: 20px; }
|
||||
<?php endif; ?>
|
||||
.main-content { flex: 1; padding: 25px; }
|
||||
.main-content { flex: 1; padding: 25px; min-width: 0; }
|
||||
.card { border: none; border-radius: 8px; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); margin-bottom: 20px; }
|
||||
.stat-card { padding: 20px; text-align: center; }
|
||||
.stat-card i { font-size: 2.5rem; color: #0056b3; margin-bottom: 10px; }
|
||||
@ -193,4 +193,4 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp
|
||||
<?php echo $message; ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
@ -1,28 +1,143 @@
|
||||
<?php
|
||||
$search_name = $_GET['name'] ?? '';
|
||||
$search_dept = $_GET['department_id'] ?? '';
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$query = "
|
||||
SELECT d.*, dept.name_$lang as department_name
|
||||
FROM doctors d
|
||||
LEFT JOIN departments dept ON d.department_id = dept.id
|
||||
WHERE 1=1";
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($search_name) {
|
||||
$query .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$where .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$params[] = "%$search_name%";
|
||||
$params[] = "%$search_name%";
|
||||
}
|
||||
if ($search_dept) {
|
||||
$query .= " AND d.department_id = ?";
|
||||
$where .= " AND d.department_id = ?";
|
||||
$params[] = $search_dept;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY d.id DESC";
|
||||
// Count Total
|
||||
$countQuery = "SELECT COUNT(*) FROM doctors d $where";
|
||||
$stmt = $db->prepare($countQuery);
|
||||
$stmt->execute($params);
|
||||
$totalDoctors = $stmt->fetchColumn();
|
||||
$totalPages = ceil($totalDoctors / $limit);
|
||||
|
||||
// Fetch Data
|
||||
$query = "
|
||||
SELECT d.*, dept.name_$lang as department_name
|
||||
FROM doctors d
|
||||
LEFT JOIN departments dept ON d.department_id = dept.id
|
||||
$where
|
||||
ORDER BY d.id DESC
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$doctors = $stmt->fetchAll();
|
||||
|
||||
// --- AJAX HANDLER ---
|
||||
if (isset($_GET['ajax_search'])) {
|
||||
ob_start();
|
||||
if (empty($doctors)):
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-person-badge display-4 d-block mb-3"></i>
|
||||
<?php echo __('no_doctors_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($doctors as $d): ?>
|
||||
<tr>
|
||||
<td class="px-4">
|
||||
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($d['name_'.$lang]); ?></div>
|
||||
<small class="text-muted"><?php echo htmlspecialchars($d['name_'.($lang == 'en' ? 'ar' : 'en')]); ?></small>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($d['specialization_'.$lang]); ?></td>
|
||||
<td>
|
||||
<span class="badge bg-primary bg-opacity-10 text-primary border border-primary border-opacity-25 px-2 py-1">
|
||||
<?php echo htmlspecialchars($d['department_name'] ?: '-'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="small text-secondary"><i class="bi bi-telephone me-1"></i> <?php echo htmlspecialchars($d['tel'] ?: '-'); ?></div>
|
||||
<div class="small text-secondary"><i class="bi bi-envelope me-1"></i> <?php echo htmlspecialchars($d['email'] ?: '-'); ?></div>
|
||||
</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="showEditDoctorModal(<?php echo htmlspecialchars(json_encode($d, 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="showDeleteDoctorModal(<?php echo $d['id']; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('delete'); ?>">
|
||||
<i class="bi bi-trash3"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif;
|
||||
$table_html = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalDoctors); ?> <?php echo __('of'); ?> <?php echo $totalDoctors; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif;
|
||||
$pagination_html = ob_get_clean();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['html' => $table_html, 'pagination' => $pagination_html]);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -35,15 +150,15 @@ $doctors = $stmt->fetchAll();
|
||||
<!-- Search Bar -->
|
||||
<div class="card shadow-sm border-0 mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" action="" class="row g-3">
|
||||
<form id="doctorsSearchForm" class="row g-3" onsubmit="return false;">
|
||||
<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 __('name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>">
|
||||
<input type="text" name="name" id="doctorSearchName" class="form-control bg-light border-start-0" placeholder="<?php echo __('name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<select name="department_id" class="form-select bg-light">
|
||||
<select name="department_id" id="doctorSearchDept" class="form-select bg-light">
|
||||
<option value=""><?php echo __('department'); ?> (<?php echo __('all'); ?>)</option>
|
||||
<?php foreach ($all_departments as $dept): ?>
|
||||
<option value="<?php echo $dept['id']; ?>" <?php echo $search_dept == $dept['id'] ? 'selected' : ''; ?>>
|
||||
@ -53,7 +168,7 @@ $doctors = $stmt->fetchAll();
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" class="btn btn-secondary w-100"><?php echo __('search'); ?></button>
|
||||
<button type="button" class="btn btn-secondary w-100" onclick="fetchDoctors(1)"><?php echo __('search'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -72,12 +187,12 @@ $doctors = $stmt->fetchAll();
|
||||
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="doctorsTableBody">
|
||||
<?php if (empty($doctors)): ?>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-person-badge display-4 d-block mb-3"></i>
|
||||
No doctors found.
|
||||
<?php echo __('no_doctors_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
@ -117,5 +232,128 @@ $doctors = $stmt->fetchAll();
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div id="doctorsPagination">
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalDoctors); ?> <?php echo __('of'); ?> <?php echo $totalDoctors; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchName = document.getElementById('doctorSearchName');
|
||||
const searchDept = document.getElementById('doctorSearchDept');
|
||||
const tableBody = document.getElementById('doctorsTableBody');
|
||||
const paginationContainer = document.getElementById('doctorsPagination');
|
||||
|
||||
let timeout = null;
|
||||
|
||||
if (searchName) {
|
||||
searchName.addEventListener('input', function() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fetchDoctors(1), 300);
|
||||
});
|
||||
}
|
||||
|
||||
if (searchDept) {
|
||||
searchDept.addEventListener('change', function() {
|
||||
fetchDoctors(1);
|
||||
});
|
||||
}
|
||||
|
||||
// Event delegation for pagination clicks
|
||||
if (paginationContainer) {
|
||||
paginationContainer.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
const link = e.target.closest('.page-link');
|
||||
if (link && !link.parentElement.classList.contains('disabled')) {
|
||||
const page = link.getAttribute('data-page');
|
||||
if (page) fetchDoctors(page);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function fetchDoctors(page) {
|
||||
const name = document.getElementById('doctorSearchName').value;
|
||||
const dept = document.getElementById('doctorSearchDept').value;
|
||||
const tableBody = document.getElementById('doctorsTableBody');
|
||||
const paginationContainer = document.getElementById('doctorsPagination');
|
||||
|
||||
if (tableBody) tableBody.style.opacity = '0.5';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (name) params.append('name', name);
|
||||
if (dept) params.append('department_id', dept);
|
||||
params.append('page', page);
|
||||
params.append('ajax_search', '1');
|
||||
|
||||
fetch('doctors.php?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (tableBody) {
|
||||
tableBody.innerHTML = data.html;
|
||||
tableBody.style.opacity = '1';
|
||||
}
|
||||
if (paginationContainer) {
|
||||
paginationContainer.innerHTML = data.pagination;
|
||||
}
|
||||
|
||||
// Re-initialize tooltips
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching doctors:', error);
|
||||
if (tableBody) tableBody.style.opacity = '1';
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -1,26 +1,41 @@
|
||||
<?php
|
||||
$search_name = $_GET['name'] ?? '';
|
||||
$search_group = $_GET['group_id'] ?? '';
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
// Build WHERE clause
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($search_name) {
|
||||
$where .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$params[] = "%$search_name%";
|
||||
$params[] = "%$search_name%";
|
||||
}
|
||||
if ($search_group) {
|
||||
$where .= " AND d.group_id = ?";
|
||||
$params[] = $search_group;
|
||||
}
|
||||
|
||||
// Count total drugs
|
||||
$countQuery = "SELECT COUNT(*) FROM drugs d $where";
|
||||
$stmt = $db->prepare($countQuery);
|
||||
$stmt->execute($params);
|
||||
$totalDrugs = $stmt->fetchColumn();
|
||||
$totalPages = ceil($totalDrugs / $limit);
|
||||
|
||||
// Fetch drugs with pagination
|
||||
$query = "
|
||||
SELECT d.*, g.name_$lang as group_name, s.name_$lang as supplier_name
|
||||
FROM drugs d
|
||||
LEFT JOIN drugs_groups g ON d.group_id = g.id
|
||||
LEFT JOIN suppliers s ON d.supplier_id = s.id
|
||||
WHERE 1=1";
|
||||
$params = [];
|
||||
$where
|
||||
ORDER BY d.id DESC
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
if ($search_name) {
|
||||
$query .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$params[] = "%$search_name%";
|
||||
$params[] = "%$search_name%";
|
||||
}
|
||||
if ($search_group) {
|
||||
$query .= " AND d.group_id = ?";
|
||||
$params[] = $search_group;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY d.id DESC";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$drugs = $stmt->fetchAll();
|
||||
@ -32,6 +47,113 @@ $all_drug_groups = $gStmt->fetchAll();
|
||||
// Fetch all suppliers
|
||||
$sStmt = $db->query("SELECT * FROM suppliers ORDER BY name_$lang");
|
||||
$all_suppliers = $sStmt->fetchAll();
|
||||
|
||||
// --- AJAX HANDLER ---
|
||||
if (isset($_GET['ajax_search'])) {
|
||||
ob_start();
|
||||
if (empty($drugs)):
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-capsule display-4 d-block mb-3"></i>
|
||||
<?php echo __('no_drugs_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($drugs as $drug): ?>
|
||||
<tr>
|
||||
<td class="px-4 fw-medium text-secondary"><?php echo $drug['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 flex-shrink-0">
|
||||
<i class="bi bi-capsule fs-5"></i>
|
||||
</div>
|
||||
<div class="text-wrap" style="word-break: break-word;">
|
||||
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($drug['name_'.$lang]); ?></div>
|
||||
<small class="text-muted d-block"><?php echo htmlspecialchars($drug['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 text-wrap text-start">
|
||||
<?php echo htmlspecialchars($drug['group_name'] ?? '-'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-nowrap"><?php echo htmlspecialchars($drug['expiry_date'] ?? '-'); ?></td>
|
||||
<td class="text-wrap" style="max-width: 150px;"><?php echo htmlspecialchars($drug['supplier_name'] ?? '-'); ?></td>
|
||||
<td class="text-secondary fw-bold"><?php echo number_format($drug['price'], 2); ?></td>
|
||||
<td class="text-end px-4 text-nowrap">
|
||||
<div class="btn-group shadow-sm border rounded bg-white">
|
||||
<button class="btn btn-link text-primary py-1 px-2 border-end"
|
||||
onclick="showEditDrugModal(<?php echo htmlspecialchars(json_encode($drug, 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="showDeleteDrugModal(<?php echo $drug['id']; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('delete'); ?>">
|
||||
<i class="bi bi-trash3"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif;
|
||||
$table_html = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalDrugs); ?> <?php echo __('of'); ?> <?php echo $totalDrugs; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page - 1; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $p; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page + 1; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif;
|
||||
$pagination_html = ob_get_clean();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['html' => $table_html, 'pagination' => $pagination_html]);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -53,7 +175,7 @@ $all_suppliers = $sStmt->fetchAll();
|
||||
<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 __('drug_name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>">
|
||||
<input type="text" name="name" id="drugSearchInput" class="form-control bg-light border-start-0" placeholder="<?php echo __('drug_name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
@ -80,15 +202,15 @@ $all_suppliers = $sStmt->fetchAll();
|
||||
<thead class="table-light text-secondary">
|
||||
<tr>
|
||||
<th class="px-4 py-3">#</th>
|
||||
<th class="py-3"><?php echo __('drug_name'); ?></th>
|
||||
<th class="py-3" style="width: 30%; min-width: 200px;"><?php echo __('drug_name'); ?></th>
|
||||
<th class="py-3"><?php echo __('drug_group'); ?></th>
|
||||
<th class="py-3"><?php echo __('expiry_date'); ?></th>
|
||||
<th class="py-3"><?php echo __('supplier'); ?></th>
|
||||
<th class="py-3" style="max-width: 150px;"><?php echo __('supplier'); ?></th>
|
||||
<th class="py-3"><?php echo __('price'); ?></th>
|
||||
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="drugsTableBody">
|
||||
<?php if (empty($drugs)): ?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-center py-5 text-muted">
|
||||
@ -102,24 +224,24 @@ $all_suppliers = $sStmt->fetchAll();
|
||||
<td class="px-4 fw-medium text-secondary"><?php echo $drug['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">
|
||||
<div class="bg-primary bg-opacity-10 text-primary p-2 rounded-circle me-3 flex-shrink-0">
|
||||
<i class="bi bi-capsule fs-5"></i>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-wrap" style="word-break: break-word;">
|
||||
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($drug['name_'.$lang]); ?></div>
|
||||
<small class="text-muted"><?php echo htmlspecialchars($drug['name_'.($lang == 'en' ? 'ar' : 'en')]); ?></small>
|
||||
<small class="text-muted d-block"><?php echo htmlspecialchars($drug['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">
|
||||
<span class="badge bg-info bg-opacity-10 text-info border border-info border-opacity-25 px-2 py-1 text-wrap text-start">
|
||||
<?php echo htmlspecialchars($drug['group_name'] ?? '-'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($drug['expiry_date'] ?? '-'); ?></td>
|
||||
<td><?php echo htmlspecialchars($drug['supplier_name'] ?? '-'); ?></td>
|
||||
<td class="text-nowrap"><?php echo htmlspecialchars($drug['expiry_date'] ?? '-'); ?></td>
|
||||
<td class="text-wrap" style="max-width: 150px;"><?php echo htmlspecialchars($drug['supplier_name'] ?? '-'); ?></td>
|
||||
<td class="text-secondary fw-bold"><?php echo number_format($drug['price'], 2); ?></td>
|
||||
<td class="text-end px-4">
|
||||
<td class="text-end px-4 text-nowrap">
|
||||
<div class="btn-group shadow-sm border rounded bg-white">
|
||||
<button class="btn btn-link text-primary py-1 px-2 border-end"
|
||||
onclick="showEditDrugModal(<?php echo htmlspecialchars(json_encode($drug, JSON_UNESCAPED_UNICODE)); ?>)"
|
||||
@ -139,6 +261,68 @@ $all_suppliers = $sStmt->fetchAll();
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div id="drugsPagination">
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalDrugs); ?> <?php echo __('of'); ?> <?php echo $totalDrugs; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page - 1; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2; // Number of pages around current page
|
||||
$pages_to_show = [];
|
||||
|
||||
// Always show first and last
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) {
|
||||
$pages_to_show[] = $totalPages;
|
||||
}
|
||||
|
||||
// Show range around current page
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) {
|
||||
$pages_to_show[] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicates and sort
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
// If there's a gap, show ellipsis
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $p; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page + 1; ?>&name=<?php echo urlencode($search_name); ?>&group_id=<?php echo urlencode($search_group); ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -325,4 +509,66 @@ function showDeleteDrugModal(id) {
|
||||
var modal = new bootstrap.Modal(document.getElementById('deleteDrugModal'));
|
||||
modal.show();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchInput = document.getElementById('drugSearchInput');
|
||||
const tableBody = document.getElementById('drugsTableBody');
|
||||
const paginationContainer = document.getElementById('drugsPagination');
|
||||
const groupIdSelect = document.querySelector('select[name="group_id"]');
|
||||
|
||||
let timeout = null;
|
||||
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', function() {
|
||||
const query = this.value.trim();
|
||||
const groupId = groupIdSelect ? groupIdSelect.value : '';
|
||||
|
||||
// Search after 2 chars or if cleared
|
||||
if (query.length >= 2 || query.length === 0) {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
fetchDrugs(query, groupId);
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (groupIdSelect) {
|
||||
groupIdSelect.addEventListener('change', function() {
|
||||
const query = searchInput ? searchInput.value.trim() : '';
|
||||
fetchDrugs(query, this.value);
|
||||
});
|
||||
}
|
||||
|
||||
function fetchDrugs(query, groupId) {
|
||||
if (tableBody) tableBody.style.opacity = '0.5';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (query) params.append('name', query);
|
||||
if (groupId) params.append('group_id', groupId);
|
||||
params.append('ajax_search', '1');
|
||||
|
||||
fetch('drugs.php?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (tableBody) {
|
||||
tableBody.innerHTML = data.html;
|
||||
tableBody.style.opacity = '1';
|
||||
}
|
||||
if (paginationContainer) {
|
||||
paginationContainer.innerHTML = data.pagination;
|
||||
}
|
||||
|
||||
// Re-initialize tooltips
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching drugs:', error);
|
||||
if (tableBody) tableBody.style.opacity = '1';
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -1,32 +1,156 @@
|
||||
<?php
|
||||
$search_name = $_GET['name'] ?? '';
|
||||
$search_group = $_GET['group_id'] ?? '';
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$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";
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($search_name) {
|
||||
$query .= " AND (t.name_en LIKE ? OR t.name_ar LIKE ?)";
|
||||
$where .= " AND (t.name_en LIKE ? OR t.name_ar LIKE ?)";
|
||||
$params[] = "%$search_name%";
|
||||
$params[] = "%$search_name%";
|
||||
}
|
||||
if ($search_group) {
|
||||
$query .= " AND t.group_id = ?";
|
||||
$where .= " AND t.group_id = ?";
|
||||
$params[] = $search_group;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY t.id DESC";
|
||||
// Count Total
|
||||
$countQuery = "SELECT COUNT(*) FROM laboratory_tests t $where";
|
||||
$stmt = $db->prepare($countQuery);
|
||||
$stmt->execute($params);
|
||||
$totalTests = $stmt->fetchColumn();
|
||||
$totalPages = ceil($totalTests / $limit);
|
||||
|
||||
// Fetch Data
|
||||
$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
|
||||
ORDER BY t.id DESC
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$tests = $stmt->fetchAll();
|
||||
|
||||
// Fetch all groups for filter dropdown
|
||||
// Fetch all groups for filter dropdown (only needed for initial load, but fast enough)
|
||||
$gStmt = $db->query("SELECT * FROM test_groups ORDER BY name_$lang");
|
||||
$all_test_groups = $gStmt->fetchAll();
|
||||
|
||||
// --- AJAX HANDLER ---
|
||||
if (isset($_GET['ajax_search'])) {
|
||||
ob_start();
|
||||
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;
|
||||
$table_html = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalTests); ?> <?php echo __('of'); ?> <?php echo $totalTests; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif;
|
||||
$pagination_html = ob_get_clean();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['html' => $table_html, 'pagination' => $pagination_html]);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -44,15 +168,15 @@ $all_test_groups = $gStmt->fetchAll();
|
||||
<!-- Search Bar -->
|
||||
<div class="card shadow-sm border-0 mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" action="" class="row g-3">
|
||||
<form id="testsSearchForm" class="row g-3" onsubmit="return false;">
|
||||
<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); ?>">
|
||||
<input type="text" name="name" id="testSearchName" 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">
|
||||
<select name="group_id" id="testSearchGroup" 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' : ''; ?>>
|
||||
@ -62,7 +186,7 @@ $all_test_groups = $gStmt->fetchAll();
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" class="btn btn-secondary w-100"><?php echo __('search'); ?></button>
|
||||
<button type="button" class="btn btn-secondary w-100" onclick="fetchTests(1)"><?php echo __('search'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -82,7 +206,7 @@ $all_test_groups = $gStmt->fetchAll();
|
||||
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="testsTableBody">
|
||||
<?php if (empty($tests)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center py-5 text-muted">
|
||||
@ -136,6 +260,56 @@ $all_test_groups = $gStmt->fetchAll();
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div id="testsPagination">
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalTests); ?> <?php echo __('of'); ?> <?php echo $totalTests; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -251,6 +425,74 @@ $all_test_groups = $gStmt->fetchAll();
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchName = document.getElementById('testSearchName');
|
||||
const searchGroup = document.getElementById('testSearchGroup');
|
||||
const paginationContainer = document.getElementById('testsPagination');
|
||||
|
||||
let timeout = null;
|
||||
|
||||
if (searchName) {
|
||||
searchName.addEventListener('input', function() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fetchTests(1), 300);
|
||||
});
|
||||
}
|
||||
|
||||
if (searchGroup) {
|
||||
searchGroup.addEventListener('change', function() {
|
||||
fetchTests(1);
|
||||
});
|
||||
}
|
||||
|
||||
if (paginationContainer) {
|
||||
paginationContainer.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
const link = e.target.closest('.page-link');
|
||||
if (link && !link.parentElement.classList.contains('disabled')) {
|
||||
const page = link.getAttribute('data-page');
|
||||
if (page) fetchTests(page);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function fetchTests(page) {
|
||||
const name = document.getElementById('testSearchName').value;
|
||||
const group = document.getElementById('testSearchGroup').value;
|
||||
const tableBody = document.getElementById('testsTableBody');
|
||||
const paginationContainer = document.getElementById('testsPagination');
|
||||
|
||||
if (tableBody) tableBody.style.opacity = '0.5';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (name) params.append('name', name);
|
||||
if (group) params.append('group_id', group);
|
||||
params.append('page', page);
|
||||
params.append('ajax_search', '1');
|
||||
|
||||
fetch('laboratory_tests.php?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (tableBody) {
|
||||
tableBody.innerHTML = data.html;
|
||||
tableBody.style.opacity = '1';
|
||||
}
|
||||
if (paginationContainer) {
|
||||
paginationContainer.innerHTML = data.pagination;
|
||||
}
|
||||
// Re-initialize tooltips
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching tests:', error);
|
||||
if (tableBody) tableBody.style.opacity = '1';
|
||||
});
|
||||
}
|
||||
|
||||
function resetTestModal() {
|
||||
document.getElementById('testModalTitle').textContent = '<?php echo __('add_test'); ?>';
|
||||
document.getElementById('testAction').value = 'add_test';
|
||||
@ -283,4 +525,4 @@ function showDeleteTestModal(id) {
|
||||
var modal = new bootstrap.Modal(document.getElementById('deleteTestModal'));
|
||||
modal.show();
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@ -1,27 +1,147 @@
|
||||
<?php
|
||||
$search_name = $_GET['name'] ?? '';
|
||||
$search_phone = $_GET['phone'] ?? '';
|
||||
$search_query = $_GET['search'] ?? '';
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
// Build Query
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($search_query) {
|
||||
$where .= " AND (p.name LIKE ? OR p.phone LIKE ?)";
|
||||
$params[] = "%$search_query%";
|
||||
$params[] = "%$search_query%";
|
||||
}
|
||||
|
||||
// Count Total
|
||||
$countQuery = "SELECT COUNT(*) FROM patients p $where";
|
||||
$stmt = $db->prepare($countQuery);
|
||||
$stmt->execute($params);
|
||||
$totalPatients = $stmt->fetchColumn();
|
||||
$totalPages = ceil($totalPatients / $limit);
|
||||
|
||||
// Fetch Data
|
||||
$query = "
|
||||
SELECT p.*, ic.name_$lang as insurance_name
|
||||
FROM patients p
|
||||
LEFT JOIN insurance_companies ic ON p.insurance_company_id = ic.id
|
||||
WHERE 1=1";
|
||||
$params = [];
|
||||
$where
|
||||
ORDER BY p.id DESC
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
if ($search_name) {
|
||||
$query .= " AND p.name LIKE ?";
|
||||
$params[] = "%$search_name%";
|
||||
}
|
||||
if ($search_phone) {
|
||||
$query .= " AND p.phone LIKE ?";
|
||||
$params[] = "%$search_phone%";
|
||||
}
|
||||
|
||||
$query .= " ORDER BY p.id DESC";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$patients = $stmt->fetchAll();
|
||||
|
||||
// --- AJAX HANDLER ---
|
||||
if (isset($_GET['ajax_search'])) {
|
||||
ob_start();
|
||||
if (empty($patients)):
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-people display-4 d-block mb-3"></i>
|
||||
<?php echo __('no_patients_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($patients as $p): ?>
|
||||
<tr>
|
||||
<td class="px-4">
|
||||
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($p['name']); ?></div>
|
||||
<small class="text-muted"><?php echo $p['dob']; ?></small>
|
||||
</td>
|
||||
<td><?php echo calculate_age($p['dob']); ?></td>
|
||||
<td><?php echo htmlspecialchars($p['phone']); ?></td>
|
||||
<td>
|
||||
<span class="badge <?php echo $p['insurance_name'] ? 'bg-primary bg-opacity-10 text-primary border border-primary border-opacity-25' : 'bg-secondary bg-opacity-10 text-secondary border border-secondary border-opacity-25'; ?> px-2 py-1">
|
||||
<?php echo $p['insurance_name'] ?: __('not_insured'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-secondary"><?php echo htmlspecialchars($p['policy_number'] ?: '-'); ?></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="showEditPatientModal(<?php echo htmlspecialchars(json_encode($p, 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-info py-1 px-2 border-end"
|
||||
onclick="showRecordVisitModal(<?php echo $p['id']; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('add_visit'); ?>">
|
||||
<i class="bi bi-clipboard2-plus"></i>
|
||||
</button>
|
||||
<button class="btn btn-link text-success py-1 px-2 border-end"
|
||||
onclick="showBillModal(null, <?php echo $p['id']; ?>, <?php echo htmlspecialchars(json_encode($p['name'], JSON_UNESCAPED_UNICODE)); ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('add_bill'); ?>">
|
||||
<i class="bi bi-receipt"></i>
|
||||
</button>
|
||||
<button class="btn btn-link text-danger py-1 px-2"
|
||||
onclick="showDeletePatientModal(<?php echo $p['id']; ?>, <?php echo htmlspecialchars(json_encode($p['name'], JSON_UNESCAPED_UNICODE)); ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('delete'); ?>">
|
||||
<i class="bi bi-trash3"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif;
|
||||
$table_html = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalPatients); ?> <?php echo __('of'); ?> <?php echo $totalPatients; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page - 1; ?>&search=<?php echo urlencode($search_query); ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $p; ?>&search=<?php echo urlencode($search_query); ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page + 1; ?>&search=<?php echo urlencode($search_query); ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif;
|
||||
$pagination_html = ob_get_clean();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['html' => $table_html, 'pagination' => $pagination_html]);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -35,16 +155,10 @@ $patients = $stmt->fetchAll();
|
||||
<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-5">
|
||||
<div class="col-md-10">
|
||||
<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 __('name'); ?>" value="<?php echo htmlspecialchars($search_name); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-telephone"></i></span>
|
||||
<input type="text" name="phone" class="form-control bg-light border-start-0" placeholder="<?php echo __('phone'); ?>" value="<?php echo htmlspecialchars($search_phone); ?>">
|
||||
<input type="text" name="search" id="patientSearchInput" class="form-control bg-light border-start-0" placeholder="<?php echo __('name') . ' ' . __('or') . ' ' . __('phone'); ?>" value="<?php echo htmlspecialchars($search_query); ?>" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
@ -68,12 +182,12 @@ $patients = $stmt->fetchAll();
|
||||
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="patientsTableBody">
|
||||
<?php if (empty($patients)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-people display-4 d-block mb-3"></i>
|
||||
No patients found.
|
||||
<?php echo __('no_patients_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
@ -121,5 +235,109 @@ $patients = $stmt->fetchAll();
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div id="patientsPagination">
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalPatients); ?> <?php echo __('of'); ?> <?php echo $totalPatients; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page - 1; ?>&search=<?php echo urlencode($search_query); ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $p; ?>&search=<?php echo urlencode($search_query); ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="?page=<?php echo $page + 1; ?>&search=<?php echo urlencode($search_query); ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchInput = document.getElementById('patientSearchInput');
|
||||
const tableBody = document.getElementById('patientsTableBody');
|
||||
const paginationContainer = document.getElementById('patientsPagination');
|
||||
|
||||
let timeout = null;
|
||||
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', function() {
|
||||
const query = this.value.trim();
|
||||
|
||||
// Search after 2 chars or if cleared
|
||||
if (query.length >= 2 || query.length === 0) {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
fetchPatients(query);
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fetchPatients(query) {
|
||||
if (tableBody) tableBody.style.opacity = '0.5';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (query) params.append('search', query);
|
||||
params.append('ajax_search', '1');
|
||||
|
||||
fetch('patients.php?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (tableBody) {
|
||||
tableBody.innerHTML = data.html;
|
||||
tableBody.style.opacity = '1';
|
||||
}
|
||||
if (paginationContainer) {
|
||||
paginationContainer.innerHTML = data.pagination;
|
||||
}
|
||||
|
||||
// Re-initialize tooltips
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching patients:', error);
|
||||
if (tableBody) tableBody.style.opacity = '1';
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -2,30 +2,49 @@
|
||||
$search_patient = $_GET['patient'] ?? '';
|
||||
$search_doctor = $_GET['doctor'] ?? '';
|
||||
$search_date = $_GET['date'] ?? '';
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = 10;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$where = "WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($search_patient) {
|
||||
$where .= " AND p.name LIKE ?";
|
||||
$params[] = "%$search_patient%";
|
||||
}
|
||||
if ($search_doctor) {
|
||||
$where .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$params[] = "%$search_doctor%";
|
||||
$params[] = "%$search_doctor%";
|
||||
}
|
||||
if ($search_date) {
|
||||
$where .= " AND DATE(v.visit_date) = ?";
|
||||
$params[] = $search_date;
|
||||
}
|
||||
|
||||
// Count Total
|
||||
$countQuery = "
|
||||
SELECT COUNT(*)
|
||||
FROM visits v
|
||||
JOIN patients p ON v.patient_id = p.id
|
||||
JOIN doctors d ON v.doctor_id = d.id
|
||||
$where";
|
||||
$stmt = $db->prepare($countQuery);
|
||||
$stmt->execute($params);
|
||||
$totalVisits = $stmt->fetchColumn();
|
||||
$totalPages = ceil($totalVisits / $limit);
|
||||
|
||||
// Fetch Data
|
||||
$query = "
|
||||
SELECT v.*, p.name as patient_name, p.dob as patient_dob, p.gender as patient_gender, d.name_$lang as doctor_name
|
||||
FROM visits v
|
||||
JOIN patients p ON v.patient_id = p.id
|
||||
JOIN doctors d ON v.doctor_id = d.id
|
||||
WHERE 1=1";
|
||||
$params = [];
|
||||
$where
|
||||
ORDER BY v.visit_date DESC
|
||||
LIMIT $limit OFFSET $offset";
|
||||
|
||||
if ($search_patient) {
|
||||
$query .= " AND p.name LIKE ?";
|
||||
$params[] = "%$search_patient%";
|
||||
}
|
||||
if ($search_doctor) {
|
||||
$query .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
||||
$params[] = "%$search_doctor%";
|
||||
$params[] = "%$search_doctor%";
|
||||
}
|
||||
if ($search_date) {
|
||||
$query .= " AND DATE(v.visit_date) = ?";
|
||||
$params[] = $search_date;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY v.visit_date DESC";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$raw_visits = $stmt->fetchAll();
|
||||
@ -49,6 +68,166 @@ foreach ($raw_visits as $v) {
|
||||
|
||||
$visits[] = $v;
|
||||
}
|
||||
|
||||
// --- AJAX HANDLER ---
|
||||
if (isset($_GET['ajax_search'])) {
|
||||
ob_start();
|
||||
if (empty($visits)):
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="9" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-clipboard2-pulse display-4 d-block mb-3"></i>
|
||||
<?php echo __('no_visits_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($visits as $v): ?>
|
||||
<tr>
|
||||
<td class="px-4 text-muted small"><?php echo $v['id']; ?></td>
|
||||
<td class="text-secondary"><?php echo date('Y-m-d H:i', strtotime($v['visit_date'])); ?></td>
|
||||
<td class="fw-semibold text-dark"><?php echo htmlspecialchars($v['patient_name'] ?? ''); ?></td>
|
||||
<td class="text-secondary"><?php echo htmlspecialchars($v['doctor_name'] ?? ''); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$diagnosis_plain = strip_tags($v['diagnosis'] ?? '');
|
||||
$snippet = mb_strimwidth($diagnosis_plain, 0, 30, "...");
|
||||
?>
|
||||
<small class="text-muted" title="<?php echo htmlspecialchars($diagnosis_plain); ?>"><?php echo htmlspecialchars($snippet); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$vitals = [];
|
||||
if(!empty($v['blood_pressure'])) $vitals[] = '<i class="bi bi-heart-pulse me-1"></i>' . htmlspecialchars($v['blood_pressure'] ?? '');
|
||||
if(!empty($v['weight'])) $vitals[] = '<i class="bi bi-speedometer2 me-1"></i>' . htmlspecialchars($v['weight'] ?? '') . 'kg';
|
||||
if(!empty($v['temperature'])) $vitals[] = '<i class="bi bi-thermometer-half me-1"></i>' . htmlspecialchars($v['temperature'] ?? '') . '°C';
|
||||
echo implode('<br>', $vitals);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$treatment_plain = strip_tags($v['treatment_plan'] ?? '');
|
||||
$t_snippet = mb_strimwidth($treatment_plain, 0, 30, "...");
|
||||
?>
|
||||
<small class="text-muted" title="<?php echo htmlspecialchars($treatment_plain); ?>"><?php echo htmlspecialchars($t_snippet); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex gap-1">
|
||||
<?php if (!empty($v['lab_inquiries'])): ?>
|
||||
<span class="badge bg-info text-white" title="<?php echo count($v['lab_inquiries']); ?> <?php echo __('laboratory'); ?>" data-bs-toggle="tooltip">
|
||||
<i class="bi bi-flask"></i> <?php echo count($v['lab_inquiries']); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($v['xray_inquiries'])): ?>
|
||||
<span class="badge bg-dark text-white" title="<?php echo count($v['xray_inquiries']); ?> <?php echo __('xray'); ?>" data-bs-toggle="tooltip">
|
||||
<i class="bi bi-camera"></i> <?php echo count($v['xray_inquiries']); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-end px-4">
|
||||
<div class="d-flex justify-content-end gap-1">
|
||||
<?php
|
||||
// Encode safely for attribute
|
||||
$json_v = htmlspecialchars(json_encode($v, JSON_UNESCAPED_UNICODE) ?: '{}', ENT_QUOTES, 'UTF-8');
|
||||
$patient_name_json = htmlspecialchars(json_encode($v['patient_name'] ?? '', JSON_UNESCAPED_UNICODE) ?: '""', ENT_QUOTES, 'UTF-8');
|
||||
?>
|
||||
<button class="btn btn-sm btn-outline-success"
|
||||
onclick="showVisitResultsModal(JSON.parse(this.getAttribute('data-visit')))"
|
||||
data-visit="<?php echo $json_v; ?>"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('view_results'); ?>">
|
||||
<i class="bi bi-eye"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-warning"
|
||||
onclick="showEditVisitModal(JSON.parse(this.getAttribute('data-visit')))"
|
||||
data-visit="<?php echo $json_v; ?>"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('edit'); ?>">
|
||||
<i class="bi bi-pencil-square"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-info"
|
||||
onclick="showLabInquiryModalFromVisit(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('add_inquiry'); ?>">
|
||||
<i class="bi bi-flask"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-dark"
|
||||
onclick="showXrayInquiryModalFromVisit(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('add_xray_inquiry'); ?>">
|
||||
<i class="bi bi-camera"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-primary"
|
||||
onclick="showReportModal(<?php echo $v['id']; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('new_report'); ?>">
|
||||
<i class="bi bi-file-earmark-plus"></i>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-success"
|
||||
onclick="showBillModal(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('create_bill'); ?>">
|
||||
<i class="bi bi-receipt"></i>
|
||||
</button>
|
||||
<a href="print_prescription.php?visit_id=<?php echo $v['id']; ?>" target="_blank"
|
||||
class="btn btn-sm btn-outline-dark"
|
||||
data-bs-toggle="tooltip" title="<?php echo __('print_prescription'); ?>">
|
||||
<i class="bi bi-printer"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif;
|
||||
$table_html = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalVisits); ?> <?php echo __('of'); ?> <?php echo $totalVisits; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif;
|
||||
$pagination_html = ob_get_clean();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['html' => $table_html, 'pagination' => $pagination_html]);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -61,27 +240,27 @@ foreach ($raw_visits as $v) {
|
||||
<!-- Search Bar -->
|
||||
<div class="card shadow-sm border-0 mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" action="" class="row g-3">
|
||||
<form id="visitsSearchForm" class="row g-3" onsubmit="return false;">
|
||||
<div class="col-md-3">
|
||||
<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="patient" class="form-control bg-light border-start-0" placeholder="<?php echo __('patient'); ?>" value="<?php echo htmlspecialchars($search_patient); ?>">
|
||||
<input type="text" name="patient" id="visitSearchPatient" class="form-control bg-light border-start-0" placeholder="<?php echo __('patient'); ?>" value="<?php echo htmlspecialchars($search_patient); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-person-badge"></i></span>
|
||||
<input type="text" name="doctor" class="form-control bg-light border-start-0" placeholder="<?php echo __('doctor'); ?>" value="<?php echo htmlspecialchars($search_doctor); ?>">
|
||||
<input type="text" name="doctor" id="visitSearchDoctor" class="form-control bg-light border-start-0" placeholder="<?php echo __('doctor'); ?>" value="<?php echo htmlspecialchars($search_doctor); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-calendar-event"></i></span>
|
||||
<input type="date" name="date" class="form-control bg-light border-start-0" value="<?php echo htmlspecialchars($search_date); ?>">
|
||||
<input type="date" name="date" id="visitSearchDate" class="form-control bg-light border-start-0" value="<?php echo htmlspecialchars($search_date); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="submit" class="btn btn-secondary w-100"><?php echo __('search'); ?></button>
|
||||
<button type="button" class="btn btn-secondary w-100" onclick="fetchVisits(1)"><?php echo __('search'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -104,12 +283,12 @@ foreach ($raw_visits as $v) {
|
||||
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="visitsTableBody">
|
||||
<?php if (empty($visits)): ?>
|
||||
<tr>
|
||||
<td colspan="9" class="text-center py-5 text-muted">
|
||||
<i class="bi bi-clipboard2-pulse display-4 d-block mb-3"></i>
|
||||
No visits found.
|
||||
<?php echo __('no_visits_found'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
@ -208,5 +387,124 @@ foreach ($raw_visits as $v) {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div id="visitsPagination">
|
||||
<?php if ($totalPages > 1): ?>
|
||||
<div class="d-flex justify-content-between align-items-center p-3 border-top">
|
||||
<div class="text-muted small">
|
||||
<?php echo __('showing'); ?> <?php echo $offset + 1; ?> - <?php echo min($offset + $limit, $totalVisits); ?> <?php echo __('of'); ?> <?php echo $totalVisits; ?>
|
||||
</div>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page - 1; ?>" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$range = 2;
|
||||
$pages_to_show = [];
|
||||
$pages_to_show[] = 1;
|
||||
if ($totalPages > 1) { $pages_to_show[] = $totalPages; }
|
||||
for ($i = $page - $range; $i <= $page + $range; $i++) {
|
||||
if ($i > 1 && $i < $totalPages) { $pages_to_show[] = $i; }
|
||||
}
|
||||
$pages_to_show = array_unique($pages_to_show);
|
||||
sort($pages_to_show);
|
||||
|
||||
$prev_page = 0;
|
||||
foreach ($pages_to_show as $p):
|
||||
if ($prev_page > 0 && $p > $prev_page + 1): ?>
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item <?php echo $page == $p ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $p; ?>">
|
||||
<?php echo $p; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
$prev_page = $p;
|
||||
endforeach;
|
||||
?>
|
||||
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
|
||||
<a class="page-link" href="#" data-page="<?php echo $page + 1; ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchPatient = document.getElementById('visitSearchPatient');
|
||||
const searchDoctor = document.getElementById('visitSearchDoctor');
|
||||
const searchDate = document.getElementById('visitSearchDate');
|
||||
const paginationContainer = document.getElementById('visitsPagination');
|
||||
|
||||
let timeout = null;
|
||||
|
||||
function debounceSearch() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fetchVisits(1), 300);
|
||||
}
|
||||
|
||||
if (searchPatient) searchPatient.addEventListener('input', debounceSearch);
|
||||
if (searchDoctor) searchDoctor.addEventListener('input', debounceSearch);
|
||||
if (searchDate) searchDate.addEventListener('change', () => fetchVisits(1));
|
||||
|
||||
if (paginationContainer) {
|
||||
paginationContainer.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
const link = e.target.closest('.page-link');
|
||||
if (link && !link.parentElement.classList.contains('disabled')) {
|
||||
const page = link.getAttribute('data-page');
|
||||
if (page) fetchVisits(page);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function fetchVisits(page) {
|
||||
const patient = document.getElementById('visitSearchPatient').value;
|
||||
const doctor = document.getElementById('visitSearchDoctor').value;
|
||||
const date = document.getElementById('visitSearchDate').value;
|
||||
const tableBody = document.getElementById('visitsTableBody');
|
||||
const paginationContainer = document.getElementById('visitsPagination');
|
||||
|
||||
if (tableBody) tableBody.style.opacity = '0.5';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (patient) params.append('patient', patient);
|
||||
if (doctor) params.append('doctor', doctor);
|
||||
if (date) params.append('date', date);
|
||||
params.append('page', page);
|
||||
params.append('ajax_search', '1');
|
||||
|
||||
fetch('visits.php?' + params.toString())
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (tableBody) {
|
||||
tableBody.innerHTML = data.html;
|
||||
tableBody.style.opacity = '1';
|
||||
}
|
||||
if (paginationContainer) {
|
||||
paginationContainer.innerHTML = data.pagination;
|
||||
}
|
||||
// Re-initialize tooltips
|
||||
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
||||
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
||||
return new bootstrap.Tooltip(tooltipTriggerEl)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching visits:', error);
|
||||
if (tableBody) tableBody.style.opacity = '1';
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -8,7 +8,15 @@ $lang = $_SESSION['lang'];
|
||||
|
||||
require_once __DIR__ . '/includes/actions.php';
|
||||
require_once __DIR__ . '/includes/common_data.php';
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
|
||||
$is_ajax = isset($_GET['ajax_search']) || isset($_POST['ajax_search']);
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/pages/laboratory_tests.php';
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
?>
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
}
|
||||
|
||||
6
lang.php
6
lang.php
@ -248,6 +248,8 @@ $translations = [
|
||||
'csv_format_drugs' => 'CSV Format: Name (EN), Name (AR), Group Name, Price, Expiry Date (YYYY-MM-DD), Supplier Name',
|
||||
'csv_format_groups' => 'CSV Format: Name (EN), Name (AR)',
|
||||
'save_visit_to_add_inquiries' => 'Please save the visit first to add inquiries.',
|
||||
'or' => 'or',
|
||||
'no_patients_found' => 'No patients found',
|
||||
],
|
||||
'ar' => [
|
||||
'attachment' => 'المرفق',
|
||||
@ -499,5 +501,7 @@ $translations = [
|
||||
'csv_format_drugs' => 'تنسيق CSV: الاسم (إنجليزي)، الاسم (عربي)، اسم المجموعة، السعر، تاريخ الانتهاء، اسم المورد',
|
||||
'csv_format_groups' => 'تنسيق CSV: الاسم (إنجليزي)، الاسم (عربي)',
|
||||
'save_visit_to_add_inquiries' => 'يرجى حفظ الزيارة أولاً لإضافة الاستفسارات.',
|
||||
'or' => 'أو',
|
||||
'no_patients_found' => 'لم يتم العثور على مرضى',
|
||||
]
|
||||
];
|
||||
];
|
||||
11
patients.php
11
patients.php
@ -8,6 +8,13 @@ $lang = $_SESSION['lang'];
|
||||
|
||||
require_once __DIR__ . '/includes/actions.php';
|
||||
require_once __DIR__ . '/includes/common_data.php';
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
|
||||
if (!isset($_GET['ajax_search'])) {
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/pages/patients.php';
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
|
||||
if (!isset($_GET['ajax_search'])) {
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
}
|
||||
13
visits.php
13
visits.php
@ -8,6 +8,15 @@ $lang = $_SESSION['lang'];
|
||||
|
||||
require_once __DIR__ . '/includes/actions.php';
|
||||
require_once __DIR__ . '/includes/common_data.php';
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
|
||||
$is_ajax = isset($_GET['ajax_search']) || isset($_POST['ajax_search']);
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/header.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/includes/pages/visits.php';
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
|
||||
if (!$is_ajax) {
|
||||
require_once __DIR__ . '/includes/layout/footer.php';
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user