Files
site_for_glpi/get_computer_location.php

18 lines
641 B
PHP

<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/glpi_api.php';
header('Content-Type: application/json');
$user = checkAuth($pdo);
if (!$user) { http_response_code(401); exit; }
$computerId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$computerId) { echo json_encode(['location_id' => null]); exit; }
$glpi = new GlpiApi(GLPI_API_URL, GLPI_APP_TOKEN, GLPI_USERNAME, GLPI_PASSWORD);
$computer = $glpi->getItem('Computer', $computerId);
if ($computer && isset($computer['locations_id'])) {
echo json_encode(['location_id' => $computer['locations_id']]);
} else {
echo json_encode(['location_id' => null]);
}