Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
124 lines (108 loc) · 4.86 KB
/
Copy pathindex.php
File metadata and controls
124 lines (108 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
require_once "./DAO/ProdutosDAO.php";
$objDAO = new ProdutosDAO();
if (isset($_POST["btn_salvar"])) {
$nome = trim(strip_tags($_POST["nome_produto"]));
$descricao = trim(strip_tags($_POST["descricao_produto"]));
$valor = trim(strip_tags($_POST["valor_produto"]));
$estoque = trim(strip_tags($_POST["estoque_produto"]));
$categoria = $_POST["id_categoria"];
$marca = $_POST["id_marca"];
if ($objDAO->CadastrarProduto($nome, $descricao, $valor, $estoque, $categoria, $marca)){
echo "<script>alert('Produto cadastrado com sucesso!');window.location='index.php';</script>";
exit();
} else {
echo "<script>alert('Erro ao cadastrar o produto!');</script>";
}
}
$listaProdutos = $objDAO->ConsultarProdutos();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sistema de Cadastro de Produtos</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="container">
<h1>Sistema de Cadastro de Produtos</h1>
<div class="card">
<h2>Faça o Cadastro de Produtos:</h2>
<form action="index.php" method="POST">
<label>Digite o Nome do Produto:</label>
<input type="text" name="nome_produto" placeholder="Digite aqui..." required>
<label>Digite a Descrição:</label>
<textarea name="descricao_produto" placeholder="Digite aqui..." required></textarea>
<label>Digite o Valor(R$):</label>
<input type="number" step="0.01" name="valor_produto" placeholder="Digite aqui..." required>
<label>Digite a Quantidade em Estoque:</label>
<input type="number" name="estoque_produto" placeholder="Digite aqui..." required>
<div class="select-grid">
<div>
<label>Selecione uma Categoria:</label>
<select name="id_categoria">
<option value="">Selecione</option>
<option value="1">Periféricos</option>
<option value="2">Hardware</option>
<option value="3">Monitores</option>
</select>
</div>
<div>
<label>Selecione uma Marca:</label>
<select name="id_marca">
<option value="">Selecione</option>
<option value="1">Logitech</option>
<option value="2">Redragon</option>
<option value="3">Dell</option>
</select>
</div>
</div>
<button type="submit" name="btn_salvar">Salvar Produto</button>
</form>
</div>
<div class="card">
<h2>Produtos Cadastrados</h2>
<table>
<thead>
<tr>
<th>Qtds.</th>
<th>Produto</th>
<th>Categoria</th>
<th>Marca</th>
<th>Valor</th>
<th>Estoque</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php
if (count($listaProdutos) > 0) {
$i=1; foreach ($listaProdutos as $produto) {
?>
<tr>
<td><?= $i++ ?></td>
<td><?= $produto["nome_produto"] ?></td>
<td><?= $produto["nome_categoria"] ?></td>
<td><?= $produto["nome_marca"] ?></td>
<td>R$ <?= number_format($produto["valor_produto"], 2, ",", ".") ?></td>
<td><?= $produto["estoque_produto"] ?></td>
<td class="celula-td">
<a href="editar.php?id=<?= $produto["id_produto"] ?>" class="btn-editar">Editar</a>
<a href="excluir.php?id=<?= $produto["id_produto"] ?>" class="btn-excluir" onclick="return confirm('Deseja excluir este produto?');">Excluir</a>
</td>
</tr>
<?php
}
} else { ?>
<tr>
<td colspan="7">Nenhum produto cadastrado.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</body>
</html>