= 1) { $mes = "Telefone já 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 = "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 = "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 .= ""; } 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 = ""; 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; } } ?>