versão aprimorada 5
This commit is contained in:
parent
74e6e52559
commit
5cd527302b
@ -7,25 +7,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$address = trim($_POST['address'] ?? '');
|
$address = trim($_POST['address'] ?? '');
|
||||||
$technician_name = trim($_POST['technician_name'] ?? '');
|
$technician_name = trim($_POST['technician_name'] ?? '');
|
||||||
$observations = trim($_POST['observations'] ?? '');
|
$observations = trim($_POST['observations'] ?? '');
|
||||||
|
$status = trim($_POST['status'] ?? 'ativo');
|
||||||
$voltage = trim($_POST['voltage'] ?? null);
|
$voltage = trim($_POST['voltage'] ?? null);
|
||||||
$phase_neutral_ground = trim($_POST['phase_neutral_ground'] ?? null);
|
$phase_neutral_ground = trim($_POST['phase_neutral_ground'] ?? null);
|
||||||
$breaker_output = trim($_POST['breaker_output'] ?? null);
|
$breaker_output = trim($_POST['breaker_output'] ?? null);
|
||||||
|
|
||||||
if (empty($client_name) || empty($address) || empty($technician_name)) {
|
// Validation removed to allow incomplete forms
|
||||||
$_SESSION['message'] = 'Por favor, preencha todos os campos obrigatórios.';
|
|
||||||
$_SESSION['message_type'] = 'danger';
|
|
||||||
header('Location: index.php');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
try {
|
try {
|
||||||
$pdo->beginTransaction();
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
$stmt = $pdo->prepare(
|
$stmt = $pdo->prepare(
|
||||||
"INSERT INTO installations (client_name, address, technician_name, observations, voltage, phase_neutral_ground, breaker_output) VALUES (?, ?, ?, ?, ?, ?, ?)"
|
"INSERT INTO installations (client_name, address, technician_name, observations, status, voltage, phase_neutral_ground, breaker_output) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
);
|
);
|
||||||
$stmt->execute([$client_name, $address, $technician_name, $observations, $voltage, $phase_neutral_ground, $breaker_output]);
|
$stmt->execute([$client_name, $address, $technician_name, $observations, $status, $voltage, $phase_neutral_ground, $breaker_output]);
|
||||||
$installation_id = $pdo->lastInsertId();
|
$installation_id = $pdo->lastInsertId();
|
||||||
|
|
||||||
// Handle multiple file uploads
|
// Handle multiple file uploads
|
||||||
@ -75,4 +71,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
1
db/migrations/005_add_status_to_installations.sql
Normal file
1
db/migrations/005_add_status_to_installations.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE installations ADD COLUMN status VARCHAR(50) NOT NULL DEFAULT 'ativo' COMMENT 'Status da instalação: ativo, em manutenção';
|
||||||
75
index.php
75
index.php
@ -173,9 +173,7 @@ try {
|
|||||||
<th>Cliente</th>
|
<th>Cliente</th>
|
||||||
<th>Endereço</th>
|
<th>Endereço</th>
|
||||||
<th>Técnico</th>
|
<th>Técnico</th>
|
||||||
<th>Tensão</th>
|
<th>Status</th>
|
||||||
<th>Fase/Neutro</th>
|
|
||||||
<th>Disjuntor</th>
|
|
||||||
<th>Data</th>
|
<th>Data</th>
|
||||||
<th>Ações</th>
|
<th>Ações</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -183,7 +181,7 @@ try {
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php if (empty($installations) && !isset($db_error)): ?>
|
<?php if (empty($installations) && !isset($db_error)): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="9" class="text-center">Nenhuma instalação encontrada.</td>
|
<td colspan="7" class="text-center">Nenhuma instalação encontrada.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php foreach ($installations as $inst): ?>
|
<?php foreach ($installations as $inst): ?>
|
||||||
@ -191,6 +189,8 @@ try {
|
|||||||
$img_stmt = $pdo->prepare("SELECT image_path FROM installation_images WHERE installation_id = ? ORDER BY id ASC LIMIT 1");
|
$img_stmt = $pdo->prepare("SELECT image_path FROM installation_images WHERE installation_id = ? ORDER BY id ASC LIMIT 1");
|
||||||
$img_stmt->execute([$inst['id']]);
|
$img_stmt->execute([$inst['id']]);
|
||||||
$first_image = $img_stmt->fetchColumn();
|
$first_image = $img_stmt->fetchColumn();
|
||||||
|
|
||||||
|
$status_badge_class = $inst['status'] == 'ativo' ? 'bg-success' : 'bg-warning';
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@ -202,16 +202,26 @@ try {
|
|||||||
N/A
|
N/A
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo htmlspecialchars($inst['client_name']); ?></td>
|
<td><?php echo htmlspecialchars($inst['client_name'] ?: 'N/A'); ?></td>
|
||||||
<td><?php echo htmlspecialchars($inst['address']); ?></td>
|
<td><?php echo htmlspecialchars($inst['address'] ?: 'N/A'); ?></td>
|
||||||
<td><?php echo htmlspecialchars($inst['technician_name']); ?></td>
|
<td><?php echo htmlspecialchars($inst['technician_name'] ?: 'N/A'); ?></td>
|
||||||
<td><?php echo htmlspecialchars($inst['voltage'] ?? 'N/A'); ?></td>
|
<td><span class="badge <?php echo $status_badge_class; ?>"><?php echo ucfirst(htmlspecialchars($inst['status'])); ?></span></td>
|
||||||
<td><?php echo htmlspecialchars($inst['phase_neutral_ground'] ?? 'N/A'); ?></td>
|
|
||||||
<td><?php echo htmlspecialchars($inst['breaker_output'] ?? 'N/A'); ?></td>
|
|
||||||
<td><?php echo date("d/m/Y", strtotime($inst['created_at'])); ?></td>
|
<td><?php echo date("d/m/Y", strtotime($inst['created_at'])); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-square"></i></a>
|
<div class="btn-group">
|
||||||
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></a>
|
<form action="update_status.php" method="POST" style="display: inline-block;">
|
||||||
|
<input type="hidden" name="id" value="<?php echo $inst['id']; ?>">
|
||||||
|
<input type="hidden" name="status" value="ativo">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-success" title="Marcar como Ativo"><i class="bi bi-check-circle"></i></button>
|
||||||
|
</form>
|
||||||
|
<form action="update_status.php" method="POST" style="display: inline-block;">
|
||||||
|
<input type="hidden" name="id" value="<?php echo $inst['id']; ?>">
|
||||||
|
<input type="hidden" name="status" value="em manutenção">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-warning" title="Marcar como Em Manutenção"><i class="bi bi-tools"></i></button>
|
||||||
|
</form>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-secondary" title="Editar"><i class="bi bi-pencil-square"></i></a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-danger" title="Excluir"><i class="bi bi-trash"></i></a>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@ -234,37 +244,48 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form action="add_installation.php" method="POST" enctype="multipart/form-data">
|
<form action="add_installation.php" method="POST" enctype="multipart/form-data">
|
||||||
<div class="mb-3">
|
<div class="row">
|
||||||
<label for="client_name" class="form-label">Nome do Cliente</label>
|
<div class="col-md-6 mb-3">
|
||||||
<input type="text" class="form-control" id="client_name" name="client_name" required>
|
<label for="client_name" class="form-label">Nome do Cliente</label>
|
||||||
|
<input type="text" class="form-control" id="client_name" name="client_name">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="technician_name" class="form-label">Nome do Técnico</label>
|
||||||
|
<input type="text" class="form-control" id="technician_name" name="technician_name">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="address" class="form-label">Endereço da Instalação</label>
|
<label for="address" class="form-label">Endereço da Instalação</label>
|
||||||
<textarea class="form-control" id="address" name="address" rows="3" required></textarea>
|
<textarea class="form-control" id="address" name="address" rows="2"></textarea>
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="technician_name" class="form-label">Nome do Técnico</label>
|
|
||||||
<input type="text" class="form-control" id="technician_name" name="technician_name" required>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="observations" class="form-label">Observações</label>
|
<label for="observations" class="form-label">Observações</label>
|
||||||
<textarea class="form-control" id="observations" name="observations" rows="3"></textarea>
|
<textarea class="form-control" id="observations" name="observations" rows="2"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="row">
|
||||||
<label for="images" class="form-label">Imagens da Instalação</label>
|
<div class="col-md-6 mb-3">
|
||||||
<input class="form-control" type="file" id="images" name="images[]" accept="image/*" multiple>
|
<label for="images" class="form-label">Imagens da Instalação</label>
|
||||||
|
<input class="form-control" type="file" id="images" name="images[]" accept="image/*" multiple>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status">
|
||||||
|
<option value="ativo" selected>Ativo</option>
|
||||||
|
<option value="em manutenção">Em Manutenção</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<h6 class="mb-3">Medições Elétricas</h6>
|
<h6 class="mb-3">Medições Elétricas (Opcional)</h6>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="voltage" class="form-label">Tensão (V)</label>
|
<label for="voltage" class="form-label">Tensão (V)</label>
|
||||||
<input type="text" class="form-control" id="voltage" name="voltage">
|
<input type="text" class="form-control" id="voltage" name="voltage">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
<label for="phase_neutral_ground" class="form-label">Fase-Neutro-Terra</label>
|
<label for="phase_neutral_ground" class="form-label">Fase-Neutro-Terra</e-label>
|
||||||
<input type="text" class="form-control" id="phase_neutral_ground" name="phase_neutral_ground">
|
<input type="text" class="form-control" id="phase_neutral_ground" name="phase_neutral_ground">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 mb-3">
|
<div class="col-md-4 mb-3">
|
||||||
@ -285,4 +306,4 @@ try {
|
|||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
26
update_status.php
Normal file
26
update_status.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/db/config.php';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$id = $_POST['id'] ?? null;
|
||||||
|
$status = $_POST['status'] ?? null;
|
||||||
|
|
||||||
|
if ($id && $status) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("UPDATE installations SET status = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$status, $id]);
|
||||||
|
|
||||||
|
$_SESSION['message'] = 'Status atualizado com sucesso!';
|
||||||
|
$_SESSION['message_type'] = 'success';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
error_log("Status update error: " . $e->getMessage());
|
||||||
|
$_SESSION['message'] = 'Erro ao atualizar o status.';
|
||||||
|
$_SESSION['message_type'] = 'danger';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
Loading…
x
Reference in New Issue
Block a user