38960-vm/includes/pages/employees.php
2026-03-04 06:26:39 +00:00

146 lines
7.2 KiB
PHP

<?php
$search_name = $_GET['name'] ?? '';
$search_mobile = $_GET['mobile'] ?? '';
$search_dept = $_GET['department_id'] ?? '';
$query = "
SELECT e.*, dept.name_$lang as department_name
FROM employees e
LEFT JOIN departments dept ON e.department_id = dept.id
WHERE 1=1";
$params = [];
if ($search_name) {
$query .= " AND (e.name_en LIKE ? OR e.name_ar LIKE ?)";
$params[] = "%$search_name%";
$params[] = "%$search_name%";
}
if ($search_mobile) {
$query .= " AND e.mobile LIKE ?";
$params[] = "%$search_mobile%";
}
if ($search_dept) {
$query .= " AND e.department_id = ?";
$params[] = $search_dept;
}
$query .= " ORDER BY e.id DESC";
$stmt = $db->prepare($query);
$stmt->execute($params);
$employees = $stmt->fetchAll();
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="fw-bold text-secondary"><?php echo __('employees'); ?></h3>
<button class="btn btn-primary shadow-sm" data-bs-toggle="modal" data-bs-target="#addEmployeeModal">
<i class="bi bi-person-plus me-1"></i> <?php echo __('add_employee'); ?>
</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-4">
<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-3">
<div class="input-group">
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-phone"></i></span>
<input type="text" name="mobile" class="form-control bg-light border-start-0" placeholder="<?php echo __('mobile'); ?>" value="<?php echo htmlspecialchars($search_mobile); ?>">
</div>
</div>
<div class="col-md-3">
<select name="department_id" 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' : ''; ?>>
<?php echo htmlspecialchars($dept['name']); ?>
</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 __('name'); ?></th>
<th class="py-3"><?php echo __('dob'); ?></th>
<th class="py-3"><?php echo __('contact_info'); ?></th>
<th class="py-3"><?php echo __('department'); ?></th>
<th class="py-3"><?php echo __('passion'); ?></th>
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php if (empty($employees)): ?>
<tr>
<td colspan="7" class="text-center py-5 text-muted">
<i class="bi bi-person-workspace display-4 d-block mb-3"></i>
<?php echo __('no_employees_found'); ?>
</td>
</tr>
<?php else: ?>
<?php foreach ($employees as $emp): ?>
<tr>
<td class="px-4 fw-medium text-secondary"><?php echo $emp['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-person fs-5"></i>
</div>
<div>
<div class="fw-semibold text-dark"><?php echo htmlspecialchars($emp['name_'.$lang]); ?></div>
<small class="text-muted"><?php echo htmlspecialchars($emp['name_'.($lang == 'en' ? 'ar' : 'en')]); ?></small>
</div>
</div>
</td>
<td><?php echo htmlspecialchars($emp['dob'] ?: '-'); ?></td>
<td>
<div class="d-flex flex-column">
<small class="text-secondary"><i class="bi bi-phone me-1"></i><?php echo htmlspecialchars($emp['mobile'] ?: '-'); ?></small>
<small class="text-muted"><i class="bi bi-envelope me-1"></i><?php echo htmlspecialchars($emp['email'] ?: '-'); ?></small>
</div>
</td>
<td class="text-secondary"><?php echo htmlspecialchars($emp['department_name'] ?? '-'); ?></td>
<td>
<small class="text-muted d-block" style="max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
<?php echo htmlspecialchars($emp['passion_'.$lang] ?: '-'); ?>
</small>
</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="showEditEmployeeModal(<?php echo htmlspecialchars(json_encode($emp)); ?>)"
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="showDeleteEmployeeModal(<?php echo $emp['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>