From 6714d8259a86cd94129064c9fe1cbf3e1c94a59a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 11 Jan 2026 15:08:42 +0000 Subject: [PATCH] Proces spotkania wersja 1 --- WorkflowEngine.php | 66 +++++ _get_meeting_attendance.php | 35 +++ _get_meeting_details.php | 27 ++ _header.php | 9 +- _navbar.php | 2 +- _update_meeting_attendance.php | 47 ++++ assets/css/custom.css | 6 + assets/pasted-20260111-143449-befa41d3.png | Bin 0 -> 5143 bytes assets/pasted-20260111-144117-aba8ec29.jpg | Bin 0 -> 124350 bytes db/migrations/030_create_meetings_table.php | 23 ++ .../031_create_meeting_attendance_table.php | 27 ++ index.php | 234 +++++++++++++++++- 12 files changed, 461 insertions(+), 15 deletions(-) create mode 100644 _get_meeting_attendance.php create mode 100644 _get_meeting_details.php create mode 100644 _update_meeting_attendance.php create mode 100644 assets/pasted-20260111-143449-befa41d3.png create mode 100644 assets/pasted-20260111-144117-aba8ec29.jpg create mode 100644 db/migrations/030_create_meetings_table.php create mode 100644 db/migrations/031_create_meeting_attendance_table.php diff --git a/WorkflowEngine.php b/WorkflowEngine.php index 245033a..30f25d0 100644 --- a/WorkflowEngine.php +++ b/WorkflowEngine.php @@ -762,4 +762,70 @@ class WorkflowEngine { throw $e; } } + + public function getOrCreateMeeting(int $groupId, string $meetingDatetime): int { + $meetingKey = $groupId . '_' . $meetingDatetime; + $stmt = $this->pdo->prepare("SELECT id FROM meetings WHERE meeting_key = ?"); + $stmt->execute([$meetingKey]); + $meetingId = $stmt->fetchColumn(); + + if (!$meetingId) { + $stmt = $this->pdo->prepare("INSERT INTO meetings (bni_group_id, meeting_datetime, meeting_key) VALUES (?, ?, ?)"); + $stmt->execute([$groupId, $meetingDatetime, $meetingKey]); + $meetingId = $this->pdo->lastInsertId(); + } + + return (int)$meetingId; + } + + public function getMeetingAttendance(int $meetingId): array { + $stmt = $this->pdo->prepare("SELECT * FROM meeting_attendance WHERE meeting_id = ?"); + $stmt->execute([$meetingId]); + $attendance_raw = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $attendance = []; + foreach ($attendance_raw as $att) { + $attendance[$att['person_id']] = $att; + } + + return $attendance; + } + + public function updateMeetingAttendance(int $meetingId, int $personId, string $status, int $userId, ?string $guestSurvey = null): void { + $sql = "INSERT INTO meeting_attendance (meeting_id, person_id, attendance_status, guest_survey, updated_by) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE attendance_status = VALUES(attendance_status), guest_survey = VALUES(guest_survey), updated_by = VALUES(updated_by)"; + $stmt = $this->pdo->prepare($sql); + $stmt->execute([$meetingId, $personId, $status, $guestSurvey, $userId]); + } + + public function getMeetingAttendanceByGroupAndDate(int $groupId, string $meetingDatetime): array { + $meetingId = $this->getOrCreateMeeting($groupId, $meetingDatetime); + return $this->getMeetingAttendance($meetingId); + } + + public function isMemberOfGroup(int $personId, int $bniGroupId): bool { + $stmt = $this->pdo->prepare("SELECT COUNT(*) FROM people WHERE id = ? AND bni_group_id = ?"); + $stmt->execute([$personId, $bniGroupId]); + return (int)$stmt->fetchColumn() > 0; + } + + public function getMeetingDetails(int $personId, int $bniGroupId, string $meetingDatetime): array { + $meetingId = $this->getOrCreateMeeting($bniGroupId, $meetingDatetime); + + $stmt = $this->pdo->prepare("SELECT * FROM meeting_attendance WHERE meeting_id = ? AND person_id = ?"); + $stmt->execute([$meetingId, $personId]); + $attendance = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($attendance) { + return $attendance; + } + + // If no record, return default state + $isMember = $this->isMemberOfGroup($personId, $bniGroupId); + return [ + 'meeting_id' => $meetingId, + 'person_id' => $personId, + 'attendance_status' => $isMember ? 'present' : 'none', + 'guest_survey' => null, + ]; + } } \ No newline at end of file diff --git a/_get_meeting_attendance.php b/_get_meeting_attendance.php new file mode 100644 index 0000000..c56eb02 --- /dev/null +++ b/_get_meeting_attendance.php @@ -0,0 +1,35 @@ + false, 'message' => 'An error occurred.', 'attendance' => []]; + +if (!isset($_SESSION['user_id'])) { + $response['message'] = 'You must be logged in to perform this action.'; + echo json_encode($response); + exit; +} + +$groupId = $_GET['group_id'] ?? null; +$meetingDate = $_GET['meeting_date'] ?? null; + +if (!$groupId || !$meetingDate) { + $response['message'] = 'Missing required parameters.'; + echo json_encode($response); + exit; +} + +try { + $workflowEngine = new WorkflowEngine(); + $attendance = $workflowEngine->getMeetingAttendanceByGroupAndDate((int)$groupId, $meetingDate); + $response['success'] = true; + $response['attendance'] = $attendance; +} catch (Exception $e) { + error_log($e->getMessage()); + $response['message'] = 'Error fetching attendance: ' . $e->getMessage(); +} + +echo json_encode($response); diff --git a/_get_meeting_details.php b/_get_meeting_details.php new file mode 100644 index 0000000..abfeb9f --- /dev/null +++ b/_get_meeting_details.php @@ -0,0 +1,27 @@ + false, 'message' => 'Invalid request']; + +$personId = $_GET['person_id'] ?? null; +$bniGroupId = $_GET['bni_group_id'] ?? null; +$meetingDatetime = $_GET['meeting_datetime'] ?? null; +$userId = $_SESSION['user_id'] ?? 0; // Ensure you have a user ID in the session + +if ($personId && $bniGroupId && $meetingDatetime && $userId) { + try { + $workflowEngine = new WorkflowEngine(); + $details = $workflowEngine->getMeetingDetails((int)$personId, (int)$bniGroupId, $meetingDatetime); + $response = ['success' => true, 'details' => $details]; + } catch (Exception $e) { + $response['message'] = $e->getMessage(); + } +} else { + $response['message'] = 'Missing required parameters.'; +} + +echo json_encode($response); diff --git a/_header.php b/_header.php index fc22757..33bb541 100644 --- a/_header.php +++ b/_header.php @@ -11,7 +11,7 @@ if (!isset($_SESSION['user_id'])) { - <?php echo getenv('PROJECT_NAME') ?: 'My App'; ?> - Dashboard + <?php echo getenv('PROJECT_NAME') ?: 'BNI obsługa regionu'; ?> - Dashboard @@ -28,7 +28,7 @@ if (!isset($_SESSION['user_id'])) { - + "> @@ -36,9 +36,10 @@ if (!isset($_SESSION['user_id'])) { - + - + diff --git a/_navbar.php b/_navbar.php index 6e71f49..2fb4c5a 100644 --- a/_navbar.php +++ b/_navbar.php @@ -1,5 +1,5 @@