89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
|
|
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
require_once 'db/config.php';
|
|
include 'includes/header.php';
|
|
include 'includes/sidebar.php';
|
|
|
|
// Fetch crops from the database
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT * FROM crops ORDER BY start_date DESC');
|
|
$crops = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$crops = [];
|
|
$error = "Erro ao buscar lavouras: " . $e->getMessage();
|
|
}
|
|
|
|
?>
|
|
|
|
<header class="top-bar">
|
|
<h1>Controle de Lavouras</h1>
|
|
</header>
|
|
|
|
<main class="content">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<span>Lavouras Cadastradas</span>
|
|
<a href="add_crop.php" class="btn" style="float: right; background-color: #3498db; color: white; text-decoration: none; padding: 5px 10px; border-radius: 4px;">Adicionar Lavoura</a>
|
|
</div>
|
|
|
|
<?php if (isset($error)): ?>
|
|
<p class="error"><?php echo $error; ?></p>
|
|
<?php endif; ?>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Lavoura</th>
|
|
<th>Área (ha)</th>
|
|
<th>Data de Início</th>
|
|
<th>Data de Colheita</th>
|
|
<th>Ações</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($crops)): ?>
|
|
<tr>
|
|
<td colspan="5">Nenhuma lavoura encontrada.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($crops as $crop): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($crop['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($crop['area']); ?></td>
|
|
<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($crop['start_date']))); ?></td>
|
|
<td><?php echo $crop['end_date'] ? htmlspecialchars(date('d/m/Y', strtotime($crop['end_date']))) : 'Em andamento'; ?></td>
|
|
<td>
|
|
<a href="view_crop.php?id=<?php echo $crop['id']; ?>">Ver Detalhes</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</main>
|
|
|
|
<style>
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
}
|
|
th, td {
|
|
border: 1px solid #ddd;
|
|
padding: 8px;
|
|
text-align: left;
|
|
}
|
|
th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
</style>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|