-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditar-produto.php
94 lines (78 loc) · 3.87 KB
/
editar-produto.php
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
<?php
require "src/conexao-bd.php";
require "src/Model/Produto.php";
require "src/Repository/ProdutoRepositorio.php";
$produtoRepositorio = new ProdutoRepositorio($pdo);
if (isset($_POST['editar'])){
$produto = new Produto($_POST['id'], $_POST['tipo'], $_POST['nome'], $_POST['descricao'], $_POST['preco']);
if (isset($_FILES['imagem'])){
$produto->setImagem(uniqid() . $_FILES['imagem']['name']);
move_uploaded_file($_FILES['imagem']['tmp_name'], $produto->getImagemDiretorio());
}
$produtoRepositorio->atualizar($produto);
header("Location: admin.php");
}else{
$produto = $produtoRepositorio->buscar($_GET['id']);
}
?>
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/admin.css">
<link rel="stylesheet" href="css/form.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="icon" href="img/icone-serenatto.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;900&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&display=swap" rel="stylesheet">
<title>Serenatto - Editar Produto</title>
</head>
<body>
<main>
<section class="container-admin-banner">
<img src="img/logo-serenatto-horizontal.png" class="logo-admin" alt="logo-serenatto">
<h1>Editar Produto</h1>
<img class="ornaments" src="img/ornaments-coffee.png" alt="ornaments">
</section>
<section class="container-form">
<form method="post" enctype="multipart/form-data">
<label for="nome">Nome</label>
<input type="text" id="nome" name="nome" placeholder="Digite o nome do produto"
value="<?= $produto->getNome() ?>" required>
<div class="container-radio">
<div>
<label for="cafe">Café</label>
<input type="radio" id="cafe" name="tipo" value="Café" <?= $produto->getTipo() == "Café" ? "checked" : "" ?>>
</div>
<div>
<label for="almoco">Almoço</label>
<input type="radio" id="almoco" name="tipo" value="Almoço" <?= $produto->getTipo() == "Almoço" ? "checked" : "" ?>>
</div>
</div>
<label for="descricao">Descrição</label>
<input type="text" name="descricao" id="descricao" value="<?= $produto->getDescricao() ?>"
placeholder="Digite uma descrição" required>
<label for="preco">Preço</label>
<input type="text" name="preco" id="preco" value="<?= number_format($produto->getPreco(), 2) ?>"
placeholder="Digite uma descrição" required>
<label for="imagem">Envie uma imagem do produto</label>
<input type="file" name="imagem" accept="image/*" id="imagem" placeholder="Envie uma imagem">
<input type="hidden" name="id" value="<?= $produto->getId() ?>">
<input type="submit" name="editar" class="botao-cadastrar" value="Editar produto" />
</form>
</section>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"
integrity="sha512-Rdk63VC+1UYzGSgd3u2iadi0joUrcwX0IWp2rTh6KXFoAmgOjRS99Vynz1lJPT8dLjvo6JZOqpAHJyfCEZ5KoA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="js/index.js"></script>
</body>
</html>