forked from SimplesIP/pabx-app
Lucas Awade
10 months ago
11 changed files with 561 additions and 418 deletions
@ -1,193 +1,202 @@
|
||||
<?php |
||||
$acao = isset($_GET['acao']) ? $_GET['acao'] : ''; |
||||
$id = isset($_GET['id']) ? $_GET['id'] : ''; |
||||
$id2 = isset($_GET['id2']) ? $_GET['id2'] : ''; |
||||
$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']); |
||||
|
||||
if ($acao == "deleta") { |
||||
$id = $_GET["id"] ?? "0"; |
||||
|
||||
$query = "SELECT * FROM pbx_iax_pbx where id=$id"; |
||||
$result = pg_query($dbcon, $query); |
||||
if ($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ção de restrição a audios cadastrada na interface de grupo de usuarios |
||||
$query = "delete from pbx_grupo_audio_ramal where nome = '$ramal' "; |
||||
pg_query($dbcon, $query); |
||||
|
||||
$query = "delete from pbx_iax_pbx where id='$id'"; |
||||
pg_query($dbcon, $query); |
||||
|
||||
$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, true, false); |
||||
gera_arquivos($dbcon, 'IAX_PBX', 1, 0); |
||||
$acao = isset($_GET['acao']) ? $_GET['acao'] : ''; |
||||
$id = isset($_GET['id']) ? $_GET['id'] : ''; |
||||
$id2 = isset($_GET['id2']) ? $_GET['id2'] : ''; |
||||
$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']); |
||||
|
||||
if ($acao == "deleta") { |
||||
$id = $_GET["id"] ?? "0"; |
||||
|
||||
$query = "SELECT * FROM pbx_iax_pbx where id=$id"; |
||||
$result = pg_query($dbcon, $query); |
||||
if ($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ção de restrição a audios cadastrada na interface de grupo de usuarios |
||||
$query = "delete from pbx_grupo_audio_ramal where nome = '$ramal' "; |
||||
pg_query($dbcon, $query); |
||||
|
||||
$query = "delete from pbx_iax_pbx where id='$id'"; |
||||
pg_query($dbcon, $query); |
||||
|
||||
$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, true, false); |
||||
gera_arquivos($dbcon, 'IAX_PBX', 1, 0); |
||||
} |
||||
?> |
||||
|
||||
<table width="99%" align="center" border="0" cellpadding="2" cellspacing="0" class="filtro"> |
||||
<table width="99%" align="center" border="0" cellpadding="2" cellspacing="0" class="filtro"> |
||||
<tr> |
||||
<td colspan="2">Ramal/Bina</td> |
||||
</tr> |
||||
<tr > |
||||
<td nowrap="nowrap" > |
||||
<tr> |
||||
<td nowrap="nowrap"> |
||||
<input name="numRamal" type="text" id="numRamal" value="<?php echo $_GET["numRamal"]; ?>" onkeyup="ConsultaRamal('index.php?idProg=10010&pbxRequest=1', event);" size="20">
|
||||
<input name="locaRamal" type="button" id="locaRamal" value="Localizar" onClick="ConsultaRamal('index.php?idProg=10010&pbxRequest=1&pesquisa=1');"> |
||||
</td> |
||||
<td align="right" nowrap="nowrap" > |
||||
<td align="right" nowrap="nowrap"> |
||||
<a href="#" onclick="abre_janela('710', '700', 'index.php?idProg=11010&pbxRequest=1&acao=inseri<?php echo $filtroNovo; ?>');"><img src="images/novo.gif" width="20" height="20" border="0" align="absmiddle" />NOVO RAMAL IAX </a>
|
||||
<a href="#" onclick="abre_janela('600', '240', 'index.php?idProg=11110&pbxRequest=1');"><img src="images/global.gif" width="20" height="20" border="0" align="absmiddle" />CONFIGURAÇÃO GLOBAL </a> |
||||
</td> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td colspan="2"> |
||||
<table width="100%" class="grid" border="0" cellspacing="0" cellpadding="2"> |
||||
<table width="100%" class="grid" border="0" cellspacing="0" cellpadding="2"> |
||||
<tr> |
||||
<th align="center" ><div align="center">Id</div></th> |
||||
<th align="left" > Ramal</th> |
||||
<th align="left" > Bina</th> |
||||
<th align="left" > Contexto</th> |
||||
<th align="left" > Dispositivo </th> |
||||
<th align="center"> |
||||
<div align="center">Id</div> |
||||
</th> |
||||
<th align="left"> Ramal</th> |
||||
<th align="left"> Bina</th> |
||||
<th align="left"> Contexto</th> |
||||
<th align="left"> Dispositivo </th> |
||||
<th align="center"> <span title="Número de Depndências">Dep</span></th> |
||||
<th align="center" >Ações</th> |
||||
<th align="center">Ações</th> |
||||
</tr> |
||||
<?php |
||||
$janW = '500'; |
||||
$janH = '400'; |
||||
$compl = ""; |
||||
$janW = '500'; |
||||
$janH = '400'; |
||||
$compl = ""; |
||||
|
||||
$tpParcial = 0; |
||||
|
||||
if (strpos($filtro, ',')) { |
||||
$tpParcial = 1; |
||||
} else if (strpos($filtro, '-')) { |
||||
$sql = "SELECT count(*) FROM pbx_iax_pbx WHERE identificador ILIKE '%$filtro%'"; |
||||
$result = pg_query($dbcon, $sql); |
||||
$param = pg_fetch_row($result); |
||||
if ($param[0] > 0) { |
||||
$tpParcial = 0; |
||||
} else { |
||||
$tpParcial = 2; |
||||
} |
||||
} |
||||
|
||||
$tpParcial = 0; |
||||
|
||||
if (strpos($filtro, ',')) { |
||||
$tpParcial = 1; |
||||
} else if (strpos($filtro, '-')) { |
||||
$sql = "select count(*) from pbx_iax_pbx where identificador 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 = " AND (nome ilike '%$filtro%' OR callerid ILIKE '%$filtro%')"; |
||||
} else if ((!empty($filtro)) && ($tpParcial == 1)) { |
||||
$params = explode(",", $filtro); |
||||
$compl = ""; |
||||
foreach ($params as $param) { |
||||
//$param = trim(str_replace("'", "", $param)); |
||||
$dado .= empty($dado) ? "'$param'" : ",'$param'"; |
||||
} |
||||
|
||||
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) { |
||||
//$param = trim(str_replace("'", "", $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'"; |
||||
$compl = " AND (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 { |
||||
$compl = ""; |
||||
$fim1 = $fim; |
||||
} |
||||
|
||||
$query = "drop table if exists ramal_iax; |
||||
create temporary table ramal_iax( |
||||
id integer, |
||||
nome character varying(100), |
||||
context character varying(100), |
||||
dispositivo character varying(250), |
||||
saldo_prepago numeric(12,4), |
||||
habilita_prepago integer, |
||||
callerid character varying(100), |
||||
ramal integer |
||||
); |
||||
|
||||
insert into ramal_iax (id,nome, context,dispositivo, saldo_prepago, habilita_prepago,callerid,ramal) |
||||
SELECT id,nome, context,dispositivo, saldo_prepago, habilita_prepago,identificador, |
||||
cast(case when (length(nome) - length(ltrim(nome,'0'))) >= 1 then '-'||(length(nome) - length(ltrim(nome,'0')))::int--||nome |
||||
$compl = " AND nome BETWEEN '$ini' AND '$fim' AND ramal BETWEEN '$ini1' AND '$fim1'"; |
||||
} else { |
||||
$compl = ""; |
||||
} |
||||
|
||||
$query = "SELECT id, nome, context, dispositivo, saldo_prepago, habilita_prepago, identificador, |
||||
cast(case when (length(nome) - length(ltrim(nome,'0'))) >= 1 then '-'||(length(nome) - length(ltrim(nome,'0')))::int |
||||
else nome |
||||
end as int) |
||||
FROM pbx_iax_pbx; |
||||
|
||||
select * from ramal_iax $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); |
||||
$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><?php echo $dados['id']; ?></div></td>
|
||||
<td align="left"><a href="#" style="color: #000" onclick="abre_janela('710', '700', 'index.php?idProg=11010&pbxRequest=1&acao=edita&id=<?php echo $dados['id']; ?><?php echo $params; ?>');"><?php echo $dados['nome']; ?></a></td>
|
||||
<td align="left"><?php echo $dados['callerid']; ?></td>
|
||||
<td align="left"><?php echo $dados['context']; ?></td>
|
||||
<td align="left"><?php echo $dados['dispositivo']; ?></td>
|
||||
<td width="30" align="center"><?php echo $dep; ?></td>
|
||||
<td width="40"> |
||||
<table width="100%" border="0" cellpadding="1" cellspacing="0" bordercolor="#EAEAEA"> |
||||
<tr> |
||||
<td width="20" style="border:0"><div align="center"><a href="#" title="Editar Ramal: <?php echo $dados['nome']; ?>" onclick="abre_janela('710', '700', 'index.php?idProg=11010&pbxRequest=1&acao=edita&id=<?php echo $dados['id']; ?><?php echo $params; ?>');"><img src="images/edit.gif" alt="EDITAR O RAMAL:<?php echo $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: <?php echo $dados['nome']; ?>" onclick="excluir('<?php echo $dados['nome']; ?>', '<?php echo $dados['id']; ?>', 'DESEJA REALMENTE EXLUIR O RAMAL:<?php echo $dados['nome']; ?>', 'index.php?idProg=10010&pbxRequest=1&acao=deleta&id=<?php echo $dados['id']; ?><?php echo $params; ?>', 'RAMAL IAX');" id="<?php echo $dados['id']; ?>" nome="<?php echo $dados['nome']; ?>" ><img src="images/delete.gif" alt="APAGAR O RAMAL:<?php echo $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ências não pode ser apagado!" alt="Este registro não pode ser apagado!" width="16" height="16" border="0" ></div></td> |
||||
<?php } ?> |
||||
</tr> |
||||
</table> |
||||
</td> |
||||
</tr> |
||||
<?php |
||||
$z++; |
||||
} if ($z == 0) { |
||||
?> |
||||
<tr align="center" valign="middle" bordercolor="#999999" class="labels"> |
||||
<td colspan="6"><div align="center" class="info"><img src="images/shutdown.gif" width="24" height="24" border="0" align="absmiddle" /> Não foram encontrados registros </div></td> |
||||
</tr> |
||||
<?php } ?> |
||||
<tr> |
||||
<th align="center" colspan="8"><table width="100%" class="grid" border="0" cellspacing="0" cellpadding="2"><tr><th align="center" style="width: 90%; border:0;"><?php echo $links; ?></th><th align="right" style="width: 10%; border:0;"><?php echo sprintf("%s/%s", $pagMostra, $totalReg); ?></th></tr></table></th>
|
||||
end as int) AS ramal |
||||
FROM pbx_iax_pbx |
||||
WHERE 1=1 |
||||
$compl ORDER BY 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); |
||||
$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><?php echo $dados['id']; ?></div>
|
||||
</td> |
||||
<td align="left"><a href="#" style="color: #000" onclick="abre_janela('710', '700', 'index.php?idProg=11010&pbxRequest=1&acao=edita&id=<?php echo $dados['id']; ?><?php echo $params; ?>');"><?php echo $dados['nome']; ?></a></td>
|
||||
<td align="left"><?php echo $dados['callerid']; ?></td>
|
||||
<td align="left"><?php echo $dados['context']; ?></td>
|
||||
<td align="left"><?php echo $dados['dispositivo']; ?></td>
|
||||
<td width="30" align="center"><?php echo $dep; ?></td>
|
||||
<td width="40"> |
||||
<table width="100%" border="0" cellpadding="1" cellspacing="0" bordercolor="#EAEAEA"> |
||||
<tr> |
||||
<td width="20" style="border:0"> |
||||
<div align="center"><a href="#" title="Editar Ramal: <?php echo $dados['nome']; ?>" onclick="abre_janela('710', '700', 'index.php?idProg=11010&pbxRequest=1&acao=edita&id=<?php echo $dados['id']; ?><?php echo $params; ?>');"><img src="images/edit.gif" alt="EDITAR O RAMAL:<?php echo $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: <?php echo $dados['nome']; ?>" onclick="excluir('<?php echo $dados['nome']; ?>', '<?php echo $dados['id']; ?>', 'DESEJA REALMENTE EXLUIR O RAMAL:<?php echo $dados['nome']; ?>', 'index.php?idProg=10010&pbxRequest=1&acao=deleta&id=<?php echo $dados['id']; ?><?php echo $params; ?>', 'RAMAL IAX');" id="<?php echo $dados['id']; ?>" nome="<?php echo $dados['nome']; ?>"><img src="images/delete.gif" alt="APAGAR O RAMAL:<?php echo $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ências não pode ser apagado!" alt="Este registro não pode ser apagado!" width="16" height="16" border="0"></div> |
||||
</td> |
||||
<?php } ?> |
||||
</tr> |
||||
</table> |
||||
</td> |
||||
</tr> |
||||
<?php |
||||
$z++; |
||||
} |
||||
if ($z == 0) { |
||||
?> |
||||
<tr align="center" valign="middle" bordercolor="#999999" class="labels"> |
||||
<td colspan="6"> |
||||
<div align="center" class="info"><img src="images/shutdown.gif" width="24" height="24" border="0" align="absmiddle" /> Não foram encontrados registros </div> |
||||
</td> |
||||
</tr> |
||||
<?php } ?> |
||||
<tr> |
||||
<th align="center" colspan="8"> |
||||
<table width="100%" class="grid" border="0" cellspacing="0" cellpadding="2"> |
||||
<tr> |
||||
<th align="center" style="width: 90%; border:0;"><?php echo $links; ?></th>
|
||||
<th align="right" style="width: 10%; border:0;"><?php echo sprintf("%s/%s", $pagMostra, $totalReg); ?></th>
|
||||
</tr> |
||||
</table> |
||||
</th> |
||||
</tr> |
||||
</table> |
||||
</table> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
|
||||
</body> |
||||
</html> |
||||
|
||||
</html> |
Loading…
Reference in new issue