Ajustes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
<?php include __DIR__ . '/../partials/sidebar_sistemas.php'; ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
@@ -6,137 +8,123 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
<!-- 📄 CONTENIDO -->
|
||||
<div class="content px-4">
|
||||
<h3 class="mb-4">Administración de Usuarios</h3>
|
||||
|
||||
include __DIR__ . '/../partials/sidebar_sistemas.php';
|
||||
?>
|
||||
<!-- FORMULARIO -->
|
||||
<form action="/IMPORTADORES/sistemas/guardar_usuario" method="POST" class="card p-4 mb-5 shadow-sm">
|
||||
<h5 class="mb-3">➕ Nuevo Usuario</h5>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<input name="nombre" class="form-control" placeholder="Nombre completo" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<input name="email" type="email" class="form-control" placeholder="Correo electrónico" required>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<input name="password" type="password" class="form-control" placeholder="Contraseña" required>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="tipo_usuario" class="form-select" required>
|
||||
<option value="">Tipo</option>
|
||||
<option value="agente_aduanal">Agente Aduanal</option>
|
||||
<option value="importador">Importador</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end mt-4">
|
||||
<button class="btn btn-success px-4">Registrar</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- 📄 CONTENIDO -->
|
||||
<div class="content px-4">
|
||||
<h3 class="mb-4">Administración de Usuarios</h3>
|
||||
|
||||
<!-- FORMULARIO -->
|
||||
<form action="/IMPORTADORES/sistemas/guardar_usuario" method="POST" class="card p-4 mb-5 shadow-sm">
|
||||
<h5 class="mb-3">➕ Nuevo Usuario</h5>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<input name="nombre" class="form-control" placeholder="Nombre completo" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<input name="email" type="email" class="form-control" placeholder="Correo electrónico" required>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<input name="password" type="password" class="form-control" placeholder="Contraseña" required>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="tipo_usuario" class="form-select" required>
|
||||
<option value="">Tipo</option>
|
||||
<option value="agente_aduanal">Agente Aduanal</option>
|
||||
<option value="importador">Importador</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end mt-4">
|
||||
<button class="btn btn-success px-4">Registrar</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- TABLA DE USUARIOS -->
|
||||
<div class="card p-4 shadow-sm">
|
||||
<h5 class="mb-3">👁️ Usuarios Registrados</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Nombre</th>
|
||||
<th>Correo</th>
|
||||
<th>Tipo</th>
|
||||
<th>Estado</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($usuarios)): ?>
|
||||
<?php foreach ($usuarios as $u): ?>
|
||||
<!-- TABLA DE USUARIOS -->
|
||||
<div class="card p-4 shadow-sm">
|
||||
<h5 class="mb-3">👁️ Usuarios Registrados</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><?= $u['id_usuario'] ?></td>
|
||||
<td><?= decrypt($u['nombre']) ?></td>
|
||||
<td><?= decrypt($u['email']) ?></td>
|
||||
<td><?= ucfirst($u['tipo_usuario']) ?></td>
|
||||
<td>
|
||||
<span class="badge <?= $u['activo'] ? 'bg-success' : 'bg-danger' ?>">
|
||||
<?= $u['activo'] ? 'Activo' : 'Inactivo' ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/IMPORTADORES/sistemas/toggle_estado?id=<?= $u['id_usuario'] ?>" class="btn btn-sm btn-warning">Toggle</a>
|
||||
<a href="/IMPORTADORES/sistemas/reset_password?id=<?= $u['id_usuario'] ?>" class="btn btn-sm btn-secondary">Reset</a>
|
||||
</td>
|
||||
<th>#</th>
|
||||
<th>Nombre</th>
|
||||
<th>Correo</th>
|
||||
<th>Tipo</th>
|
||||
<th>Estado</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">No hay usuarios registrados aún.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($usuarios)): ?>
|
||||
<?php foreach ($usuarios as $u): ?>
|
||||
<tr>
|
||||
<td><?= $u['id_usuario'] ?></td>
|
||||
<td><?= decrypt($u['nombre']) ?></td>
|
||||
<td><?= decrypt($u['email']) ?></td>
|
||||
<td><?= ucfirst($u['tipo_usuario']) ?></td>
|
||||
<td>
|
||||
<span class="badge <?= $u['activo'] ? 'bg-success' : 'bg-danger' ?>">
|
||||
<?= $u['activo'] ? 'Activo' : 'Inactivo' ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/IMPORTADORES/sistemas/toggle_estado?id=<?= $u['id_usuario'] ?>" class="btn btn-sm btn-warning">Toggle</a>
|
||||
<a href="/IMPORTADORES/sistemas/reset_password?id=<?= $u['id_usuario'] ?>" class="btn btn-sm btn-secondary">Reset</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">No hay usuarios registrados aún.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<?php if (isset($_GET['reset'], $_GET['pass'], $_GET['email']) && $_GET['reset'] === 'ok'): ?>
|
||||
<script>
|
||||
const nuevaPassword = "<?= htmlspecialchars($_GET["pass"]) ?>";
|
||||
const emailUsuario = "<?= htmlspecialchars($_GET["email"]) ?>";
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<?php if (isset($_GET['reset'], $_GET['pass'], $_GET['email']) && $_GET['reset'] === 'ok'): ?>
|
||||
<script>
|
||||
const nuevaPassword = "<?= htmlspecialchars($_GET["pass"]) ?>";
|
||||
const emailUsuario = "<?= htmlspecialchars($_GET["email"]) ?>";
|
||||
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Contraseña restablecida',
|
||||
html: `
|
||||
Nueva contraseña generada:<br>
|
||||
<strong style="font-size:18px;">${nuevaPassword}</strong>
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-outline-primary btn-sm" onclick="copiarPassword()">📋 Copiar</button>
|
||||
<button class="btn btn-outline-success btn-sm" onclick="enviarPorCorreo()">📧 Enviar por correo</button>
|
||||
</div>
|
||||
`,
|
||||
showConfirmButton: false,
|
||||
});
|
||||
|
||||
function copiarPassword() {
|
||||
navigator.clipboard.writeText(nuevaPassword).then(() => {
|
||||
Swal.fire('Copiado', 'La contraseña fue copiada al portapapeles.', 'success');
|
||||
});
|
||||
}
|
||||
|
||||
function enviarPorCorreo() {
|
||||
fetch(`/IMPORTADORES/sistemas/enviar_password?email=${encodeURIComponent(emailUsuario)}&pass=${encodeURIComponent(nuevaPassword)}`)
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
Swal.fire('Enviado', 'La contraseña fue enviada al correo del usuario.', 'success');
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Error', 'No se pudo enviar el correo.', 'error');
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Contraseña restablecida',
|
||||
html: `
|
||||
Nueva contraseña generada:<br>
|
||||
<strong style="font-size:18px;">${nuevaPassword}</strong>
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-outline-primary btn-sm" onclick="copiarPassword()">📋 Copiar</button>
|
||||
<button class="btn btn-outline-success btn-sm" onclick="enviarPorCorreo()">📧 Enviar por correo</button>
|
||||
</div>
|
||||
`,
|
||||
showConfirmButton: false,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
function copiarPassword() {
|
||||
navigator.clipboard.writeText(nuevaPassword).then(() => {
|
||||
Swal.fire('Copiado', 'La contraseña fue copiada al portapapeles.', 'success');
|
||||
});
|
||||
}
|
||||
|
||||
function enviarPorCorreo() {
|
||||
fetch(`/IMPORTADORES/sistemas/enviar_password?email=${encodeURIComponent(emailUsuario)}&pass=${encodeURIComponent(nuevaPassword)}`)
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
Swal.fire('Enviado', 'La contraseña fue enviada al correo del usuario.', 'success');
|
||||
})
|
||||
.catch(() => {
|
||||
Swal.fire('Error', 'No se pudo enviar el correo.', 'error');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Reference in New Issue
Block a user