- 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
31 lines
896 B
PHP
31 lines
896 B
PHP
<?php
|
|
require_once __DIR__ . '/../../../session.php';
|
|
require_once '../../../assets/utils/db_auth.php';
|
|
require_once '../../../assets/utils/classes/PurchaseRequestManager.php';
|
|
require_role($user_role, ['owner', 'admin', 'staff']);
|
|
|
|
$id = (int)($data['id'] ?? 0);
|
|
$action = $data['action_type'] ?? '';
|
|
|
|
if (!$id || !$action) {
|
|
http_response_code(400);
|
|
$answer['message'] = 'ID and action are required.';
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
$prm = new PurchaseRequestManager($pdo2, $company_id);
|
|
|
|
try {
|
|
$prm->updateStatus($id, $action, $logging);
|
|
$answer['success'] = 1;
|
|
$answer['message'] = 'Status updated.';
|
|
} catch (PDOException $e) {
|
|
$answer['message'] = 'Database error, please try again.';
|
|
http_response_code(500);
|
|
} catch (Exception $e) {
|
|
$answer['message'] = $e->getMessage();
|
|
http_response_code(400);
|
|
}
|
|
|
|
exit(json_encode($answer));
|