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'] ?? '');
|
||||
$technician_name = trim($_POST['technician_name'] ?? '');
|
||||
$observations = trim($_POST['observations'] ?? '');
|
||||
$status = trim($_POST['status'] ?? 'ativo');
|
||||
$voltage = trim($_POST['voltage'] ?? null);
|
||||
$phase_neutral_ground = trim($_POST['phase_neutral_ground'] ?? null);
|
||||
$breaker_output = trim($_POST['breaker_output'] ?? null);
|
||||
|
||||
if (empty($client_name) || empty($address) || empty($technician_name)) {
|
||||
$_SESSION['message'] = 'Por favor, preencha todos os campos obrigatórios.';
|
||||
$_SESSION['message_type'] = 'danger';
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
// Validation removed to allow incomplete forms
|
||||
|
||||
$pdo = db();
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$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();
|
||||
|
||||
// Handle multiple file uploads
|
||||
|
||||
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';
|
||||
67
index.php
67
index.php
@ -173,9 +173,7 @@ try {
|
||||
<th>Cliente</th>
|
||||
<th>Endereço</th>
|
||||
<th>Técnico</th>
|
||||
<th>Tensão</th>
|
||||
<th>Fase/Neutro</th>
|
||||
<th>Disjuntor</th>
|
||||
<th>Status</th>
|
||||
<th>Data</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
@ -183,7 +181,7 @@ try {
|
||||
<tbody>
|
||||
<?php if (empty($installations) && !isset($db_error)): ?>
|
||||
<tr>
|
||||
<td colspan="9" class="text-center">Nenhuma instalação encontrada.</td>
|
||||
<td colspan="7" class="text-center">Nenhuma instalação encontrada.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?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->execute([$inst['id']]);
|
||||
$first_image = $img_stmt->fetchColumn();
|
||||
|
||||
$status_badge_class = $inst['status'] == 'ativo' ? 'bg-success' : 'bg-warning';
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
@ -202,16 +202,26 @@ try {
|
||||
N/A
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($inst['client_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($inst['address']); ?></td>
|
||||
<td><?php echo htmlspecialchars($inst['technician_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($inst['voltage'] ?? 'N/A'); ?></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 htmlspecialchars($inst['client_name'] ?: 'N/A'); ?></td>
|
||||
<td><?php echo htmlspecialchars($inst['address'] ?: 'N/A'); ?></td>
|
||||
<td><?php echo htmlspecialchars($inst['technician_name'] ?: 'N/A'); ?></td>
|
||||
<td><span class="badge <?php echo $status_badge_class; ?>"><?php echo ucfirst(htmlspecialchars($inst['status'])); ?></span></td>
|
||||
<td><?php echo date("d/m/Y", strtotime($inst['created_at'])); ?></td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-square"></i></a>
|
||||
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></a>
|
||||
<div class="btn-group">
|
||||
<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>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@ -234,37 +244,48 @@ try {
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="add_installation.php" method="POST" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="client_name" class="form-label">Nome do Cliente</label>
|
||||
<input type="text" class="form-control" id="client_name" name="client_name" required>
|
||||
<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 class="mb-3">
|
||||
<label for="address" class="form-label">Endereço da Instalação</label>
|
||||
<textarea class="form-control" id="address" name="address" rows="3" required></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>
|
||||
<textarea class="form-control" id="address" name="address" rows="2"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<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>
|
||||
|
||||
<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="col-md-4 mb-3">
|
||||
<label for="voltage" class="form-label">Tensão (V)</label>
|
||||
<input type="text" class="form-control" id="voltage" name="voltage">
|
||||
</div>
|
||||
<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">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
|
||||
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