prepare("INSERT INTO meetings (title, description, agenda, attendees, absentees, meeting_details, start_time, end_time, location, status, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$title, $description, $agenda, $attendees, $absentees, $meeting_details, $start_time, $end_time, $location, $status, $_SESSION['user_id']]); $_SESSION['success'] = 'تم جدولة الاجتماع بنجاح'; } else { $stmt = $db->prepare("UPDATE meetings SET title=?, description=?, agenda=?, attendees=?, absentees=?, meeting_details=?, start_time=?, end_time=?, location=?, status=? WHERE id=?"); $stmt->execute([$title, $description, $agenda, $attendees, $absentees, $meeting_details, $start_time, $end_time, $location, $status, $id]); $_SESSION['success'] = 'تم تحديث الاجتماع بنجاح'; } redirect('meetings.php'); } catch (PDOException $e) { $error = 'حدث خطأ: ' . $e->getMessage(); } } } } if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { if (!canDelete('meetings')) redirect('meetings.php'); $id = $_GET['id']; $db = db(); $stmt = $db->prepare("DELETE FROM meetings WHERE id = ?"); $stmt->execute([$id]); $_SESSION['success'] = 'تم حذف الاجتماع بنجاح'; redirect('meetings.php'); } // Fetch Data for List $date_from = $_GET['date_from'] ?? date('Y-m-01'); $date_to = $_GET['date_to'] ?? date('Y-m-t'); $status_filter = $_GET['status'] ?? ''; $search = $_GET['search'] ?? ''; // Base WHERE conditions $whereConditions = ["DATE(m.start_time) BETWEEN ? AND ?"]; $params = [$date_from, $date_to]; if ($status_filter) { $whereConditions[] = "m.status = ?"; $params[] = $status_filter; } if ($search) { $whereConditions[] = "(m.title LIKE ? OR m.description LIKE ? OR m.location LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; $params[] = "%$search%"; } $whereClause = implode(' AND ', $whereConditions); // Pagination $page = $_GET['page'] ?? 1; $perPage = 10; // Count Total Items $countSql = "SELECT COUNT(*) FROM meetings m WHERE $whereClause"; $countStmt = db()->prepare($countSql); $countStmt->execute($params); $totalMeetings = $countStmt->fetchColumn(); $pagination = getPagination($page, $totalMeetings, $perPage); // Fetch Items with Limit $sql = "SELECT m.*, u.username as created_by_name FROM meetings m LEFT JOIN users u ON m.created_by = u.id WHERE $whereClause ORDER BY m.start_time ASC LIMIT ? OFFSET ?"; // Add LIMIT and OFFSET to params $params[] = $pagination['limit']; $params[] = $pagination['offset']; $stmt = db()->prepare($sql); // Bind params manually because limit/offset must be integers // But wait, $params is mixed string/int. // PDO::execute($params) treats all as strings which is fine for limit/offset in MySQL usually, // but strictly speaking, LIMIT/OFFSET should be ints. // Let's bind all params. foreach ($params as $k => $v) { // 1-based index $type = is_int($v) ? PDO::PARAM_INT : PDO::PARAM_STR; $stmt->bindValue($k + 1, $v, $type); } $stmt->execute(); $meetings = $stmt->fetchAll(PDO::FETCH_ASSOC); if (isset($_SESSION['success'])) { $success = $_SESSION['success']; unset($_SESSION['success']); } ?>