PABX da Simples IP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
19 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="admin/css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="ISO-8859-1" />
<script type="text/javascript" src="admin/js/jquery-1.4.js"></script>
<script type="text/javascript" src="admin/js/jquery.blockUI.js?v2.29"></script>
<script src="admin/js/jquery.min.js" type="text/javascript"></script>
<script src="admin/js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="admin/js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="admin/js/pbxAjax.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#form1").validationEngine({
sucess: function() {
document.form1.submit();
},
failure: function() {}
})
});
function selecionados() {
var j = document.form1.disponiveis.length;
for (var i = 0; i < j; i++) {
if (document.form1.disponiveis.options[i].selected) {
var x = document.getElementById("ramais"); //retorna o objeto select
var options = x.getElementsByTagName("option"); //pega a lista de options do select
var y = document.createElement('option'); //cria um novo elemento option
y.text = document.form1.disponiveis.options[i].text;
y.value = document.form1.disponiveis.options[i].value;
try {
x.add(y, null); // adiciona um novo option no fim da lista para navegadores complacentes
} catch (ex) {
x.add(y); // adiciona um novo option no fim da lista para o IE
}
}
}
j = document.form1.ramais.length;
for (var n = 0; n < j; n++) {
for (var i = 0; i < document.form1.disponiveis.length; i++) {
if (document.form1.disponiveis.options[i].text == document.form1.ramais.options[n].text) {
document.form1.disponiveis.options[i] = null;
}
}
}
}
function _remove() {
for (var i = 0; i < document.form1.ramais.length; i++) {
if (document.form1.ramais.options[i].selected) {
var x = document.getElementById("disponiveis"); //retorna o objeto select
var options = x.getElementsByTagName("option"); //pega a lista de options do select
var y = document.createElement('option'); //cria um novo elemento option
y.text = document.form1.ramais.options[i].text;
y.value = document.form1.ramais.options[i].value;
try {
x.add(y, null); // adiciona um novo option no fim da lista para navegadores complacentes
} catch (ex) {
x.add(y); // adiciona um novo option no fim da lista para o IE
}
}
}
j = document.form1.disponiveis.length;
for (var n = 0; n < j; n++) {
for (var i = 0; i < document.form1.ramais.length; i++) {
if (document.form1.ramais.options[i].text == document.form1.disponiveis.options[n].text) {
document.form1.ramais.options[i] = null;
}
}
}
}
function marca_todos() {
for (var i = 0; i < document.form1.ramais.length; i++) {
document.form1.ramais.options[i].selected = true;
}
}
</script>
<link href="admin/css/forms.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$acao = $_GET["acao"];
$acao2 = $_GET["acao2"];
$org_id = GetOrganizacao();
/*
* Parametros necessarios para manter a pagina<EFBFBD><EFBFBD>o.
*/
$param = sprintf('&numRamal=%s&pgn=%s&bloco=%s&pg=%s', $_REQUEST['numRamal'], $_REQUEST['pgn'], $_REQUEST['bloco'], $_REQUEST['pg']);
if ($acao2 == "salva") {
$id = $_POST["id"] ?? 0;
$nome = RemoveAcentos($_POST["nome"], true);
$numero = 0;
if ($acao == "edita") {
$query = "select nome from pbx_grupos_atendimento where nome='$nome' and id <> $id";
} else {
$query = "select nome from pbx_grupos_atendimento where nome='$nome'";
$numero = GetIdGrupoAtendimento($dbcon);
}
$msg = '';
$result = pg_query($dbcon, $query);
$dados = pg_fetch_array($result);
$existe = trim($dados['nome']);
if ($existe != '') {
$msg = "JA EXISTE UM GRUPO COM O NOME $existe";
}
if ($numero > 63) {
$msg = "<EFBFBD> PERMITIDO CADASTRAR APENAS 63 GRUPOS";
}
if (!empty($msg)) {
echo "<script>
alert({$msg};);
history.back();
</script>";
} else {
if ($acao == "inseri") {
$query = "INSERT INTO pbx_grupos_atendimento(id,nome,org_id) VALUES ('$numero','$nome', $org_id)";
pg_query($dbcon, $query);
$id_ult = $numero;
}
if ($acao == "edita") {
$ramaisExistentes = array();
$query = "select ramal from pbx_grupos_atendimento_ramais where id_grupo = $id";
$result = pg_query($dbcon, $query);
while ($row = pg_fetch_row($result))
$ramaisExistentes[] = $row[0];
$query = "UPDATE pbx_grupos_atendimento
SET nome='$nome'
WHERE id=$id";
pg_query($dbcon, $query);
$query = "delete from pbx_grupos_atendimento_ramais where id_grupo=$id";
pg_query($dbcon, $query);
}
$ramais = $_POST["ramais"];
for ($i = 0; $i < count($ramais); $i++) {
if ($acao == "edita") {
$query = "insert into pbx_grupos_atendimento_ramais (id_grupo,ramal,org_id) values ($id,'$ramais[$i]', $org_id)";
} else {
$query = "insert into pbx_grupos_atendimento_ramais (id_grupo,ramal,org_id) values ($id_ult,'$ramais[$i]', $org_id)";
}
pg_query($dbcon, $query);
}
AtualizaRamaisCaptura($dbcon);
////gera arquivos e executa o reload dos dados no asterisk
gera_arquivos($dbcon, 'SIP_RAMAIS'); //gera arquivos e executa o reload dos dados no asterisk
gera_arquivos($dbcon, 'IAX_PBX'); //gera arquivos e executa o reload dos dados no asterisk
// GeraDahdi($dbcon, 1);
GeraKhomp($dbcon, 1);
gera_arquivos($dbcon, 'DIGIVOICE');
echo "<script type=\"text/javascript\">
//fecha a janela presa no meio do sistema
fecha_popup(0,'index.php?idProg=10030&pbxRequest=1$param&acao=$acao');
</script>";
}
}
if ($acao == "edita") {
$id = $_GET["id"] ?? "0";
$query = "SELECT * FROM pbx_grupos_atendimento where id=$id";
$result = pg_query($dbcon, $query);
} else {
$id = 0;
$query = "SELECT * FROM pbx_grupos_atendimento where id is null";
}
$result = pg_query($dbcon, $query);
while ($dados = pg_fetch_array($result)) {
$id = $dados["id"];
$nome = $dados["nome"];
}
function GetTableRamal($tipo)
{
$org_id = GetOrganizacao();
//if((strpos($tipo, 'SIP') !== false) || (strpos($tipo, 'DAHDI') !== false)){return "update pbx_sip_ramais set pickupgroup = '%s', callgroup = '%s' where nome = '%s'";}
if (strpos($tipo, 'SIP') !== false) {
return "update pbx_sip_ramais set pickupgroup = '%s', callgroup = '%s' where nome = '%s' and org_id = {$org_id}";
}
if (strpos($tipo, 'IAX') !== false) {
return "update pbx_iax_pbx set pickupgroup = '%s', callgroup = '%s' where nome = '%s' and org_id = {$org_id}";
}
if (strpos($tipo, 'DGV') !== false) {
return "update pbx_dgv set capturar = '%s', grupo = '%s' where numero = '%s' and org_id = {$org_id}";
}
if (strpos($tipo, 'DAHDI') !== false) {
return "update pbx_dahdi set capturar = '%s', grupo = '%s' where numero = '%s' and org_id = {$org_id}";
}
if (strpos($tipo, 'KHOMP') !== false) {
return "update pbx_khomp set capturar = '%s', grupo = '%s' where numero = '%s' and org_id = {$org_id}";
}
return false;
}
function AtualizaRamaisCaptura($dbcon)
{
LimpaGruposCapturaRamais($dbcon);
$org_id = GetOrganizacao();
$query = "SELECT a.ramal
FROM pbx_grupos_atendimento_ramais a, pbx_ramais b
WHERE b.nome = a.ramal
AND a.org_id = {$org_id}
ORDER BY a.ramal, a.id_grupo";
$result = pg_query($dbcon, $query);
$ramais = array();
while ($dados = pg_fetch_array($result)) {
$ramais[] = $dados['ramal'];
}
foreach ($ramais as $ramalGrupo) {
$query = "SELECT a.id_grupo, a.ramal, b.tipo_ramal as dispositivo
FROM pbx_grupos_atendimento_ramais a, pbx_ramais b
WHERE b.nome = a.ramal
AND a.ramal = '$ramalGrupo'
ORDER BY a.ramal, a.id_grupo";
$result = pg_query($dbcon, $query);
$pick = '';
$callgrupRamal = '';
$start = 0;
$tipo = '';
while ($dados = pg_fetch_array($result)) {
if (!$start) {
$callgrupRamal = $dados['id_grupo'];
$start++;
}
$pick .= !$pick ? $dados['id_grupo'] : ',' . $dados['id_grupo'];
$tipo = strtoupper($dados['dispositivo']);
}
$query = GetTableRamal($tipo);
$query = sprintf($query, $pick, $callgrupRamal, $ramalGrupo);
pg_query($dbcon, $query);
}
}
function GetRamaisExcluidos($ramaisExistentes, $ramais)
{
$ramaisExcl = array();
$exist = false;
foreach ($ramaisExistentes as $ramal) {
$exist = false;
foreach ($ramais as $ramalAtu) {
if ($ramal == $ramalAtu) {
$exist = true;
break;
}
}
if (!$exist) {
$ramaisExcl[] = $ramal;
}
}
return $ramaisExcl;
}
function GetIdGrupoAtendimento($dbcon)
{
$org_id = GetOrganizacao();
$query = "SELECT id as id FROM pbx_grupos_atendimento WHERE 1=1 AND org_id = {$org_id} ORDER BY id";
$sql = pg_query($dbcon, $query);
$id = 1;
if (!pg_num_rows($sql))
return $id;
while ($row = pg_fetch_row($sql)) {
$idBanco = $row[0];
if ($idBanco != $id)
return $id;
$id++;
}
return $id;
}
function LimpaGruposCapturaRamais($db)
{
$org_id = GetOrganizacao();
$query = "update pbx_sip_ramais set pickupgroup = '', callgroup = '' where 1=1 and org_id = {$org_id}";
pg_query($db, $query);
$query = "update pbx_iax_pbx set pickupgroup = '', callgroup = '' where 1=1 and org_id = {$org_id}";
pg_query($db, $query);
$query = "update pbx_dgv set capturar = '', grupo = '' where 1=1 and org_id = {$org_id}";
pg_query($db, $query);
$query = "update pbx_dahdi set capturar = '', grupo = '' where 1=1 and org_id = {$org_id}";
pg_query($db, $query);
$query = "update pbx_khomp set capturar = '', grupo = '' where 1=1 and org_id = {$org_id}";
pg_query($db, $query);
}
?>
<form name="form1" method="post" action="index.php?idProg=11030&pbxRequest=1&acao=<?php echo $acao; ?>&acao2=salva<?php echo $param; ?>" id="form1">
<table border="1" align="center" cellpadding="0" cellspacing="0" class="tabela">
<tr bordercolor="#EAEAEA" class="cabecalho">
<td>
<div align="center">CADASTRO DE GRUPOS DE CAPTURA
<input name="id" type="hidden" id="id" value="<?= ($acao == 'edita') ? $id : null; ?>" />
</div>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<fieldset>
<legend class="labels"><span class="style5">Nome:</span></legend>
<input name="nome" type="text" class="validate[required,length[0,100]] caixas" id="nome2" value="<?= ($acao == 'edita') ? $nome : null; ?>" size="70\" maxlength="50" />
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr class="labels" bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td>
<fieldset>
<legend>Grupo:</legend>
<table width="94%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabela">
<tr class="labels">
<td width="44%">
<div align="center">Ramais Dispon&iacute;veis</div>
</td>
<td width="9%">&nbsp;</td>
<td width="47%">
<div align="center">Ramais Selecionados</div>
</td>
</tr>
<tr>
<td width="45%">
<div align="center">
<select name="disponiveis[]" size="10" multiple="multiple" class="caixas" id="disponiveis">
<?php
if ($acao == 'edita') {
$query2 = "SELECT id, nome FROM pbx_ramais WHERE org_id = {$org_id} AND tipo_ramal not in('IAX', 'PBX') and nome not in (select ramal from pbx_grupos_atendimento_ramais where id_grupo=$id) order by nome asc";
} else {
$query2 = "SELECT id, nome FROM pbx_ramais WHERE org_id = {$org_id} AND tipo_ramal not in('IAX', 'PBX') order by nome asc";
}
$result2 = pg_query($dbcon, $query2);
while ($dados2 = pg_fetch_array($result2)) { ?>
<option value="<?php echo $dados2['nome'] ?>"><?php echo $dados2['nome']; ?></option>
<?php } ?>
</select>
</div>
</td>
<td width="10%">
<div align="center">
<br />
<input name="btinclui" type="button" id="btinclui" class="labels" value="&gt;" onclick="selecionados(); marca_todos();" />
<br />
<input name="btRemove" type="button" id="btRemove" class="labels" value="&lt;" onclick="_remove();" />
<br />
<br />
</div>
</td>
<td width="45%">
<div align="center">
<select name="ramais[]" size="10" multiple="multiple" class="validate[required] caixas" id="ramais">
<?php
$query2 = "SELECT * from pbx_grupos_atendimento_ramais where id_grupo = $id";
$result2 = pg_query($dbcon, $query2);
$ramaisInc = array();
while ($dados2 = pg_fetch_array($result2)) { ?>
<option value="<?php echo $dados2['ramal'] ?>"><?php echo $dados2['ramal']; ?></option>
<?php
if (!isset($_POST['Submit'])) {
$ramaisInc[] = $dados2['ramal'];
}
}
if (!isset($_POST['Submit'])) {
$_SESSION['ramaisInc'] = $ramaisInc;
}
?>
</select>
</div>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td>
<div align="center">
<span class="style1"></span>
<span class="style1"></span>
<span class="style1"></span>
<span class="style1">
<input name="Submit2" type="button" class="labels" onclick="fecha_popup();" value="Fechar">
<input name="Submit" type="submit" class="labels" value="Salvar" OnClick="marca_todos();">
</span>
</div>
</td>
</tr>
</table>
</form>