diff --git a/api/lab/get_firma_usuario.php b/api/lab/get_firma_usuario.php new file mode 100644 index 0000000..10f7a51 --- /dev/null +++ b/api/lab/get_firma_usuario.php @@ -0,0 +1,16 @@ +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]); diff --git a/api/lab/get_lab_users.php b/api/lab/get_lab_users.php index 8d41b51..150c2d1 100644 --- a/api/lab/get_lab_users.php +++ b/api/lab/get_lab_users.php @@ -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'; } diff --git a/api/lab/save_firma_usuario.php b/api/lab/save_firma_usuario.php new file mode 100644 index 0000000..9488f61 --- /dev/null +++ b/api/lab/save_firma_usuario.php @@ -0,0 +1,28 @@ +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.']); diff --git a/lab_usuarios.php b/lab_usuarios.php index b5be092..86dfcf4 100644 --- a/lab_usuarios.php +++ b/lab_usuarios.php @@ -210,6 +210,56 @@ require_once __DIR__ . '/shared/components/sidebar.php'; + +
+ @@ -460,6 +510,11 @@ const usuarios = {