ليس لديك صلاحية للوصول إلى هذه الصفحة."; require_once 'includes/footer.php'; exit; } $error = ''; $success = ''; // Handle Form Submissions if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['save_employee'])) { if (!canAdd('hr_employees') && !canEdit('hr_employees')) { $error = "لا تملك صلاحية التعديل."; } else { $id = !empty($_POST['id']) ? $_POST['id'] : null; $first_name = trim($_POST['first_name']); $last_name = trim($_POST['last_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $department_id = !empty($_POST['department_id']) ? $_POST['department_id'] : null; $job_title = trim($_POST['job_title']); $basic_salary = floatval($_POST['basic_salary']); $join_date = $_POST['join_date']; $status = $_POST['status']; $gender = $_POST['gender']; $birth_date = !empty($_POST['birth_date']) ? $_POST['birth_date'] : null; if (empty($first_name) || empty($last_name) || empty($join_date)) { $error = "يرجى تعبئة الحقول الإلزامية."; } else { try { if ($id) { // Update $stmt = db()->prepare("UPDATE hr_employees SET first_name=?, last_name=?, email=?, phone=?, department_id=?, job_title=?, basic_salary=?, join_date=?, status=?, gender=?, birth_date=? WHERE id=?"); $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date, $id]); $success = "تم تحديث بيانات الموظف بنجاح."; } else { // Insert $stmt = db()->prepare("INSERT INTO hr_employees (first_name, last_name, email, phone, department_id, job_title, basic_salary, join_date, status, gender, birth_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date]); $success = "تم إضافة الموظف بنجاح."; } } catch (PDOException $e) { $error = "خطأ في قاعدة البيانات: " . $e->getMessage(); } } } } elseif (isset($_POST['delete_employee'])) { if (!canDelete('hr_employees')) { $error = "لا تملك صلاحية الحذف."; } else { $id = $_POST['id']; try { $stmt = db()->prepare("DELETE FROM hr_employees WHERE id = ?"); $stmt->execute([$id]); $success = "تم حذف الموظف بنجاح."; } catch (PDOException $e) { $error = "لا يمكن حذف الموظف لوجود سجلات مرتبطة به."; } } } elseif (isset($_POST['save_department'])) { $dept_name = trim($_POST['name']); if (!empty($dept_name)) { $stmt = db()->prepare("INSERT INTO hr_departments (name) VALUES (?)"); $stmt->execute([$dept_name]); $success = "تم إضافة القسم بنجاح."; } } elseif (isset($_POST['delete_department'])) { $dept_id = $_POST['id']; try { $stmt = db()->prepare("DELETE FROM hr_departments WHERE id = ?"); $stmt->execute([$dept_id]); $success = "تم حذف القسم."; } catch (PDOException $e) { $error = "لا يمكن حذف القسم لأنه مرتبط بموظفين."; } } } // Fetch Departments for Dropdown $departments = db()->query("SELECT * FROM hr_departments ORDER BY name")->fetchAll(); // Pagination $page = $_GET['page'] ?? 1; $perPage = 10; $totalEmployees = db()->query("SELECT COUNT(*) FROM hr_employees")->fetchColumn(); $pagination = getPagination($page, $totalEmployees, $perPage); ?>

إدارة الموظفين

prepare($sql); $stmt->bindValue(1, $pagination['limit'], PDO::PARAM_INT); $stmt->bindValue(2, $pagination['offset'], PDO::PARAM_INT); $stmt->execute(); while ($row = $stmt->fetch()): ?>
الاسم القسم المسمى الوظيفي تاريخ التعيين الحالة الإجراءات
'success', 'terminated' => 'danger', 'resigned' => 'warning', 'on_leave' => 'info', default => 'secondary' }; ?>