Files
ferramentas/clientes/client_details.php
T
rodrigo a1beb6a2e0 Primeiro commit
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
2025-01-01 21:15:15 -03:00

222 lines
11 KiB
PHP

<?php
// Verificar se o usuário está logado
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Detalhes do Cliente</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="../script/formatacoes.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.note-actions {
display: inline-block;
margin-left: 10px;
}
.note-actions i {
cursor: pointer;
margin-right: 5px;
}
</style>
</head>
<body>
<div class="container">
<?php
// Conectar ao banco de dados
$mysqli = new mysqli("10.15.0.42", "root", "34641747", "valida");
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
if (isset($_GET['id'])) {
$client_id = $_GET['id'];
$result = $mysqli->query("SELECT * FROM clients WHERE id = $client_id");
if ($result->num_rows > 0) {
$client = $result->fetch_assoc();
echo "<h2>Detalhes do Cliente: " . htmlspecialchars($client['name'] ?? '') . "</h2>";
echo "<a href='index.php?page=edit_client&id=$client_id'><button>Editar Cliente</button></a>";
echo "";
echo "<div class='client-details'>";
if (!empty($client['cpf'])) {
echo "<div class='client-info'><strong>CPF:</strong> <span id='numero-cpf'>" . htmlspecialchars($client['cpf'] ?? '') . "</span></div>"; // Adicione id="numero-cpf"
}
if (!empty($client['rg'])) {
echo "<div class='client-info'><strong>RG:</strong> " . htmlspecialchars($client['rg'] ?? '') . " (" . htmlspecialchars($client['rg_emissor'] ?? '') . ")</div>";
}
if (!empty($client['sexo'])) {
echo "<div class='client-info'><strong>Sexo:</strong> " . htmlspecialchars($client['sexo'] ?? '') . "</div>";
}
if (!empty($client['estado_civil'])) {
echo "<div class='client-info'><strong>Estado Civil:</strong> " . htmlspecialchars($client['estado_civil'] ?? '') . "</div>";
}
if (!empty($client['phone'])) {
echo "<div class='client-info'><strong>Telefone:</strong> <span id='numero-telefone'>" . htmlspecialchars($client['phone'] ?? '') . ($client['whatsapp'] ? " (WhatsApp)" : "") . "</span></div>"; // Adicione id="numero-telefone"
}
if (!empty($client['email'])) {
echo "<div class='client-info'><strong>Email:</strong> " . htmlspecialchars($client['email'] ?? '') . "</div>";
}
if (!empty($client['senha_meu_inss'])) {
echo "<div class='client-info'><strong>Senha do Meu INSS:</strong> " . htmlspecialchars($client['senha_meu_inss'] ?? '') . "</div>";
}
if (!empty($client['perfil_instagram'])) {
echo "<div class='client-info'><strong>Perfil do Instagram:</strong> @" . htmlspecialchars($client['perfil_instagram'] ?? '') . "</div>";
}
if (!empty($client['tipo_logradouro']) || !empty($client['endereco']) || !empty($client['bairro']) || !empty($client['cidade']) || !empty($client['estado']) || !empty($client['cep'])) {
echo "<div class='client-info'><strong>Endereço:</strong> " . htmlspecialchars($client['tipo_logradouro'] ?? '') . " " . htmlspecialchars($client['endereco'] ?? '') . ", " . htmlspecialchars($client['bairro'] ?? '') . ", " . htmlspecialchars($client['cidade'] ?? '') . " - " . htmlspecialchars($client['estado'] ?? '') . ", " . htmlspecialchars($client['cep'] ?? '') . "</div>";
}
if (!empty($client['certidao_nascimento'])) {
echo "<div class='client-info'><strong>Certidão de Nascimento/Casamento:</strong> " . htmlspecialchars($client['certidao_nascimento'] ?? '') . "</div>";
}
if (!empty($client['pis_pasep'])) {
echo "<div class='client-info'><strong>PIS/PASEP:</strong> " . htmlspecialchars($client['pis_pasep'] ?? '') . "</div>";
}
if (!empty($client['inss_beneficio'])) {
echo "<div class='client-info'><strong>Número do Benefício INSS:</strong> " . htmlspecialchars($client['inss_beneficio'] ?? '') . "</div>";
}
if (!empty($client['filiacao_pai'])) {
echo "<div class='client-info'><strong>Filiação (Pai):</strong> " . htmlspecialchars($client['filiacao_pai'] ?? '') . "</div>";
}
if (!empty($client['filiacao_mae'])) {
echo "<div class='client-info'><strong>Filiação (Mãe):</strong> " . htmlspecialchars($client['filiacao_mae'] ?? '') . "</div>";
}
echo "</div>";
// Abas
echo "<div class='tabs'>
<button class='tab-button' onclick='showTab(\"notes\")'>Notas</button>
<button class='tab-button' onclick='showTab(\"documents\")'>Documentos de Texto</button>
<button class='tab-button' onclick='showTab(\"files\")'>Arquivos</button>
<button class='tab-button' onclick='showTab(\"processes\")'>Processos</button>
</div>";
// Conteúdo das abas
echo "<div id='notes' class='tab-content'>";
echo "<h3>Notas</h3>";
// Formulário de nova nota
echo "<form id='new-note-form' action='index.php?page=client_details&id=$client_id' method='post'>
<textarea name='note' placeholder='Digite uma nova nota'></textarea>
<button type='submit'>Adicionar Nota</button>
</form>";
// Inserir nova nota no banco de dados
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['note'])) {
$note = $_POST['note'];
$stmt = $mysqli->prepare("INSERT INTO notes (client_id, note) VALUES (?, ?)");
$stmt->bind_param("is", $client_id, $note);
$stmt->execute();
$stmt->close();
}
// Listar notas
$notes_result = $mysqli->query("SELECT * FROM notes WHERE client_id = $client_id");
if ($notes_result->num_rows > 0) {
while ($note = $notes_result->fetch_assoc()) {
echo "<div class='note' id='note-" . $note['id'] . "'>";
echo "<p>" . htmlspecialchars($note['note'] ?? '') . " <small>(" . $note['created_at'] . ")</small></p>";
echo "<div class='note-actions'>";
echo "<i class='fas fa-edit edit-note' data-note-id='" . $note['id'] . "' title='Editar nota'></i>";
echo "<i class='fas fa-trash delete-note' data-note-id='" . $note['id'] . "' title='Excluir nota'></i>";
echo "</div>";
echo "</div>";
}
} else {
echo "<p>Sem notas.</p>";
}
echo "</div>";
echo "<div id='documents' class='tab-content' style='display:none;'>
<h3>Documentos de Texto</h3>
<p>Conteúdo da aba Documentos de Texto.</p>
</div>";
echo "<div id='files' class='tab-content' style='display:none;'>
<h3>Arquivos</h3>
<p>Conteúdo da aba Arquivos.</p>
</div>";
echo "<div id='processes' class='tab-content' style='display:none;'>
<h3>Processos</h3>
<p>Conteúdo da aba Processos.</p>
</div>";
} else {
echo "<p>Cliente não encontrado.</p>";
}
} else {
echo "<p>ID do cliente não fornecido.</p>";
}
$mysqli->close();
?>
</div>
<script>
$(document).ready(function() {
var telefone = "<?php echo $client['phone']; ?>";
if (telefone) {
$("#numero-telefone").text(formatarTelefone(telefone)); // Usando .text() para substituir o conteúdo
}
var cpf = "<?php echo $client['cpf']; ?>";
if (cpf) {
$("#numero-cpf").text(formatarCPF(cpf)); // Formata o CPF
}
// Editar nota
$(document).on('click', '.edit-note', function() {
var noteId = $(this).data('note-id');
var noteContent = $(this).closest('.note').find('p').text();
var editForm = `
<form class="edit-note-form" data-note-id="${noteId}">
<textarea name="note">${noteContent}</textarea>
<button type="submit">Salvar</button>
<button type="button" class="cancel-edit">Cancelar</button>
</form>
`;
$(this).closest('.note').html(editForm);
});
// Cancelar edição de nota
$(document).on('click', '.cancel-edit', function() {
location.reload();
});
// Salvar edição de nota
$(document).on('submit', '.edit-note-form', function(e) {
e.preventDefault();
var noteId = $(this).data('note-id');
var noteContent = $(this).find('textarea[name="note"]').val();
$.post('index.php?page=edit_note', { id: noteId, note: noteContent }, function(response) {
location.reload();
});
});
// Excluir nota
$(document).on('click', '.delete-note', function() {
if (confirm('Tem certeza que deseja excluir esta nota?')) {
var noteId = $(this).data('note-id');
$.post('index.php?page=delete_note', { id: noteId }, function(response) {
location.reload();
});
}
});
});
function showTab(tabId) {
var tabs = document.getElementsByClassName('tab-content');
for (var i = 0; i < tabs.length; i++) {
tabs[i].style.display = 'none';
}
document.getElementById(tabId).style.display = 'block';
}
</script>
</body>
</html>