<?php
$acao = isset($_GET['acao']) ? trim($_GET['acao']) : 'select';
$id = isset($_GET['id']) ? trim($_GET['id']) : 0;
$filtro = isset($_GET["numRamal"]) ? trim($_GET["numRamal"]) : '';
$filtroNovo = !isset($_GET["pgn"]) ? '' : sprintf("& numRamal%s& pgn=%s& bloco=%s& pg=%s", $_GET["numRamal"], $_GET["pgn"], $_GET["bloco"], $_GET["pg"]);
$recontaPag = ($acao == 'inseri') || ($acao == "deleta") || isset($_GET['pesquisa']);
$janW = '700';
$janH = '400';
$org_id = GetOrganizacao();
if ($acao == "deleta") {
$id = $_GET["id"] ?? "0";
$query = "SELECT * FROM pbx_sip_ramais where id=$id";
$result = pg_query($dbcon, $query);
$dados = pg_fetch_array($result);
$ramal = $dados['nome'];
//Apaga a relacao entre rotas e ramais
$query = "delete from pbx_rotas_saida_ramais where ramal = '$ramal'";
pg_query($dbcon, $query);
//Apaga ch secretaria
$query = "delete from pbx_chefe_secretaria where numero = '$ramal'";
pg_query($dbcon, $query);
//Rela<EFBFBD> <EFBFBD> o de restri<EFBFBD> <EFBFBD> o a audios cadastrada na interface de grupo de usuarios
$query = "delete from pbx_grupo_audio_ramal where nome = '$ramal' ";
pg_query($dbcon, $query);
//Remove ramais da agenda
$query = "delete from rma_depto_ramais where nome = '$ramal' ";
pg_query($dbcon, $query);
$query = "delete from pbx_sip_ramais where id='$id'";
pg_query($dbcon, $query);
GrvAudita($dbcon, $idProg, 'pbx_sip_ramais', 'DEL', array(), array('id' => $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);
?>
< table width = "99%" align = "center" border = "0" cellpadding = "2" cellspacing = "0" class = "filtro" >
< tr >
< td colspan = "2" > Ramal/Bina< / td >
< / tr >
< tr >
< td align = "left" nowrap = "nowrap" >
< input name = "numRamal" type = "text" id = "numRamal" value = " <? = $_GET [ "numRamal" ]; ?> " onkeyup = "ConsultaRamal('index.php?idProg=10009&pbxRequest=1', event);" size = "20" >
< input name = "locaRamal" type = "button" id = "locaRamal" value = "Localizar" onClick = "ConsultaRamal('index.php?idProg=10009&pbxRequest=1&pesquisa=1', 0);" >
< / td >
< td align = "right" nowrap = "nowrap" >
< a href = "#" onclick = "NovaJanela('index.php?idProg=11009&pbxRequest=1&acao=inseri <? = $filtroNovo ; ?> ', 'CadRamalSip', '950', '900', 'resizable=YES,scrollbars=YES');" >< img src = "images/novo.gif" width = "20" height = "20" border = "0" align = "absmiddle" /> NOVO RAMAL SIP </ a >
< a href = "#" onclick = "abre_janela('500', '410', 'index.php?idProg=11109&pbxRequest=1');" > < img src = "images/global.gif" width = "20" height = "20" border = "0" align = "absmiddle" / > CONFIGURAÇ Ã O GLOBAL < / a >
< / td >
< / tr >
< tr >
< td colspan = "2" >
< table width = "100%" class = "grid" border = "0" cellspacing = "0" cellpadding = "2" >
< tr >
< th align = "center" > Id< / th >
< th align = "left" > Ramal< / th >
< th align = "left" > Bina< / th >
< th align = "left" > Contexto < / th >
< th align = "left" > Dispositivo< / th >
< th align = "right" > Saldo Pré -pago< / th >
< th align = "center" > Pré -pago< / th >
< th align = "center" > < span title = "N<EFBFBD> mero de Depend<EFBFBD> ncias" > Dep< / span > < / th >
< th align = "center" > A<EFBFBD> <EFBFBD> es< / th >
< / tr >
<?php
$z = 0;
while ($dados = pg_fetch_array($result)) {
$totaldep = GetTotalDependencias('ramal', $dados['nome']);
$opcao = 'ramal';
$acao = $dados['nome'];
$recursoTipo = 'Ramal';
$nomeRecurso = $dados['nome'];
$dep = GetLinkDependenciaRecurso($opcao, $acao, $recursoTipo, $nomeRecurso, $totaldep);
?>
< tr >
< td width = "50" align = "center" >
< div > <? = $dados [ 'id' ]; ?> </ div >
< / td >
< td align = "left" >
< a href = "" style = "color:#000" onclick = "abre_janela('1024', '700', 'index.php?idProg=11009&pbxRequest=1&acao=edita&id= <? = $dados [ 'id' ]; ?><? = $params ; ?> ');" >
<? = $dados [ 'nome' ]; ?>
< / a >
< / td >
< td align = "left" > <? = $dados [ 'callerid' ]; ?> </ td >
< td align = "left" > <? = $dados [ 'context' ]; ?> </ td >
< td align = "left" > <? = $dados [ 'dispositivo' ]; ?> </ td >
< td align = "right" > <? = FormataValor ( $dados [ 'saldo_prepago' ]); ?> </ td >
< td width = "20" align = "center" >
<? = $dados [ 'habilita_prepago' ] ? '<img src="images/button_ok16.png" alt="Habilitado!" width="16" height="16" border="0">' : '<img src="images/fecha16.png" alt="Desabilitado!" width="16" height="16" border="0">' ; ?>
< / td >
< td width = "30" align = "center" > <? = $dep ; ?> </ td >
< td width = "40" >
< table width = "100%" border = "0" cellspacing = "0" cellpadding = "1" align = "center" style = "border-color:#FFFFFF " >
< tr >
< td width = "20" style = "border:0" >
< div align = "center" >
< a href = "#" title = "Editar Ramal: <? = $dados [ 'nome' ]; ?> " onclick = "abre_janela('850', '700', 'index.php?idProg=11009&pbxRequest=1&acao=edita&id= <? = $dados [ 'id' ]; ?><? = $params ; ?> ');" >
< img src = "images/edit.gif" alt = "EDITAR O RAMAL: <? = $dados [ 'nome' ]; ?> " width = "16" height = "16" border = "0" >
< / a >
< / div >
< / td >
<?php if ( ! $totaldep ) { ?>
< td width = "20" style = "border:0" >
< div align = "center" >
< a href = "#" title = "Excluir Ramal: <? = $dados [ 'nome' ]; ?> " onclick = "excluir(' <? = $dados [ 'nome' ]; ?> ', ' <? = $dados [ 'id' ]; ?> ', 'DESEJA REALMENTE EXLUIR O RAMAL: <? = trim ( $dados [ 'nome' ]); ?> ', 'index.php?idProg=10009&pbxRequest=1&acao=deleta&id= <? = $dados [ 'id' ]; ?> &numRamal= <? = $params ; ?> ');" >
< img src = "images/delete.gif" alt = "APAGAR O RAMAL: <? = $dados [ 'nome' ]; ?> " width = "16" height = "16" border = "0" >
< / a >
< / div >
< / td >
<?php } else { ?>
< td style = "border:0" width = "33%" >
< div align = "center" >
< img src = "images/delete.gif" title = "Este registro possui depend<EFBFBD> ncias n<EFBFBD> o pode ser apagado!" alt = "Este registro n<EFBFBD> o pode ser apagado!" width = "16" height = "16" border = "0" >
< / div >
< / td >
<?php } ?>
< / tr >
< / table >
< / td >
< / tr >
<?php $z ++ ; ?>
<?php } ?>
<?php if ( $z == 0 ) { ?>
< tr align = "center" valign = "middle" bordercolor = "#999999" class = "labels" >
< td colspan = "9" >
< div align = "center" class = "info" >
< img src = "images/shutdown.gif" width = "24" height = "24" border = "0" align = "absmiddle" / > N<EFBFBD> o foram encontrados registros
< / div >
< / td >
< / tr >
<?php } ?>
< tr >
< th align = "center" colspan = "9" >
< table width = "100%" class = "grid" border = "0" cellspacing = "0" cellpadding = "2" >
< tr >
< th align = "center" style = "width: 90%; border:0;" > <? = $links ; ?> </ th >
< th align = "right" style = "width: 10%; border:0;" > <? = sprintf ( "%s/%s" , $pagMostra , $totalReg ); ?> </ th >
< / tr >
< / table >
< / th >
< / tr >
< / table >
< / td >
< / tr >
< / table >
< / body >
< / html >