initial commit
This commit is contained in:
44
categoria/cad_cat.php
Normal file
44
categoria/cad_cat.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
if (session_status() !== PHP_SESSION_ACTIVE){
|
||||
session_start();
|
||||
}
|
||||
include('../menu.php');
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title> Cadastro de categorias </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 }?>
|
||||
<p><h1> Categorias - inclusão</h1></p>
|
||||
<form method="POST" action="inc_cat.php">
|
||||
<p> Nome: <input type="text" name="nome" required>
|
||||
<table class='input'>
|
||||
<td><input class='buttons' type="submit" value="Enviar"></td>
|
||||
<td><input class='buttons' type="reset" value="Limpar"></td>
|
||||
</table>
|
||||
</form>
|
||||
</section>
|
||||
</article>
|
||||
<?php
|
||||
echo $footer;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
33
categoria/del_cat.php
Normal file
33
categoria/del_cat.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("..\conexao.php");
|
||||
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$result = "SELECT * FROM categoria WHERE id = '$id'";
|
||||
$resultado = mysqli_query($con, $result);
|
||||
$row = mysqli_fetch_assoc($resultado);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-br">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CRUD - Excluir</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="index.php">Listar</a><br>
|
||||
<h1>Excluir Categoria</h1>
|
||||
<?php
|
||||
if(isset($_SESSION['msg'])){
|
||||
echo $_SESSION['msg'];
|
||||
unset($_SESSION['msg']);
|
||||
}
|
||||
?>
|
||||
<form method="POST" action="proc_del_cat.php">
|
||||
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
||||
|
||||
<label>Categoria: </label>
|
||||
<input type="text" name="nome" placeholder="Digite a categoria" value="<?php echo $row['categoria']; ?>"><br><br>
|
||||
|
||||
<input type="submit" value="Confirma exclusão">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
49
categoria/edit_cat.php
Normal file
49
categoria/edit_cat.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("../conexao.php");
|
||||
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$result = "SELECT * FROM categoria WHERE id = '$id'";
|
||||
$resultado = mysqli_query($con, $result);
|
||||
$row = mysqli_fetch_assoc($resultado);
|
||||
include('../menu.php');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-br">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Alterar Categoria</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 - Categoria</h1>
|
||||
<form method="POST" action="proc_edit_cat.php">
|
||||
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
||||
|
||||
<label>Categoria: </label>
|
||||
<input type="text" name="nome" placeholder="Digite a categoria" value="<?php echo $row['categoria']; ?>"><br><br>
|
||||
|
||||
<table class='input'>
|
||||
<td><input class='buttons' type="submit" value="Salvar"></td>
|
||||
<td><input class='buttons' type="reset" value="Limpar"></td>
|
||||
</table>
|
||||
</form>
|
||||
</section>
|
||||
</article>
|
||||
<?php echo $footer;?>
|
||||
</body>
|
||||
</html>
|
20
categoria/inc_cat.php
Normal file
20
categoria/inc_cat.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
if (session_status() !== PHP_SESSION_ACTIVE){
|
||||
session_start();
|
||||
}
|
||||
$nome=(empty($_POST["nome"])) ? " ": $_POST["nome"];
|
||||
include('..\conexao.php');
|
||||
|
||||
$query= "INSERT INTO categoria (categoria) VALUES ('$nome')";
|
||||
$resu= mysqli_query($con,$query);
|
||||
if (mysqli_insert_id($con)) {
|
||||
$_SESSION['msg']= "<p style='color:blue;'> Categoria cadastrado com sucesso!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
else{
|
||||
$_session['msg']= "<p style='color:red;'> Categoria n<>o foi cadastrado!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
|
||||
mysqli_close($con);
|
||||
?>
|
86
categoria/index.php
Normal file
86
categoria/index.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("../conexao.php");
|
||||
include('../menu.php');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-br">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Categorias</title>
|
||||
<link rel="stylesheet" href="../css/menu.css">
|
||||
<link rel="stylesheet" href="../css/tables.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php echo $nav;?>
|
||||
<section>
|
||||
<?php if(isset($_SESSION['msg'])){?>
|
||||
<div class="msg">
|
||||
<?php echo $_SESSION['msg'];
|
||||
unset($_SESSION['msg']);?>
|
||||
</div>
|
||||
<?php }?>
|
||||
<a href="cad_cat.php">Cadastrar</a><br>
|
||||
<h1>Listar Categorias</h1>
|
||||
<table border="1" width="100%">
|
||||
<tr>
|
||||
<td>N°</td>
|
||||
<td>Categoria</td>
|
||||
<td colspan='2'>Operações</td>
|
||||
</tr>
|
||||
<?php
|
||||
$pagina_atual = filter_input(INPUT_GET,'pagina', FILTER_SANITIZE_NUMBER_INT);
|
||||
$pagina = (!empty($pagina_atual)) ? $pagina_atual : 1;
|
||||
|
||||
$qnt_result_pg = 15;
|
||||
|
||||
$inicio = ($qnt_result_pg * $pagina) - $qnt_result_pg;
|
||||
|
||||
$result_usuarios = "SELECT * FROM categoria LIMIT $inicio, $qnt_result_pg";
|
||||
$resultado_usuarios = mysqli_query($con, $result_usuarios);
|
||||
while($row = mysqli_fetch_assoc($resultado_usuarios)){
|
||||
echo "<tr><td>" . $row['id'] . "</td><td> ";
|
||||
echo $row['categoria'] . "</td><td> <a href='edit_cat.php?id=". $row['id'] . "'>Editar</a>";
|
||||
echo "</td><td> <a href='del_cat.php?id=". $row['id'] . "'>Excluir </a></td></tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
$result_pg = "SELECT COUNT(id) AS num_result FROM categoria";
|
||||
$resultado_pg = mysqli_query($con, $result_pg);
|
||||
$row_pg = mysqli_fetch_assoc($resultado_pg);
|
||||
$quantidade_pg = ceil($row_pg['num_result'] / $qnt_result_pg);
|
||||
|
||||
$max_links = 2;
|
||||
echo "<a href='index.php?pagina=1'>Primeira</a> ";
|
||||
|
||||
$paginant = $pagina - 1;
|
||||
$pagprox = $pagina + 1;
|
||||
if($paginant >= 1)
|
||||
{
|
||||
echo "<a href='index.php?pagina=$paginant'><<</a> ";
|
||||
}
|
||||
|
||||
for($pag_ant = $pagina - $max_links; $pag_ant <= $pagina - 1; $pag_ant++){
|
||||
if($pag_ant >= 1){
|
||||
echo "<a href='index.php?pagina=$pag_ant'>$pag_ant</a> ";
|
||||
}
|
||||
}
|
||||
|
||||
echo "$pagina ";
|
||||
|
||||
for($pag_dep = $pagina + 1; $pag_dep <= $pagina + $max_links; $pag_dep++){
|
||||
if($pag_dep <= $quantidade_pg){
|
||||
echo "<a href='index.php?pagina=$pag_dep'>$pag_dep</a> ";
|
||||
}
|
||||
}
|
||||
|
||||
if($pagprox <= $quantidade_pg)
|
||||
{
|
||||
echo "<a href='index.php?pagina=$pagprox'>>></a> ";
|
||||
}
|
||||
|
||||
echo "<a href='index.php?pagina=$quantidade_pg'>Última</a>";
|
||||
?>
|
||||
</section>
|
||||
<?php echo $footer;?>
|
||||
</body>
|
||||
</html>
|
27
categoria/proc_del_cat.php
Normal file
27
categoria/proc_del_cat.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("..\conexao.php");
|
||||
|
||||
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
|
||||
|
||||
$verif="SELECT * from servicos WHERE id_categoria='$id'";
|
||||
$resu= mysqli_query($con, $verif);
|
||||
if (mysqli_affected_rows($con)){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Esta categoria não pode ser excluída, pois existe serviço cadastrado</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
|
||||
$result= "DELETE FROM categoria WHERE id='$id'";
|
||||
$resultado= mysqli_query($con, $result);
|
||||
|
||||
|
||||
if(mysqli_affected_rows($con)){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Categoria excluida com sucesso</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
$_SESSION['msg'] = "<p style='color:red;'>Categoria não foi excluida</p>";
|
||||
header("Location: edit_cat.php?id=$id");
|
||||
}
|
||||
}
|
||||
?>
|
20
categoria/proc_edit_cat.php
Normal file
20
categoria/proc_edit_cat.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("..\conexao.php");
|
||||
|
||||
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
|
||||
|
||||
$result= "UPDATE categoria SET categoria='$nome' WHERE id='$id'";
|
||||
$resultado= mysqli_query($con, $result);
|
||||
|
||||
|
||||
if(mysqli_affected_rows($con)){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Categoria alterada com sucesso</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
$_SESSION['msg'] = "<p style='color:red;'>Categoria não foi alterada</p>";
|
||||
header("Location: edit_cat.php?id=$id");
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user