Files
urbackup/front/dropdown_host.ajax.php
T
2026-08-31 10:10:30 +02:00

50 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* AJAX endpoint providing the asset dropdown for the "Hardware host"
* field of the UrBackup server form.
*
* Called through Ajax::updateItemOnSelectEvent when the host itemtype
* selection changes. GET only, no state changes are performed.
*/
use GlpiPlugin\Urbackup\Config;
use GlpiPlugin\Urbackup\Profile;
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__, 4));
}
include_once GLPI_ROOT . '/inc/includes.php';
Html::header_nocache();
Session::checkLoginUser();
if (!Profile::canCurrentUser(READ)) {
http_response_code(403);
exit;
}
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET') {
http_response_code(405);
exit;
}
$itemtype = (string) ($_GET['itemtype'] ?? '');
if ($itemtype === '' || !class_exists($itemtype) || !Config::isItemtypeEnabled($itemtype)) {
exit;
}
$value = (int) ($_GET['value'] ?? 0);
Dropdown::show($itemtype, [
'name' => 'host_items_id',
'value' => $value,
'entity' => Session::getActiveEntities(),
'display_emptychoice' => true,
]);