prepare("SELECT * FROM committees WHERE id = ?"); $stmt->execute([$id]); $committee = $stmt->fetch(PDO::FETCH_ASSOC); if (!$committee) { redirect('committees.php'); } // Check membership for non-admins if (!isAdmin()) { $check_stmt = $db->prepare(" SELECT 1 FROM committee_members m JOIN charity_members cm ON m.charity_member_id = cm.id JOIN users u ON (u.id = cm.user_id) OR (cm.email != '' AND cm.email = u.email) OR (cm.name = u.full_name) OR (cm.name = u.username) WHERE m.committee_id = ? AND u.id = ? "); $check_stmt->execute([$id, $_SESSION['user_id']]); if (!$check_stmt->fetchColumn()) { $_SESSION['error'] = 'غير مصرح لك بعرض هذه اللجنة'; redirect('committees.php'); } } $tab = $_GET['tab'] ?? 'members'; $allowed_tabs = ['members', 'plans', 'activities']; if (!in_array($tab, $allowed_tabs)) { $tab = 'members'; } $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; try { if ($action === 'add_member' && canAdd('committees')) { $charity_member_id = $_POST['charity_member_id'] ?? 0; $role = trim($_POST['role'] ?? 'عضو'); if ($charity_member_id) { $stmt = $db->prepare("INSERT INTO committee_members (committee_id, charity_member_id, role, joined_at) VALUES (?, ?, ?, CURDATE())"); $stmt->execute([$id, $charity_member_id, $role]); $_SESSION['success'] = 'تم إضافة العضو بنجاح'; } } elseif ($action === 'edit_member' && canEdit('committees')) { $member_id = $_POST['member_id'] ?? 0; $role = trim($_POST['role'] ?? 'عضو'); if ($member_id) { $stmt = $db->prepare("UPDATE committee_members SET role = ? WHERE id = ?"); $stmt->execute([$role, $member_id]); $_SESSION['success'] = 'تم تحديث دور العضو بنجاح'; } } elseif ($action === 'delete_member' && canDelete('committees')) { $member_id = $_POST['member_id'] ?? 0; if ($member_id) { $stmt = $db->prepare("DELETE FROM committee_members WHERE id = ?"); $stmt->execute([$member_id]); $_SESSION['success'] = 'تم حذف العضو بنجاح'; } } elseif ($action === 'add_plan' && canAdd('committees')) { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $start_date = $_POST['start_date'] ?: null; $end_date = $_POST['end_date'] ?: null; if ($title) { $stmt = $db->prepare("INSERT INTO committee_plans (committee_id, title, description, start_date, end_date) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$id, $title, $description, $start_date, $end_date]); $_SESSION['success'] = 'تم إضافة الخطة بنجاح'; } } elseif ($action === 'edit_plan' && canEdit('committees')) { $plan_id = $_POST['plan_id'] ?? 0; $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $start_date = $_POST['start_date'] ?: null; $end_date = $_POST['end_date'] ?: null; $status = $_POST['status'] ?? 'pending'; if ($plan_id && $title) { $stmt = $db->prepare("UPDATE committee_plans SET title = ?, description = ?, start_date = ?, end_date = ?, status = ? WHERE id = ?"); $stmt->execute([$title, $description, $start_date, $end_date, $status, $plan_id]); $_SESSION['success'] = 'تم تحديث الخطة بنجاح'; } } elseif ($action === 'delete_plan' && canDelete('committees')) { $plan_id = $_POST['plan_id'] ?? 0; if ($plan_id) { $stmt = $db->prepare("DELETE FROM committee_plans WHERE id = ?"); $stmt->execute([$plan_id]); $_SESSION['success'] = 'تم حذف الخطة بنجاح'; } } elseif ($action === 'add_activity' && canAdd('committees')) { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $activity_date = $_POST['activity_date'] ?: null; $location = trim($_POST['location'] ?? ''); if ($title) { $stmt = $db->prepare("INSERT INTO committee_activities (committee_id, title, description, activity_date, location) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$id, $title, $description, $activity_date, $location]); $_SESSION['success'] = 'تم إضافة النشاط بنجاح'; } } elseif ($action === 'edit_activity' && canEdit('committees')) { $activity_id = $_POST['activity_id'] ?? 0; $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $activity_date = $_POST['activity_date'] ?: null; $location = trim($_POST['location'] ?? ''); if ($activity_id && $title) { $stmt = $db->prepare("UPDATE committee_activities SET title = ?, description = ?, activity_date = ?, location = ? WHERE id = ?"); $stmt->execute([$title, $description, $activity_date, $location, $activity_id]); $_SESSION['success'] = 'تم تحديث النشاط بنجاح'; } } elseif ($action === 'delete_activity' && canDelete('committees')) { $activity_id = $_POST['activity_id'] ?? 0; if ($activity_id) { $stmt = $db->prepare("DELETE FROM committee_activities WHERE id = ?"); $stmt->execute([$activity_id]); $_SESSION['success'] = 'تم حذف النشاط بنجاح'; } } } catch (PDOException $e) { $_SESSION['error'] = 'حدث خطأ: ' . $e->getMessage(); } redirect("view_committee.php?id=$id&tab=$tab"); } if (isset($_SESSION['success'])) { $success = $_SESSION['success']; unset($_SESSION['success']); } if (isset($_SESSION['error'])) { $error = $_SESSION['error']; unset($_SESSION['error']); } // Fetch tab data $members = []; $plans = []; $activities = []; if ($tab === 'members') { $stmt = $db->prepare("SELECT cm.*, u.name as full_name, u.email, u.phone FROM committee_members cm JOIN charity_members u ON cm.charity_member_id = u.id WHERE cm.committee_id = ? ORDER BY cm.id DESC"); $stmt->execute([$id]); $members = $stmt->fetchAll(PDO::FETCH_ASSOC); // Get available users to add $member_ids = array_column($members, 'charity_member_id'); $not_in = count($member_ids) > 0 ? implode(',', array_map('intval', $member_ids)) : '0'; $available_users = $db->query("SELECT id, name as full_name, email FROM charity_members WHERE status = 'active' AND id NOT IN ($not_in) ORDER BY full_name ASC")->fetchAll(PDO::FETCH_ASSOC); } elseif ($tab === 'plans') { $stmt = $db->prepare("SELECT * FROM committee_plans WHERE committee_id = ? ORDER BY id DESC"); $stmt->execute([$id]); $plans = $stmt->fetchAll(PDO::FETCH_ASSOC); } elseif ($tab === 'activities') { $stmt = $db->prepare("SELECT * FROM committee_activities WHERE committee_id = ? ORDER BY activity_date DESC, id DESC"); $stmt->execute([$id]); $activities = $stmt->fetchAll(PDO::FETCH_ASSOC); } ?>

إدارة اللجنة:

عودة للجان

أعضاء اللجنة
0): ?>
الاسم البريد الإلكتروني الهاتف الدور تاريخ الانضمام الإجراءات
لا يوجد أعضاء في هذه اللجنة حالياً.
خطط اللجنة
'secondary', 'in_progress' => 'primary', 'completed' => 'success', 'cancelled' => 'danger' ]; $status_labels = [ 'pending' => 'قيد الانتظار', 'in_progress' => 'قيد التنفيذ', 'completed' => 'مكتملة', 'cancelled' => 'ملغاة' ]; if (count($plans) > 0): ?>
عنوان الخطة تاريخ البداية تاريخ النهاية الحالة الإجراءات
لا توجد خطط مضافة حالياً.
أنشطة وفعاليات اللجنة
طباعة الأنشطة
0): ?>
النشاط التاريخ الموقع الإجراءات
لا توجد أنشطة مضافة حالياً.