'Unauthorized']); exit; } require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; header('Content-Type: application/json'); ini_set('display_errors', '0'); error_reporting(E_ALL); try { // Cache file (1 hour TTL) $cacheFile = __DIR__ . '/cache/matrici.json'; if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < 3600)) { readfile($cacheFile); exit; } $api = VisualLimsApiClient::getInstance(); $data = $api->get('Matrice'); $matrici = []; if (isset($data['value']) && is_array($data['value'])) { foreach ($data['value'] as $item) { $nome = $item['NomeMatrice'] ?? ''; if ($nome !== '' && substr($nome, 0, 1) !== '*') { $matrici[] = [ 'IdMatrice' => $item['IdMatrice'], 'NomeMatrice' => $nome, 'MacroMatrice' => $item['MacroMatrice'] ?? null, ]; } } usort($matrici, fn($a, $b) => strcasecmp($a['NomeMatrice'], $b['NomeMatrice'])); } $json = json_encode(['success' => true, 'value' => $matrici]); if (!is_dir(__DIR__ . '/cache')) mkdir(__DIR__ . '/cache', 0777, true); file_put_contents($cacheFile, $json); echo $json; } catch (Exception $e) { http_response_code(500); echo json_encode(['success' => false, 'message' => $e->getMessage()]); }