| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcfs/NAOPOS/php-api/api/ |
Upload File : |
<?php
declare(strict_types=1);
require __DIR__ . '/db.php';
require __DIR__ . '/helpers.php';
const SETTINGS_KEY = 'pos_settings';
function ensure_settings_table(PDO $pdo): void
{
$pdo->exec(
'CREATE TABLE IF NOT EXISTS settings (
setting_key VARCHAR(100) PRIMARY KEY,
setting_value JSON NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)'
);
}
function default_pos_settings(): array
{
return [
'groceryTaxRate' => 2,
'quickButtons' => [
[
'id' => 'unleaded',
'label' => 'Unleaded',
'shortLabel' => 'GAS',
'taxable' => true,
'reportCategory' => 'Unleaded',
],
[
'id' => 'unleaded-plus',
'label' => 'Unleaded Plus',
'shortLabel' => 'GAS+',
'taxable' => true,
'reportCategory' => 'Unleaded Plus',
],
[
'id' => 'diesel',
'label' => 'Diesel',
'shortLabel' => 'DSL',
'taxable' => true,
'reportCategory' => 'Diesel',
],
[
'id' => 'off-road-diesel',
'label' => 'Off Road Diesel',
'shortLabel' => 'ORD',
'taxable' => false,
'reportCategory' => 'Off Road Diesel',
],
[
'id' => 'hardware',
'label' => 'Hardware',
'shortLabel' => 'HDW',
'taxable' => true,
'reportCategory' => 'Hardware',
],
[
'id' => 'oil',
'label' => 'Oil',
'shortLabel' => 'OIL',
'taxable' => true,
'reportCategory' => 'Oil',
],
],
];
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pdo = db();
ensure_settings_table($pdo);
$stmt = $pdo->prepare(
'SELECT setting_value FROM settings WHERE setting_key = :setting_key'
);
$stmt->execute(['setting_key' => SETTINGS_KEY]);
$row = $stmt->fetch();
if (!$row) {
json_response(default_pos_settings());
}
$decoded = json_decode((string) $row['setting_value'], true);
if (!is_array($decoded)) {
json_response(default_pos_settings());
}
json_response($decoded);
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
json_response(['error' => 'Method not allowed'], 405);
}
$payload = read_json_body();
if (
!isset($payload['groceryTaxRate'], $payload['quickButtons']) ||
!is_array($payload['quickButtons'])
) {
json_response(['error' => 'Missing settings payload'], 400);
}
$pdo = db();
ensure_settings_table($pdo);
$stmt = $pdo->prepare(
'INSERT INTO settings (setting_key, setting_value)
VALUES (:setting_key, :setting_value)
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)'
);
$stmt->execute([
'setting_key' => SETTINGS_KEY,
'setting_value' => json_encode($payload, JSON_UNESCAPED_UNICODE),
]);
json_response(['ok' => true]);