$tpl->MES = $mes; $tpl->MESNOME = getMesNome($mes, false); $tpl->block('EACH_MESREF'); $tpl->ANO = $ano; $tpl->block('EACH_ANOREF'); $tpl->HIDEMESREF = $mes . "-" . $ano; $tpl->CHECKED_DATA = 'checked="checked"'; } else { $conts = $user->getContratos(); if ($conts[0]['id'] != null) { $qtdCont = count($conts); $z = 1; foreach ($conts as $cont) { $contrato = new Contrato($cont['id']); //$tpl->CONTNOME = "-------- ".$contrato->geraNome(). " --------"; $rgis = $contrato->getAllUcs(true); if ($rgis[0]['id'] != null) { $qtdRgi = count($rgis); $w = 1; foreach ($rgis as $rgi) { $uc = new UnidadeConsumidora($rgi['id']); $tpl->RGID = $rgi['id']; $tpl->DISABLE_OPT = ""; $tpl->RGI = $uc->get('rgi'); $tpl->RGINOME = $uc->getEndereco() . " ~> " . $uc->getNome(); $tpl->block('EACH_RGI'); if ($z < $qtdCont) { $tpl->MS_COMA = ","; } elseif ($z == $qtdCont) { $tpl->MS_COMA = $w < $qtdRgi ? "," : ""; }