diff --git a/hr_employees.php b/hr_employees.php index d49bfcd..62bf167 100644 --- a/hr_employees.php +++ b/hr_employees.php @@ -21,6 +21,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = !empty($_POST['id']) ? $_POST['id'] : null; $first_name = trim($_POST["first_name"]); $zkteco_uid = !empty($_POST["zkteco_uid"]) ? trim($_POST["zkteco_uid"]) : null; + $user_id = !empty($_POST["user_id"]) ? $_POST["user_id"] : null; $last_name = trim($_POST['last_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); @@ -38,13 +39,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { 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=?, zkteco_uid=? WHERE id=?"); - $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date, $zkteco_uid, $id]); + $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=?, zkteco_uid=?, user_id=? WHERE id=?"); + $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date, $zkteco_uid, $user_id, $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, zkteco_uid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); - $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date, $zkteco_uid]); + $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, zkteco_uid, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$first_name, $last_name, $email, $phone, $department_id, $job_title, $basic_salary, $join_date, $status, $gender, $birth_date, $zkteco_uid, $user_id]); $success = "تم إضافة الموظف بنجاح."; } } catch (PDOException $e) { @@ -86,6 +87,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Fetch Departments for Dropdown $departments = db()->query("SELECT * FROM hr_departments ORDER BY name")->fetchAll(); +$users = db()->query("SELECT id, full_name, email FROM users ORDER BY full_name")->fetchAll(); // Pagination $page = $_GET['page'] ?? 1; @@ -188,6 +190,15 @@ $pagination = getPagination($page, $totalEmployees, $perPage); +
+ + +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ + + إلغاء + +
+ +
+ +
@@ -212,7 +287,10 @@ $requests = db()->query($sql)->fetchAll();
- +
diff --git a/includes/header.php b/includes/header.php index 0ab61db..5cb6107 100644 --- a/includes/header.php +++ b/includes/header.php @@ -578,6 +578,7 @@ $is_admin_open = in_array($cp, $admin_pages); diff --git a/my_leaves.php b/my_leaves.php new file mode 100644 index 0000000..934400e --- /dev/null +++ b/my_leaves.php @@ -0,0 +1,215 @@ +يرجى تسجيل الدخول."; + require_once 'includes/footer.php'; + exit; +} + +$user_id = $_SESSION['user_id']; +$error = ''; +$success = ''; +if (isset($_SESSION["success"])) { + $success = $_SESSION["success"]; + unset($_SESSION["success"]); +} + +// Check if current user is linked to an employee +$stmt = db()->prepare("SELECT id, first_name, last_name, department_id FROM hr_employees WHERE user_id = ? AND status = 'active'"); +$stmt->execute([$user_id]); +$employee = $stmt->fetch(); + +if (!$employee) { + echo "
"; + echo "
"; + echo "

لم يتم العثور على ملف موظف مرتبط بحسابك

"; + echo "

يرجى التواصل مع قسم الموارد البشرية لربط حسابك بملف الموظف الخاص بك لتتمكن من تقديم طلبات الإجازات.

"; + echo "
"; + require_once 'includes/footer.php'; + exit; +} + +$emp_id = $employee['id']; + +// Handle Form Submissions +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['request_leave'])) { + $type = $_POST['leave_type']; + $start = $_POST['start_date']; + $end = $_POST['end_date']; + $reason = trim($_POST['reason']); + + $start_dt = new DateTime($start); + $end_dt = new DateTime($end); + $days = $end_dt->diff($start_dt)->days + 1; + + if ($days <= 0) { + $error = "تاريخ النهاية يجب أن يكون بعد أو نفس تاريخ البداية."; + } else { + try { + $stmt = db()->prepare("INSERT INTO hr_leaves (employee_id, leave_type, start_date, end_date, days_count, reason, status) VALUES (?, ?, ?, ?, ?, ?, 'pending')"); + $stmt->execute([$emp_id, $type, $start, $end, $days, $reason]); + $_SESSION["success"] = "تم تقديم طلب الإجازة بنجاح، بانتظار الاعتماد."; header("Location: my_leaves.php"); exit; + } catch (PDOException $e) { + $error = "حدث خطأ أثناء تقديم الطلب: " . $e->getMessage(); + } + } + } +} + +// Pagination +$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; +if ($page < 1) $page = 1; +$limit = 10; +$offset = ($page - 1) * $limit; + +// Fetch My Leaves +$countStmt = db()->prepare("SELECT COUNT(*) FROM hr_leaves WHERE employee_id = ?"); +$countStmt->execute([$emp_id]); +$totalFiltered = $countStmt->fetchColumn(); + +$sql = "SELECT l.*, u.full_name as approver_name + FROM hr_leaves l + LEFT JOIN users u ON l.approved_by = u.id + WHERE l.employee_id = ? + ORDER BY l.created_at DESC + LIMIT $limit OFFSET $offset"; +$stmt = db()->prepare($sql); +$stmt->execute([$emp_id]); +$requests = $stmt->fetchAll(); + +?> + +
+

إجازاتي

+
+ +
+
+ + +
+ + +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
نوع الإجازةالفترةالمدةالسببتاريخ التقديمالحالةالمعتمد
لا توجد طلبات إجازات سابقة.
+ 'سنوية', + 'sick' => 'مرضية', + 'unpaid' => 'بدون راتب', + 'maternity' => 'أمومة', + 'emergency' => 'طارئة', + 'other' => 'أخرى' + ]; + echo $type_map[$req['leave_type']] ?? $req['leave_type']; + ?> + + من
إلى +
يوم + 'success', + 'rejected' => 'danger', + default => 'warning' + }; + $status_txt = match($req['status']) { + 'approved' => 'مقبولة', + 'rejected' => 'مرفوضة', + default => 'معلقة' + }; + ?> + +
+
+ + + +
+
+ + + + + diff --git a/view_mail.php b/view_mail.php index 54d33dc..8012633 100644 --- a/view_mail.php +++ b/view_mail.php @@ -311,11 +311,7 @@ if ($type == 'internal') {
لا يوجد محتوى إضافي'; - } else { - echo nl2br(htmlspecialchars($mail['description'] ?: 'لا يوجد محتوى إضافي')); - } + echo $mail['description'] ?: 'لا يوجد محتوى إضافي'; ?>
@@ -512,4 +508,4 @@ if ($type == 'internal') { }); - \ No newline at end of file +