- users, SMTP and batch-lock endpoints are owner/admin only - engines answer 400/403/404/409/500 instead of 200 with an error body; database errors no longer leak to the client
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../../session.php';
|
|
require_once '../../../assets/utils/db_auth.php';
|
|
require_once '../../../assets/utils/classes/CompanySettingManager.php';
|
|
require_role($user_role, ['owner', 'admin']);
|
|
|
|
$csm = new CompanySettingManager($pdo1, $company_id);
|
|
|
|
if ($data['action'] === 'read') {
|
|
$open_from = $csm->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)) {
|
|
http_response_code(400);
|
|
$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)) {
|
|
http_response_code(400);
|
|
$answer['message'] = 'Invalid open_to date. Use YYYY-MM-DD.';
|
|
exit(json_encode($answer));
|
|
}
|
|
if ($from && $to && $from > $to) {
|
|
http_response_code(400);
|
|
$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));
|
|
}
|
|
|
|
http_response_code(400);
|
|
$answer['message'] = 'Invalid action.';
|
|
exit(json_encode($answer));
|