save(array_merge($data, ['id' => 0, 'items' => $items]), $logging); $answer['success'] = 1; $answer['message'] = 'Quotation created.'; $answer['new_id'] = $new_id; } elseif ($action === 'update') { require_role($user_role, ['owner', 'admin', 'staff']); $qm->save(array_merge($data, ['id' => $id, 'items' => $items]), $logging); $answer['success'] = 1; $answer['message'] = 'Quotation updated.'; } else { throw new Exception('Unknown action.'); } } 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));