$id), array('id' => 'ID'), array('id'), true);
$query = "delete from pbx_voicemail_usuarios where numero_ramal ='$ramal'";
pg_query($dbcon, $query);
Ajusta_ramais($ramal, $dbcon, false, false);
Ajusta_tabelas('ramal', $ramal, $dbcon);
}
$tpParcial = 0;
if (strpos($filtro, ',')) {
$tpParcial = 1;
} else if (strpos($filtro, '-')) {
$sql = "select count(*) from pbx_sip_ramais where callerid ilike '%$filtro%'";
$result = pg_query($dbcon, $sql);
$param = pg_fetch_row($result);
if ($param[0] > 0) {
$tpParcial = 0;
} else {
$tpParcial = 2;
}
}
if ((!empty($filtro)) && ($tpParcial == 0)) {
$compl = " where (nome ilike '%$filtro%' or callerid ilike '%$filtro%')";
} else if ((!empty($filtro)) && ($tpParcial == 1)) {
$params = explode(",", $filtro);
$compl = "";
foreach ($params as $param) {
$dado .= empty($dado) ? "'$param'" : ",'$param'";
}
$compl = " where (nome in($dado) or callerid in($dado))";
} else if ((!empty($filtro)) && ($tpParcial == 2)) {
$params = explode("-", $filtro);
$compl = "";
$ini = $params[0];
$fim = $params[1];
$qtd1 = strlen($ini) - strlen(ltrim($ini, "0"));
$qtd2 = strlen($fim) - strlen(ltrim($fim, "0"));
if ($qtd1 >= 1) {
$ini1 = '-' . $qtd1;
} else {
$ini1 = $ini;
}
if ($qtd2 >= 1) {
$fim1 = '-' . $qtd2;
} else {
$fim1 = $fim;
}
$compl = " where nome between '$ini' and '$fim' and ramal between '$ini1' and '$fim1'";
} else {
$compl = "";
}
$query = "SELECT id, nome, context, dispositivo, saldo_prepago, habilita_prepago, callerid,
CAST(case when (length(nome) - length(ltrim(nome,'0'))) >= 1 then '-'||(length(nome) - length(ltrim(nome,'0')))::bigint ELSE nome END AS bigint) AS ramal
FROM pbx_sip_ramais
WHERE org_id = {$org_id}
$compl
ORDER BY ramal ASC, nome ASC";
$params = "&pbxRequest=1&numRamal=$filtro";
$links = PaginaDados($idProg, $query, $params, $regPagina, $offSet, $pagMostra, true);
$query .= " limit $regPagina offset $offSet";
$result = pg_query($dbcon, $query);
?>