Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionado sessão e alterado os DAO #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions exemplo_alunos/code/db/banco.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ INSERT INTO `tb_curso` (`id`, `nome`, `descricao`, `carga_horaria`, `data_inicio
(1, 'Tec. Teste', 'Curso para teste do CursoDao', 200, '2000-01-30', '2000-03-30'),
(2, 'Tec. Info', 'Técnico em Informática (Teste 1)', 1000, '2011-01-01', '2012-01-01');

DROP TABLE IF EXISTS `tb_turma`;
CREATE TABLE `tb_turma` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(100) NOT NULL,
`id_curso` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `id_curso` (`id_curso`),
CONSTRAINT `tb_turma_ibfk_1` FOREIGN KEY (`id_curso`) REFERENCES `tb_curso` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `tb_turma` (`id`, `nome`, `id_curso`) VALUES
(1, 'Turma 2009', 1),
(2, 'Turma de 2010', 2),
(3, '2a', 2);

DROP TABLE IF EXISTS `tb_login`;
CREATE TABLE `tb_login` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`usuario` varchar(200) NOT NULL,
`senha` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `tb_login` (`id`, `usuario`, `senha`) VALUES
(1, 'root', '123');

DROP TABLE IF EXISTS `tb_matricula`;
CREATE TABLE `tb_matricula` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -49,17 +75,3 @@ INSERT INTO `tb_matricula` (`id`, `id_aluno`, `id_turma`, `data_matricula`) VALU
(1, 3, 2, '2020-01-01'),
(2, 2, 1, '2023-05-01');

DROP TABLE IF EXISTS `tb_turma`;
CREATE TABLE `tb_turma` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(100) NOT NULL,
`id_curso` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `id_curso` (`id_curso`),
CONSTRAINT `tb_turma_ibfk_1` FOREIGN KEY (`id_curso`) REFERENCES `tb_curso` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

