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.
 
 
 
 
 
 

536 lines
26 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/utils.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 MM_jumpMenu(targ, selObj, restore) { //v3.0
eval("deps.location='index.php?idProg=11228&pbxRequest=1&id1=" + selObj.options[selObj.selectedIndex].value + "'");
if (restore) {
selObj.selectedIndex = 0;
}
}
function seleciona_tudo(val) {
for (i = 0; i < document.form1.elements.length; i++) {
if (document.form1.elements[i].type == "checkbox") {
if ((document.form1.elements[i].name != "grava") && (document.form1.elements[i].name != "ddds[]")) {
document.form1.elements[i].checked = val;
}
}
}
}
function TodosMarcados() {
for (i = 0; i < document.form1.elements.length; i++) {
if (document.form1.elements[i].type == "checkbox") {
if ((document.form1.elements[i].name != "grava") && (document.form1.elements[i].name != "ddds[]")) {
if ((document.form1.elements[i].name != 'marcaTodos') && (!document.form1.elements[i].checked)) {
return 0;
}
}
}
}
return 1;
}
function FocusDepto() {
deps.document.getElementById('departamento').focus();
}
var win;
function NovaJanela(pagina, nome, w, h, add_atributos) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
//Atributos
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += 'resizable=yes,scrollbars=yes,location=no';
if (add_atributos != "") {
settings += ',' + add_atributos;
}
win = window.open(pagina, nome, settings);
//Corre<EFBFBD><EFBFBD>o para outros navegadores
if (parseInt(navigator.appVersion) >= 4) {
win.window.focus();
}
}
function abre(w, h, url) {
NovaJanela(url, 'localidades', w, h, 'Scrollbars=yes');
}
</script>
<link href="admin/css/forms.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$acao = $_GET["acao"];
$acao2 = isset($_GET["acao2"]) ? $_GET["acao2"] : 'novo';
$numErros = 0;
$msgErro = '';
$acao2 = $_GET["acao2"];
$org_id = GetOrganizacao();
$param = sprintf('&numRamal=%s&pgn=%s&bloco=%s&pg=%s', $_REQUEST['numRamal'], $_REQUEST['pgn'], $_REQUEST['bloco'], $_REQUEST['pg']);
if ($acao2 == "salva") {
if (md5($_SESSION['SSKeepPassword']) == $_POST["senha"]) {
$senha = substr($_SESSION['SSKeepPassword'], 0, GetQtdeDigitoSenha());
} else {
$senha = substr($_POST["senha"], 0, GetQtdeDigitoSenha());
}
$id = $_POST["id"];
$ativaUsuario = $_POST['ativaUsuario'] == 1 ? "A" : "D";
$nome = RemoveAcentos($_POST["nome"], true);
$apelido = strtolower(RemoveAcentos($_POST["apelido"]));
$empresa = $_POST["empresa"];
$departamento = $_POST["departamento"];
$matricula = str_pad($_POST["matricula"], GetQtdeDigitoConta(), '0', STR_PAD_LEFT);
$lfixo = $_POST["lfixo"];
$lcelular = $_POST["lcelular"];
$ifixo = $_POST["ifixo"];
$icelular = $_POST["icelular"];
$l0300 = $_POST["l0300"];
$l0500 = $_POST["l0500"];
$l0303 = $_POST["l0303"];
$l0800 = $_POST["l0800"];
$l0900 = $_POST["l0900"];
$internacional = $_POST["internacional"];
$grava = isset($_POST["grava"]) ? 1 : 0;
$temporizador = (isset($_POST["temporizador"]) && is_numeric($_POST["temporizador"])) ? $_POST["temporizador"] : 0;
$habilita_prepago = !HabilitaPrepago() ? '0' : $_POST['habilita_prepago'];
if ($lfixo != 1) {
$lfixo = 0;
}
if ($lcelular != 1) {
$lcelular = 0;
}
if ($ifixo != 1) {
$ifixo = 0;
}
if ($icelular != 1) {
$icelular = 0;
}
if ($l0300 != 1) {
$l0300 = 0;
} else {
$todos = "0300-";
}
if ($l0500 != 1) {
$l0500 = 0;
} else {
$todos = $todos . "0500-";
}
if ($l0303 != 1) {
$l0303 = 0;
} else {
$todos = $todos . "0303-";
}
if ($l0800 != 1) {
$l0800 = 0;
} else {
$todos = $todos . "0800-";
}
if ($l0900 != 1) {
$l0900 = 0;
} else {
$todos = $todos . "0900";
}
if (substr($todos, -1, 1) == "-") {
$todos = substr($todos, 0, strlen($todos) - 1);
}
if ($internacional != 1) {
$internacional = 0;
}
$cmd = array();
if ($acao == "inseri") {
$cmdId = "pbx_cs_usuarios";
$ret = GetSequencias($cmdId);
$result = $ret > 0;
if (!$result) {
$numErros++;
$msgErro = "N<EFBFBD>o foi poss<EFBFBD>vel acessar a base de dados!";
} else {
$id = $ret;
$cmd[] = "INSERT INTO pbx_cs_usuarios
(id,nome, apelido, matricula, senha, empresa, departamento, local_fixo, local_celular, inter_fixo, inter_celular, internacional, lig_0300, lig_0500, lig_0303, lig_0800, lig_0900, grava_ligacao, temporizacao, todos_lig, status, habilita_prepago, org_id)
VALUES ('$id','$nome', '$apelido', '$matricula','$senha', '$empresa', '$departamento', '$lfixo', '$lcelular', '$ifixo', '$icelular', '$internacional', '$l0300', '$l0500', '$l0300', '$l0800', '$l0900', '$grava', '$temporizador','$todos','$ativaUsuario','$habilita_prepago', $org_id)";
}
}
if ($acao == "edita") {
$cmd[] = "UPDATE pbx_cs_usuarios SET nome='$nome', apelido='$apelido', senha='$senha', empresa='$empresa', departamento='$departamento',
local_fixo='$lfixo', local_celular='$lcelular', inter_fixo='$ifixo', inter_celular='$icelular', internacional='$internacional',
lig_0300='$l0300', lig_0500='$l0500', lig_0303='$l0303', lig_0800='$l0800', lig_0900='$l0900', grava_ligacao='$grava',
temporizacao='$temporizador', todos_lig='$todos', habilita_prepago='$habilita_prepago', status='$ativaUsuario'
WHERE matricula='$matricula'";
}
$cmd[] = "delete from pbx_cs_usuarios_ddd where id_usuario= (SELECT id FROM pbx_cs_usuarios where matricula = '$matricula')";
$ddds = $_POST["ddds"];
if (isset($ddds) && $result) {
foreach ($ddds as $dis) {
$cmd[] = "insert into pbx_cs_usuarios_ddd (id_ddd,id_usuario, org_id) values ($dis, (SELECT id FROM pbx_cs_usuarios where matricula = '$matricula'), $org_id)";
}
}
if (!$numErros) {
$inTran = 0;
$result = pg_query($dbcon, 'begin');
try {
if (!$result) {
throw new Exception('N<EFBFBD>o foi poss<EFBFBD>vel acessar a base de dados!');
}
$inTran = 1;
foreach ($cmd as $queryRpl) {
$result = pg_query($dbcon, $queryRpl);
if (!$result) {
throw new Exception('N<EFBFBD>o foi poss<EFBFBD>vel gravar dados da sincroniza<EFBFBD><EFBFBD>o!');
}
}
$result = pg_query($dbcon, 'commit');
if (!$result) {
throw new Exception('N<EFBFBD>o foi poss<EFBFBD>vel finalizar a transa<EFBFBD><EFBFBD>o!');
}
} catch (Exception $ex) {
if ($inTran) {
pg_query($dbcon, 'rollback');
}
$msgErro = $ex->getMessage();
$numErros++;
}
}
} //fim salva
if ($acao == "edita") {
$id = $_REQUEST["id"] ?? "0";
$query = "SELECT * FROM pbx_cs_usuarios where id=$id";
$result = pg_query($dbcon, $query);
$dados = pg_fetch_array($result);
} else if ($acao2 == 'novo') {
$matricula = 0;
$numErros = 0;
if (GeraContaAuto()) {
//$matricula = GetContaFromMaster($dbMaster);
$cmdId = "pbx_cs_usuarios_conta";
$ret = GetSequencias($cmdId);
$result = $ret > 0;
if ($result) {
$mat = $ret;
$mat = str_pad($mat, GetQtdeDigitoConta(), '0', STR_PAD_LEFT);
$matricula = $mat;
} else {
$msgErro = "N<EFBFBD>o foi poss<EFBFBD>vel gerar a conta!";
$numErros++;
}
}
$query = "SELECT * FROM pbx_cs_usuarios where org_id = {$org_id} ";
$result = pg_query($dbcon, $query);
$dados = pg_fetch_array($result);
$dados['matricula'] = $matricula;
}
if ($numErros) {
$dados = $_POST;
}
$digitosConta = GetQtdeDigitoConta();
$ativaUsuario = $dados['status'];
$id = $dados["id"];
$nome = $dados["nome"];
$apelido = $dados["apelido"];
$empresa = $dados["empresa"];
$departamento = $dados["departamento"];
$matricula = $dados["matricula"];
$_SESSION['SSKeepPassword'] = $dados["senha"];
$senha = md5($dados["senha"]);
$lfixo = $dados["local_fixo"];
$lcelular = $dados["local_celular"];
$ifixo = $dados["inter_fixo"];
$icelular = $dados["inter_celular"];
$l0300 = $dados["lig_0300"];
$l0500 = $dados["lig_0500"];
$l0303 = $dados["lig_0303"];
$l0800 = $dados["lig_0800"];
$l0900 = $dados["lig_0900"];
$internacional = $dados["internacional"];
$grava = $dados["grava_ligacao"];
$temporizador = $dados["temporizacao"];
$saldo_prepago = FormataValor($dados["saldo_prepago"]);
$habilita_prepago = !HabilitaPrepago() ? '0' : $dados["habilita_prepago"];
?>
<form name="form1" method="post" action="index.php?idProg=11028&pbxRequest=1&acao=<?= $acao; ?>&acao2=salva<?= $param; ?>" id="form1">
<br />
<br>
<table border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" class="tabela">
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA" class="cabecalho">
<td>
<div align="center">CADASTRO DE CONTAS
<input name="id" type="hidden" id="id2" value="<?= (($acao == 'edita') || ($numErros)) ? $id : null; ?>">
<input name="departamento" type="hidden" class="textbox" id="departamento3" value="<?= (($acao == 'edita') || ($numErros)) ? $departamento : null; ?>" size="10" maxlength="10" />
</div>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="labels">
<td width="52%">
<fieldset>
<legend class="labels">Nome:</legend>
<input name="nome" type="text" class="validate[required,length[0,100]] caixas" id="nome" value="<?= (($acao == 'edita') || ($numErros)) ? $nome : null; ?>" size="50" maxlength="100" />
</fieldset>
</td>
<td width="27%">
<fieldset>
<legend class="labels">Apelido:</legend>
<input name="apelido" type="text" class="validate[optional,length[0,100]] caixas" id="apelido3" value="<?= (($acao == 'edita') || ($numErros)) ? $apelido : null; ?>" size="20" maxlength="100" />
</fieldset>
</td>
<td width="21%">
<fieldset>
<legend class="labels">Senha:</legend>
<input name="senha" type="password" class="caixas" id="senha2" value="<?= (($acao == 'edita') || ($numErros)) ? $senha : "1234"; ?>" onkeyup="somenteNumeros(this);" size="20" maxlength="<?= GetQtdeDigitoSenha(); ?>" />
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="labels">
<td width="22%">
<fieldset>
<legend class="labels">Matricula:</legend>
<input name="matricula" type="text" class="validate[required,custom[onlyNumber],length[0,<?= $digitosConta; ?>]] caixas" id="matricula" value="<?= $matricula; ?>" size="15" maxlength="<?= $digitosConta; ?>" />
</fieldset>
</td>
<td width="14%">
<fieldset>
<legend class="labels">Empresa:</legend>
<select name="empresa" class="validate[required] caixas" id="empresa" onChange="MM_jumpMenu('deps', this, 0);" onblur="FocusDepto();">
<option value="">----------</option>
<?php
$query2 = "SELECT * FROM pbx_empresa WHERE org_id = {$org_id} ORDER BY id ASC";
$result2 = pg_query($dbcon, $query2);
$z = 1;
while ($dados2 = pg_fetch_array($result2)) { ?>
<option value="<?= $dados2['id']; ?>" <?= ($empresa == trim($dados2['id'])) ? " selected" : null; ?>><?= $dados2['nome']; ?></option>
<?php } ?>
</select>
</fieldset>
</td>
<td width="40%">
<fieldset>
<legend class="labels">Departamento:</legend>
<iframe src="index.php?idProg=11228&pbxRequest=1&id1=<?= ($acao == "inseri") ? $empresa2 : $empresa; ?><?= ($acao == "edita") ? "&id2=" . $departamento : null; ?>" width="100%" height="20" frameborder="0" scrolling="no" name="deps">
</iframe>
</fieldset>
</td>
<td width="25%">
<fieldset>
<legend class="labels">Ativar Usu<EFBFBD>rio</legend>
<input name="ativaUsuario" type="checkbox" value="1" <?= ($ativaUsuario == "A" || !$ativaUsuario) ? "checked" : null; ?> /> Ativar
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<fieldset>
<legend class="labels">Tipos de Liga&ccedil;&atilde;o:
<input type="checkbox" id="marcaTodos" name="marcaTodos" value="1" onclick="seleciona_tudo(this.checked);" />
Marcar Todos
</legend>
<span class="labels"><input name="lfixo" type="checkbox" id="lfixo" value="1" <?= ($lfixo == 't') ? "checked" : null; ?>>
Local Fixo
<input name="lcelular" type="checkbox" id="lcelular" value="1" <?= ($lcelular == 't') ? "checked" : null; ?>>
Local Celular
<input name="ifixo" type="checkbox" id="ifixo" value="1" <?= ($ifixo == 't') ? "checked" : null; ?>>
Interubano Fixo
<input name="icelular" type="checkbox" id="icelular" value="1" <?= ($icelular == 't') ? "checked" : null; ?>>
Interubano Celular
<input name="internacional" type="checkbox" id="internacional" value="1" <?= ($internacional == 't') ? "checked" : null; ?>>
Internacional
<input name="l0300" type="checkbox" id="l0300" value="1" <?= ($l0300 == 't') ? "checked" : null; ?>>
0300
<input name="l0303" type="checkbox" id="l050024" value="1" <?= ($l0303 == 't') ? "checked" : null; ?> />
0303
<br />
<input name="l0500" type="checkbox" id="l0500" value="1" <?= ($l0500 == 't') ? "checked" : null; ?>>
0500
<input name="l0800" type="checkbox" id="l0800" value="1" <?= ($l0800 == 't') ? "checked" : null; ?> />
0800
<input name="l0900" type="checkbox" id="l0900" value="1" <?= ($l0900 == 't') ? "checked" : null; ?> />
0900</span>
</fieldset>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="labels">
<td width="25%">
<fieldset>
<legend class="labels">Grava Liga&ccedil;&atilde;o:</legend>
<input name="grava" type="checkbox" id="grava2" value="1" <?= ($grava) ? "checked" : null; ?> />
</fieldset>
</td>
<td width="25%">
<fieldset>
<legend class="labels">Temporizador:</legend>
<input name="temporizador" type="text" class="validate[optional,custom[onlyNumber],length[0,100]] caixas" id="temporizador4" value="<?= (($acao == 'edita') || ($numErros)) ? $temporizador : "0"; ?>" size="10" maxlength="100" />
</fieldset>
</td>
<td width="25%">
<fieldset>
<legend class="labels">Habilita Pr<EFBFBD>-pago</legend>
<input name="habilita_prepago" type="radio" value="1" <?= (!HabilitaPrepago()) ? 'disabled="disabled"' : null; ?> <?= ($acao == 'edita') && ($habilita_prepago) ? "checked" : null; ?> />Sim
<input name="habilita_prepago" type="radio" value="0" <?= (!HabilitaPrepago()) ? 'disabled="disabled"' : null; ?> <?= ($acao == 'edita') && (!$habilita_prepago) ? "checked" : null ?> <?= ($acao != 'edita') ? "checked" : null; ?> />N&atilde;o</span>
</fieldset>
</td>
<td width="25%">
<fieldset>
<legend class="labels">Saldo Pr<EFBFBD>-pago:</legend>
<input name="saldo_prepago" type="text" id="saldo_prepago" class="caixas" value="<?= ($acao == 'edita') ? $saldo_prepago : '0,00'; ?>" disabled="disabled" />
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="cabecalho">
<div align="center">DDD'S LIBERADOS: </div>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td class="labels">
<div align="left">
<?php
$headTable = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$linhas = "<tr><td>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">
<tr>
<td bgcolor=\"#066BB6\" width=\"20\"><span style=\"color:#FFFFFF\">{UF}</span></td>
{CELULAS}
</tr>
</table>
</td></tr>";
//$celuas = "<td><a href=\"dddlocalidades.php?ddd=$ddd\">$ddd</a></td>";
$footTable = "</table>";
$query2 = "SELECT min(idddd) AS id, uf, codigo AS ddd FROM pbx_tab_ddd GROUP BY uf, codigo ORDER BY 2,3";
$result2 = pg_query($dbcon, $query2);
$z = 0;
$tabDDD = "";
$ufAtu = "";
$cells = "";
$start = 0;
while ($dados2 = pg_fetch_array($result2)) {
$idDdd = $dados2['id'];
$uf = $dados2['uf'];
$ddd = $dados2['ddd'];
if ($acao == 'edita') {
$query3 = "SELECT id_usuario FROM pbx_cs_usuarios_ddd where id_usuario=$id and id_ddd='$idDdd'";
$result3 = pg_query($dbcon, $query3);
$marca = "";
if ($result3 && pg_num_rows($result3))
$marca = "checked";
}
if (!$start++) {
$ufAtu = $uf;
}
if ($ufAtu != $uf) {
$linhaTmp = str_replace("{UF}", $ufAtu, $linhas);
$tabDDD .= str_replace("{CELULAS}", $cells, $linhaTmp);
$ufAtu = $uf;
$cells = "";
}
$bgColor = ($z % 2) == 0 ? "#CCCCCC" : "#BBBBFF";
$chek = "<input name=\"ddds[]\" type=\"checkbox\" id=\"ddds[]\" value=\"$idDdd\" $marca>";
$cells .= "<td>$chek<a href=\"javaScript:abre('530','400','index.php?idProg=11128&pbxRequest=1&ddd=$ddd');\">$ddd</a></td>";
$z++;
}
echo "<div style=\"height: 160px; width: 600px; overflow: auto; padding: 8px;\">" . $headTable . $tabDDD . $footTable . "</div>";
?>
</div>
</td>
</tr>
<tr bordercolor="#EAEAEA" bgcolor="#EAEAEA">
<td>
<div align="center">
<input name="Submit2" type="button" class="labels" onclick="fecha_popup();" value="Fechar">
<input name="Submit" type="submit" class="labels" value="Salvar">
</div>
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
if (TodosMarcados()) {
document.getElementById('marcaTodos').checked = 'checked';
}
<?php
if (($acao == 'edita') || (GeraContaAuto())) {
echo "document.getElementById('matricula').readOnly = true;\n";
}
if ($numErros) {
if ($msgErro) {
echo "alert('$msgErro');\n";
}
} else if ($acao2 == "salva") {
echo "fecha_popup(0,'index.php?idProg=10028&pbxRequest=1$param&acao=$acao');";
}
?>
</script>
</form>