'en-us', 'chs' => 'zh-cn', 'cht' => 'zh-tw', ]; $localeJs = $localesMap[$lang] ?? 'en-us'; \Nexus\Nexus::js("vendor/fullcalendar-5.10.2/locales/{$localeJs}.js", 'footer', true); $today = \Carbon\Carbon::today(); $tomorrow = \Carbon\Carbon::tomorrow(); $end = $today->clone()->endOfMonth(); $start = $today->clone()->subMonth(2); $attendanceRepository = new \App\Repositories\AttendanceRepository(); $attendanceCaptchaSetting = \App\Models\Setting::get('captcha.attendance.enabled', config('captcha.attendance.enabled', true)); if (is_string($attendanceCaptchaSetting)) { $attendanceCaptchaEnabled = in_array(strtolower($attendanceCaptchaSetting), ['1', 'true', 'yes'], true); } else { $attendanceCaptchaEnabled = (bool) $attendanceCaptchaSetting; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($attendanceCaptchaEnabled && $iv == 'yes') { check_code($_POST['imagehash'] ?? null, $_POST['imagestring'] ?? null, 'attendance.php'); } $attendance = $attendanceRepository->attend($CURUSER['id']); if (!$attendance->is_updated) { stderr($lang_attendance['sorry'], $lang_attendance['already_attended']); } } else { $attendance = $attendanceRepository->getAttendance($CURUSER['id']); } $hasAttendedToday = $attendance && $attendance->added && $attendance->added->isSameDay($today); if (!$attendanceCaptchaEnabled && !$hasAttendedToday) { $attendance = $attendanceRepository->attend($CURUSER['id']); $hasAttendedToday = $attendance && $attendance->added && $attendance->added->isSameDay($today); } if (!$attendance) { $attendance = new \App\Models\Attendance([ 'uid' => $CURUSER['id'], 'points' => 0, 'days' => 0, 'total_days' => 0, ]); $attendance->added = null; $hasAttendedToday = false; } stdhead($lang_attendance['title']); begin_main_frame(); if ($hasAttendedToday) { $todayDate = $today->format('Y-m-d'); $baseQuery = \App\Models\AttendanceLog::query()->where('date', $todayDate); $todayCounts = $baseQuery->count(); $myLog = (clone $baseQuery)->where('uid', $CURUSER['id'])->first(['id']); $myRanking = 0; if ($myLog) { $myRanking = (clone $baseQuery)->where('id', '<=', $myLog->id)->count(); } $count = $attendance->total_days; $cdays = $attendance->days; $points = $attendance->points; $headerLeft = sprintf($lang_attendance['attend_info'] . $lang_attendance['retroactive_description'], $count, $cdays, $points, $CURUSER['attendance_card']); $headerRight = nexus_trans('attendance.ranking', ['ranking' => $myRanking, 'counts' => $todayCounts]); begin_frame($lang_attendance['success']); printf('

%s%s

', $headerLeft, $headerRight); end_frame(); $logs = \App\Models\AttendanceLog::query() ->where('uid', $CURUSER['id']) ->where('date', '>=', $start->format('Y-m-d')) ->get() ->keyBy('date'); $interval = new \DateInterval('P1D'); $period = new \DatePeriod($start, $interval, $end); $interval = \Carbon\CarbonInterval::make($interval); $period = \Carbon\CarbonPeriod::make($period); $events = []; foreach ($period as $value) { if ($value->gte($tomorrow)) { continue; } $checkDate = $value->format('Y-m-d'); $eventBase = ['start' => $checkDate, 'end' => $checkDate]; if ($logs->has($checkDate)) { $logValue = $logs->get($checkDate); $events[] = array_merge($eventBase, ['display' => 'background']); if ($logValue->points > 0) { $events[] = array_merge($eventBase, ['title' => $logValue->points]); } if ($logValue->is_retroactive) { $events[] = array_merge($eventBase, ['title' => $lang_attendance['retroactive_event_text'], 'display' => 'list-item']); } } elseif ($value->lte($today) && $value->diffInDays($today, true) <= \App\Models\Attendance::MAX_RETROACTIVE_DAYS) { $events[] = array_merge($eventBase, ['groupId' => 'to_do', 'display' => 'list-item']); } } $eventStr = json_encode($events); $validRangeStr = json_encode(['start' => $start->format('Y-m-d'), 'end' => $end->clone()->addDays(1)->format('Y-m-d')]); $calendarScript = <<
'; echo ''; } else { $buttonLabel = $lang_attendance['attend_button'] ?? 'Check in'; begin_frame($lang_attendance['title']); echo ''; echo ''; echo '
'; echo '
'; echo '
'; echo ''; if ($attendanceCaptchaEnabled && $iv == 'yes') { show_image_code(); } echo ''; echo '
'; echo '
'; echo '
'; echo '
'; end_frame(); } end_main_frame(); stdfoot();