<?php
declare(strict_types=1);
require_once __DIR__.'/common.php';
pcApiMethod('POST');$cfg=pcApiCfg($mysqli);$agent=pcApiAuth($mysqli);$payload=pcApiJson(32768);$id=(int)$agent['id'];$version=pcApiText($payload['agent_version']??'',40);$code=pcApiInt($payload['agent_version_code']??0,0,1000000000,'agent_version_code');$ip=pcApiIp();$stmt=$mysqli->prepare("UPDATE ti_pc_agentes SET ultima_comunicacao=NOW(),ultimo_ip_remoto=?,agent_version=COALESCE(NULLIF(?,''),agent_version),agent_version_code=IF(?=0,agent_version_code,?) WHERE id=?");$stmt->bind_param('ssiii',$ip,$version,$code,$code,$id);$stmt->execute();$stmt->close();pcApiOut(200,['ok'=>true,'status'=>'ATIVO','server_time'=>date(DATE_ATOM),'sync_interval_min'=>(int)($cfg['sync_interval_min']??30)]);
