fix: harden backend synchronization
This commit is contained in:
@@ -50,6 +50,23 @@ function attach_rule_scope(AppContext $ctx, array $rule): array
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $rule */
|
||||
function enforce_rule_backend_constraints(AppContext $ctx, ?string $currentId, array $rule): void
|
||||
{
|
||||
if ($ctx->settings->backendMode() !== 'da' || empty($rule['enabled'])) {
|
||||
return;
|
||||
}
|
||||
foreach ($ctx->rules->all($ctx->daUser->username()) as $existing) {
|
||||
if (empty($existing['enabled'])) {
|
||||
continue;
|
||||
}
|
||||
if ($currentId !== null && (string)($existing['id'] ?? '') === $currentId) {
|
||||
continue;
|
||||
}
|
||||
throw new RuntimeException($ctx->t('DirectAdmin backend supports only one enabled global rule.'));
|
||||
}
|
||||
}
|
||||
|
||||
function render_calendar_picker(AppContext $ctx, string $name, string $title, string $value): string
|
||||
{
|
||||
$mode = $ctx->settings->scheduleMode();
|
||||
@@ -79,15 +96,24 @@ function render_calendar_picker(AppContext $ctx, string $name, string $title, st
|
||||
'</select>';
|
||||
}
|
||||
return '<div class="panel"><h3>' . AppContext::e($title) . '</h3><div class="br-restore-layout"><div class="br-restore-calendar" data-calendar-picker data-schedule-mode="' . AppContext::e($mode) . '" data-calendar-name="' . AppContext::e($name) . '" data-visible-month="' . AppContext::e($visibleMonth) . '" data-selected-date="' . AppContext::e($selectedDate) . '"><h4>' . AppContext::e($title) . '</h4><div class="br-month-nav"><button type="button" class="br-month-btn" data-calendar-prev>‹</button><span class="br-month-label" data-calendar-month-label>' . AppContext::e($monthLabel) . '</span><button type="button" class="br-month-btn" data-calendar-next>›</button></div>' .
|
||||
'<table class="br-calendar-grid"><thead><tr><th>Pn</th><th>Wt</th><th>Śr</th><th>Cz</th><th>Pt</th><th>Sb</th><th>Nd</th></tr></thead><tbody data-calendar-days>' . $days . '</tbody></table>' .
|
||||
'<div class="br-date-label" id="' . AppContext::e($name . '_label') . '">Wybrano: ' . AppContext::e($selectedDate) . '</div><input type="hidden" id="' . AppContext::e($name . '_date') . '" name="' . AppContext::e($name . '_date') . '" value="' . AppContext::e($selectedDate) . '"></div>' .
|
||||
'<table class="br-calendar-grid"><thead><tr>' . render_weekday_headers($ctx) . '</tr></thead><tbody data-calendar-days>' . $days . '</tbody></table>' .
|
||||
'<div class="br-date-label" id="' . AppContext::e($name . '_label') . '">' . AppContext::e($ctx->t('Selected')) . ': ' . AppContext::e($selectedDate) . '</div><input type="hidden" id="' . AppContext::e($name . '_date') . '" name="' . AppContext::e($name . '_date') . '" value="' . AppContext::e($selectedDate) . '"></div>' .
|
||||
'<div class="br-restore-calendar"><h4>' . AppContext::e($ctx->t('Time')) . '</h4>' . $timeControl . '</div></div>' .
|
||||
'<input type="hidden" id="' . AppContext::e($name) . '" name="' . AppContext::e($name) . '" value="' . AppContext::e($value) . '" data-canonical-value="' . AppContext::e($name) . '"></div>';
|
||||
}
|
||||
|
||||
function render_preview_box(array $rule): string
|
||||
function render_preview_box(AppContext $ctx, array $rule): string
|
||||
{
|
||||
return '<div class="preview-box"><div><strong>Temat:</strong> ' . AppContext::e((string)$rule['subject']) . '</div><br><div>' . nl2br(AppContext::e((string)$rule['body'])) . '</div></div>';
|
||||
return '<div class="preview-box"><div><strong>' . AppContext::e($ctx->t('Subject')) . ':</strong> ' . AppContext::e((string)$rule['subject']) . '</div><br><div>' . nl2br(AppContext::e((string)$rule['body'])) . '</div></div>';
|
||||
}
|
||||
|
||||
function render_weekday_headers(AppContext $ctx): string
|
||||
{
|
||||
$html = '';
|
||||
foreach (['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] as $day) {
|
||||
$html .= '<th>' . AppContext::e($ctx->t($day)) . '</th>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function render_calendar_days(string $name, string $selectedDate, DateTimeImmutable $monthStart): string
|
||||
|
||||
Reference in New Issue
Block a user