57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
|
// Obtener usuario autenticado
|
|
$user = $_SERVER['REMOTE_USER'] ?? '';
|
|
if (empty($user)) {
|
|
http_response_code(401);
|
|
exit("# Error\n\nNo autenticado.");
|
|
}
|
|
|
|
// Leer markdown
|
|
$file = __DIR__ . '/data/tabla-de-seguimiento.md';
|
|
if (!file_exists($file)) {
|
|
http_response_code(404);
|
|
exit("# Dashboard sin Datos\n\nEl profesor aún no ha subido la tabla.");
|
|
}
|
|
|
|
$markdown = file_get_contents($file);
|
|
$lines = explode("\n", $markdown);
|
|
|
|
// Filtrar solo sección del usuario
|
|
$output = [];
|
|
$inUserSection = false;
|
|
$headerShown = false;
|
|
|
|
foreach ($lines as $line) {
|
|
// Título principal
|
|
if (!$headerShown && preg_match('/^# /', $line)) {
|
|
$output[] = $line;
|
|
$headerShown = true;
|
|
continue;
|
|
}
|
|
|
|
// Detectar sección ## username
|
|
if (preg_match('/^## (.+)$/', $line, $matches)) {
|
|
$sectionUser = trim($matches[1]);
|
|
$inUserSection = ($sectionUser === $user);
|
|
if ($inUserSection) {
|
|
$output[] = $line;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
// Si estamos en sección del usuario, capturar
|
|
if ($inUserSection) {
|
|
$output[] = $line;
|
|
}
|
|
}
|
|
|
|
// Si no hay datos para el usuario
|
|
if (count($output) <= 1) {
|
|
$output[] = "\n## $user\n";
|
|
$output[] = "**No hay datos registrados.**\n";
|
|
}
|
|
|
|
echo implode("\n", $output);
|