Skip to content

Commit d8ac71c

Browse files
Atualização Geral 1
Modifiquei alguns detalhes sobre o login, agora index, nestas páginas. Lembrando que não há maneiras de cadastro de usuário indiretamente do Banco de Dados, mas já tem um ADM cadastrado.
1 parent 6d794b4 commit d8ac71c

File tree

8 files changed

+703
-0
lines changed

8 files changed

+703
-0
lines changed

bancoDeDados.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
-- DROP DATABASE CameraCruzamento;
2+
3+
CREATE DATABASE IF NOT EXISTS CameraCruzamento
4+
DEFAULT CHARACTER SET utf8mb4
5+
DEFAULT COLLATE utf8mb4_general_ci;
6+
7+
USE CameraCruzamento;
8+
9+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
10+
START TRANSACTION;
11+
SET time_zone = "+00:00";
12+
13+
SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;
14+
SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;
15+
SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;
16+
SET NAMES utf8mb4;
17+
18+
-- Usuários do sistema (Secretaria, Operador, etc.)
19+
CREATE TABLE Usuarios (
20+
id INT AUTO_INCREMENT PRIMARY KEY,
21+
nome VARCHAR(100) NOT NULL,
22+
email VARCHAR(100) NOT NULL UNIQUE,
23+
senha VARCHAR(255) NOT NULL,
24+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
25+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
26+
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
27+
28+
-- Dispositivos (Câmeras)
29+
CREATE TABLE Dispositivos (
30+
id INT AUTO_INCREMENT PRIMARY KEY,
31+
nome VARCHAR(100) NOT NULL,
32+
id_ponto VARCHAR(50) NOT NULL,
33+
localizacao VARCHAR(255) NOT NULL, -- endereço ou coordenadas
34+
status ENUM('Ativo', 'Inativo', 'Manutenção') NOT NULL DEFAULT 'Ativo',
35+
observacao VARCHAR(255),
36+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
37+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
38+
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
39+
40+
-- Eventos detectados pelas câmeras
41+
CREATE TABLE Eventos_Cameras (
42+
id INT AUTO_INCREMENT PRIMARY KEY,
43+
id_camera INT NOT NULL,
44+
id_ponto VARCHAR(50) NOT NULL,
45+
timestamp DATETIME NOT NULL,
46+
tipo ENUM('carro', 'caminhao', 'moto', 'onibus', 'pedestre') NOT NULL,
47+
status_camera ENUM('em funcionamento', 'pouco alterado', 'muito alterado', 'desligado') NOT NULL,
48+
observacao VARCHAR(255),
49+
FOREIGN KEY (id_camera) REFERENCES Dispositivos(id)
50+
ON DELETE CASCADE
51+
ON UPDATE CASCADE
52+
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
53+
54+
COMMIT;
55+
56+
-- Exemplo de inserção de usuário
57+
INSERT INTO Usuarios (nome, email, senha) VALUES
58+
('Administrador', '[email protected]', 'admin');
59+
60+
-- Exemplo de inserção de dispositivos
61+
INSERT INTO Dispositivos (nome, id_ponto, localizacao, status, observacao) VALUES
62+
('Câmera Cruzamento 1', 'P1', '-23.55052,-46.633308', 'Ativo', 'Cruzamento Av. Paulista x Rua Augusta'),
63+
('Câmera Cruzamento 2', 'P2', '-23.551234,-46.634567', 'Manutenção', 'Cruzamento Av. Brasil x Rua Bela Vista');
64+
65+
-- Exemplo de inserção de eventos
66+
INSERT INTO Eventos_Cameras (id_camera, id_ponto, timestamp, tipo, status_camera, observacao) VALUES
67+
(1, 'P1', '2025-10-01 14:23:00', 'carro', 'em funcionamento', 'Trânsito normal'),
68+
(2, 'P2', '2025-10-01 14:25:00', 'pedestre', 'pouco alterado', 'Movimento incomum detectado');

cadastro.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
include 'config.php';
3+
session_start();
4+
if (!isset($_SESSION['usuario_id'])) {
5+
header("Location: index.php");
6+
exit;
7+
}
8+
$mensagem = '';
9+
$mensagem_tipo = '';
10+
11+
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
12+
$nome = $_POST['nome'];
13+
$id_ponto = $_POST['id_ponto'];
14+
$localizacao = $_POST['localizacao'];
15+
$status = $_POST['status'];
16+
$observacao = $_POST['observacao'];
17+
18+
$sql = "INSERT INTO Dispositivos (nome, id_ponto, localizacao, status, observacao) VALUES (?, ?, ?, ?, ?)";
19+
$valores = [$nome, $id_ponto, $localizacao, $status, $observacao];
20+
21+
$stmt = $conn->prepare($sql);
22+
if ($stmt->execute($valores)) {
23+
$mensagem = "Dispositivo cadastrado com sucesso!";
24+
$mensagem_tipo = "sucesso";
25+
} else {
26+
$mensagem = "Erro ao cadastrar dispositivo: " . $stmt->errorInfo()[2];
27+
$mensagem_tipo = "erro";
28+
}
29+
}
30+
?>
31+
<!DOCTYPE html>
32+
<html lang="pt-BR">
33+
<head>
34+
<meta charset="UTF-8">
35+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
36+
<title>Cadastro de Dispositivo</title>
37+
<script src="https://cdn.tailwindcss.com"></script>
38+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
39+
<link rel="stylesheet" href="estilo.css">
40+
</head>
41+
<body class="bg-gray-50 font-sans">
42+
<?php include 'cabecalho.php'; ?>
43+
<div class="w-full min-h-screen gradient-bg flex items-center justify-center p-4" style="padding-top: 88px;">
44+
<div class="bg-white rounded-xl shadow-2xl p-8 w-full max-w-2xl">
45+
<div class="text-center mb-8">
46+
<h1 class="text-2xl font-bold text-gray-800 mt-4">Cadastro de Dispositivo</h1>
47+
<p class="text-gray-600">Preencha os dados para cadastrar um novo dispositivo de monitoramento</p>
48+
</div>
49+
<?php if ($mensagem): ?>
50+
<div class="mb-4">
51+
<div class="<?php echo $mensagem_tipo === 'sucesso' ? 'bg-green-100 border border-green-400 text-green-700' : 'bg-red-100 border border-red-400 text-red-700'; ?> px-4 py-3 rounded relative text-center" role="alert">
52+
<?php echo $mensagem; ?>
53+
</div>
54+
</div>
55+
<?php if ($mensagem_tipo === 'sucesso'): ?>
56+
<script>
57+
setTimeout(() => { window.location.href = "menu.php"; }, 2000);
58+
</script>
59+
<?php endif; ?>
60+
<?php endif; ?>
61+
<form id="cadastro-dispositivo-form" class="space-y-6" method="POST" autocomplete="off">
62+
<div class="mb-4">
63+
<label for="nome" class="block text-sm font-medium text-gray-700">Nome do Dispositivo</label>
64+
<input type="text" id="nome" name="nome" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
65+
</div>
66+
<div class="mb-4">
67+
<label for="id_ponto" class="block text-sm font-medium text-gray-700">ID do Ponto</label>
68+
<input type="text" id="id_ponto" name="id_ponto" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
69+
</div>
70+
<div class="mb-4">
71+
<label for="localizacao" class="block text-sm font-medium text-gray-700">Localização (Endereço ou Coordenadas)</label>
72+
<input type="text" id="localizacao" name="localizacao" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
73+
</div>
74+
<div class="mb-4">
75+
<label for="status" class="block text-sm font-medium text-gray-700">Status</label>
76+
<select id="status" name="status" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
77+
<option value="Ativo">Ativo</option>
78+
<option value="Inativo">Inativo</option>
79+
<option value="Manutenção">Manutenção</option>
80+
</select>
81+
</div>
82+
<div class="mb-4">
83+
<label for="observacao" class="block text-sm font-medium text-gray-700">Observação</label>
84+
<textarea id="observacao" name="observacao" rows="2" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500"></textarea>
85+
</div>
86+
<div class="flex flex-col sm:flex-row justify-end sm:space-x-2 space-y-2 sm:space-y-0">
87+
<a href="menu.php" class="w-full sm:w-auto inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">Cancelar</a>
88+
<button type="submit"
89+
class="w-full sm:w-auto inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
90+
Cadastrar
91+
</button>
92+
</div>
93+
</form>
94+
</div>
95+
</div>
96+
</body>
97+
</html>

editarCamera.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
include 'config.php';
3+
session_start();
4+
if (!isset($_SESSION['usuario_id'])) {
5+
header("Location: index.php");
6+
exit;
7+
}
8+
9+
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
10+
if ($id <= 0) {
11+
header("Location: menu.php");
12+
exit;
13+
}
14+
15+
// Busca o dispositivo pelo ID
16+
$stmt = $conn->prepare("SELECT * FROM Dispositivos WHERE id = ?");
17+
$stmt->execute([$id]);
18+
$camera = $stmt->fetch(PDO::FETCH_ASSOC);
19+
if (!$camera) {
20+
header("Location: menu.php");
21+
exit;
22+
}
23+
24+
$mensagem = '';
25+
$mensagem_tipo = '';
26+
27+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
28+
$nome = $_POST['nome'];
29+
$id_ponto = $_POST['id_ponto'];
30+
$localizacao = $_POST['localizacao'];
31+
$status = $_POST['status'];
32+
$observacao = $_POST['observacao'];
33+
34+
$sql = "UPDATE Dispositivos SET nome = ?, id_ponto = ?, localizacao = ?, status = ?, observacao = ? WHERE id = ?";
35+
$stmt = $conn->prepare($sql);
36+
if ($stmt->execute([$nome, $id_ponto, $localizacao, $status, $observacao, $id])) {
37+
$mensagem = "Dados da câmera atualizados com sucesso!";
38+
$mensagem_tipo = "sucesso";
39+
// Atualiza os dados exibidos no formulário
40+
$stmt = $conn->prepare("SELECT * FROM Dispositivos WHERE id = ?");
41+
$stmt->execute([$id]);
42+
$camera = $stmt->fetch(PDO::FETCH_ASSOC);
43+
} else {
44+
$mensagem = "Erro ao atualizar dados: " . $stmt->errorInfo()[2];
45+
$mensagem_tipo = "erro";
46+
}
47+
}
48+
?>
49+
<!DOCTYPE html>
50+
<html lang="pt-BR">
51+
<head>
52+
<meta charset="UTF-8">
53+
<title>Editar Câmera</title>
54+
<script src="https://cdn.tailwindcss.com"></script>
55+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
56+
<link rel="stylesheet" href="estilo.css">
57+
</head>
58+
<body class="bg-gray-50 font-sans">
59+
<?php include 'cabecalho.php'; ?>
60+
<div class="w-full min-h-screen gradient-bg flex items-center justify-center p-6" style="padding-top: 88px;">
61+
<div class="bg-white rounded-xl shadow-2xl p-8 w-full max-w-3xl">
62+
<h1 class="text-2xl font-bold text-gray-800 mb-6 text-center">Editar Câmera</h1>
63+
64+
<?php if ($mensagem): ?>
65+
<div class="mb-4 text-center">
66+
<div class="<?= $mensagem_tipo === 'sucesso' ? 'bg-green-100 border border-green-400 text-green-700' : 'bg-red-100 border border-red-400 text-red-700'; ?> px-4 py-3 rounded">
67+
<?= $mensagem; ?>
68+
</div>
69+
</div>
70+
<?php endif; ?>
71+
72+
<form method="POST" class="space-y-6">
73+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
74+
<div>
75+
<label for="nome" class="block text-sm font-medium text-gray-700">Nome da Câmera</label>
76+
<input type="text" name="nome" value="<?= htmlspecialchars($camera['nome']) ?>" required class="mt-1 w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
77+
</div>
78+
<div>
79+
<label for="id_ponto" class="block text-sm font-medium text-gray-700">ID do Ponto</label>
80+
<input type="text" name="id_ponto" value="<?= htmlspecialchars($camera['id_ponto']) ?>" required class="mt-1 w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
81+
</div>
82+
<div>
83+
<label for="localizacao" class="block text-sm font-medium text-gray-700">Localização</label>
84+
<input type="text" name="localizacao" value="<?= htmlspecialchars($camera['localizacao']) ?>" required class="mt-1 w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
85+
</div>
86+
<div>
87+
<label for="status" class="block text-sm font-medium text-gray-700">Status</label>
88+
<select name="status" required class="mt-1 w-full border border-gray-300 rounded-md shadow-sm py-2 px-3">
89+
<option value="Ativo" <?= $camera['status'] === 'Ativo' ? 'selected' : '' ?>>Ativo</option>
90+
<option value="Inativo" <?= $camera['status'] === 'Inativo' ? 'selected' : '' ?>>Inativo</option>
91+
<option value="Manutenção" <?= $camera['status'] === 'Manutenção' ? 'selected' : '' ?>>Manutenção</option>
92+
</select>
93+
</div>
94+
</div>
95+
<div>
96+
<label for="observacao" class="block text-sm font-medium text-gray-700">Observação</label>
97+
<textarea name="observacao" rows="2" class="mt-1 w-full border border-gray-300 rounded-md shadow-sm py-2 px-3"><?= htmlspecialchars($camera['observacao']) ?></textarea>
98+
</div>
99+
<div class="flex justify-end space-x-2">
100+
<a href="menu.php" class="bg-gray-300 text-gray-800 px-4 py-2 rounded hover:bg-gray-400">Cancelar</a>
101+
<button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">Salvar Alterações</button>
102+
</div>
103+
</form>
104+
</div>
105+
</div>
106+
</body>
107+
</html>

index.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
session_start();
3+
include 'config.php';
4+
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
5+
$email = $_POST['email'];
6+
$senha = $_POST['senha'];
7+
$stmt = $conn->prepare("SELECT * FROM Usuarios WHERE email = ? LIMIT 1");
8+
$stmt->execute([$email]);
9+
$usuario = $stmt->fetch();
10+
if ($usuario && password_verify($senha, $usuario['senha'])) {
11+
$_SESSION['usuario_id'] = $usuario['id'];
12+
$_SESSION['nome'] = $usuario['nome'];
13+
header("Location: menu.php");
14+
exit;
15+
} else {
16+
$_SESSION['erro_index'] = "Email ou senha inválidos.";
17+
header("Location: index.php");
18+
exit;
19+
}
20+
}
21+
?>
22+
<!DOCTYPE html>
23+
<html lang="pt-BR">
24+
<head>
25+
<meta charset="UTF-8">
26+
<title>Login</title>
27+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
28+
<script src="https://cdn.tailwindcss.com"></script>
29+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
30+
<link rel="stylesheet" href="estilo.css">
31+
</head>
32+
<body class="bg-gray-50 font-sans">
33+
<div class="w-full min-h-screen gradient-bg flex items-center justify-center p-4">
34+
<div class="bg-white rounded-xl shadow-2xl p-8 w-full max-w-md">
35+
<div class="text-center mb-8">
36+
<h1 class="text-2xl font-bold text-gray-800 mt-4">Acesso ao Sistema</h1>
37+
<p class="text-gray-600">Gerencie o monitoramento de câmeras</p>
38+
</div>
39+
<?php if (isset($_SESSION['erro_index'])): ?>
40+
<div class="mb-4">
41+
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert" id="alerta-balao">
42+
<?php echo $_SESSION['erro_index']; unset($_SESSION['erro_index']); ?>
43+
</div>
44+
</div>
45+
<?php endif; ?>
46+
<form id="index-form" class="space-y-4" action="index.php" method="post">
47+
<div>
48+
<label for="email" class="block text-sm font-medium text-gray-700">E-mail</label>
49+
<input type="email" id="email" name="email" required
50+
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500"
51+
placeholder="[email protected]">
52+
</div>
53+
<div>
54+
<label for="senha" class="block text-sm font-medium text-gray-700">Senha</label>
55+
<input type="password" id="senha" name="senha" required
56+
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
57+
</div>
58+
<div>
59+
<button type="submit"
60+
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
61+
Entrar
62+
</button>
63+
</div>
64+
</form>
65+
</div>
66+
</div>
67+
<script>
68+
document.addEventListener("DOMContentLoaded", () => {
69+
const alert = document.getElementById('alerta-balao');
70+
if (alert) {
71+
setTimeout(() => {
72+
alert.style.opacity = '0';
73+
alert.style.transition = 'opacity 0.5s ease-in-out';
74+
setTimeout(() => alert.remove(), 500);
75+
}, 5000);
76+
}
77+
});
78+
</script>
79+
</body>
80+
</html>

logout.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
session_start();
3+
session_destroy();
4+
header("Location: index.php");
5+
exit;

0 commit comments

Comments
 (0)