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.
89 lines
2.5 KiB
89 lines
2.5 KiB
<?php |
|
|
|
$tpLayout = 1; |
|
//LIMPA VARIAVEIS |
|
$uf = ""; |
|
$ddd = ""; |
|
$nome = ""; |
|
$acao = ""; |
|
//Recebe |
|
if ($_GET['acao'] == "in") { |
|
$ddd = $_GET['ddd']; |
|
$uf = $_GET['uf']; |
|
$nome = $_GET['municipio']; |
|
} else { |
|
$uf = $_POST['uf']; |
|
$ddd = $_POST['ddd']; |
|
$nome = $_POST['nome']; |
|
} |
|
$acao = $_GET['acao']; |
|
|
|
//Trata Valores |
|
function TrataValor($uf, $ddd, $nome) { |
|
if (empty($uf) || empty($ddd) || empty($nome)) { |
|
return "Preencha todos os campos!"; |
|
} |
|
if (!is_numeric($ddd)) { |
|
$erro = "2"; |
|
return "Preencha o campo DDD corretamente!"; |
|
} |
|
if ($erro < 1) { |
|
return 1; |
|
} |
|
} |
|
|
|
//funcao insert |
|
function ExecBanco($dbcon, $tabela, $uf, $ddd, $nome, $id) { |
|
//verifica se ja exite municipio |
|
$sql = "SELECT uf,mun_nome,mun_ddd FROM $tabela WHERE uf='$uf' AND mun_ddd='$ddd' AND mun_nome='$nome'"; |
|
$query = pg_query($dbcon, $sql); |
|
if ($resultRow = pg_num_rows($query) >= 1) { |
|
return 0; |
|
} else { |
|
$insert = "INSERT INTO $tabela (uf,mun_ddd,mun_nome) VALUES ('$uf','$ddd','$nome')"; |
|
$query = pg_query($dbcon, $insert); |
|
|
|
$sql = "SELECT mun_id FROM $tabela WHERE uf='$uf' AND mun_ddd='$ddd' AND mun_nome='$nome'"; |
|
$query = pg_query($dbcon, $sql); |
|
if (pg_num_rows($query) >= 1) { |
|
return 1; |
|
} else { |
|
return 0; |
|
} |
|
} |
|
} |
|
|
|
//verifica tratamento dos valores |
|
if (TrataValor($uf, $ddd, $nome) == 1) { |
|
|
|
$tabela = "pbx_municipio_classifica"; |
|
$inseri = ExecBanco($dbcon, $tabela, $uf, $ddd, $nome, $id); |
|
//retorna verdadeiro se registro for inserido |
|
if ($inseri == 1) { |
|
$mes = "Registro inserido com sucesso!"; |
|
} else { |
|
$mes = "O registro já existe na base de dados!"; |
|
} |
|
} |
|
// |
|
if (!is_numeric(TrataValor($uf, $ddd, $nome))) { |
|
$mes .= TrataValor($uf, $ddd, $nome); |
|
} |
|
if ($_GET['acao'] == "inEX") { |
|
$nome = $_GET['municipio']; |
|
$uf = $_GET['uf']; |
|
} |
|
|
|
//IMPRIMI COMBO UF---- |
|
$sqlUF = "SELECT uf FROM pbx_uf ORDER BY 1"; |
|
$resultUF = pg_query($dbcon, $sqlUF); |
|
while ($rowUF = pg_fetch_array($resultUF)) { |
|
$uf_select = $rowUF["uf"]; |
|
$optionUF .= "<option value=\"" . $uf_select . "\" " . ($uf_select == $uf ? 'selected' : '' ) . ">" . $uf_select . "</option>"; |
|
} |
|
$smarty->assign('mes', $mes); |
|
$smarty->assign('optionUF', $optionUF); |
|
$smarty->assign('ddd', $ddd); |
|
$smarty->assign('nome', $nome); |
|
$smarty->display("cadastros/municipio/municipioInsert.html"); |
|
?>
|
|
|