|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$tpLayout = 1;
|
|
|
|
|
$tipoAgenda = $_GET['tipoTable'];
|
|
|
|
|
$ddd = GetDddPadrao();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* RECEBE VALORES VIA POST
|
|
|
|
|
*/
|
|
|
|
|
if ($_POST['concluir'] == "Finalizar") {
|
|
|
|
|
$nome = $_POST['nome'];
|
|
|
|
|
$ramal = $_POST['ramal'];
|
|
|
|
|
$departamento = $_POST['depto'];
|
|
|
|
|
$ddd = $_POST['ddd'];
|
|
|
|
|
$valor = TrataValor($nome, $ddd, $ramal);
|
|
|
|
|
if ($valor == 1) {
|
|
|
|
|
/*
|
|
|
|
|
* VERIFICA SE JA POSSUI ALGUM RAMAL CADASTRADO
|
|
|
|
|
*/
|
|
|
|
|
$query = "SELECT nome FROM pbx_ramais_mesa WHERE nome='$ramal'";
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
if (pg_num_rows($result) >= 1) {
|
|
|
|
|
|
|
|
|
|
$mes = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">Telefone j<EFBFBD> esta cadastrado!";
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* INSERI REGISTROS
|
|
|
|
|
*/
|
|
|
|
|
$insertRamal = "INSERT INTO pbx_ramais_agenda (rma_telefone,rma_nome,ddd) VALUES ('$ramal','$nome','$ddd')";
|
|
|
|
|
$result = pg_query($dbcon, $insertRamal);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* VERIFICA SE REGISTROS FORAM INSERIDOS
|
|
|
|
|
*/
|
|
|
|
|
$busca = "SELECT rma_telefone,rma_nome FROM pbx_ramais_agenda WHERE rma_telefone='$ramal' AND rma_nome='$nome' AND ddd='$ddd'";
|
|
|
|
|
$result = pg_query($dbcon, $busca);
|
|
|
|
|
if (pg_num_rows($result) >= 1) {
|
|
|
|
|
/*
|
|
|
|
|
* RELACIONA REGISTRO COM O DEPARTAMENTO
|
|
|
|
|
*/
|
|
|
|
|
$insert = "INSERT INTO rma_depto_ramais (nome,dpto_id) VALUES ('$ramal','$departamento')";
|
|
|
|
|
$query = pg_query($dbcon, $insert);
|
|
|
|
|
|
|
|
|
|
//$mes = "<img src=\"imgSite/stAprovado.png\">Telefone Cadastrado com sucesso!";
|
|
|
|
|
$msg = "alert('Opera<EFBFBD><EFBFBD>o realizada com sucesso!');";
|
|
|
|
|
$nome = "";
|
|
|
|
|
$ramal = "";
|
|
|
|
|
$departamento = "";
|
|
|
|
|
|
|
|
|
|
$jsStartup[] = $msg;
|
|
|
|
|
$jsStartup[] = "window.close();";
|
|
|
|
|
$jsStartup[] = "window.opener.ResetForm();";
|
|
|
|
|
} else {
|
|
|
|
|
$mes = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">Erro ao inserir Telefone!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$mes = TrataValor($nome, $ddd, $ramal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* LOOP QUE TRAS RAMAIS
|
|
|
|
|
*/
|
|
|
|
|
$query = "SELECT dpto_id,dpto_nome FROM rma_departamentos WHERE dpto_status='1'";
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
while ($rowDep = pg_fetch_array($result)) {
|
|
|
|
|
$id = $rowDep['dpto_id'];
|
|
|
|
|
$nomedpto = $rowDep['dpto_nome'];
|
|
|
|
|
$optionDep .= "<option value=\"" . $id . "\" " . ($id == $departamento ? 'selected' : '' ) . ">" . $nomedpto . "</option>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($tipoAgenda == "AGD") {
|
|
|
|
|
$trDDD = true;
|
|
|
|
|
} else {
|
|
|
|
|
$trDDD = false;
|
|
|
|
|
}
|
|
|
|
|
$smarty->assign('optionDep', $optionDep);
|
|
|
|
|
$smarty->assign('nome', $nome);
|
|
|
|
|
$smarty->assign('ramal', $ramal);
|
|
|
|
|
$smarty->assign('mes', $mes);
|
|
|
|
|
$smarty->assign('ddd', $ddd);
|
|
|
|
|
$smarty->assign('trDDD', $trDDD);
|
|
|
|
|
$smarty->display("agendaRamais/ramais/ramaisInsert.html");
|
|
|
|
|
|
|
|
|
|
function TrataValor($nome, $ddd, $ramal) {
|
|
|
|
|
$img = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">";
|
|
|
|
|
if (empty($nome)) {
|
|
|
|
|
return " $img Por favor preencha o campo nome!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($ramal)) {
|
|
|
|
|
return " $img Por favor preencha o campo telefone!";
|
|
|
|
|
}
|
|
|
|
|
if (!is_numeric($ramal)) {
|
|
|
|
|
$erro = 2;
|
|
|
|
|
return " $img Preencha o campo Telefone corretamente,permitido somente numero!";
|
|
|
|
|
}
|
|
|
|
|
if ($erro != 2) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|