initial commit
This commit is contained in:
68
servicos/cad_ser.php
Normal file
68
servicos/cad_ser.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
if (session_status() !== PHP_SESSION_ACTIVE){
|
||||
session_start();
|
||||
}
|
||||
include('../menu.php');
|
||||
include("../conexao.php");
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title> Cadastro de serviços </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> Serviços - inclusão</h1></p>
|
||||
<form method="POST" action="inc_ser.php">
|
||||
<p> Nome: <input type="text" name="nome" required>
|
||||
<label> Categoria: </label>
|
||||
<select name="id_categoria">
|
||||
<?php
|
||||
$query= 'SELECT * from categoria ORDER BY categoria;';
|
||||
$resu = mysqli_query($con,$query) or die(mysqli_connect_error());
|
||||
while ($reg = mysqli_fetch_array($resu)){
|
||||
?>
|
||||
<option value="<?php echo $reg['id'];?>"> <?php echo $reg['categoria'];?> </option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<label> Prestador: </label>
|
||||
<select name="id_prestador">
|
||||
<option value="NULL">Nenhum</option>
|
||||
<?php
|
||||
$query= 'SELECT * from prestadores ORDER BY nome;';
|
||||
$resu = mysqli_query($con,$query) or die(mysqli_connect_error());
|
||||
while ($reg = mysqli_fetch_array($resu)){
|
||||
?>
|
||||
<option value="<?php echo $reg['id'];?>"> <?php echo $reg['nome'];?> </option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<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
servicos/del_ser.php
Normal file
33
servicos/del_ser.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 servicos 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>Excluir Serviço</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="index.php">Listar</a><br>
|
||||
<h1>Excluir Serviço</h1>
|
||||
<?php
|
||||
if(isset($_SESSION['msg'])){
|
||||
echo $_SESSION['msg'];
|
||||
unset($_SESSION['msg']);
|
||||
}
|
||||
?>
|
||||
<form method="POST" action="proc_del_ser.php">
|
||||
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
||||
|
||||
<label>Serviço: </label>
|
||||
<input type="text" name="nome" placeholder="Digite o serviço" value="<?php echo $row['servico']; ?>"><br><br>
|
||||
|
||||
<input type="submit" value="Confirma exclusão">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
62
servicos/edit_ser.php
Normal file
62
servicos/edit_ser.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("../conexao.php");
|
||||
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$result = "SELECT * FROM servicos 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>Editar Serviços</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 - Serviços</h1>
|
||||
<form method="POST" action="proc_edit_ser.php">
|
||||
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
||||
|
||||
<label>Serviço: </label>
|
||||
<input type="text" name="nome" placeholder="Digite o serviço" value="<?php echo $row['servico']; ?>"><br><br>
|
||||
|
||||
<label> Prestador: </label>
|
||||
<select name="id_prestador">
|
||||
<?php
|
||||
$query= 'SELECT * from prestadores ORDER BY nome;';
|
||||
$resu = mysqli_query($con,$query) or die(mysqli_connect_error());
|
||||
while ($reg = mysqli_fetch_array($resu)){
|
||||
?>
|
||||
<option value="<?php echo $reg['id'];?>"> <?php echo $reg['nome'];?> </option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
<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>
|
38
servicos/inc_ser.php
Normal file
38
servicos/inc_ser.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
if (session_status() !== PHP_SESSION_ACTIVE){
|
||||
session_start();
|
||||
}
|
||||
$nome=(empty($_POST["nome"])) ? " ": $_POST["nome"];
|
||||
$id_categoria=(empty($_POST["id_categoria"])) ? 0 : $_POST["id_categoria"];
|
||||
$id_prestador=(empty($_POST["id_prestador"])) ? NULL : $_POST["id_prestador"];
|
||||
|
||||
|
||||
include('../conexao.php');
|
||||
|
||||
$query= "INSERT INTO servicos (servico, id_categoria) VALUES ('$nome', '$id_categoria')";
|
||||
$resu= mysqli_query($con,$query);
|
||||
$id_servico;
|
||||
if ($id_servico = mysqli_insert_id($con)) {
|
||||
if($id_prestador !== NULL)
|
||||
{
|
||||
$sql = "INSERT INTO prestadores_servicos (id_prestador, id_servico) VALUES (?,?)";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param('ss',$id_prestador,$id_servico);
|
||||
if($stmt->execute())
|
||||
{
|
||||
$_SESSION['msg']= "<p style='color:blue;'> Serviço cadastrado com sucesso!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
else{
|
||||
$_session['msg']= "<p style='color:red;'> Serviço não foi cadastrado!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$_session['msg']= "<p style='color:red;'> Serviço não foi cadastrado!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
mysqli_close($con);
|
||||
?>
|
87
servicos/index.php
Normal file
87
servicos/index.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("../conexao.php");
|
||||
include('../menu.php');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-br">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Serviços</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_ser.php">Cadastrar</a><br>
|
||||
<h1>Listar Serviços</h1>
|
||||
<table border="1" width="100%">
|
||||
<tr>
|
||||
<td>N°</td>
|
||||
<td>Nome</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 s.id, s.servico, c.categoria FROM servicos as s, categoria AS
|
||||
c WHERE s.id_categoria = c.id 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['servico'] . "</td><td>".$row['categoria']."</td><td> <a href='edit_ser.php?id=". $row['id'] . "'>Editar</a>";
|
||||
echo "</td><td> <a href='del_ser.php?id=". $row['id'] . "'>Excluir </a></td></tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
$result_pg = "SELECT COUNT(id) AS num_result FROM servicos";
|
||||
$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>
|
26
servicos/proc_del_ser.php
Normal file
26
servicos/proc_del_ser.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?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 orcamentos, prestadores_servicos WHERE id_servico='$id'";
|
||||
$resu= mysqli_query($con, $verif);
|
||||
if (mysqli_affected_rows($con)){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Este serviço não pode ser excluído, pois existe orçamento ou prestadores_serviços cadastrado</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
$result= "DELETE FROM servicos WHERE id='$id'";
|
||||
$resultado= mysqli_query($con, $result);
|
||||
|
||||
|
||||
if(mysqli_affected_rows($con)){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Serviço excluido com sucesso</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
$_SESSION['msg'] = "<p style='color:red;'>Serviço não foi excluido</p>";
|
||||
header("Location: edit_ser.php?id=$id");
|
||||
}
|
||||
}
|
||||
?>
|
59
servicos/proc_edit_ser.php
Normal file
59
servicos/proc_edit_ser.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once("../conexao.php");
|
||||
|
||||
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$id_prestador=(empty($_POST["id_prestador"])) ? NULL : $_POST["id_prestador"];
|
||||
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
|
||||
|
||||
|
||||
if($id_prestador != NULL)
|
||||
{
|
||||
$check_query = "SELECT * FROM prestadores_servicos WHERE id_servico = ?";
|
||||
$stmt = $con->prepare($check_query);
|
||||
$stmt->bind_param('s',$id);
|
||||
$stmt->execute();
|
||||
$res = $stmt->get_result();
|
||||
if(is_array($res->fetch_assoc()))
|
||||
{
|
||||
$stmt->close();
|
||||
$sql = "UPDATE prestadores_servicos SET id_servico = ?, id_prestador = ? WHERE id_servico = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param('sss',$id,$id_prestador,$id);
|
||||
if($stmt->execute()){
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Serviço alterado com sucesso</p>";
|
||||
header("Location: index.php");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$stmt->close();
|
||||
$sql = "INSERT INTO prestadores_servicos (id_prestador, id_servico) VALUES (?,?)";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param('ss',$id_prestador,$id);
|
||||
if($stmt->execute())
|
||||
{
|
||||
$_SESSION['msg']= "<p style='color:blue;'> Serviço cadastrado com sucesso!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
else{
|
||||
$_session['msg']= "<p style='color:red;'> Serviço não foi cadastrado!</p>";
|
||||
header('Location: index.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result= "UPDATE servicos SET servico = ? WHERE id = ?";
|
||||
$stmt = $con->prepare($result);
|
||||
$stmt->bind_param('ss',$nome,$id);
|
||||
|
||||
if($stmt->execute()){
|
||||
$stmt->close();
|
||||
$_SESSION['msg'] = "<p style='color:green;'>Serviço alterado com sucesso</p>";
|
||||
header("Location: index.php");
|
||||
}else{
|
||||
$stmt->close();
|
||||
$_SESSION['msg'] = "<p style='color:red;'>Serviço não foi alterado</p>";
|
||||
header("Location: edit_ser.php?id=$id");
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user