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.
 
 
 
 
 
 

111 lines
3.5 KiB

<?php
$tpLayout = 1;
$tipoAgenda = $_GET['tipoTable'];
$ddd = GetDddPadrao();
$org_id = GetOrganizacao();
/*
* RECEBE VALORES VIA POST
*/
if ($_POST['concluir'] == "Finalizar") {
$nome = $_POST['nome'];
$ramal = $_POST['ramal'];
$departamento = $_POST['depto'];
$ddd = $_POST['ddd'];
$valor = TrataValor($nome, $ramal);
if ($valor == 1) {
/*
* VERIFICA SE JA POSSUI ALGUM RAMAL CADASTRADO
*/
$query = "SELECT nome FROM pbx_ramais_mesa WHERE nome='$ramal' AND org_id = {$org_id}";
$result = pg_query($dbcon, $query);
if (pg_num_rows($result) >= 1) {
$mes = "<img src=\"imgSite/icone_alert.png\" width=\"16\" height=\"16\">Telefone já esta cadastrado!";
} else {
/*
* INSERI REGISTROS
*/
$insertRamal = "INSERT INTO pbx_ramais_agenda (rma_telefone, rma_nome, ddd, org_id) VALUES ('$ramal','$nome','$ddd', $org_id)";
$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'
AND org_id = {$org_id}";
$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, org_id) VALUES ('$ramal','$departamento', $org_id)";
$query = pg_query($dbcon, $insert);
//$mes = "<img src=\"imgSite/stAprovado.png\">Telefone Cadastrado com sucesso!";
$msg = "alert('Operaçã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, $ramal);
}
}
/*
* LOOP QUE TRAS RAMAIS
*/
$query = "SELECT dpto_id,dpto_nome FROM rma_departamentos WHERE dpto_status='1' AND org_id = {$org_id}";
$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, $ramal)
{
$erro = 0;
$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;
}
}