url($isUpdate ? 'update.html' : 'create.html'); $intent = $isUpdate ? 'update:' . $id : 'create'; $csrf = $ctx->csrfField($intent); $hiddenId = $isUpdate ? '' : ''; return '
' . $csrf . $hiddenId . '

' . AppContext::e($ctx->t('Response content')) . '

' . '
' . '
' . render_calendar_picker($ctx, 'start_value', $ctx->t('Start date'), $startValue) . render_calendar_picker($ctx, 'end_value', $ctx->t('End date'), $endValue) . '
' . AppContext::e($ctx->t('Cancel')) . '
' . '
'; } /** @param array $post @return array */ function normalize_rule_post(array $post): array { foreach (['start_value', 'end_value'] as $key) { $date = trim((string)($post[$key . '_date'] ?? '')); $time = trim((string)($post[$key . '_time'] ?? '')); $period = trim((string)($post[$key . '_period'] ?? '')); if ($date !== '' && preg_match('/^[0-9]{2}:[0-9]{2}$/', $time)) { $post[$key] = $date . 'T' . $time; } elseif ($date !== '' && preg_match('/^(morning|afternoon|evening)$/', $period)) { $post[$key] = $date . '|' . $period; } } return $post; } /** @param array $rule @return array */ function attach_rule_scope(AppContext $ctx, array $rule): array { if (empty($rule['dynamic_scope'])) { $rule['mailbox_snapshot'] = (new MailboxDirectory())->mailboxesForUser($ctx->daUser->username()); } return $rule; } function render_calendar_picker(AppContext $ctx, string $name, string $title, string $value): string { $mode = $ctx->settings->scheduleMode(); $selectedDate = substr($value, 0, 10); if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $selectedDate)) { $selectedDate = date('Y-m-d'); } $selectedTime = '09:00'; $selectedPeriod = 'morning'; if ($mode === 'exact_hour' && preg_match('/T([0-9]{2}:[0-9]{2})$/', $value, $m)) { $selectedTime = $m[1]; } elseif ($mode === 'directadmin_period' && preg_match('/\|(morning|afternoon|evening)$/', $value, $m)) { $selectedPeriod = $m[1]; } $selectedDt = DateTimeImmutable::createFromFormat('!Y-m-d', $selectedDate) ?: new DateTimeImmutable('today'); $monthStart = $selectedDt->modify('first day of this month'); $days = render_calendar_days($name, $selectedDate, $monthStart); $visibleMonth = $monthStart->format('Y-m'); $monthLabel = calendar_month_label($ctx, $monthStart); if ($mode === 'exact_hour') { $timeControl = ''; } else { $timeControl = ''; } return '

' . AppContext::e($title) . '

' . AppContext::e($title) . '

' . AppContext::e($monthLabel) . '
' . '' . $days . '
PnWtŚrCzPtSbNd
' . '
Wybrano: ' . AppContext::e($selectedDate) . '
' . '

' . AppContext::e($ctx->t('Time')) . '

' . $timeControl . '
' . '
'; } function render_preview_box(array $rule): string { return '
Temat: ' . AppContext::e((string)$rule['subject']) . '

' . nl2br(AppContext::e((string)$rule['body'])) . '
'; } function render_calendar_days(string $name, string $selectedDate, DateTimeImmutable $monthStart): string { $offset = ((int)$monthStart->format('N')) - 1; $daysInMonth = (int)$monthStart->format('t'); $html = ''; $day = 1; for ($week = 0; $week < 6; $week++) { $html .= ''; for ($i = 0; $i < 7; $i++) { if (($week === 0 && $i < $offset) || $day > $daysInMonth) { $html .= ''; continue; } $date = $monthStart->setDate((int)$monthStart->format('Y'), (int)$monthStart->format('m'), $day)->format('Y-m-d'); $class = $date === $selectedDate ? ' is-selected' : ''; $html .= ''; $day++; } $html .= ''; if ($day > $daysInMonth) { break; } } return $html; } function calendar_month_label(AppContext $ctx, DateTimeImmutable $monthStart): string { $pl = ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień']; $en = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; $months = $ctx->lang->code() === 'pl' ? $pl : $en; return $months[((int)$monthStart->format('n')) - 1] . ' ' . $monthStart->format('Y'); }