-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplantiomensal.php
398 lines (327 loc) · 13.2 KB
/
plantiomensal.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<?php
require_once('bd.class.php');
require_once('funcoes.php');
session_start();
if(!isset($_SESSION['email'])){
header('Location: index.php');
}
$objBd = new bd();
$link = $objBd->conecta_mysql();
$email = $_SESSION['email'];
$select = "select email from proprietarios where email = '". $email ."';";
$result = mysqli_query($link, $select);
if($result){
$user_id = array();
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$user_id = $row;
}
$email = $user_id['email'];
$pagina = (isset($_GET['pagina'])) ? $_GET['pagina'] : 1;
$sql = "SELECT idplantiomensal, cultura, variedade, observacao FROM plantiomensal WHERE proprietarios_email = '". $email ."' ORDER BY idplantiomensal;";
$resultado = mysqli_query($link, $sql);
$total_plantiomensal= mysqli_num_rows($resultado);
$quantidade_pg = 10;
$num_pg = ceil($total_plantiomensal/$quantidade_pg);
$inicio = ($quantidade_pg*$pagina)-$quantidade_pg;
?>
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<?php require_once("head.php") ?>
<title>Plantio Mensal</title>
</head>
<body class="branco">
<?php
require_once("menu.php");
?>
<div class="container">
<div class="page-header espaco">
<h1>Plantio Mensal</h1>
</div>
<div class="pull-right">
<button type="button" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#myModalcad">
Registrar
</button>
<div class="modal fade" id="myModalcad" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Registrar - Plantio Mensal</h4>
</div>
<div class="modal-body">
<form method="POST" action="plantiomensal.php" enctype="multipart/form-data">
<div class="form-group">
<label for="cultura" class="control-label">Cultura *</label>
<input type="text" class="form-control" pattern="[A-Za-zÀ-ú0-9., -]{3,}$" id="cultura" name="cultura" placeholder="Ex: grãos, vegetais, algas, árvores" required>
</div>
<div class="form-group">
<label for="variedade" class="control-label">Variedade *</label>
<textarea class="form-control" id="variedade" pattern="[A-Za-zÀ-ú0-9., -]{5,}$" name="variedade" placeholder="" required=""></textarea>
</div>
<div class="form-group">
<label for="observacao" class="control-label">Observação</label>
<textarea class="form-control" id="observacao" pattern="[A-Za-zÀ-ú0-9., -]{5,}$" name="observacao" placeholder=""></textarea>
</div>
<br />
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-success" name="salvar">Registrar</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<br />
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Cultura</th>
<th>Variedade</th>
<th>Observação</th>
</tr>
</thead>
<tbody>
<?php while($plantio = mysqli_fetch_assoc($resultado)){ ?>
<tr class="linha">
<td><?php echo $plantio['cultura']; ?></td>
<td><?php echo $plantio['variedade']; ?></td>
<td><?php echo $plantio['observacao']; ?></td>
<td>
<!---<button type="button" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#exampleModal"
data-codinvestimento="<?php echo $investimento['id']; ?>"
data-nome="<?php echo $investimento['nome_investimento']; ?>"
data-descricao="<?php echo $investimento['descricao']; ?>"
data-valor="<?php echo formata_moeda($investimento['valor']); ?>"
data-data="<?php echo date("d/m/Y", strtotime($investimento['data'])); ?>">
Editar
</button> ---->
<a href="javascript:m(); function m(){ modal({
type: 'confirm',
title: 'Confimação',
text: 'Tem certeza que deseja excluir este Plantio ?',
buttonText: {
yes: 'Confirmar',
cancel: 'Cancelar'
},
callback: function(result) {
$('.modal-btn').attr('style', 'display: none !important');
if(result==true){
location.href='plantiomensal_excluir.php?inves=<?php echo $plantio['idplantiomensal']?>'
}
}
}); $('.modal-btn').attr('style', 'display: inline !important'); };" class="btn btn-xs btn-danger"">Excluir</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="clearfix"></div>
<div class="col-md-4"></div>
<div class="col-md-4">
<?php
$pagina_anterior = $pagina - 1;
$pagina_posterior = $pagina + 1;
?>
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<?php
if($pagina_anterior != 0){ ?>
<a href="plantiomensal.php?pagina=<?php echo $pagina_anterior; ?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
<?php }else{ ?>
<span aria-hidden="true">«</span>
<?php } ?>
</li>
<?php
for($i = 1; $i < $num_pg + 1; $i++){ ?>
<li><a href="plantiomensal.php?pagina=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php } ?>
<li>
<?php
if($pagina_posterior <= $num_pg){ ?>
<a href="plantiomensal.php?pagina=<?php echo $pagina_posterior; ?>" aria-label="Previous">
<span aria-hidden="true">»</span>
</a>
<?php }else{ ?>
<span aria-hidden="true">»</span>
<?php } ?>
</li>
</ul>
</nav>
</div>
<div class="col-md-4"></div>
</div>
<!---<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Editar</h4>
</div>
<div class="modal-body">
<form method="POST" action="investimentos.php">
<div class="form-group">
<label for="produto-name" class="control-label">Nome *</label>
<input name="nome" type="text" class="form-control" pattern="[A-Za-zÀ-ú0-9., -]{5,}$" id="investimento-name" required="requiored">
</div>
<div class="form-group">
<label for="descricao-name" class="control-label">Descrição </label>
<textarea name="descricao" type="text" class="form-control" id="descricao-name"></textarea>
</div>
<div class="row">
<div class="form-group col-md-8">
<label for="valor-name" class="control-label">Valor R$ *</label>
<input name="valor" type="text" class="form-control ValoresItens" data-affixes-stay="true" data-prefix="R$ " data-thousands="." data-decimal="," id="valor-name" name="valor" placeholder="Valor R$" id="valor-name" required="requiored">
</div>
<div class="form-group col-md-4">
<label for="data-name" class="control-label">Data *</label>
<input type="date" class="form-control" id="data-name" name="data" required="requiored">
</div>
</div>
<input name="id" type="hidden" id="cod-investimento">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-primary" name="editar">Alterar</button>
</div>
</form>
</div>
</div>
</div>
</div> --->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!---<script type="text/javascript">
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipientcultura = button.data('cultura') // Extract info from data-* attributes
var recipientcod = button.data('codplantio')
var recipientobservacao = button.data('observacao')
var recipientvariedade = button.data('variedade')
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text('Editar - Investimento #' + recipientcod)
modal.find('#cod-investimento').val(recipientcod)
modal.find('#investimento-name').val(recipientnome)
modal.find('#descricao-name').val(recipientdescricao)
modal.find('#valor-name').val(recipientvalor)
modal.find('#data-name').val(recipientdata)
})
</script> --->
<?php
function registraPlantio(){
$cultura = $_POST['cultura'];
$variedade = $_POST['variedade'];
$observacao = $_POST['observacao'];
$objBd = new bd();
$link = $objBd->conecta_mysql();
$email = $_SESSION['email'];
$select = "select email from proprietarios where email = '". $email. "';";
$resultado = mysqli_query($link, $select);
if($resultado){
$user_id = array();
$row = mysqli_fetch_array($resultado, MYSQLI_ASSOC);
$user_id = $row;
}
$email = $user_id['email'];
$sql = "CALL plantiomensal('".$cultura."', '".$variedade."', '".$observacao."', '".$email."');";
//executar a query
mysqli_query($link, $sql);
if($sql){
echo "
<META HTTP-EQUIV=REFRESH CONTENT = '2;URL=plantiomensal.php'>
<script type=\"text/javascript\">
$(window).load(function() {
modal({
type: 'success',
title: 'Sucesso',
text: 'Plantio registrado!',
autoclose: false,
size: 'large',
center: false,
theme: 'atlant',
});
});
</script>
";
}
else{
echo "
<META HTTP-EQUIV=REFRESH CONTENT = '2;URL=plantiomensal.php'>
<script type=\"text/javascript\">
$(window).load(function() {
modal({
type: 'error',
title: 'Erro',
text: 'Não foi possível registrar o Plantio!',
autoclose: false,
size: 'large',
center: false,
theme: 'atlant',
});
});
</script>
";
}
}
if(isset($_POST['salvar'])){
registraPlantio();
}
/*function editarInvestimento(){
$cod = $_POST['id'];
$nome = $_POST['nome'];
$descricao = $_POST['descricao'];
$valor = $_POST['valor'];
$data = str_replace("/", "-", $_POST["data"]);
$data1 = date('Y-m-d', strtotime($data));
$objBd = new bd();
$link = $objBd->conecta_mysql();
$valor=moeda_clean($valor);
$sql = "CALL investimentos_edt('$nome', '$descricao', '$data1','$valor','$cod');";
$resultado = mysqli_query($link, $sql);
if(mysql_affected_rows($link) != 0){
echo "
<META HTTP-EQUIV=REFRESH CONTENT = '2;URL=investimentos.php'>
<script type=\"text/javascript\">
$(window).load(function() {
modal({
type: 'success',
title: 'Sucesso',
text: 'Investimento alterado com sucesso!',
autoclose: false,
size: 'large',
center: false,
theme: 'atlant',
});
});
</script>
";
}else{
echo "
<META HTTP-EQUI=REFRESH CONTENT = '2;URL=investimentos.php'>
<script type=\"text/javascript\">
$(window).load(function() {
modal({
type: 'error',
title: 'Error',
text: 'Investimento não pode ser alterado!',
autoclose: true,
size: 'large',
center: false,
theme: 'atlant',
});
});
</script>
";
}
}
if(isset($_POST['editar'])){
editarInvestimento();
}*/
?>
</body>
</html>