forked from SimplesIP/pabx-app
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.
249 lines
8.5 KiB
249 lines
8.5 KiB
<?php |
|
|
|
$tpLayout = 1; |
|
if (empty($_POST['tipoTable'])) { |
|
$tipoTable = $_GET['tipoTable']; |
|
} else { |
|
$tipoTable = $_POST['tipoTable']; |
|
} |
|
if (empty($_POST['ramal'])) { |
|
$ramal = $_GET['ramal']; |
|
} else { |
|
$ramal = $_POST['ramal']; |
|
} |
|
$busca = " |
|
SELECT |
|
coalesce(c.dpto_nome, 'PADRÃO') as dpto_nome, |
|
c.dpto_id, |
|
a.nome, |
|
a.ddd , |
|
a.callerid as nome_completo, |
|
a.tipo_table |
|
FROM |
|
pbx_ramais_mesa a |
|
left join rma_depto_ramais b ON b.nome = a.nome |
|
left join rma_departamentos c ON c.dpto_id = b.dpto_id |
|
WHERE |
|
a.nome='$ramal' |
|
ORDER BY |
|
a.nome |
|
ASC"; |
|
|
|
|
|
|
|
$result = pg_query($busca); |
|
if ($rowRamal = pg_fetch_array($result)) { |
|
$telefone = $rowRamal["nome"]; |
|
$dispositivo = $rowRamal["dispositivo"]; |
|
$nome = $rowRamal["nome_completo"]; |
|
$departamentoNome = $rowRamal["dpto_nome"]; |
|
$depto_id = $rowRamal["dpto_id"]; |
|
$tipoTable = $rowRamal["tipo_table"]; |
|
$ddd = $rowRamal["ddd"]; |
|
$tipoTable = $rowRamal["tipo_table"]; |
|
} |
|
|
|
|
|
|
|
/* |
|
* VERIFICA SE CLIENTE CLICOU EM FINALIZAR OPERACAO |
|
*/ |
|
|
|
|
|
if ($_POST['concluir'] == "Finalizar") { |
|
/* |
|
* RECEBE VALORES DO FORMULARIO |
|
*/ |
|
$nome = $_POST['nome']; |
|
$depto_id = $_POST['depto']; |
|
$ramal = $_POST['ramal']; |
|
$telefone = $_POST['telefone']; |
|
$ddd = $_POST['ddd']; |
|
if (TrataValor($nome, $ddd, $telefone, $trDDD) == 1) { |
|
|
|
/* |
|
* VERIFICA SE JA EXISTE ALGUM REGISTRO COM AS INFORMACOES PASSADAS NO FORMULARIO! |
|
*/ |
|
$query = "SELECT a.callerid,c.dpto_nome FROM pbx_ramais_mesa a,rma_depto_ramais b,rma_departamentos c WHERE a.nome='$telefone' AND a.callerid='$nome' AND b.dpto_id=c.dpto_id AND a.nome=b.nome AND b.dpto_id='$depto_id'"; |
|
$result = pg_query($dbcon, $query); |
|
if (pg_num_rows($result) >= 1) { |
|
$query = "SELECT dpto_nome FROM rma_depto_ramais WEHRE nome='$telefone' AND dpto_id='$depto_id'"; |
|
$result = pg_query($dbcon, $query); |
|
if (pg_num_rows($result) >= 1) { |
|
$mes = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">Ja existe registro com essas informacoes!"; |
|
} |
|
} else { |
|
/* |
|
* VERIFICA QUAL TABELA ESTA O RAMAL |
|
*/ |
|
|
|
if ($tipoTable == "SIP") { |
|
$tabela = "pbx_sip_ramais"; |
|
$campoRamal = "nome"; |
|
$campoNome = "callerid"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "IAX") { |
|
$tabela = "pbx_iax_pbx"; |
|
$campoRamal = "nome"; |
|
$campoNome = "identificador"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "DGV") { |
|
$tabela = "pbx_dgv"; |
|
$campoRamal = "nome"; |
|
$campoNome = "callerid"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "PBX") { |
|
$tabela = "pbx_ramais_pbx"; |
|
$campoRamal = "numero"; |
|
$campoNome = "identificador"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "DAHDI") { |
|
$tabela = "pbx_dahdi"; |
|
$campoRamal = "numero"; |
|
$campoNome = "identificador"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "KHOMP") { |
|
$tabela = "pbx_khomp"; |
|
$campoRamal = "numero"; |
|
$campoNome = "identificador"; |
|
$telefone = $ramal; |
|
} elseif ($tipoTable == "AGD") { |
|
$tabela = "pbx_ramais_agenda"; |
|
$campoRamal = "rma_telefone"; |
|
$campoNome = "rma_nome"; |
|
$campoTelefone = ", rma_telefone='$telefone'"; |
|
} else { |
|
$tabela = ""; |
|
$campoRamal = ""; |
|
$campoNome = ""; |
|
} |
|
|
|
/* |
|
* VERIFICA SE RAMAL JA ESTÁ RELACIONADO COM ALGUM DEPARTAMENTO |
|
*/ |
|
$query = "SELECT nome FROM rma_depto_ramais WHERE nome='$ramal'"; |
|
$result = pg_query($dbcon, $query); |
|
if (pg_num_rows($result) >= 1) { |
|
/* |
|
* SE O PARAMETRO DO DEPARTAMENTO RECEBIDO FOR IGUAL A 0(zero) DELETA REGISTRO NA TABELA DE RELACIONAMENTO |
|
*/ |
|
if ($depto_id == '0') { |
|
$delete = "DELETE FROM rma_depto_ramais WHERE nome='$telefone'"; |
|
$result = pg_query($dbcon, $delete); |
|
} |
|
/* |
|
* ATUALIZA DEPARTAMENTO DO RAMAL |
|
*/ |
|
$update = "UPDATE rma_depto_ramais SET dpto_id='$depto_id' ,nome='$telefone', data_reg = now() WHERE nome='$ramal'"; |
|
$result = pg_query($dbcon, $update); |
|
|
|
/* |
|
* VERIFICA SE DEPARTAMENTO FOI ATUALIZADO COM SUCESSO |
|
*/ |
|
$query = "SELECT dpto_id,nome FROM rma_depto_ramais WHERE dpto_id='$depto_id' AND nome='$telefone'"; |
|
$result = pg_query($dbcon, $query); |
|
if (pg_num_rows($result) < 1) { |
|
$mes = "Erro ao alterar o departmaneto!"; |
|
} |
|
} else { |
|
/* |
|
* SE RAMAL NÃO ESTIVER RELACIONADO COM NENHUM DEPARTAMENTO,SISTEMA FAZ A INSERÇÃO DO RAMAL NA TABELA |
|
*/ |
|
$insert = "INSERT INTO rma_depto_ramais (dpto_id,nome) VALUES ('$depto_id','$telefone')"; |
|
$result = pg_query($dbcon, $insert); |
|
$query = "SELECT dpto_id,nome FROM rma_depto_ramais WHERE dpto_id='$depto_id' AND nome='$telefone'"; |
|
$result = pg_query($dbcon, $query); |
|
if (pg_num_rows($result) < 1) { |
|
$mes = "Erro ao inserir o departmaneto!"; |
|
} |
|
} |
|
|
|
/* |
|
* EXECUTA UPDATE NA TABELA |
|
*/ |
|
$update = "UPDATE $tabela SET $campoNome='$nome' $campoTelefone WHERE $campoRamal='$ramal'"; |
|
$query = pg_query($dbcon, $update); |
|
/* |
|
* ATUALIZA DDD DO RAMAL |
|
*/ |
|
$update = "UPDATE pbx_ramais_agenda SET ddd='$ddd' WHERE rma_telefone='$ramal'"; |
|
$result = pg_query($dbcon, $update); |
|
|
|
/* |
|
* VERIFICA SE UPDATE FOI REALIZADO COM SUCESSO! |
|
*/ |
|
$query = "SELECT callerid FROM pbx_ramais_mesa WHERE callerid='$nome' AND nome='$telefone'"; |
|
$result = pg_query($dbcon, $query); |
|
|
|
|
|
|
|
if (pg_num_rows($result) >= 1) { |
|
if ($tipoTable != 'AGD') { |
|
__GravaAstDb($dbcon, $ramal, $nome); |
|
} |
|
$mes = "<img src=\"imgSite/stAprovado.png\">Registro alterado com sucesso!"; |
|
} else { |
|
$mes = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">Não foi possivel alterar registro!"; |
|
} |
|
} |
|
} |
|
echo "<script>opener.location.reload(); |
|
fecha_popup(0,'index.php?idProg=140&pbxRequest=1'); |
|
</script>"; |
|
} |
|
/* |
|
* LOOP DE DEPARTAMENTOS |
|
*/ |
|
$buscaDep = "SELECT dpto_nome,dpto_id FROM rma_departamentos WHERE dpto_status='1'"; |
|
$resultDep = pg_query($dbcon, $buscaDep); |
|
while ($rowDep = pg_fetch_array($resultDep)) { |
|
$nomeDep = $rowDep['dpto_nome']; |
|
$idDep = $rowDep['dpto_id']; |
|
$optionDep .= "<option value=\"" . $idDep . "\" " . ($idDep == $depto_id ? "selected" : "") . ">" . $nomeDep . "</option>"; |
|
} |
|
$optionDep .= "<option value=\"0\" " . ($depto_id == "0" ? "selected" : "") . ">PADRÃO</option>"; |
|
|
|
function TrataValor($nome, $ddd, $telefone, $trDDD) { |
|
$img = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">"; |
|
if (empty($nome)) { |
|
return " $img Por favor preencha o campo nome!"; |
|
} |
|
|
|
if (empty($telefone)) { |
|
return " $img Por favor preencha o campo telefone!"; |
|
} |
|
if (!is_numeric($telefone)) { |
|
$erro = 2; |
|
return " $img Preencha o campo Telefone corretamente,permitido somente numero!"; |
|
} |
|
if ($erro != 2) { |
|
return 1; |
|
} |
|
} |
|
|
|
if (TrataValor($nome, $ddd, $telefone, $trDDD) != 1) { |
|
$mes = TrataValor($nome, $ddd, $telefone, $trDDDD); |
|
} |
|
|
|
|
|
if ($tipoTable == "AGD") { |
|
$trDDD = true; |
|
} else { |
|
$trDDD = false; |
|
} |
|
$smarty->assign('nome', $nome); |
|
$smarty->assign('idRamal', $ramal); |
|
$smarty->assign('ramal', $telefone); |
|
$smarty->assign('tipoAgenda', $tipoTable); |
|
$smarty->assign('mes', $mes); |
|
$smarty->assign('optionDep', $optionDep); |
|
$smarty->assign('trDDD', $trDDD); |
|
$smarty->assign('ddd', $ddd); |
|
$smarty->display("agendaRamais/ramais/ramaisUpdate.html"); |
|
|
|
function __GravaAstDb($dbcon, $ramal, $nome) { |
|
include_once('admin/funcoes.php'); |
|
CommandAsterisk2($dbcon, 'BINA-NOME', $ramal, $nome); |
|
} |
|
|
|
?>
|
|
|