get('posting_open_from'); if ($open_from === null || $open_from === '') { $open_from = $csm->get('gl_open_from') ?: ''; } $open_to = $csm->get('posting_open_to'); if ($open_to === null || $open_to === '') { $open_to = $csm->get('gl_open_to') ?: ''; } $answer['output'] = [ 'open_from' => $open_from ?: '', 'open_to' => $open_to ?: '', ]; $answer['success'] = 1; exit(json_encode($answer)); } if ($data['action'] === 'save') { $from = trim((string)($data['open_from'] ?? '')); $to = trim((string)($data['open_to'] ?? '')); if ($from !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) { $answer['message'] = 'Invalid open_from date. Use YYYY-MM-DD.'; exit(json_encode($answer)); } if ($to !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) { $answer['message'] = 'Invalid open_to date. Use YYYY-MM-DD.'; exit(json_encode($answer)); } if ($from && $to && $from > $to) { $answer['message'] = 'Open From must be on or before Open To.'; exit(json_encode($answer)); } $csm->set('posting_open_from', $from); $csm->set('posting_open_to', $to); $answer['success'] = 1; $answer['message'] = 'Posting window saved.'; exit(json_encode($answer)); } $answer['message'] = 'Invalid action.'; exit(json_encode($answer));