feat(usuarios): gestión de firma por profesional desde perfil de usuario
Botón firma en tabla de usuarios (verde si ya tiene, gris si no). Modal con canvas para dibujar o subir imagen, vista previa de firma actual y opción de eliminar. APIs get/save_firma_usuario.php para admins. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
bad3d42a92
commit
233144c017
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* GET ?user_id=X — Devuelve la firma_svg de un usuario (solo admins).
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireAdmin();
|
||||
|
||||
$userId = (int)($_GET['user_id'] ?? 0);
|
||||
if ($userId <= 0) jsonError('user_id requerido.');
|
||||
|
||||
$db = Database::getInstance()->getConnection();
|
||||
$row = $db->prepare("SELECT firma_svg FROM admin_users WHERE id = ? LIMIT 1");
|
||||
$row->execute([$userId]);
|
||||
$data = $row->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
jsonOk(['firma_svg' => $data['firma_svg'] ?? null]);
|
||||
@@ -21,6 +21,7 @@ $users = $db->fetchAll("
|
||||
u.enfermera_id,
|
||||
u.last_login,
|
||||
u.created_at,
|
||||
(u.firma_svg IS NOT NULL) AS tiene_firma,
|
||||
r.name AS role_name,
|
||||
r.color AS role_color,
|
||||
r.slug AS role_slug,
|
||||
@@ -33,6 +34,7 @@ $users = $db->fetchAll("
|
||||
|
||||
foreach ($users as &$u) {
|
||||
$u['is_active'] = (bool)$u['is_active'];
|
||||
$u['tiene_firma'] = (bool)$u['tiene_firma'];
|
||||
$u['role_name'] = $u['role_name'] ?? ucfirst($u['role'] ?? 'admin');
|
||||
$u['role_color'] = $u['role_color'] ?? '#0d6efd';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* POST — Admin guarda/borra la firma pre-configurada de cualquier usuario.
|
||||
* Body JSON: { user_id: 5, firma_svg: "data:image/png;base64,..." }
|
||||
* { user_id: 5, _borrar: true }
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireAdmin();
|
||||
|
||||
$body = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$userId = (int)($body['user_id'] ?? 0);
|
||||
if ($userId <= 0) jsonError('user_id requerido.');
|
||||
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
if (!empty($body['_borrar'])) {
|
||||
$db->prepare("UPDATE admin_users SET firma_svg = NULL WHERE id = ?")->execute([$userId]);
|
||||
jsonOk(['mensaje' => 'Firma eliminada.']);
|
||||
}
|
||||
|
||||
$svg = $body['firma_svg'] ?? '';
|
||||
if (strlen($svg) < 100) jsonError('Firma requerida.');
|
||||
if (!preg_match('/^data:image\/(svg\+xml|png|jpeg|webp);base64,/i', $svg)) {
|
||||
jsonError('Formato de firma no válido.');
|
||||
}
|
||||
|
||||
$db->prepare("UPDATE admin_users SET firma_svg = ? WHERE id = ?")->execute([$svg, $userId]);
|
||||
jsonOk(['mensaje' => 'Firma guardada correctamente.']);
|
||||
Reference in New Issue
Block a user