<?php
declare(strict_types=1);
require_once __DIR__.'/auth.php';require_once __DIR__.'/conexao.php';require_once __DIR__.'/inventario_pc_helpers.php';date_default_timezone_set('America/Sao_Paulo');
if(!pcEhRenan()){http_response_code(403);exit('Somente Renan pode executar este instalador.');}$mysqli->set_charset('utf8mb4');$error='';$done=[];$code=null;
if($_SERVER['REQUEST_METHOD']==='POST'){try{pcCheckCsrf();if(!pcTableExists($mysqli,'ti_computadores'))throw new RuntimeException('Instale primeiro o modulo de computadores.');pcRunSql($mysqli,__DIR__.'/SQL_INVENTARIO_WINDOWS.sql');$done[]='Banco e indices do inventario Windows criados ou confirmados.';$code=strtoupper(substr(bin2hex(random_bytes(8)),0,4).'-'.substr(bin2hex(random_bytes(8)),0,4).'-'.substr(bin2hex(random_bytes(8)),0,4));$hash=hash('sha256',$code);$actor=pcUsuario();$stmt=$mysqli->prepare('UPDATE ti_pc_config SET enrollment_hash=?,enrollment_expires_at=DATE_ADD(NOW(),INTERVAL 24 HOUR),enrollment_uses_remaining=1,updated_by=? WHERE id=1');$stmt->bind_param('ss',$hash,$actor);$stmt->execute();$stmt->close();$done[]='Codigo inicial criado para uma ativacao e 24 horas.';$done[]='O modulo usa a permissao existente de Computadores.';$done[]='Agente Windows: '.(pcAgentExists()?'pacote disponivel em downloads/.':'publique Agente-TI-Extrema-Windows.zip em downloads/.');}catch(Throwable $e){$error=$e->getMessage();}}
$csrf=pcCsrf();
?><!doctype html><html lang="pt-BR"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Instalar inventario Windows</title><link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet"><link href="inventario_mobile_style.css?v=3" rel="stylesheet"></head><body><div class="app"><main class="main"><section class="hero"><div><h2>Inventario automatico <span>Windows</span></h2><p>Complementa o cadastro de computadores e notebooks sem apagar ou duplicar os registros atuais.</p></div></section><?php if($error):?><div class="flash err"><?=pcE($error)?></div><?php endif;?><?php foreach($done as $item):?><div class="flash ok"><i class="bi bi-check-circle-fill"></i><?=pcE($item)?></div><?php endforeach;?><?php if($code):?><section class="form-card"><div class="codebox"><span>Codigo inicial</span><code><?=pcE($code)?></code></div><p class="callout warn">Copie agora. O banco armazena somente o hash.</p><a class="btn primary" href="inventario_computadores.php">Abrir painel</a></section><?php else:?><section class="form-card"><p class="callout">Execute uma vez como Renan. Repetir nao apaga registros.</p><form method="post"><input type="hidden" name="csrf_token" value="<?=pcE($csrf)?>"><button class="btn primary" type="submit"><i class="bi bi-database-check"></i>Instalar inventario Windows</button></form></section><?php endif;?></main></div></body></html>
