-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodifica-menu.php
112 lines (101 loc) · 3.79 KB
/
modifica-menu.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
require_once 'funcoes/selectOrdem.inc.php';
require_once 'servidor.php';
// deleta um item
if(isset($_GET['acao'])){
if($_GET['acao'] == 'deletar' && !empty($_GET['id'])){
$id = (int)$_GET['id'];
consultaDados("delete from itensMenu where id = '$id'");
header("Location: modifica-menu.php");
}
}
// edita um item
if(isset($_POST['id'])){
$id = (int)$_POST['id'];
$texto = $_POST['texto'];
$url = $_POST['url'];
$ordem = (int)$_POST['ordem'];
$aviso = '';
if(empty($texto)){
$aviso .= 'o texto é obrigatório<br>';
}
if(empty($url)){
$aviso .= 'a url é obrigatória<br>';
}
if(empty($aviso)){
consultaDados("update itensMenu set texto = '$texto', url = '$url', ordem = '$ordem', dataAtualizacao = now() where id = '$id'");
$aviso = 'item editado com sucesso';
}
// cadastra um item
}elseif(isset($_POST['texto'])){
$texto = $_POST['texto'];
$url = $_POST['url'];
$ordem = (int)$_POST['ordem'];
$aviso = '';
if(empty($texto)){
$aviso .= 'o texto é obrigatório<br>';
}
if(empty($url)){
$aviso .= 'a url é obrigatória<br>';
}
if(empty($aviso)){
consultaDados("insert into itensMenu (texto, url, ordem, dataCadastro, dataAtualizacao)
values ('$texto', '$url', '$ordem', now(), now())");
$aviso = 'item cadastrado com sucesso';
header("Location: modifica-menu.php");
}
}
// busca os itens do banco
$itensQuery = consultaDados("select * from itensMenu order by ordem asc");
?>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function deletaItem(id){
if(confirm("deleta item?")){
window.location = "modifica-menu.php?acao=deletar&id=" + id;
}
}
</script>
<?php include 'headers.php'; ?>
</head>
<body>
<?php include 'menu1.php'; ?>
<h1>Modifica o menu</h1>
<?php if(isset($aviso)){ echo $aviso; } ?>
<table width="100%" border="1">
<tr>
<th>texto</th>
<th>url</th>
<th>ordem</th>
<th>ações</th>
</tr>
<?php mysql_data_seek($itensQuery, 0); while($itens = mysql_fetch_array($itensQuery)): ?>
<tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="id" value="<?php print $itens['id']; ?>" />
<td><input type="text" name="texto" value="<?php print $itens['texto']; ?>" /></td>
<td><input type="text" name="url" value="<?php print $itens['url']; ?>" /></td>
<td><?php print selectOrdem($itens['ordem']); ?></td>
<td>
<input type="submit" value="editar" />
<input type="button" value="deletar" onclick="deletaItem(<?php print $itens['id']; ?>)" />
</td>
</form>
</tr>
<?php endwhile; ?>
<tr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<td><input type="text" name="texto" value="" /></td>
<td><input type="text" name="url" value="" /></td>
<td><?php print selectOrdem(); ?></td>
<td><input type="submit" value="cadastrar" /></td>
</form>
</tr>
</table>
<?php include 'menu2.php'; ?>
</body>
</html>