banco_projeto/cliente/edit_cliente.php
2021-09-02 08:27:03 -03:00

106 lines
3.7 KiB
PHP

<?php
session_start();
include_once("../conexao.php");
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$result = "SELECT * FROM tbclientes WHERE id = '$id'";
$resultado = mysqli_query($con, $result);
$row = mysqli_fetch_assoc($resultado);
$has_user = false;
$login_id = NULL;
$username = NULL;
$tipo = NULL;
$sql = "SELECT login_id, usuario, tipo_usuario FROM consulta_usuarios WHERE nome_usuario = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param('s', $row['nome']);
if($stmt->execute())
{
$fetch = $stmt->get_result()->fetch_assoc();
$has_user = is_array($fetch);
if($has_user)
{
$login_id = $fetch['login_id'];
$username = $fetch['usuario'];
$tipo = $fetch['tipo_usuario'];
}
}
$stmt->close();
include('../menu.php');
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title> Editar Cliente </title>
<link rel="stylesheet" href="../css/menu.css">
<link rel="stylesheet" href="../css/forms.css">
<link rel="stylesheet" href="../css/article.css">
<link rel="stylesheet" href="../css/input.css">
</head>
<body>
<?php
echo $nav;
?>
<article>
<section class='center'>
<a href="index.php">Listar</a>
<?php if(isset($_SESSION['msg'])){?>
<div class="msg">
<?php echo $_SESSION['msg'];
unset($_SESSION['msg']);?>
</div>
<?php }?>
<h1> Alteração - Cliente </h1>
<form method="POST" action="proc_editar_cliente.php">
<input type="hidden" name="id" value="<?php echo $row['id'];?>">
<h4>Informações Básicas</h4>
<p>Nome: <input type="text" name="nome" value="<?php echo $row['nome'];?>"></p>
<p>Endereço: <input type="text" name="endereco" value="<?php echo $row['endereco'];?>"></p>
<hr>
<h4>Detalhes do Endereço</h4>
<p>Complemento: <input type="text" name="complemento" value="<?php echo $row['complemento'];?>"></p>
<p>Bairro: <input type="text" name="bairro" value="<?php echo $row['bairro'];?>"></p>
<p>Cidade: <input type="text" name="cidade" value="<?php echo $row['cidade'];?>"></p>
<p>Estado: <input type="text" name="estado" value="<?php echo $row['estado'];?>"></p>
<hr>
<h4>Dados Pessoais</h4>
<p>CEP: <input type="number" name="cep" value="<?php echo $row['cep'];?>"></p>
<p>CPF/CNPJ: <input type="number" name="cpf_cnpj" value="<?php echo $row['cpf_cnpj'];?>"></p>
<p>RG: <input type="number" name="rg" value="<?php echo $row['rg'];?>"></p>
<hr>
<h4>Informações de Contato</h4>
<p>Email: <input type="email" name="email" value="<?php echo $row['email'];?>"></p>
<p>Telefone: <input type="tel" name="telefone" value="<?php echo $row['telefone'];?>"></p>
<p>Celular: <input type="tel" name="celular" value="<?php echo $row['celular'];?>"></p>
<?php
if(isset($_SESSION['tipo'])){
if(strcmp($_SESSION['tipo'],'adm')==0){
$_SESSION['tmp'] = $id;
?>
<hr>
<h4>Informações de usuário -> <?php echo $username." : ".$tipo;?></h4>
<?php if($has_user){?>
<p><a class='button' href="../login/alt_user.php?id=<?php echo $login_id;?>">Desejo editar usuário</a>
<a class='button' href="../login/rem_user.php?id=<?php echo $login_id;?>">Desejo remover usuário</a></p>
<?php }else{?>
<p><a class='button' href="cad_user.php">Desejo criar usuário</a></p>
<?php }?>
</p>
<?php
}
}
?>
<table class='input'>
<td><input class='buttons' type="submit" value="Salvar"></td>
<td><input class='buttons' type="reset" value="Limpar"></td>
</table>
</section>
</article>
<?php echo $footer;?>
</body>
</html>