136 lines
6.3 KiB
PHP
136 lines
6.3 KiB
PHP
<?php
|
|
$search_name = $_GET['name'] ?? '';
|
|
$search_group = $_GET['group_id'] ?? '';
|
|
|
|
$query = "
|
|
SELECT d.*, g.name_$lang as group_name
|
|
FROM drugs d
|
|
LEFT JOIN drugs_groups g ON d.group_id = g.id
|
|
WHERE 1=1";
|
|
$params = [];
|
|
|
|
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();
|
|
|
|
// Fetch all groups for filter dropdown
|
|
$gStmt = $db->query("SELECT * FROM drugs_groups ORDER BY name_$lang");
|
|
$all_drug_groups = $gStmt->fetchAll();
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h3 class="fw-bold text-secondary"><?php echo __('drugs'); ?></h3>
|
|
<button class="btn btn-primary shadow-sm" data-bs-toggle="modal" data-bs-target="#addDrugModal">
|
|
<i class="bi bi-plus-circle me-1"></i> <?php echo __('add_drug'); ?>
|
|
</button>
|
|
</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 __('drug_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 __('drug_group'); ?> (<?php echo __('all'); ?>)</option>
|
|
<?php foreach ($all_drug_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 __('drug_name'); ?></th>
|
|
<th class="py-3"><?php echo __('drug_group'); ?></th>
|
|
<th class="py-3"><?php echo __('default_dosage'); ?></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($drugs)): ?>
|
|
<tr>
|
|
<td colspan="6" 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">
|
|
<i class="bi bi-capsule fs-5"></i>
|
|
</div>
|
|
<div>
|
|
<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>
|
|
</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($drug['group_name'] ?? '-'); ?>
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="text-muted small italic">
|
|
<?php echo htmlspecialchars($drug['default_dosage'] ?? '-'); ?>
|
|
</span>
|
|
</td>
|
|
<td class="text-secondary fw-bold"><?php echo number_format($drug['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="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; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|