INSERT INTO `tb_turma` (`id`, `nome`, `id_curso`) VALUES
(1, 'Turma 2009', 1),
(2, 'Turma de 2010', 2),
(3, '2a', 2);
3 changes: 2 additions & 1 deletion exemplo_alunos/code/model/aluno_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class AlunoDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
3 changes: 2 additions & 1 deletion exemplo_alunos/code/model/curso_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class CursoDao
{
private $conexao;

public function __construct(Conexao $conexao)
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

Expand Down
9 changes: 5 additions & 4 deletions exemplo_alunos/code/model/matricula_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class MatriculaDao
{
private $conexao;

public function __construct(Conexao $conexao)
{
$this->conexao = $conexao->conectar();
}
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

public function inserir(Matricula $matricula)
{
Expand Down
9 changes: 5 additions & 4 deletions exemplo_alunos/code/model/turma_dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class TurmaDao
{
private $conexao;

public function __construct(Conexao $conexao)
{
$this->conexao = $conexao->conectar();
}
public function __construct()
{
$conexao = new Conexao();
$this->conexao = $conexao->conectar();
}

public function inserir(Turma $turma)
{
Expand Down
32 changes: 32 additions & 0 deletions exemplo_alunos/code/public/autenticar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?
require_once '../db/conexao.php';
session_start();
$acao = isset($_GET["acao"]);
if(isset($acao) && $acao == 'Sair') {
unset($_SESSION['logado']);
header('Location: index.html');
}
else {
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$conexao = new Conexao();
$conectado = $conexao->conectar();

$sql = 'SELECT * from tb_login WHERE usuario= :usuario AND senha= :senha';

// preencher SQL com dados do aluno que eu quero inserir
$stmt = $conectado->prepare($sql);
$stmt->bindValue(':usuario', $usuario);
$stmt->bindValue(':senha', $senha);
$stmt->execute();
// manda executar SQL
$result = $stmt->rowCount();

if($result === 1) {
$_SESSION['logado'] = 'true';
header('Location: menu.php');
}
else {
header('Location: index.html');
}
}
68 changes: 43 additions & 25 deletions exemplo_alunos/code/public/index.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
<!DOCTYPE html>
<html lang="en">

<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Login</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
<style>
body{
display: flex;
flex-direction: column;
gap: 8px;
justify-content: center;
align-items: center;
height: 100vh;
overflow-y: hidden;
}
.login {
gap:8px;
}
.login, .usuario, .senha {
display: flex;
flex-direction: column;
}
.acessar-sem-login {
text-decoration: none;
color: #000;
}
</style>
</head>

<body>
<h1>Bem vindo</h1>

<h3>Controle de Alunos</h3>
<a href="cadastrar_aluno.html">Cadastro de aluno</a> <br>
<a href="listar_alunos.php">Listar alunos</a> <br><br>

<h3>Controle de Curso</h3>
<a href="cadastrar_curso.html">Cadastro de curso</a> <br>
<a href="listar_cursos.php">Listar cursos</a> <br><br>

<h3>Controle de Turma</h3>
<a href="cadastrar_turma.php">Cadastro de turma</a> <br>
<a href="listar_turmas.php">Listar turmas</a> <br><br>

<h3>Controle de Matrícula</h3>
<a href="cadastrar_matricula.php">Realizar matrícula</a> <br>
<a href="listar_matriculas.php">Listar matrículas</a> <br><br>
<form class="login" action="autenticar.php" method="post">
<div class="usuario">
<label for="username">Login</label>
<input type="text" name="usuario" id="usuario">
</div>
<div class="senha">
<label for="password">Senha</label>
<input type="password" name="senha" id="senha">
</div>
<button>Acessar</button>
</form>
<div class="acessar-sem-login">
<a href="menu.php">Acessar sem login</a>
</div>
</body>

</html>
5 changes: 2 additions & 3 deletions exemplo_alunos/code/public/inserir_aluno.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

$aluno = new Aluno(0, $nome, $endereco, $telefone, $data_nascimento);

$conexao = new Conexao();
$alunoDao = new AlunoDao($conexao);
$alunoDao = new AlunoDao();

$alunoDao->inserir($aluno);

// echo '<pre>';
// print_r($aluno);
// echo '</pre>';

header('Location: index.html');
header('Location: menu.php');

6 changes: 3 additions & 3 deletions exemplo_alunos/code/public/inserir_curso.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

$curso = new Curso(0, $nome, $descricao, $carga_horaria, $data_inicio, $data_fim);

$conexao = new Conexao();
$cursoDao = new CursoDao($conexao);

$cursoDao = new CursoDao();

$cursoDao->inserir($curso);

header('Location: index.html');
header('Location: menu.php');
10 changes: 5 additions & 5 deletions exemplo_alunos/code/public/inserir_matricula.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
$turma_id = $_POST['turma'];
$data_matricula = $_POST['data_matricula'];

$conexao = new Conexao();

$alunoDao = new AlunoDao($conexao);

$alunoDao = new AlunoDao();
$aluno = $alunoDao->buscar_id($aluno_id);

$turmaDao = new TurmaDao($conexao);
$turmaDao = new TurmaDao();
$turma = $turmaDao->buscar_id($turma_id);

$matricula = new Matricula(0, $aluno, $turma, $data_matricula);
$matriculaDao = new MatriculaDao($conexao);
$matriculaDao = new MatriculaDao();
$matriculaDao->inserir($matricula);

header('Location: index.html');
header('Location: menu.php');
7 changes: 3 additions & 4 deletions exemplo_alunos/code/public/inserir_turma.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
$nome = $_POST['nome'];
$curso_id = $_POST['curso'];

$conexao = new Conexao();

$cursoDao = new CursoDao($conexao);
$cursoDao = new CursoDao();
$curso = $cursoDao->buscar_id($curso_id);

$turma = new Turma(0, $nome, $curso);
$turmaDao = new TurmaDao($conexao);
$turmaDao = new TurmaDao();
$turmaDao->inserir($turma);

header('Location: index.html');
header('Location: menu.php');
40 changes: 40 additions & 0 deletions exemplo_alunos/code/public/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<? session_start(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<h1>Bem vindo</h1>

<h3>Controle de Alunos</h3>
<? if(isset($_SESSION['logado'])) { echo '<a href="cadastrar_aluno.html">Cadastro de aluno</a> <br>'; } ?>
<a href="listar_alunos.php">Listar alunos</a> <br><br>

<h3>Controle de Curso</h3>
<? if(isset($_SESSION['logado'])) { echo '<a href="cadastrar_curso.html">Cadastro de curso</a> <br>'; } ?>
<a href="listar_cursos.php">Listar cursos</a> <br><br>

<h3>Controle de Turma</h3>
<? if(isset($_SESSION['logado'])) { echo '<a href="cadastrar_turma.php">Cadastro de turma</a> <br>'; } ?>
<a href="listar_turmas.php">Listar turmas</a> <br><br>

<h3>Controle de Matrícula</h3>
<? if(isset($_SESSION['logado'])) { echo '<a href="cadastrar_matricula.php">Realizar matrícula</a> <br>'; } ?>
<a href="listar_matriculas.php">Listar matrículas</a> <br><br>
<? if(isset($_SESSION['logado'])) {
echo '<form action="autenticar.php" method="get"><input type="submit" name="acao" value="Sair"></input ></form>';
}
else {
echo '<form action="index.html" method=""><input type="submit" name="voltar" value="Voltar"></input ></form>';
}
?>

</body>

</html>