9262b09c4d
- Implemented roadmap.php for managing roadmap items with filtering options by quarter and status. - Added a service worker (sw.js) to handle push notifications and click events for calendar appointments. - Created users.php for admin to manage team members and invitations, including user creation and deletion functionalities.
115 lines
3.7 KiB
PHP
115 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* Centrale Systeeminstellingen Helper voor Fociz
|
|
* Beheert organisatie-brede werkdagstandaarden (v1.4) en AI configuratie (v1.5).
|
|
*/
|
|
|
|
require_once __DIR__ . '/../config/database.php';
|
|
|
|
/**
|
|
* Zorgt ervoor dat de system_settings tabel bestaat in MariaDB
|
|
*/
|
|
function ensure_system_settings_table(?PDO $db = null): void {
|
|
static $ensured = false;
|
|
if ($ensured) return;
|
|
|
|
try {
|
|
$pdo = $db ?: get_db_connection();
|
|
$pdo->exec("
|
|
CREATE TABLE IF NOT EXISTS `system_settings` (
|
|
`setting_key` VARCHAR(64) PRIMARY KEY,
|
|
`setting_value` TEXT NULL,
|
|
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
");
|
|
$ensured = true;
|
|
} catch (Throwable $e) {
|
|
error_log("ensure_system_settings_table error: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Haalt een enkele instelling op uit MariaDB
|
|
*/
|
|
function get_system_setting(string $key, $default = null) {
|
|
try {
|
|
$db = get_db_connection();
|
|
ensure_system_settings_table($db);
|
|
|
|
$stmt = $db->prepare("SELECT setting_value FROM system_settings WHERE setting_key = ?");
|
|
$stmt->execute([$key]);
|
|
$val = $stmt->fetchColumn();
|
|
|
|
if ($val === false || $val === null) {
|
|
return $default;
|
|
}
|
|
|
|
// Decodeer JSON indien van toepassing
|
|
$decoded = json_decode($val, true);
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
return $decoded;
|
|
}
|
|
|
|
return $val;
|
|
} catch (Throwable $e) {
|
|
error_log("get_system_setting error for {$key}: " . $e->getMessage());
|
|
return $default;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Slaat een instelling op in MariaDB
|
|
*/
|
|
function set_system_setting(string $key, $value): bool {
|
|
try {
|
|
$db = get_db_connection();
|
|
ensure_system_settings_table($db);
|
|
|
|
$valToStore = is_array($value) || is_object($value) ? json_encode($value) : (string)$value;
|
|
|
|
$stmt = $db->prepare("
|
|
INSERT INTO system_settings (setting_key, setting_value)
|
|
VALUES (?, ?)
|
|
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value), updated_at = NOW()
|
|
");
|
|
return $stmt->execute([$key, $valToStore]);
|
|
} catch (Throwable $e) {
|
|
error_log("set_system_setting error for {$key}: " . $e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Haalt alle organisatie werkdag standaarden op (Release v1.4)
|
|
*/
|
|
function get_workday_settings(): array {
|
|
return [
|
|
'workday_start' => get_system_setting('workday_start', '08:30'),
|
|
'workday_end' => get_system_setting('workday_end', '17:30'),
|
|
'lunch_start' => get_system_setting('lunch_start', '12:30'),
|
|
'lunch_end' => get_system_setting('lunch_end', '13:00'),
|
|
'pomodoro_focus' => (int)get_system_setting('pomodoro_focus', 25),
|
|
'pomodoro_deep' => (int)get_system_setting('pomodoro_deep', 50),
|
|
'pomodoro_break' => (int)get_system_setting('pomodoro_break', 5),
|
|
'default_task_duration' => (int)get_system_setting('default_task_duration', 30),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Haalt AI configuratie-instellingen op (Release v1.5)
|
|
*/
|
|
function get_ai_settings(): array {
|
|
$envKey = fociz_env('OPENAI_API_KEY', '');
|
|
$savedKey = get_system_setting('ai_api_key', '');
|
|
$apiKey = !empty($savedKey) ? $savedKey : $envKey;
|
|
|
|
return [
|
|
'ai_enabled' => (bool)get_system_setting('ai_enabled', !empty($apiKey)),
|
|
'ai_provider' => get_system_setting('ai_provider', 'openai'),
|
|
'ai_api_key' => $apiKey,
|
|
'ai_model' => get_system_setting('ai_model', 'gpt-4o-mini'),
|
|
'has_key' => !empty($apiKey),
|
|
];
|
|
}
|
|
|