Files
urbackup/front/config.form.php
T
2026-08-07 14:27:33 +02:00

70 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use GlpiPlugin\Urbackup\Config;
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__, 4));
}
include_once GLPI_ROOT . '/inc/includes.php';
// Check user has right to manage plugin configuration
if (!Session::haveRight('config', UPDATE)) {
Html::displayRightError();
}
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
// CSRF token is validated by the global CheckCsrfListener on every POST.
if (isset($_POST['update'])) {
global $DB;
$enable_computer = (string) ($_POST['enable_computer'] ?? '0') === '1' ? '1' : '0';
$table = Config::getTable();
$iterator = $DB->request([
'FROM' => $table,
'WHERE' => ['name' => 'enable_computer'],
'LIMIT' => 1,
]);
$row = $iterator->current();
$values = [
'value' => $enable_computer,
'date_mod' => $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s'),
];
if ($row === false) {
$values['name'] = 'enable_computer';
$values['date_creation'] = $_SESSION['glpi_currenttime'] ?? date('Y-m-d H:i:s');
$DB->insert($table, $values);
} else {
$DB->update($table, $values, ['name' => 'enable_computer']);
}
Session::addMessageAfterRedirect(
__('Configuration saved.', 'urbackup'),
false,
INFO
);
Html::redirect(Config::getFormURL());
}
}
// Display GLPI header
Html::header(
__('UrBackup configuration', 'urbackup'),
'',
'Config',
'PluginUrbackupConfig'
);
// Show configuration form
$config = new Config();
$config->showForm(1);
// Display GLPI footer
Html::footer();