- 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
27 lines
726 B
PHP
27 lines
726 B
PHP
<?php
|
|
require_once __DIR__ . '/../../../session.php';
|
|
require_once '../../../assets/utils/db_auth.php';
|
|
require_once '../../../assets/utils/classes_ac/DepartmentManager.php';
|
|
|
|
require_role($user_role, ['owner', 'admin']);
|
|
|
|
if (empty($data['dept_code']) || empty($data['dept_name'])) {
|
|
http_response_code(400);
|
|
$answer['message'] = 'Department code and name are required';
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
$dept = new DepartmentManager($pdo2, $company_id);
|
|
$id = (int)($data['id'] ?? 0);
|
|
|
|
if ($id) {
|
|
$dept->update($id, $data);
|
|
$answer['message'] = 'Department updated';
|
|
} else {
|
|
$dept->create($data);
|
|
$answer['message'] = 'Department created';
|
|
}
|
|
|
|
$answer['success'] = 1;
|
|
exit(json_encode($answer));
|