55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require '../includes/config.php';
|
|
|
|
if (!is_logged_in()) {
|
|
http_response_code(401);
|
|
echo json_encode(['error' => 'No autenticado']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$profesorId = $_GET['profesor_id'] ?? null;
|
|
|
|
$query = "
|
|
SELECT
|
|
d.codigo_unico,
|
|
d.fecha_emision,
|
|
a.nombre AS alumno_nombre,
|
|
a.email AS alumno_email,
|
|
c.nombre AS curso_nombre,
|
|
c.tipo AS curso_tipo
|
|
FROM diplomas d
|
|
JOIN alumnos_cursos ac ON d.alumno_curso_id = ac.id
|
|
JOIN alumnos a ON ac.alumno_id = a.id
|
|
JOIN cursos c ON ac.curso_id = c.id
|
|
";
|
|
|
|
$params = [];
|
|
if ($profesorId) {
|
|
$query .= " WHERE c.profesor_id = ?";
|
|
$params[] = $profesorId;
|
|
}
|
|
|
|
$query .= " ORDER BY d.fecha_emision DESC";
|
|
|
|
$stmt = $pdo->prepare($query);
|
|
$stmt->execute($params);
|
|
|
|
$diplomas = [];
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$row['fecha_formateada'] = date("d/m/Y", strtotime($row['fecha_emision']));
|
|
$diplomas[] = $row;
|
|
}
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'data' => $diplomas,
|
|
'count' => count($diplomas)
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|