One Hat Cyber Team
Your IP :
216.73.216.36
Server IP :
162.240.179.46
Server :
Linux vps-14493116.nutrivittasaude.com.br 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
Server Software :
Apache
PHP Version :
8.2.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
lifeprimeti
/
meta.lifeprimeti.com.br
/
site
/
View File Name :
agendar_salvar.php
<?php require_once __DIR__ . '/../config/database.php'; $empresaId = (int)($_POST['empresa_id'] ?? 0); $servicoId = (int)($_POST['servico_id'] ?? 0); $profissionalId = (int)($_POST['profissional_id'] ?? 0); $data = $_POST['data'] ?? ''; $hora = $_POST['hora'] ?? ''; $nome = trim($_SESSION['usuario_nome'] ?? ''); $email = trim($_SESSION['usuario_email'] ?? ''); $telefone = trim($_SESSION['usuario_telefone'] ?? ''); $hashLink = trim($_POST['hash_link'] ?? ''); $userId = (int)($_SESSION['usuario_id'] ?? 0); if (!$empresaId || !$servicoId || !$profissionalId || !$data || !$hora) { $_SESSION['site_msg'] = 'Preencha todos os campos obrigatorios.'; redirect(URL_BASE . 'site/index.php' . ($hashLink ? '?hash=' . $hashLink : '')); } $hoje = date('Y-m-d'); if ($data < $hoje) { $_SESSION['site_msg'] = 'Nao e permitido agendar em datas passadas.'; redirect(URL_BASE . 'site/index.php' . ($hashLink ? '?hash=' . $hashLink : '')); } if ($data === $hoje && $hora <= date('H:i')) { $_SESSION['site_msg'] = 'Nao e permitido agendar em horarios passados.'; redirect(URL_BASE . 'site/index.php' . ($hashLink ? '?hash=' . $hashLink : '')); } try { $clienteId = $userId; if ($hashLink) { $stmt = $pdo->prepare("SELECT id FROM usuarios WHERE hash_link = ? AND empresa_id = ? AND ativo = 1"); $stmt->execute([$hashLink, $empresaId]); $cliente = $stmt->fetch(); $clienteId = $cliente ? (int)$cliente['id'] : null; } if (!$clienteId && $email) { $check = $pdo->prepare("SELECT id FROM usuarios WHERE email = ? AND empresa_id = ?"); $check->execute([$email, $empresaId]); $exist = $check->fetch(); if ($exist) { $clienteId = (int)$exist['id']; } else { $senha = password_hash(gerarSenha(8), PASSWORD_DEFAULT); $hash = gerarHash(16); $pdo->prepare("INSERT INTO usuarios (empresa_id, nome, email, telefone, senha, tipo, hash_link) VALUES (?,?,?,?,?,'cliente',?)") ->execute([$empresaId, $nome, $email, $telefone, $senha, $hash]); $clienteId = (int)$pdo->lastInsertId(); } } if (!$clienteId) { $_SESSION['site_msg'] = 'Identifique-se antes de agendar.'; redirect(URL_BASE . 'login.php'); } $serv = $pdo->prepare("SELECT duracao, preco, comissao_tipo, comissao_valor FROM servicos WHERE id = ? AND empresa_id = ?"); $serv->execute([$servicoId, $empresaId]); $sData = $serv->fetch(); if (!$sData) { $_SESSION['site_msg'] = 'Servico nao encontrado.'; redirect(URL_BASE . 'site/index.php'); } $duracao = (int)$sData['duracao']; $precoServico = (float)$sData['preco']; $horaFim = calcularHoraFim($hora, $duracao); $checkAg = $pdo->prepare("SELECT id FROM agendamentos WHERE profissional_id=? AND data=? AND hora=? AND status NOT IN ('cancelado')"); $checkAg->execute([$profissionalId, $data, $hora]); if ($checkAg->fetch()) { $_SESSION['site_msg'] = 'Este horario ja esta agendado. Escolha outro.'; redirect(URL_BASE . 'site/index.php' . ($hashLink ? '?hash=' . $hashLink : '')); } $comissaoInfo = getComissaoServico($servicoId, $profissionalId); if (!$comissaoInfo) $comissaoInfo = $sData; $comissaoValor = calcComissao($precoServico, $comissaoInfo['comissao_tipo'], $comissaoInfo['comissao_valor']); $repasseProf = $precoServico - $comissaoValor; $config = $pdo->prepare("SELECT opcao_pagar, gateway_padrao FROM configuracoes WHERE empresa_id = ?"); $config->execute([$empresaId]); $configData = $config->fetch(); $exigePagamento = $configData['opcao_pagar'] ?? 'nao'; $gateway = $configData['gateway_padrao'] ?? 'nenhum'; $pagamentoStatus = 'pendente'; $agStatus = 'pendente'; $pagTipo = 'gratis'; if ($exigePagamento === 'sim' && $gateway !== 'nenhum') { $pagTipo = $gateway; } elseif ($exigePagamento === 'nao') { $pagamentoStatus = 'aprovado'; $agStatus = 'confirmado'; $pagTipo = 'gratis'; } $pdo->beginTransaction(); $pdo->prepare("INSERT INTO agendamentos (empresa_id, cliente_id, profissional_id, servico_id, data, hora, hora_fim, status, pagamento_tipo, pagamento_status, confirmado_cliente) VALUES (?,?,?,?,?,?,?,?,?,?,1)") ->execute([$empresaId, $clienteId, $profissionalId, $servicoId, $data, $hora, $horaFim, $agStatus, $pagTipo, $pagamentoStatus]); $agId = $pdo->lastInsertId(); $pdo->prepare("INSERT INTO contas_receber (empresa_id, agendamento_id, cliente_id, profissional_id, servico_id, valor_total, comissao_valor, repasse_profissional, data_vencimento, status) VALUES (?,?,?,?,?,?,?,?,?,?)") ->execute([$empresaId, $agId, $clienteId, $profissionalId, $servicoId, $precoServico, $comissaoValor, $repasseProf, $data, $pagamentoStatus === 'aprovado' ? 'pago' : 'pendente']); enviarConfirmacaoAgendamento($pdo, $agId, $empresaId); $pdo->commit(); $msg = 'Agendamento realizado com sucesso!'; if ($pagTipo === 'gratis') { $msg .= ' Seu horario foi confirmado.'; } else { $msg .= ' Aguarde a confirmacao do pagamento.'; } $_SESSION['site_msg'] = $msg; } catch (Exception $e) { $pdo->rollBack(); $_SESSION['site_msg'] = 'Erro ao agendar: ' . $e->getMessage(); } redirect(URL_BASE . 'site/index.php' . ($hashLink ? '?hash=' . $hashLink : ''));