-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a85f382
commit 6d43169
Showing
166 changed files
with
14,947 additions
and
1,017 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
session_start(); | ||
require_once 'conexao_bd.php'; | ||
|
||
if (isset($_POST['btn-cadastrar-end'])) { | ||
$id_usuario = $_SESSION['id_usuario']; | ||
$rua = $_POST['rua']; | ||
$bairro = $_POST['bairro']; | ||
$uf = $_POST['uf']; | ||
$pais = $_POST['pais']; | ||
$cidade = $_POST['cidade']; | ||
$complemento = $_POST['complemento']; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
try { | ||
$sql = "INSERT INTO tb_endereco (ID_USUARIO,RUA_ENDERECO,BAIRRO_ENDERECO,ESTADO_ENDERECO,PAIS_ENDERECO,CIDADE_ENDERECO,COMPLEMENTO_ENDERECO) | ||
VALUES (:id_usuario,:rua,:bairro,:uf,:pais,:cidade,:complemento)"; | ||
|
||
$stmt = $pdo->prepare($sql); | ||
|
||
$stmt->bindParam(':id_usuario', $id_usuario); | ||
$stmt->bindParam(':rua', $rua); | ||
$stmt->bindParam(':bairro', $bairro); | ||
$stmt->bindParam(':uf', $uf); | ||
$stmt->bindParam(':pais', $pais); | ||
$stmt->bindParam(':cidade', $cidade); | ||
$stmt->bindParam(':complemento', $complemento); | ||
|
||
$stmt->execute(); | ||
|
||
if($stmt->rowCount() > 0){ | ||
header('Location: ../pages/perfil.php?sucesso=endereco cadastrado'); | ||
}else{ | ||
header('Location: ../pages/perfil.php?erro=endereco não cadastrado'); | ||
} | ||
|
||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
global $pdo; | ||
require_once 'conexao_bd.php'; | ||
|
||
//verifica se botao btn-cadastrar foi clicado | ||
if (isset($_POST['btn-cadastrar'])) { | ||
|
||
$nome = $_POST['nome']; | ||
$sobrenome = $_POST['sobrenome']; | ||
$email = $_POST['email']; | ||
$tel = $_POST['tel']; | ||
$identidade = $_POST['identidade']; | ||
$senha = $_POST['senha']; | ||
$dtaNasc = $_POST['dtaNasc']; | ||
$status = "ATIVO"; | ||
$hash = password_hash($senha, PASSWORD_DEFAULT); | ||
|
||
|
||
try { | ||
|
||
$sql = "INSERT INTO tb_usuario (EMAIL_USUARIO,SENHA_USUARIO,STATUS_USUARIO,DTA_NASC) VALUES (:email, :senha, :status, :dtaNasc)"; | ||
|
||
$stmt = $pdo->prepare($sql); | ||
$stmt->bindParam(':email', $email); | ||
$stmt->bindParam(':senha', $hash); | ||
$stmt->bindParam(':status', $status); | ||
$stmt->bindParam(':dtaNasc', $dtaNasc); | ||
$stmt->execute(); | ||
|
||
$id_usuario = $pdo->lastInsertId(); | ||
|
||
$sql2 = "INSERT INTO tb_cliente (ID_USUARIO,NOME_CLIENTE,SOBRENOME_CLIENTE,FONE_CLIENTE,IDENTIDADE_CLIENTE) VALUES (:id_usuario,:nome,:sobrenome,:tel,:identidade)"; | ||
|
||
$stmt2 = $pdo->prepare($sql2); | ||
$stmt2->bindParam(':id_usuario', $id_usuario); | ||
$stmt2->bindParam(':nome', $nome); | ||
$stmt2->bindParam(':sobrenome', $sobrenome); | ||
$stmt2->bindParam(':tel', $tel); | ||
$stmt2->bindParam(':identidade', $identidade); | ||
$stmt2->execute(); | ||
|
||
header('Location: ../pages/autenticacao/login.php?sucesso=Cadastrado com sucesso'); | ||
} catch (PDOException $e) { | ||
header('Location: ../pages/autenticacao/cadastro.php?erro=Erro ao cadastrar'); | ||
echo 'Error: ' . $e->getMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
require_once "../conexao_bd.php"; | ||
|
||
// Verifica se o parâmetro chat_id foi passado na URL | ||
if (isset($_GET['chat_id'])) { | ||
// Obtém o valor do parâmetro chat_id | ||
$chat_id = $_GET['chat_id']; | ||
|
||
// Consulta SQL para buscar as mensagens do chat | ||
$sql = "SELECT * FROM tb_mensagens WHERE CHAT_ID = :chat_id ORDER BY DTA_ENVIO"; | ||
$stmt = $pdo->prepare($sql); | ||
$stmt->bindParam(":chat_id", $chat_id); | ||
$stmt->execute(); | ||
|
||
// Array para armazenar as mensagens | ||
$mensagens = array(); | ||
|
||
// Loop através das linhas de resultado | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
// Adiciona a mensagem ao array de mensagens | ||
$mensagens[] = $row; | ||
} | ||
|
||
// Verifica se o array de mensagens está vazio | ||
if (empty($mensagens)) { | ||
// Se não houver mensagens, envia uma mensagem indicando que não há mensagens disponíveis | ||
$response = array("mensagem" => "Nenhuma mensagem encontrada para este chat."); | ||
} else { | ||
// Se houver mensagens, envia as mensagens em formato JSON | ||
$response = $mensagens; | ||
} | ||
} else { | ||
// Se o parâmetro chat_id não foi passado, envia uma mensagem de erro | ||
$response = array("erro" => "Parâmetro chat_id não foi fornecido."); | ||
} | ||
|
||
// Retorna a resposta como JSON | ||
echo json_encode($response); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
|
||
require_once "../actions/conexao_bd.php"; | ||
|
||
// Verifica se o usuário está logado | ||
if (isset($_SESSION["id_usuario"])) { | ||
$id_usuario = $_SESSION["id_usuario"]; | ||
|
||
// Query para buscar os chats do usuário | ||
$sql = "SELECT * FROM tb_chats | ||
WHERE REMETENTE = :id_usuario_remetente OR DESTINATARIO = :id_usuario_destinatario"; | ||
|
||
$stmt = $pdo->prepare($sql); | ||
$stmt->bindParam(":id_usuario_remetente", $id_usuario); | ||
$stmt->bindParam(":id_usuario_destinatario", $id_usuario); | ||
$stmt->execute(); | ||
|
||
// Array para armazenar os chats do usuário | ||
$chats = []; | ||
|
||
// Verifica se existem chats encontrados | ||
if ($stmt->rowCount() > 0) { | ||
// Adiciona os chats encontrados ao array | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$chats[] = $row; // Adiciona toda a linha do chat ao array | ||
} | ||
} | ||
|
||
// Armazena o array de chats na sessão | ||
$_SESSION["chats"] = $chats; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
require_once '../conexao_bd.php'; | ||
|
||
if (isset($_POST['btn-chat'])) { | ||
$remetente = $_POST['remetente']; | ||
$destinatario = $_POST['destinatario']; | ||
|
||
// Verifica se o chat já existe | ||
$sql_verificar = "SELECT COUNT(*) FROM tb_chats WHERE REMETENTE = :remetente AND DESTINATARIO = :destinatario"; | ||
$stmt_verificar = $pdo->prepare($sql_verificar); | ||
$stmt_verificar->bindParam(':remetente', $remetente); | ||
$stmt_verificar->bindParam(':destinatario', $destinatario); | ||
$stmt_verificar->execute(); | ||
|
||
$chat_existente = $stmt_verificar->fetchColumn(); | ||
|
||
if ($chat_existente > 0) { | ||
// Se o chat já existe, redireciona com mensagem de erro | ||
header('Location: ../../pages/chats.php?erro=Chat já existente'); | ||
exit(); | ||
} | ||
|
||
// Recupera os nomes do remetente e destinatário da tabela tb_clientes | ||
$sql_dados_remetente = "SELECT NOME_CLIENTE FROM tb_cliente WHERE ID_CLIENTE = :remetente"; | ||
$stmt_dados_remetente = $pdo->prepare($sql_dados_remetente); | ||
$stmt_dados_remetente->bindParam(':remetente', $remetente); | ||
$stmt_dados_remetente->execute(); | ||
$nome_remetente = $stmt_dados_remetente->fetchColumn(); | ||
|
||
$sql_dados_destinatario = "SELECT NOME_CLIENTE FROM tb_cliente WHERE ID_CLIENTE = :destinatario"; | ||
$stmt_dados_destinatario = $pdo->prepare($sql_dados_destinatario); | ||
$stmt_dados_destinatario->bindParam(':destinatario', $destinatario); | ||
$stmt_dados_destinatario->execute(); | ||
$nome_destinatario = $stmt_dados_destinatario->fetchColumn(); | ||
|
||
// Insere os dados na tabela de chats | ||
$sql = "INSERT INTO tb_chats (REMETENTE,DESTINATARIO,DTA_CRIACAO,NOME_REMETENTE, NOME_DESTINATARIO) VALUES (:remetente, :destinatario, NOW(), :nome_remetente, :nome_destinatario )"; | ||
$stmt = $pdo->prepare($sql); | ||
$stmt->bindParam(':remetente', $remetente); | ||
$stmt->bindParam(':destinatario', $destinatario); | ||
$stmt->bindParam(':nome_remetente', $nome_remetente); | ||
$stmt->bindParam(':nome_destinatario', $nome_destinatario); | ||
$stmt->execute(); | ||
|
||
if ($stmt->rowCount() > 0) { | ||
header('Location: ../../pages/chats.php?ID_CHAT=' . $pdo->lastInsertId() . '&sucesso=Chat criado com sucesso'); | ||
} else { | ||
header('Location: ../../pages/listarPedidos.php?erro=Erro ao criar chat'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
session_start(); | ||
require_once "../conexao_bd.php"; | ||
|
||
// Verifica se a solicitação é do tipo POST | ||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
// Verifica se a mensagem foi recebida | ||
if (isset($_POST["mensagem"]) && isset($_POST["chat_id"])) { | ||
// Captura a mensagem e o chat_id enviados pelo cliente | ||
$mensagem = $_POST["mensagem"]; | ||
$chat_id = $_POST["chat_id"]; | ||
|
||
// Consulta SQL para buscar as informações do chat | ||
$sql = "SELECT REMETENTE, DESTINATARIO FROM tb_chats WHERE ID_CHAT = :chat_id"; | ||
$stmt = $pdo->prepare($sql); | ||
$stmt->bindParam(":chat_id", $chat_id); | ||
$stmt->execute(); | ||
$chat_info = $stmt->fetch(PDO::FETCH_ASSOC); | ||
|
||
// Verifica se o usuário atual é o remetente da conversa | ||
if ($chat_info['REMETENTE'] == $_SESSION['id_cliente']) { | ||
// Insere a mensagem no banco de dados mantendo o destinatário atual | ||
$sql_insert = "INSERT INTO tb_mensagens (REMETENTE, DESTINATARIO, MENSAGEM, DTA_ENVIO, CHAT_ID) VALUES (:remetente, :destinatario, :mensagem, NOW(), :chat_id)"; | ||
$stmt_insert = $pdo->prepare($sql_insert); | ||
$stmt_insert->bindParam(":remetente", $_SESSION['id_cliente']); | ||
$stmt_insert->bindParam(":destinatario", $chat_info['DESTINATARIO']); | ||
$stmt_insert->bindParam(":mensagem", $mensagem); | ||
$stmt_insert->bindParam(":chat_id", $chat_id); | ||
$stmt_insert->execute(); | ||
|
||
if ($stmt_insert->rowCount() > 0) { | ||
echo "✓ Mensagem enviada com sucesso!"; | ||
} else { | ||
echo "✘ Erro: Mensagem não enviada"; | ||
} | ||
} else { | ||
// Atualiza os registros na tabela tb_chats para trocar os papéis de remetente e destinatário | ||
$novo_remetente = $chat_info['DESTINATARIO']; | ||
$novo_destinatario = $chat_info['REMETENTE']; | ||
$sql_update = "UPDATE tb_chats SET REMETENTE = :novo_remetente, DESTINATARIO = :novo_destinatario WHERE ID_CHAT = :chat_id"; | ||
$stmt_update = $pdo->prepare($sql_update); | ||
$stmt_update->bindParam(":novo_remetente", $novo_remetente); | ||
$stmt_update->bindParam(":novo_destinatario", $novo_destinatario); | ||
$stmt_update->bindParam(":chat_id", $chat_id); | ||
$stmt_update->execute(); | ||
|
||
// Insere a mensagem no banco de dados com o novo destinatário | ||
$sql_insert = "INSERT INTO tb_mensagens (REMETENTE, DESTINATARIO, MENSAGEM, DTA_ENVIO, CHAT_ID) VALUES (:remetente, :destinatario, :mensagem, NOW(), :chat_id)"; | ||
$stmt_insert = $pdo->prepare($sql_insert); | ||
$stmt_insert->bindParam(":remetente", $_SESSION['id_cliente']); | ||
$stmt_insert->bindParam(":destinatario", $novo_destinatario); | ||
$stmt_insert->bindParam(":mensagem", $mensagem); | ||
$stmt_insert->bindParam(":chat_id", $chat_id); | ||
$stmt_insert->execute(); | ||
|
||
if ($stmt_insert->rowCount() > 0) { | ||
echo "✓ Mensagem enviada com sucesso!"; | ||
} else { | ||
echo "✘ Erro: Mensagem não enviada"; | ||
} | ||
} | ||
} else { | ||
// Se a mensagem ou chat_id não foram recebidos, retorna uma mensagem de erro | ||
echo "Erro: Mensagem ou ID do chat não recebidos"; | ||
} | ||
} else { | ||
|
||
echo "Erro: Método não suportado"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
$host = 'localhost'; | ||
$dbname = 'zippybd'; | ||
$username = 'root'; | ||
$password = ''; | ||
|
||
try { | ||
$dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4"; | ||
$options = [ | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | ||
PDO::ATTR_EMULATE_PREPARES => false, | ||
]; | ||
|
||
$pdo = new PDO($dsn, $username, $password, $options); | ||
|
||
|
||
} catch (PDOException $e) { | ||
echo "Connection failed: " . $e->getMessage(); | ||
} |
Oops, something went wrong.