PABX da Simples IP
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.
 
 
 
 
 
 

90 lines
2.7 KiB

<?php
$tpLayout = 1;
//LIMPA VARIAVEIS
$uf = "";
$ddd = "";
$nome = "";
$acao = "";
//Recebe
$id = $_GET['idMunicipio'];
$acao = $_POST['concluir'];
//imprimi registro na tela
$sql = "SELECT a.mun_id,a.mun_nome,a.mun_ddd,a.uf FROM pbx_municipio_classifica a LEFT OUTER JOIN pbx_municipio_prefixo b ON a.mun_id=b.mun_id WHERE a.mun_id='$id'";
$query = pg_query($dbcon, $sql);
while ($row = pg_fetch_array($query)) {
$nome = $row['mun_nome'];
$ddd = $row['mun_ddd'];
$uf = $row['uf'];
}
$prefixo = substr($prefixo, (strlen($prefixo) - 4), strlen($prefixo));
if ($acao == "Finalizar") {
//recebe valores post
$uf = $_POST['uf'];
$nome = $_POST['nome'];
$ddd = $_POST['ddd'];
$prefixo = $_POST['prefixo'];
$id = $_POST['idMunicipio'];
//trata os valores
TrataValor($uf, $ddd, $nome);
//verifica se valores estao corretos
if (TrataValor($uf, $ddd, $nome) == 1) {
$tabela = "pbx_municipio_classifica";
$update = ExecBancoUpdate($dbcon, $tabela, $uf, $ddd, $nome, $id);
//retorna verdadeiro se registro for inserido
if ($update == 1) {
$mes = "Registro alterado com sucesso!";
} else {
$mes = "Nao foi possivel realizar a operação!";
}
}
}
//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 update
function ExecBancoUpdate($dbcon, $tabela, $uf, $ddd, $nome, $id) {
$update = "UPDATE $tabela SET uf='$uf' , mun_ddd='$ddd' , mun_nome='$nome' WHERE mun_id='$id'";
$query = pg_query($dbcon, $update);
$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;
}
}
//
if (!is_numeric(TrataValor($uf, $ddd, $nome))) {
$mes .= TrataValor($uf, $ddd, $nome);
}
//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->assign('id', $id);
$smarty->assign('prefixo', $prefixo);
$smarty->display("cadastros/municipio/municipioUpdate.html");
?>